Ejemplo n.º 1
0
        private bool LoadRepository()
        {
            var path = ConfigPathHelper.GetRepositoryConfigPath();

            Logger.Current.Trace("Start LoadRepository. Config file: " + path);

            if (!File.Exists(path))
            {
                Logger.Current.Debug("Repository config file {0} does not exist", path);
                return(false);
            }

            try
            {
                XmlRepository xmlRepository;
                using (var stream = new StreamReader(path, Encoding.UTF8))
                {
                    string state = stream.ReadToEnd();
                    xmlRepository = state.Deserialize <XmlRepository>();
                    stream.Close();
                }

                ApplyRepositoryConfig(xmlRepository);
                Logger.Current.Trace("End LoadRepository");
                return(true);
            }
            catch (Exception ex)
            {
                MessageService.Current.Info("Failed to load the state of the repository: " + ex.Message);
            }
            return(false);
        }
Ejemplo n.º 2
0
        private bool SaveRepository()
        {
            _repository.PrepareToSave();

            try
            {
                using (var stream = new StreamWriter(ConfigPathHelper.GetRepositoryConfigPath(), false))
                {
                    var state = new XmlRepository(_repository).Serialize(false);
                    stream.Write(state);
                    stream.Flush();
                    stream.Close();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                const string msg = "Failed to save the state of the repository.";
                Logger.Current.Error(msg, ex);
                MessageService.Current.Info(msg);
            }
            return(false);
        }