Пример #1
0
        private string SerializeFile(string serializedFileName)
        {
            string         result        = "";
            ISerialization serialization = null;

            try
            {
                if (BinarySerializationSelected())
                {
                    serialization = new BinSerialization();
                }
                else if (TextSerializationSelected())
                {
                    serialization = new myTextSerialization();
                }
                else
                {
                    MessageBox.Show("Select serialization method");
                }

                if (serialization != null)
                {
                    SerializationStrategy strategy = new SerializationStrategy(serialization);
                    result = strategy.OnSave(list.ListOfObjects, serializedFileName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(result);
        }
Пример #2
0
        private List <object> DeserializeFile(string unzipFileName, string decryptedFileName)
        {
            ISerialization deserialization = null;

            try
            {
                if (BinarySerializationSelected())
                {
                    deserialization = new BinSerialization();
                }
                else if (TextSerializationSelected())
                {
                    deserialization = new myTextSerialization();
                }
                else
                {
                    MessageBox.Show("Select deserialization method");
                }

                if (deserialization != null)
                {
                    SerializationStrategy strategy = new SerializationStrategy(deserialization);
                    if (ArchivationSelected())
                    {
                        list.ListOfObjects = strategy.OnLoad(unzipFileName);
                    }
                    else if (EncryptionSelected())
                    {
                        list.ListOfObjects = strategy.OnLoad(decryptedFileName);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(list.ListOfObjects);
        }