public static void PerformReplication(Configuration.FileReplicationSettingCollection fileReplicationSettings) { foreach (var item in fileReplicationSettings.OfType<Configuration.FileReplicationSetting>()) { try { if (File.Exists(item.Source)) { if (File.Exists(item.Destination)) { File.Delete(item.Destination); } else if (!Directory.Exists(Path.GetDirectoryName(item.Destination))) { Directory.CreateDirectory(Path.GetDirectoryName(item.Destination)); } File.Copy(item.Source, item.Destination, true); ("ReplicationSuccess for " + item).Log(); } } catch (Exception ex) { ("FileReplicationFailed for " + item).Log(); ex.Log(); } } }
public static void List(Configuration cfg) { var aliases = cfg.OfType<ConfigurationEntry<string>>() .Where(e => e.Key.StartsWith(prefix)) .Select(e => new { Name = e.Key.Substring(prefix.Length), Value = e.Value }); // make it prettier and align the equal sign var width = aliases.Select(p => p.Name.Length).Max(); foreach (var alias in aliases) Console.WriteLine("{0} = {1}", alias.Name.PadRight(width), alias.Value); }