public static void WriteParameters(string filename, ArchiveOptions appconf)
 {
     if (appconf != null)
     {
         SerializeParameters(filename, appconf);
     }
 }
 private static void SerializeParameters(string filename, ArchiveOptions appconf)
 {
     try
     {
         using (TextWriter tw = new StreamWriter(filename))
         {
             //XmlSerializer xmls = new XmlSerializer(typeof(Archiveoptions));
             XmlSerializer xmls = XmlSerializer.FromTypes(new[] { typeof(ArchiveOptions) })[0];
             xmls.Serialize(tw, appconf);
         }
     }
     catch (Exception ex)
     {
         _logger.Error("Error in Archiveoptions serialization: {0}", ex.Message);
     }
 }
        private static ArchiveOptions DeserializeParameters(string filename)
        {
            ArchiveOptions appconf = new ArchiveOptions();

            try
            {
                TextReader    tr   = new StreamReader(filename);
                XmlSerializer xmls = new XmlSerializer(typeof(ArchiveOptions));
                //XmlSerializer xmls = XmlSerializer.FromTypes(new[] { typeof(ArchiveOptions) })[0];

                appconf = (ArchiveOptions)xmls.Deserialize(tr);

                tr.Close();
            }
            catch (Exception ex)
            {
                _logger.Error("Error during ArchiveOptions deserialization: {0}", ex.Message);
            }
            return(appconf);
        }
        public static ArchiveOptions ReadParameters(string filename)
        {
            string exeFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            string configFilePath = filename;

            if (File.Exists(configFilePath))
            {
                _logger.Info("ArchiveOption.xml is attempted to read from: {0} ", configFilePath);
            }
            else
            {
                configFilePath = exeFolder + @"\" + @filename;
            }

            // create new ArchiveOptions if previously it didn't exist
            if (File.Exists(configFilePath))
            {
                _logger.Info("Previous path was not existing. ArchiveOption.xml is attempted to read from: {0} ", configFilePath);
            }
            else
            {
                configFilePath = exeFolder + @"\Configs\ArchiveOptions.xml";
                _logger.Info("Previous path was not existing. A new ArchiveOption.xml will be created in: {0} ", configFilePath);

                ArchiveOptions aop = new ArchiveOptions();
                aop.OptionList = new ObservableCollection <ArchOption> {
                    new ArchOption()
                    {
                        Name = "Log", FileDirList = new List <ArchPath> {
                            new ArchPath()
                            {
                                Path = "*.logs", RecursiveDir = false, NumOfDays = 2
                            }
                        }
                    },
                    new ArchOption()
                    {
                        Name = "All", FileDirList = new List <ArchPath> {
                            new ArchPath()
                            {
                                Path = "*.xml", RecursiveDir = true
                            }
                        }
                    }
                };
                try
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(configFilePath));
                }
                catch (Exception ex)
                {
                    _logger.Error("ArchiveOptions was not existing, a new file was tried to create -> Error during CreateDirectory: {0}", ex.Message);
                }

                WriteParameters(configFilePath, aop);

                return(aop);
            }

            return(DeserializeParameters(configFilePath));
        }