Пример #1
0
        public void SerializationList()
        {
            if (list == null)
            {
                return;
            }
            if (File.Exists(nameFile))
            {
                File.Delete(nameFile);
            }

            try
            {//*/
                ConverterData[] ser = new ConverterData[this.OurList.Count];
                int             i   = 0;
                foreach (var item in this.OurList)
                {
                    ser[i] = ConverterData.ToConverterData(item);
                    i++;
                }
                using (FileStream fs = new FileStream(nameFile, FileMode.OpenOrCreate))
                {
                    XmlSerializer formatter = new XmlSerializer(typeof(ConverterData[]));
                    formatter.Serialize(fs, ser);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Convert.ToString(ex.InnerException));
            }//*/
        }
Пример #2
0
        public ObservableCollection <Event> DeserializationList()
        {
            if (!File.Exists(nameFile))
            {
                return(null);
            }
            ObservableCollection <Event> result = new ObservableCollection <Event>();

            try
            {//*/
                ConverterData[] loadedList = null;

                using (FileStream fs = new FileStream(nameFile, FileMode.OpenOrCreate))
                {
                    XmlSerializer formatter = new XmlSerializer(typeof(ConverterData[]));
                    loadedList = (ConverterData[])formatter.Deserialize(fs);
                }
                for (int i = 0; i < loadedList.Length; i++)
                {
                    result.Add(ConverterData.ToEvent(loadedList[i]));
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
                return(null);
            }//*/
            return(result);
        }