Beispiel #1
0
        public IoResult Load(string fromPath, out IAppConfiguration configuration)
        {
            configuration = null;

            try
            {
                var serializer = _configurationFactory.CreateSerializerFor <AppConfiguration>();

                using (var reader = _configurationFactory
                                    .CreateSerializationReaderFor(fromPath))
                {
                    configuration = (IAppConfiguration)serializer.Deserialize(reader);
                    return(IoResult.ForSuccess());
                }
            }
            catch (InvalidOperationException ex) when(ex.InnerException is XmlException)
            {
                return(IoResult.ForReadError(ex));
            }
            catch (FileNotFoundException ex)
            {
                return(IoResult.ForNotFound(ex));
            }
            catch (DirectoryNotFoundException ex)
            {
                return(IoResult.ForNotFound(ex));
            }
            catch (Exception ex)
            {
                return(IoResult.ForException(ex));
            }
        }
Beispiel #2
0
 public IoResult Save(IAppConfiguration configuration, string toPath)
 {
     try
     {
         return(Save(_configurationFactory.ToXmlConfiguration(configuration), toPath));
     }
     catch (Exception ex)
     {
         return(IoResult.ForException(ex));
     }
 }
Beispiel #3
0
        public IoResult Create(string atPath, out IAppConfiguration configuration)
        {
            try
            {
                var xmlConfiguration = _configurationFactory.CreateXmlConfiguration();
                configuration = xmlConfiguration;

                return(Save(xmlConfiguration, atPath));
            }
            catch (Exception ex)
            {
                configuration = null;
                return(IoResult.ForException(ex));
            }
        }
Beispiel #4
0
        private IoResult Save(AppConfiguration configuration, string toPath)
        {
            try
            {
                var serializer = _configurationFactory
                                 .CreateSerializerFor <AppConfiguration>();

                using (var writer = _configurationFactory
                                    .CreateSerializationWriterFor(toPath))
                {
                    serializer.Serialize(writer, configuration);
                    return(IoResult.ForSuccess());
                }
            }
            catch (Exception ex)
            {
                return(IoResult.ForException(ex));
            }
        }
Beispiel #5
0
 public void UsingThisConfiguration()
 {
     _result = IoResult.ForException(Error);
 }