diff --git a/src/CalcManager/CalculatorManager.cpp b/src/CalcManager/CalculatorManager.cpp
index 569e0114..d054f5b1 100644
--- a/src/CalcManager/CalculatorManager.cpp
+++ b/src/CalcManager/CalculatorManager.cpp
@@ -244,8 +244,6 @@ namespace CalculationManager
{
m_savedCommands.push_back(MapCommandForSerialize(command));
}
- this->SerializePrimaryDisplay();
- this->SerializeMemory();
m_savedDegreeMode = m_currentDegreeMode;
return;
}
@@ -330,47 +328,6 @@ namespace CalculationManager
return commandToLoad;
}
- ///
- /// Return saved degree mode which is saved when last time the expression was cleared.
- ///
- Command CalculatorManager::SerializeSavedDegreeMode()
- {
- return m_savedDegreeMode;
- }
-
- void CalculatorManager::SerializePrimaryDisplay()
- {
- m_savedPrimaryValue.clear();
- m_currentCalculatorEngine->ProcessCommand(IDC_STORE);
- auto memoryObject = m_currentCalculatorEngine->PersistedMemObject();
- if (memoryObject != nullptr)
- {
- m_savedPrimaryValue = SerializeRational(*memoryObject);
- }
- }
-
- ///
- /// Return serialized primary display that is saved when the expression line was cleared.
- ///
- vector CalculatorManager::GetSerializedPrimaryDisplay()
- {
- return m_savedPrimaryValue;
- }
-
- ///
- /// DeSerialize the primary display from vector of long
- ///
- /// Serialized Rational of primary display
- void CalculatorManager::DeSerializePrimaryDisplay(const vector& serializedPrimaryDisplay)
- {
- if (serializedPrimaryDisplay.empty())
- {
- return;
- }
- m_persistedPrimaryValue = DeSerializeRational(serializedPrimaryDisplay.begin());
- this->LoadPersistedPrimaryValue();
- }
-
///
/// Load the persisted value that is saved in memory of CalcEngine
///
@@ -380,112 +337,6 @@ namespace CalculationManager
m_currentCalculatorEngine->ProcessCommand(IDC_RECALL);
}
- ///
- /// Serialize the Memory to vector of long
- ///
- /// Serialized Rational of memory
- void CalculatorManager::SerializeMemory()
- {
- m_serializedMemory.clear();
-
- for (auto const& memoryItem : m_memorizedNumbers)
- {
- auto serialMem = SerializeRational(memoryItem);
- m_serializedMemory.insert(m_serializedMemory.end(), serialMem.begin(), serialMem.end());
- }
- }
-
- vector CalculatorManager::GetSerializedMemory()
- {
- return m_serializedMemory;
- }
-
- ///
- /// DeSerialize the Memory from vector of long
- ///
- /// Serialized Rational of memory
- void CalculatorManager::DeSerializeMemory(const vector& serializedMemory)
- {
- vector::const_iterator itr = serializedMemory.begin();
- while (itr != serializedMemory.end())
- {
- Rational memoryItem = DeSerializeRational(itr);
- auto lengthMemoryItem = (2 * SERIALIZED_NUMBER_MINSIZE) + memoryItem.P().Mantissa().size() + memoryItem.Q().Mantissa().size();
- m_memorizedNumbers.push_back(memoryItem);
- itr += lengthMemoryItem;
- }
- this->SetMemorizedNumbersString();
- }
-
- ///
- /// Return the commands saved since the expression has been cleared.
- ///
- vector CalculatorManager::SerializeCommands()
- {
- return m_savedCommands;
- }
-
- ///
- /// Replay the serialized commands
- ///
- /// Serialized commands
- void CalculatorManager::DeSerializeCommands(_In_ const vector& serializedData)
- {
- m_savedCommands.clear();
-
- for (auto commandItr = serializedData.begin(); commandItr != serializedData.end(); ++commandItr)
- {
- if (*commandItr >= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizeNumber)
- && *commandItr <= MEMORY_COMMAND_TO_UNSIGNED_CHAR(MemoryCommand::MemorizedNumberClearAll))
- {
- // MemoryCommands(which have values above 255) are pushed on m_savedCommands upon casting to unsigned char.
- // SerializeCommands uses m_savedCommands, which is then used in DeSerializeCommands.
- // Hence, a simple cast to MemoryCommand is not sufficient.
- MemoryCommand memoryCommand = static_cast(*commandItr + UCHAR_MAX + 1);
- unsigned int indexOfMemory = 0;
- switch (memoryCommand)
- {
- case MemoryCommand::MemorizeNumber:
- this->MemorizeNumber();
- break;
- case MemoryCommand::MemorizedNumberLoad:
- if (commandItr + 1 == serializedData.end())
- {
- throw out_of_range("Expecting index of memory, data ended prematurely");
- }
- indexOfMemory = *(++commandItr);
- this->MemorizedNumberLoad(indexOfMemory);
- break;
- case MemoryCommand::MemorizedNumberAdd:
- if (commandItr + 1 == serializedData.end())
- {
- throw out_of_range("Expecting index of memory, data ended prematurely");
- }
- indexOfMemory = *(++commandItr);
- this->MemorizedNumberAdd(indexOfMemory);
- break;
- case MemoryCommand::MemorizedNumberSubtract:
- if (commandItr + 1 == serializedData.end())
- {
- throw out_of_range("Expecting index of memory, data ended prematurely");
- }
- indexOfMemory = *(++commandItr);
- this->MemorizedNumberSubtract(indexOfMemory);
- break;
- case MemoryCommand::MemorizedNumberClearAll:
- this->MemorizedNumberClearAll();
- break;
- default:
- break;
- }
- }
- else
- {
- this->SendCommand(static_cast(MapCommandForDeSerialize(*commandItr)));
- }
- }
- }
-
///
/// Memorize the current displayed value
/// Notify the client with new the new memorize value vector
diff --git a/src/CalcManager/CalculatorManager.h b/src/CalcManager/CalculatorManager.h
index a288bdf2..37406ed4 100644
--- a/src/CalcManager/CalculatorManager.h
+++ b/src/CalcManager/CalculatorManager.h
@@ -63,7 +63,6 @@ namespace CalculationManager
// For persistence
std::vector m_savedCommands;
std::vector m_savedPrimaryValue;
- std::vector m_serializedMemory;
std::vector m_currentSerializedMemory;
Command m_currentDegreeMode;
Command m_savedDegreeMode;
@@ -111,15 +110,6 @@ namespace CalculationManager
void SetScientificMode();
void SetProgrammerMode();
void SendCommand(_In_ Command command);
- std::vector SerializeCommands();
- void DeSerializeCommands(_In_ const std::vector& serializedData);
- void SerializeMemory();
- std::vector GetSerializedMemory();
- void DeSerializeMemory(const std::vector& serializedMemory);
- void SerializePrimaryDisplay();
- std::vector GetSerializedPrimaryDisplay();
- void DeSerializePrimaryDisplay(const std::vector& serializedPrimaryDisplay);
- Command SerializeSavedDegreeMode();
void MemorizeNumber();
void MemorizedNumberLoad(_In_ unsigned int);
diff --git a/src/CalcManager/UnitConverter.cpp b/src/CalcManager/UnitConverter.cpp
index 3b5490a0..57cd49bd 100644
--- a/src/CalcManager/UnitConverter.cpp
+++ b/src/CalcManager/UnitConverter.cpp
@@ -11,8 +11,6 @@ using namespace concurrency;
using namespace std;
using namespace UnitConversionManager;
-static constexpr uint32_t EXPECTEDSERIALIZEDTOKENCOUNT = 7;
-static constexpr uint32_t EXPECTEDSERIALIZEDCONVERSIONDATATOKENCOUNT = 3;
static constexpr uint32_t EXPECTEDSERIALIZEDCATEGORYTOKENCOUNT = 3;
static constexpr uint32_t EXPECTEDSERIALIZEDUNITTOKENCOUNT = 6;
static constexpr uint32_t EXPECTEDSTATEDATATOKENCOUNT = 5;
@@ -217,18 +215,6 @@ vector UnitConverter::StringToVector(const wstring& w, const wchar_t* d
}
return serializedTokens;
}
-
-Category UnitConverter::StringToCategory(const wstring& w)
-{
- vector tokenList = StringToVector(w, L";");
- assert(tokenList.size() == EXPECTEDSERIALIZEDCATEGORYTOKENCOUNT);
- Category serializedCategory;
- serializedCategory.id = _wtoi(Unquote(tokenList[0]).c_str());
- serializedCategory.supportsNegative = (tokenList[1].compare(L"1") == 0);
- serializedCategory.name = Unquote(tokenList[2]);
- return serializedCategory;
-}
-
wstring UnitConverter::UnitToString(const Unit& u, const wchar_t* delimiter)
{
wstringstream out(wstringstream::out);
@@ -253,150 +239,15 @@ Unit UnitConverter::StringToUnit(const wstring& w)
return serializedUnit;
}
-ConversionData UnitConverter::StringToConversionData(const wstring& w)
+Category UnitConverter::StringToCategory(const wstring& w)
{
vector tokenList = StringToVector(w, L";");
- assert(tokenList.size() == EXPECTEDSERIALIZEDCONVERSIONDATATOKENCOUNT);
- ConversionData serializedConversionData;
- serializedConversionData.ratio = stod(Unquote(tokenList[0]).c_str());
- serializedConversionData.offset = stod(Unquote(tokenList[1]).c_str());
- serializedConversionData.offsetFirst = (tokenList[2].compare(L"1") == 0);
- return serializedConversionData;
-}
-
-wstring UnitConverter::ConversionDataToString(ConversionData d, const wchar_t* delimiter)
-{
- wstringstream out(wstringstream::out);
- out.precision(32);
- out << fixed << d.ratio;
- wstring ratio = out.str();
- out.str(L"");
- out << fixed << d.offset;
- wstring offset = out.str();
- out.str(L"");
- TrimString(ratio);
- TrimString(offset);
- out << Quote(ratio) << delimiter << Quote(offset) << delimiter << std::to_wstring(d.offsetFirst) << delimiter;
- return out.str();
-}
-
-///
-/// Serializes the data in the converter and returns it as a string
-///
-wstring UnitConverter::Serialize()
-{
- if (!CheckLoad())
- {
- return wstring();
- }
-
- wstringstream out(wstringstream::out);
- const wchar_t* delimiter = L";";
-
- out << UnitToString(m_fromType, delimiter) << "|";
- out << UnitToString(m_toType, delimiter) << "|";
- out << CategoryToString(m_currentCategory, delimiter) << "|";
- out << std::to_wstring(m_currentHasDecimal) << delimiter << std::to_wstring(m_returnHasDecimal) << delimiter << std::to_wstring(m_switchedActive)
- << delimiter;
- out << m_currentDisplay << delimiter << m_returnDisplay << delimiter << "|";
- wstringstream categoryString(wstringstream::out);
- wstringstream categoryToUnitString(wstringstream::out);
- wstringstream unitToUnitToDoubleString(wstringstream::out);
- for (const Category& c : m_categories)
- {
- categoryString << CategoryToString(c, delimiter) << ",";
- }
-
- for (const auto& cur : m_categoryToUnits)
- {
- categoryToUnitString << CategoryToString(cur.first, delimiter) << "[";
- for (const Unit& u : cur.second)
- {
- categoryToUnitString << UnitToString(u, delimiter) << ",";
- }
- categoryToUnitString << "["
- << "]";
- }
-
- for (const auto& cur : m_ratioMap)
- {
- unitToUnitToDoubleString << UnitToString(cur.first, delimiter) << "[";
- for (const auto& curConversion : cur.second)
- {
- unitToUnitToDoubleString << UnitToString(curConversion.first, delimiter) << ":";
- unitToUnitToDoubleString << ConversionDataToString(curConversion.second, delimiter) << ":,";
- }
- unitToUnitToDoubleString << "["
- << "]";
- }
-
- out << categoryString.str() << "|";
- out << categoryToUnitString.str() << "|";
- out << unitToUnitToDoubleString.str() << "|";
- wstring test = out.str();
- return test;
-}
-
-///
-/// De-Serializes the data in the converter from a string
-///
-/// wstring holding the serialized data. If it does not have expected number of parameters, we will ignore it
-void UnitConverter::DeSerialize(const wstring& serializedData)
-{
- ClearValues();
- ResetCategoriesAndRatios();
-
- if (serializedData.empty())
- {
- return;
- }
-
- vector outerTokens = StringToVector(serializedData, L"|");
- assert(outerTokens.size() == EXPECTEDSERIALIZEDTOKENCOUNT);
- m_fromType = StringToUnit(outerTokens[0]);
- m_toType = StringToUnit(outerTokens[1]);
- m_currentCategory = StringToCategory(outerTokens[2]);
- vector stateDataTokens = StringToVector(outerTokens[3], L";");
- assert(stateDataTokens.size() == EXPECTEDSTATEDATATOKENCOUNT);
- m_currentHasDecimal = (stateDataTokens[0].compare(L"1") == 0);
- m_returnHasDecimal = (stateDataTokens[1].compare(L"1") == 0);
- m_switchedActive = (stateDataTokens[2].compare(L"1") == 0);
- m_currentDisplay = stateDataTokens[3];
- m_returnDisplay = stateDataTokens[4];
- vector categoryListTokens = StringToVector(outerTokens[4], L",");
- for (wstring token : categoryListTokens)
- {
- m_categories.push_back(StringToCategory(token));
- }
- vector unitVectorTokens = StringToVector(outerTokens[5], L"]");
- for (wstring unitVector : unitVectorTokens)
- {
- vector mapcomponents = StringToVector(unitVector, L"[");
- assert(mapcomponents.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
- Category key = StringToCategory(mapcomponents[0]);
- vector units = StringToVector(mapcomponents[1], L",");
- for (wstring unit : units)
- {
- m_categoryToUnits[key].push_back(StringToUnit(unit));
- }
- }
- vector ratioMapTokens = StringToVector(outerTokens[6], L"]");
- for (wstring token : ratioMapTokens)
- {
- vector ratioMapComponentTokens = StringToVector(token, L"[");
- assert(ratioMapComponentTokens.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
- Unit key = StringToUnit(ratioMapComponentTokens[0]);
- vector ratioMapList = StringToVector(ratioMapComponentTokens[1], L",");
- for (wstring subtoken : ratioMapList)
- {
- vector ratioMapSubComponentTokens = StringToVector(subtoken, L":");
- assert(ratioMapSubComponentTokens.size() == EXPECTEDMAPCOMPONENTTOKENCOUNT);
- Unit subkey = StringToUnit(ratioMapSubComponentTokens[0]);
- ConversionData conversion = StringToConversionData(ratioMapSubComponentTokens[1]);
- m_ratioMap[key][subkey] = conversion;
- }
- }
- UpdateViewModel();
+ assert(tokenList.size() == EXPECTEDSERIALIZEDCATEGORYTOKENCOUNT);
+ Category serializedCategory;
+ serializedCategory.id = _wtoi(Unquote(tokenList[0]).c_str());
+ serializedCategory.supportsNegative = (tokenList[1].compare(L"1") == 0);
+ serializedCategory.name = Unquote(tokenList[2]);
+ return serializedCategory;
}
///
diff --git a/src/CalcManager/UnitConverter.h b/src/CalcManager/UnitConverter.h
index b111ee79..19582245 100644
--- a/src/CalcManager/UnitConverter.h
+++ b/src/CalcManager/UnitConverter.h
@@ -237,8 +237,6 @@ namespace UnitConversionManager
virtual Category GetCurrentCategory() = 0;
virtual void SetCurrentUnitTypes(const Unit& fromType, const Unit& toType) = 0;
virtual void SwitchActive(const std::wstring& newValue) = 0;
- virtual std::wstring Serialize() = 0;
- virtual void DeSerialize(const std::wstring& serializedData) = 0;
virtual std::wstring SaveUserPreferences() = 0;
virtual void RestoreUserPreferences(_In_ const std::wstring& userPreferences) = 0;
virtual void SendCommand(Command command) = 0;
@@ -262,8 +260,6 @@ namespace UnitConversionManager
Category GetCurrentCategory() override;
void SetCurrentUnitTypes(const Unit& fromType, const Unit& toType) override;
void SwitchActive(const std::wstring& newValue) override;
- std::wstring Serialize() override;
- void DeSerialize(const std::wstring& serializedData) override;
std::wstring SaveUserPreferences() override;
void RestoreUserPreferences(const std::wstring& userPreference) override;
void SendCommand(Command command) override;
@@ -290,8 +286,6 @@ namespace UnitConversionManager
std::wstring CategoryToString(const Category& c, const wchar_t* delimiter);
std::wstring UnitToString(const Unit& u, const wchar_t* delimiter);
Unit StringToUnit(const std::wstring& w);
- ConversionData StringToConversionData(const std::wstring& w);
- std::wstring ConversionDataToString(ConversionData d, const wchar_t* delimiter);
void UpdateCurrencySymbols();
void UpdateViewModel();
bool AnyUnitIsEmpty();
diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp
index 0dc9865b..acda9bad 100644
--- a/src/CalcViewModel/StandardCalculatorViewModel.cpp
+++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp
@@ -1163,110 +1163,6 @@ void StandardCalculatorViewModel::OnMemoryClear(_In_ Object ^ memoryItemPosition
}
}
-Array ^ StandardCalculatorViewModel::Serialize()
-{
- DataWriter ^ writer = ref new DataWriter();
- writer->WriteUInt32(static_cast(m_CurrentAngleType));
- writer->WriteBoolean(IsFToEChecked);
- writer->WriteBoolean(IsCurrentViewPinned);
- writer->WriteUInt32(static_cast(m_standardCalculatorManager.SerializeSavedDegreeMode()));
-
- // Serialize Memory
- vector serializedMemory;
- serializedMemory = m_standardCalculatorManager.GetSerializedMemory();
- size_t lengthOfSerializedMemory = serializedMemory.size();
- writer->WriteUInt32(static_cast(lengthOfSerializedMemory));
- for (auto data : serializedMemory)
- {
- writer->WriteInt32(data);
- }
-
- // Serialize Primary Display
- vector serializedPrimaryDisplay = m_standardCalculatorManager.GetSerializedPrimaryDisplay();
- writer->WriteUInt32(static_cast(serializedPrimaryDisplay.size()));
- for (auto data : serializedPrimaryDisplay)
- {
- writer->WriteInt32(data);
- }
-
- // For ProgrammerMode
- writer->WriteUInt32(static_cast(CurrentRadixType));
-
- // Serialize commands of calculator manager
- vector serializedCommand = m_standardCalculatorManager.SerializeCommands();
- writer->WriteUInt32(static_cast(serializedCommand.size()));
- writer->WriteBytes(ref new Array(serializedCommand.data(), static_cast(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 ^ viewModelDataAsBytes = ref new Array(buffer->Length);
- reader->ReadBytes(viewModelDataAsBytes);
-
- // Return byte array
- return viewModelDataAsBytes;
-}
-
-void StandardCalculatorViewModel::Deserialize(Array ^ 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(reader->ReadUInt32());
-
- m_standardCalculatorManager.SendCommand(serializedDegreeMode);
-
- // Deserialize Memory
- UINT32 memoryDataLength = reader->ReadUInt32();
- vector 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 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 ^ modelDataAsBytes = ref new Array(modeldatalength);
- reader->ReadBytes(modelDataAsBytes);
- m_standardCalculatorManager.DeSerializeCommands(vector(modelDataAsBytes->begin(), modelDataAsBytes->end()));
-
- // After recalculation. If there is an error then
- // IsInError should be set synchronously.
- if (IsInError)
- {
- shared_ptr>> commandVector = Utils::DeserializeCommands(reader);
- shared_ptr>> tokenVector = Utils::DeserializeTokens(reader);
- SetExpressionDisplay(tokenVector, commandVector);
- }
- }
-}
-
void StandardCalculatorViewModel::OnPropertyChanged(String ^ propertyname)
{
if (propertyname == IsScientificPropertyName)
diff --git a/src/CalcViewModel/StandardCalculatorViewModel.h b/src/CalcViewModel/StandardCalculatorViewModel.h
index 5a1a4dea..59dbbcb1 100644
--- a/src/CalcViewModel/StandardCalculatorViewModel.h
+++ b/src/CalcViewModel/StandardCalculatorViewModel.h
@@ -348,8 +348,6 @@ namespace CalculatorApp
void OnBinaryOperatorReceived();
void OnMemoryItemChanged(unsigned int indexOfMemory);
- Platform::Array ^ Serialize();
- void Deserialize(Platform::Array ^ state);
Platform::String ^ GetLocalizedStringFormat(Platform::String ^ format, Platform::String ^ displayValue);
void OnPropertyChanged(Platform::String ^ propertyname);
diff --git a/src/CalcViewModel/UnitConverterViewModel.cpp b/src/CalcViewModel/UnitConverterViewModel.cpp
index 7c48e7c4..dea918e9 100644
--- a/src/CalcViewModel/UnitConverterViewModel.cpp
+++ b/src/CalcViewModel/UnitConverterViewModel.cpp
@@ -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(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 tokens = UCM::UnitConverter::StringToVector(serializedData, L"[###]");
- assert(tokens.size() >= 2);
- vector 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()
{
diff --git a/src/CalcViewModel/UnitConverterViewModel.h b/src/CalcViewModel/UnitConverterViewModel.h
index 1fb67ee8..b0cc0241 100644
--- a/src/CalcViewModel/UnitConverterViewModel.h
+++ b/src/CalcViewModel/UnitConverterViewModel.h
@@ -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();
diff --git a/src/CalculatorUnitTests/CalculatorManagerTest.cpp b/src/CalculatorUnitTests/CalculatorManagerTest.cpp
index 809fe919..a2ed8127 100644
--- a/src/CalculatorUnitTests/CalculatorManagerTest.cpp
+++ b/src/CalculatorUnitTests/CalculatorManagerTest.cpp
@@ -181,12 +181,6 @@ namespace CalculatorManagerTest
TEST_METHOD(CalculatorManagerTestMemory);
- TEST_METHOD(CalculatorManagerTestSerialize);
- TEST_METHOD(CalculatorManagerTestSerializePrecision);
- TEST_METHOD(CalculatorManagerTestSerializeMultiple);
- TEST_METHOD(CalculatorManagerTestSerializeDegreeMode);
- TEST_METHOD(CalculatorManagerTestSerializeMemory);
-
TEST_METHOD(CalculatorManagerTestMaxDigitsReached);
TEST_METHOD(CalculatorManagerTestMaxDigitsReached_LeadingDecimal);
TEST_METHOD(CalculatorManagerTestMaxDigitsReached_TrailingDecimal);
@@ -263,35 +257,6 @@ namespace CalculatorManagerTest
// MaxDigitsReached should have been called once
VERIFY_IS_LESS_THAN(0, pCalculatorDisplay->GetMaxDigitsCalledCount());
}
-
- void SerializeAndDeSerialize()
- {
- auto serializedCommands = m_calculatorManager->SerializeCommands();
- auto serializedMemory = m_calculatorManager->GetSerializedMemory();
- auto serializedDisplay = m_calculatorManager->GetSerializedPrimaryDisplay();
-
- Cleanup();
-
- m_calculatorManager->DeSerializePrimaryDisplay(serializedDisplay);
- m_calculatorManager->DeSerializeMemory(serializedMemory);
- m_calculatorManager->DeSerializeCommands(serializedCommands);
- }
-
- void VerifyPersistence()
- {
- auto savedPrimary = m_calculatorDisplayTester->GetPrimaryDisplay();
- auto savedExpression = m_calculatorDisplayTester->GetExpression();
- auto savedMemory = m_calculatorDisplayTester->GetMemorizedNumbers();
- SerializeAndDeSerialize();
- VERIFY_ARE_EQUAL(savedPrimary, m_calculatorDisplayTester->GetPrimaryDisplay());
- VERIFY_ARE_EQUAL(savedExpression, m_calculatorDisplayTester->GetExpression());
- auto loadedMemory = m_calculatorDisplayTester->GetMemorizedNumbers();
- VERIFY_ARE_EQUAL(savedMemory.size(), loadedMemory.size());
- for (unsigned int i = 0; i < savedMemory.size(); i++)
- {
- VERIFY_ARE_EQUAL(savedMemory.at(i), loadedMemory.at(i));
- }
- }
};
std::shared_ptr CalculatorManagerTest::m_calculatorManager;
@@ -826,181 +791,6 @@ namespace CalculatorManagerTest
m_calculatorManager->MemorizeNumber();
}
- void CalculatorManagerTest::CalculatorManagerTestSerializeMemory()
- {
- Cleanup();
-
- Command commands[] = { Command::Command1, Command::CommandNULL };
- ExecuteCommands(commands);
-
- for (int i = 0; i < 110; i++)
- {
- m_calculatorManager->MemorizeNumber();
- }
-
- VerifyPersistence();
- }
-
- void CalculatorManagerTest::CalculatorManagerTestSerializeDegreeMode()
- {
- Cleanup();
-
- Command commands[] = { Command::Command1, Command::CommandRAD, Command::CommandSIN, Command::CommandADD, Command::Command1,
- Command::CommandGRAD, Command::CommandCOS, Command::CommandADD, Command::Command1, Command::CommandDEG,
- Command::CommandTAN, Command::CommandADD, Command::CommandNULL };
- ExecuteCommands(commands);
-
- VerifyPersistence();
- }
-
- // 1 + 2 then serialize and deserialize 3 times
- // Check if the values are persisted correctly
- void CalculatorManagerTest::CalculatorManagerTestSerializeMultiple()
- {
- Cleanup();
-
- Command commands[] = { Command::Command1, Command::CommandADD, Command::Command2, Command::CommandNULL };
- ExecuteCommands(commands);
-
- VerifyPersistence();
- VerifyPersistence();
- VerifyPersistence();
- }
-
- // Calculate 1/3 then serialize and deserialize
- // Multiply by 3 and check if the result is 1 not 0.999999999999999999...
- void CalculatorManagerTest::CalculatorManagerTestSerializePrecision()
- {
- CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester*)m_calculatorDisplayTester.get();
- wstring resultPrimary = L"";
- wstring resultExpression = L"";
- Cleanup();
-
- Command commands[] = { Command::Command1, Command::CommandDIV, Command::Command3, Command::CommandEQU, Command::CommandNULL };
- ExecuteCommands(commands);
-
- SerializeAndDeSerialize();
-
- Command commands2[] = { Command::CommandMUL, Command::Command3, Command::CommandEQU, Command::CommandNULL };
- ExecuteCommands(commands2);
-
- VERIFY_ARE_EQUAL(StringReference(L"1"), ref new String(pCalculatorDisplay->GetPrimaryDisplay().c_str()));
- }
-
- void CalculatorManagerTest::CalculatorManagerTestSerialize()
- {
- CalculatorManagerDisplayTester* pCalculatorDisplay = (CalculatorManagerDisplayTester*)m_calculatorDisplayTester.get();
- wstring resultPrimary = L"";
- wstring resultExpression = L"";
- Cleanup();
-
- m_calculatorManager->SendCommand(Command::ModeScientific);
- m_calculatorManager->SendCommand(Command::Command1);
- m_calculatorManager->SendCommand(Command::CommandADD);
- m_calculatorManager->SendCommand(Command::Command2);
- m_calculatorManager->SendCommand(Command::CommandMUL);
- m_calculatorManager->SendCommand(Command::Command2);
- m_calculatorManager->MemorizeNumber();
- m_calculatorManager->SendCommand(Command::CommandEQU);
- m_calculatorManager->MemorizeNumber();
-
- vector memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers();
- wstring primaryDisplay = pCalculatorDisplay->GetPrimaryDisplay();
- wstring expressionDisplay = pCalculatorDisplay->GetExpression();
-
- SerializeAndDeSerialize();
-
- vector memorizedNumbersAfterDeSerialize = pCalculatorDisplay->GetMemorizedNumbers();
- wstring primaryDisplayAfterDeSerialize = pCalculatorDisplay->GetPrimaryDisplay();
- wstring expressionDisplayAfterDeSerialize = pCalculatorDisplay->GetExpression();
-
- VERIFY_ARE_EQUAL(primaryDisplay, primaryDisplayAfterDeSerialize);
- VERIFY_ARE_EQUAL(expressionDisplay, expressionDisplayAfterDeSerialize);
-
- bool isEqual = false;
-
- if (memorizedNumbers.size() < memorizedNumbersAfterDeSerialize.size())
- {
- isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), memorizedNumbersAfterDeSerialize.begin());
- }
- else
- {
- isEqual = std::equal(memorizedNumbersAfterDeSerialize.begin(), memorizedNumbersAfterDeSerialize.end(), memorizedNumbers.begin());
- }
- VERIFY_IS_TRUE(isEqual);
-
- m_calculatorManager->SendCommand(Command::CommandGRAD);
- m_calculatorManager->SendCommand(Command::Command5);
- m_calculatorManager->SendCommand(Command::Command0);
- m_calculatorManager->SendCommand(Command::CommandSIGN);
- m_calculatorManager->SendCommand(Command::CommandMUL);
-
- memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers();
- primaryDisplay = pCalculatorDisplay->GetPrimaryDisplay();
- expressionDisplay = pCalculatorDisplay->GetExpression();
-
- SerializeAndDeSerialize();
-
- memorizedNumbersAfterDeSerialize = pCalculatorDisplay->GetMemorizedNumbers();
- primaryDisplayAfterDeSerialize = pCalculatorDisplay->GetPrimaryDisplay();
- expressionDisplayAfterDeSerialize = pCalculatorDisplay->GetExpression();
-
- VERIFY_ARE_EQUAL(primaryDisplay, primaryDisplayAfterDeSerialize);
- VERIFY_ARE_EQUAL(expressionDisplay, expressionDisplayAfterDeSerialize);
-
- isEqual = false;
- if (memorizedNumbers.size() < memorizedNumbersAfterDeSerialize.size())
- {
- isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), memorizedNumbersAfterDeSerialize.begin());
- }
- else
- {
- isEqual = std::equal(memorizedNumbersAfterDeSerialize.begin(), memorizedNumbersAfterDeSerialize.end(), memorizedNumbers.begin());
- }
- VERIFY_IS_TRUE(isEqual);
-
- m_calculatorManager->SendCommand(Command::Command1);
- m_calculatorManager->SendCommand(Command::Command2);
- m_calculatorManager->SendCommand(Command::Command3);
- m_calculatorManager->SendCommand(Command::CommandPNT);
- m_calculatorManager->SendCommand(Command::Command8);
- m_calculatorManager->SendCommand(Command::CommandSIGN);
- m_calculatorManager->MemorizeNumber();
- m_calculatorManager->SendCommand(Command::Command2);
- m_calculatorManager->SendCommand(Command::Command3);
- m_calculatorManager->MemorizedNumberAdd(0);
- m_calculatorManager->SendCommand(Command::CommandCENTR);
- m_calculatorManager->SendCommand(Command::Command3);
- m_calculatorManager->SendCommand(Command::Command1);
- m_calculatorManager->SendCommand(Command::CommandSIN);
- m_calculatorManager->MemorizedNumberSubtract(2);
- m_calculatorManager->MemorizedNumberLoad(2);
-
- memorizedNumbers = pCalculatorDisplay->GetMemorizedNumbers();
- primaryDisplay = pCalculatorDisplay->GetPrimaryDisplay();
- expressionDisplay = pCalculatorDisplay->GetExpression();
-
- SerializeAndDeSerialize();
-
- memorizedNumbersAfterDeSerialize = pCalculatorDisplay->GetMemorizedNumbers();
- primaryDisplayAfterDeSerialize = pCalculatorDisplay->GetPrimaryDisplay();
- expressionDisplayAfterDeSerialize = pCalculatorDisplay->GetExpression();
-
- VERIFY_ARE_EQUAL(primaryDisplay, primaryDisplayAfterDeSerialize);
- VERIFY_ARE_EQUAL(expressionDisplay, expressionDisplayAfterDeSerialize);
-
- isEqual = false;
- if (memorizedNumbers.size() < memorizedNumbersAfterDeSerialize.size())
- {
- isEqual = std::equal(memorizedNumbers.begin(), memorizedNumbers.end(), memorizedNumbersAfterDeSerialize.begin());
- }
- else
- {
- isEqual = std::equal(memorizedNumbersAfterDeSerialize.begin(), memorizedNumbersAfterDeSerialize.end(), memorizedNumbers.begin());
- }
- VERIFY_IS_TRUE(isEqual);
- }
-
// Send 12345678910111213 and verify MaxDigitsReached
void CalculatorManagerTest::CalculatorManagerTestMaxDigitsReached()
{
diff --git a/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp b/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp
index 78493153..aad7e03a 100644
--- a/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp
+++ b/src/CalculatorUnitTests/StandardViewModelUnitTests.cpp
@@ -75,7 +75,6 @@ namespace CalculatorUnitTests
viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::Clear);
viewModel->ButtonPressed->Execute(NumbersAndOperatorsEnum::ClearEntry);
viewModel->ClearMemoryCommand->Execute(nullptr);
- viewModel->Deserialize(ref new Platform::Array(0));
}
TESTITEM* currentItem = item;
diff --git a/src/CalculatorUnitTests/UnitConverterTest.cpp b/src/CalculatorUnitTests/UnitConverterTest.cpp
index a9cf3929..3f3559d2 100644
--- a/src/CalculatorUnitTests/UnitConverterTest.cpp
+++ b/src/CalculatorUnitTests/UnitConverterTest.cpp
@@ -199,8 +199,6 @@ namespace UnitConverterUnitTests
TEST_METHOD(UnitConverterTestGetters);
TEST_METHOD(UnitConverterTestGetCategory);
TEST_METHOD(UnitConverterTestUnitTypeSwitching);
- TEST_METHOD(UnitConverterTestSerialization);
- TEST_METHOD(UnitConverterTestDeSerialization);
TEST_METHOD(UnitConverterTestQuote);
TEST_METHOD(UnitConverterTestUnquote);
TEST_METHOD(UnitConverterTestBackspace);
@@ -253,7 +251,7 @@ namespace UnitConverterUnitTests
// Resets calculator state to start state after each test
void UnitConverterTest::Cleanup()
{
- s_unitConverter->DeSerialize(wstring());
+ s_unitConverter->SendCommand(Command::Reset);
s_testVMCallback->Reset();
}
@@ -325,22 +323,6 @@ namespace UnitConverterUnitTests
VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>()));
}
- // Test serialization
- void UnitConverterTest::UnitConverterTestSerialization()
- {
- wstring test1 = wstring(L"4;Kilograms;Kg;0;0;0;|3;Pounds;Lb;1;1;0;|2;0;Weight;|1;1;0;52.8;116.4039;|1;1;Length;,2;0;Weight;,|1;1;Length;[1;Inches;In;1;"
- L"1;0;,2;Feet;Ft;0;0;0;,[]2;0;Weight;[3;Pounds;Lb;1;1;0;,4;Kilograms;Kg;0;0;0;,[]|1;Inches;In;1;1;0;[1;Inches;In;1;1;0;:1;0;0;:"
- L",2;Feet;Ft;0;0;0;:0.08333333333333332870740406406185;0;0;:,[]2;Feet;Ft;0;0;0;[1;Inches;In;1;1;0;:12;0;0;:,2;Feet;Ft;0;0;0;:1;"
- L"0;0;:,[]3;Pounds;Lb;1;1;0;[3;Pounds;Lb;1;1;0;:1;0;0;:,4;Kilograms;Kg;0;0;0;:0.45359199999999999519673110626172;0;0;:,[]4;"
- L"Kilograms;Kg;0;0;0;[3;Pounds;Lb;1;1;0;:2.20461999999999980204279381723609;0;0;:,4;Kilograms;Kg;0;0;0;:1;0;0;:,[]|");
- s_unitConverter->SendCommand(Command::Five);
- s_unitConverter->SendCommand(Command::Two);
- s_unitConverter->SendCommand(Command::Decimal);
- s_unitConverter->SendCommand(Command::Eight);
- s_unitConverter->SetCurrentCategory(s_testWeight);
- s_unitConverter->SetCurrentUnitTypes(s_testKilograms, s_testPounds);
- VERIFY_IS_TRUE(s_unitConverter->Serialize().compare(test1) == 0);
- }
// Test input escaping
void UnitConverterTest::UnitConverterTestQuote()
@@ -368,19 +350,6 @@ namespace UnitConverterUnitTests
VERIFY_IS_TRUE(UnitConverter::Unquote(UnitConverter::Quote(input3)) == input3);
}
- // Test de-serialization
- void UnitConverterTest::UnitConverterTestDeSerialization()
- {
- wstring test1 = wstring(L"4;Kilograms;Kg;0;0;0;|3;Pounds;Lb;1;1;0;|2;0;Weight;|1;1;0;52.8;116.4039;|1;1;Length;,2;0;Weight;,|1;1;Length;[1;Inches;In;1;"
- L"1;0;,2;Feet;Ft;0;0;0;,[]2;0;Weight;[3;Pounds;Lb;1;1;0;,4;Kilograms;Kg;0;0;0;,[]|1;Inches;In;1;1;0;[1;Inches;In;1;1;0;:1;0;0;:"
- L",2;Feet;Ft;0;0;0;:0.08333333333333332870740406406185;0;0;:,[]2;Feet;Ft;0;0;0;[1;Inches;In;1;1;0;:12;0;0;:,2;Feet;Ft;0;0;0;:1;"
- L"0;0;:,[]3;Pounds;Lb;1;1;0;[3;Pounds;Lb;1;1;0;:1;0;0;:,4;Kilograms;Kg;0;0;0;:0.45359199999999999519673110626172;0;0;:,[]4;"
- L"Kilograms;Kg;0;0;0;[3;Pounds;Lb;1;1;0;:2.20461999999999980204279381723609;0;0;:,4;Kilograms;Kg;0;0;0;:1;0;0;:,[]|");
- s_unitConverter->DeSerialize(test1);
- VERIFY_IS_TRUE(s_testVMCallback->CheckDisplayValues(wstring(L"52.8"), wstring(L"116.4039")));
- VERIFY_IS_TRUE(s_testVMCallback->CheckSuggestedValues(vector>()));
- }
-
// Test backspace commands
void UnitConverterTest::UnitConverterTestBackspace()
{
diff --git a/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp b/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp
index 24ac03e0..4e91e619 100644
--- a/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp
+++ b/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.cpp
@@ -129,8 +129,6 @@ UnitConverterMock::UnitConverterMock()
, m_switchActiveCallCount(0)
, m_sendCommandCallCount(0)
, m_setVMCallbackCallCount(0)
- , m_serializeCallCount(0)
- , m_deSerializeCallCount(0)
{
}
@@ -224,21 +222,10 @@ void UnitConverterMock::SwitchActive(const std::wstring& newValue)
m_curValue = newValue;
}
-wstring UnitConverterMock::Serialize()
-{
- m_serializeCallCount++;
- return wstring(L"");
-}
-
-void UnitConverterMock::DeSerialize(const wstring& /*serializedData*/)
-{
- m_deSerializeCallCount++;
-}
-
-std::wstring UnitConverterMock::SaveUserPreferences()
-{
- return L"TEST";
-};
+ std::wstring UnitConverterMock::SaveUserPreferences()
+ {
+ return L"TEST";
+ };
void UnitConverterMock::RestoreUserPreferences(_In_ const std::wstring& /*userPreferences*/){};
@@ -858,37 +845,6 @@ TEST_METHOD(TestSupplementaryResultsWhimsicalUnits)
VERIFY_IS_TRUE(vm.SupplementaryResults->GetAt(0)->Unit->GetModelUnit() == UNITWHIMSY);
}
-// Test deserialization
-TEST_METHOD(TestUnitConverterViewModelDeserialization)
-{
- String ^ serializedTest = L"0[;;;]0[;;;]0[;;;]1[;;;]1.5[;;;]25[;;;]1.5[;;;]25[;;;][###][###]";
- shared_ptr mock = make_shared();
- VM::UnitConverterViewModel vm(mock);
- vm.Deserialize(serializedTest);
- VERIFY_IS_TRUE(vm.Value1 == L"1.5");
- VERIFY_IS_TRUE(vm.Value2 == L"25");
- VERIFY_IS_TRUE(vm.GetValueFromUnlocalized() == L"1.5");
- VERIFY_IS_TRUE(vm.GetValueToUnlocalized() == L"25");
- VERIFY_ARE_EQUAL(vm.Value1Active, false);
- VERIFY_ARE_EQUAL(vm.Value2Active, true);
- VERIFY_IS_TRUE(mock->m_deSerializeCallCount == 1);
-}
-
-// Test serialization
-/*TEST_METHOD(TestUnitConverterViewModelSerialization)
-{
- String ^ serializedTest = L"0[;;;]0[;;;]0[;;;]1[;;;];;;]1.5[;;;[;;;]25[###[;;;]0[;;;]0[;;;][###][###]";
- shared_ptr mock = make_shared();
- VM::UnitConverterViewModel vm(mock);
- vm.Value1 = L";;;]1.5[;;;";
- vm.Value2 = L"25[###";
- vm.Value1Active = false;
- vm.Value2Active = true;
- String ^ test = vm.Serialize();
- VERIFY_IS_TRUE(serializedTest == test);
- VERIFY_IS_TRUE(mock->m_serializeCallCount == 1);
-}*/
-
TEST_METHOD(TestOnPaste)
{
shared_ptr mock = make_shared();
diff --git a/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.h b/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.h
index da2048f3..08c0f954 100644
--- a/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.h
+++ b/src/CalculatorUnitTests/UnitConverterViewModelUnitTests.h
@@ -34,8 +34,6 @@ namespace CalculatorUnitTests
UCM::Category GetCurrentCategory();
void SetCurrentUnitTypes(const UCM::Unit& fromType, const UCM::Unit& toType) override;
void SwitchActive(const std::wstring& newValue);
- std::wstring Serialize() override;
- void DeSerialize(const std::wstring& serializedData) override;
std::wstring SaveUserPreferences() override;
void RestoreUserPreferences(_In_ const std::wstring& userPreferences) override;
void SendCommand(UCM::Command command) override;
@@ -61,8 +59,6 @@ namespace CalculatorUnitTests
UINT m_switchActiveCallCount;
UINT m_sendCommandCallCount;
UINT m_setVMCallbackCallCount;
- UINT m_serializeCallCount;
- UINT m_deSerializeCallCount;
UCM::Category m_curCategory;
UCM::Unit m_curFrom;