Exemplo n.º 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));
            }
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 3
0
 public void UsingThisConfiguration()
 {
     _result = IoResult.ForSuccess();
 }