Exemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var pathConfig = new PathConfig
            {
                SourceFolder = sourceTxt.Text,
                TargetFolder = targetTxt.Text
            };

            ConfigManager.UpdatePathConfig(pathConfig);
            System.Windows.MessageBox.Show("Successfully saved path");
        }
Exemplo n.º 2
0
 public static void UpdatePathConfig(PathConfig config)
 {
     try
     {
         File.WriteAllText(pathConfigFileName, JsonConvert.SerializeObject(config));
         Logger.Log(nameof(UpdatePathConfig), $"Update path successful");
     }
     catch (Exception ex)
     {
         Logger.Log(nameof(UpdatePathConfig), $"Exception: { JsonConvert.SerializeObject(ex)}");
         throw ex;
     }
 }
Exemplo n.º 3
0
        public static Configs GetConfigs()
        {
            try
            {
                string     path, date;
                PathConfig pathConfig = null;
                DateConfig dateConfig = new DateConfig();

                if (File.Exists(pathConfigFileName))
                {
                    path = File.ReadAllText(pathConfigFileName);
                    if (!string.IsNullOrEmpty(path))
                    {
                        pathConfig = JsonConvert.DeserializeObject <PathConfig>(path);
                    }
                }
                if (File.Exists(dateConfigFileName))
                {
                    date = File.ReadAllText(dateConfigFileName);
                    if (!string.IsNullOrEmpty(date))
                    {
                        dateConfig = JsonConvert.DeserializeObject <DateConfig>(date);
                    }
                }

                return(new Configs
                {
                    SourceFolder = pathConfig?.SourceFolder,
                    TargetFolder = pathConfig?.TargetFolder,
                    LatestBackupTime = dateConfig?.LatestBackupTime
                });
            }
            catch (Exception ex)
            {
                Logger.Log(nameof(GetConfigs), $"Exception: { JsonConvert.SerializeObject(ex)}");
                throw ex;
            }
        }