Remove Serialize/Deserialize functions never used in StandardCalculatorViewModel, UnitConverter, UnitConverterViewModel and CalculatorManager (#392)
* remove unused serializer * remove all unused serialization/deserialization from StandardCalculatorViewModel and UnitConverterViewModel * formatting
This commit is contained in:
@@ -1163,110 +1163,6 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
|
||||
}
|
||||
}
|
||||
|
||||
Array<unsigned char> ^ StandardCalculatorViewModel::Serialize()
|
||||
{
|
||||
DataWriter ^ writer = ref new DataWriter();
|
||||
writer->WriteUInt32(static_cast<UINT32>(m_CurrentAngleType));
|
||||
writer->WriteBoolean(IsFToEChecked);
|
||||
writer->WriteBoolean(IsCurrentViewPinned);
|
||||
writer->WriteUInt32(static_cast<UINT32>(m_standardCalculatorManager.SerializeSavedDegreeMode()));
|
||||
|
||||
// Serialize Memory
|
||||
vector<long> serializedMemory;
|
||||
serializedMemory = m_standardCalculatorManager.GetSerializedMemory();
|
||||
size_t lengthOfSerializedMemory = serializedMemory.size();
|
||||
writer->WriteUInt32(static_cast<UINT32>(lengthOfSerializedMemory));
|
||||
for (auto data : serializedMemory)
|
||||
{
|
||||
writer->WriteInt32(data);
|
||||
}
|
||||
|
||||
// Serialize Primary Display
|
||||
vector<long> serializedPrimaryDisplay = m_standardCalculatorManager.GetSerializedPrimaryDisplay();
|
||||
writer->WriteUInt32(static_cast<UINT32>(serializedPrimaryDisplay.size()));
|
||||
for (auto data : serializedPrimaryDisplay)
|
||||
{
|
||||
writer->WriteInt32(data);
|
||||
}
|
||||
|
||||
// For ProgrammerMode
|
||||
writer->WriteUInt32(static_cast<UINT32>(CurrentRadixType));
|
||||
|
||||
// Serialize commands of calculator manager
|
||||
vector<unsigned char> serializedCommand = m_standardCalculatorManager.SerializeCommands();
|
||||
writer->WriteUInt32(static_cast<UINT32>(serializedCommand.size()));
|
||||
writer->WriteBytes(ref new Array<unsigned char>(serializedCommand.data(), static_cast<unsigned int>(serializedCommand.size())));
|
||||
|
||||
if (IsInError)
|
||||
{
|
||||
Utils::SerializeCommandsAndTokens(m_tokens, m_commands, writer);
|
||||
}
|
||||
|
||||
// Convert viewmodel data in writer to bytes
|
||||
IBuffer ^ buffer = writer->DetachBuffer();
|
||||
DataReader ^ reader = DataReader::FromBuffer(buffer);
|
||||
Platform::Array<unsigned char> ^ viewModelDataAsBytes = ref new Array<unsigned char>(buffer->Length);
|
||||
reader->ReadBytes(viewModelDataAsBytes);
|
||||
|
||||
// Return byte array
|
||||
return viewModelDataAsBytes;
|
||||
}
|
||||
|
||||
void StandardCalculatorViewModel::Deserialize(Array<unsigned char> ^ state)
|
||||
{
|
||||
// Read byte array into a buffer
|
||||
DataWriter ^ writer = ref new DataWriter();
|
||||
writer->WriteBytes(state);
|
||||
IBuffer ^ buffer = writer->DetachBuffer();
|
||||
|
||||
// Read view model data
|
||||
if (buffer->Length != 0)
|
||||
{
|
||||
DataReader ^ reader = DataReader::FromBuffer(buffer);
|
||||
m_CurrentAngleType = ConvertIntegerToNumbersAndOperatorsEnum(reader->ReadUInt32());
|
||||
|
||||
IsFToEChecked = reader->ReadBoolean();
|
||||
IsCurrentViewPinned = reader->ReadBoolean();
|
||||
Command serializedDegreeMode = static_cast<Command>(reader->ReadUInt32());
|
||||
|
||||
m_standardCalculatorManager.SendCommand(serializedDegreeMode);
|
||||
|
||||
// Deserialize Memory
|
||||
UINT32 memoryDataLength = reader->ReadUInt32();
|
||||
vector<long> serializedMemory;
|
||||
for (unsigned int i = 0; i < memoryDataLength; i++)
|
||||
{
|
||||
serializedMemory.push_back(reader->ReadInt32());
|
||||
}
|
||||
m_standardCalculatorManager.DeSerializeMemory(serializedMemory);
|
||||
|
||||
// Serialize Primary Display
|
||||
UINT32 serializedPrimaryDisplayLength = reader->ReadUInt32();
|
||||
vector<long> serializedPrimaryDisplay;
|
||||
for (unsigned int i = 0; i < serializedPrimaryDisplayLength; i++)
|
||||
{
|
||||
serializedPrimaryDisplay.push_back(reader->ReadInt32());
|
||||
}
|
||||
m_standardCalculatorManager.DeSerializePrimaryDisplay(serializedPrimaryDisplay);
|
||||
|
||||
CurrentRadixType = reader->ReadUInt32();
|
||||
// Read command data and Deserialize
|
||||
UINT32 modeldatalength = reader->ReadUInt32();
|
||||
Array<unsigned char> ^ modelDataAsBytes = ref new Array<unsigned char>(modeldatalength);
|
||||
reader->ReadBytes(modelDataAsBytes);
|
||||
m_standardCalculatorManager.DeSerializeCommands(vector<unsigned char>(modelDataAsBytes->begin(), modelDataAsBytes->end()));
|
||||
|
||||
// After recalculation. If there is an error then
|
||||
// IsInError should be set synchronously.
|
||||
if (IsInError)
|
||||
{
|
||||
shared_ptr<CalculatorVector<shared_ptr<IExpressionCommand>>> commandVector = Utils::DeserializeCommands(reader);
|
||||
shared_ptr<CalculatorVector<pair<wstring, int>>> tokenVector = Utils::DeserializeTokens(reader);
|
||||
SetExpressionDisplay(tokenVector, commandVector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StandardCalculatorViewModel::OnPropertyChanged(String ^ propertyname)
|
||||
{
|
||||
if (propertyname == IsScientificPropertyName)
|
||||
|
@@ -348,8 +348,6 @@ namespace CalculatorApp
|
||||
void OnBinaryOperatorReceived();
|
||||
void OnMemoryItemChanged(unsigned int indexOfMemory);
|
||||
|
||||
Platform::Array<unsigned char> ^ Serialize();
|
||||
void Deserialize(Platform::Array<unsigned char> ^ state);
|
||||
|
||||
Platform::String ^ GetLocalizedStringFormat(Platform::String ^ format, Platform::String ^ displayValue);
|
||||
void OnPropertyChanged(Platform::String ^ propertyname);
|
||||
|
@@ -612,52 +612,6 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String ^ prop)
|
||||
}
|
||||
}
|
||||
|
||||
String ^ UnitConverterViewModel::Serialize()
|
||||
{
|
||||
wstringstream out(wstringstream::out);
|
||||
const wchar_t* delimiter = L"[;;;]";
|
||||
out << std::to_wstring(m_resettingTimer) << delimiter;
|
||||
out << std::to_wstring(static_cast<int>(m_value1cp)) << delimiter;
|
||||
out << m_Value1Active << delimiter << m_Value2Active << delimiter;
|
||||
out << m_Value1->Data() << delimiter << m_Value2->Data() << delimiter;
|
||||
out << m_valueFromUnlocalized << delimiter << m_valueToUnlocalized << delimiter << L"[###]";
|
||||
wstring unitConverterSerializedData = m_model->Serialize();
|
||||
|
||||
if (!unitConverterSerializedData.empty())
|
||||
{
|
||||
out << m_model->Serialize() << L"[###]";
|
||||
String ^ serializedData = ref new String(wstring(out.str()).c_str());
|
||||
return serializedData;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UnitConverterViewModel::Deserialize(Platform::String ^ state)
|
||||
{
|
||||
wstring serializedData = wstring(state->Data());
|
||||
vector<wstring> tokens = UCM::UnitConverter::StringToVector(serializedData, L"[###]");
|
||||
assert(tokens.size() >= 2);
|
||||
vector<wstring> viewModelData = UCM::UnitConverter::StringToVector(tokens[0], L"[;;;]");
|
||||
assert(viewModelData.size() == EXPECTEDVIEWMODELDATATOKENS);
|
||||
m_resettingTimer = (viewModelData[0].compare(L"1") == 0);
|
||||
m_value1cp = (ConversionParameter)_wtoi(viewModelData[1].c_str());
|
||||
m_Value1Active = (viewModelData[2].compare(L"1") == 0);
|
||||
m_Value2Active = (viewModelData[3].compare(L"1") == 0);
|
||||
m_Value1 = ref new String(viewModelData[4].c_str());
|
||||
m_Value2 = ref new String(viewModelData[5].c_str());
|
||||
m_valueFromUnlocalized = viewModelData[6];
|
||||
m_valueToUnlocalized = viewModelData[7];
|
||||
wstringstream modelData(wstringstream::out);
|
||||
for (unsigned int i = 1; i < tokens.size(); i++)
|
||||
{
|
||||
modelData << tokens[i] << L"[###]";
|
||||
}
|
||||
m_model->DeSerialize(modelData.str());
|
||||
InitializeView();
|
||||
RaisePropertyChanged(nullptr); // Update since all props have been updated.
|
||||
}
|
||||
|
||||
// Saving User Preferences of Category and Associated-Units across Sessions.
|
||||
void UnitConverterViewModel::SaveUserPreferences()
|
||||
{
|
||||
|
@@ -219,9 +219,6 @@ namespace CalculatorApp
|
||||
_In_ Platform::String ^ toUnit);
|
||||
void UpdateValue1AutomationName();
|
||||
void UpdateValue2AutomationName();
|
||||
Platform::String ^ Serialize();
|
||||
void Deserialize(Platform::String ^ state);
|
||||
void ResetCategoriesAndRatio();
|
||||
|
||||
// Saving And Restoring User Preferences of Category and Associated-Units across Sessions.
|
||||
void SaveUserPreferences();
|
||||
|
Reference in New Issue
Block a user