Esempio n. 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);
        }
Esempio n. 2
0
        private void DeserializeButton_Click(object sender, RoutedEventArgs e)
        {
            ISerialization deserializer;

            deserializer  = new BinSerialization();
            ListOfObjects = deserializer.DeserializeObjects(FILE_NAME);

            if (ListOfObjects.Count > 0)
            {
                MessageBox.Show("Deserialization was successful!");
            }
            UpdateListBox();
        }
Esempio n. 3
0
        private void SerializeButton_Click(object sender, RoutedEventArgs e)
        {
            ISerialization serializer;

            serializer = new BinSerialization();
            string SerializeResult = serializer.SerializeObjects(ListOfObjects, FILE_NAME);

            if (SerializeResult == "Serialization was successful!")
            {
                MessageBox.Show(SerializeResult);
            }
            else
            {
                MessageBox.Show(SerializeResult);
            }
        }
Esempio n. 4
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);
        }