コード例 #1
0
 public void Rename(string targetGroupName, string newName)
 {
     SafeCall.Execute(() => {
         config.RenameGroup(targetGroupName, newName);
         JsonConfigOperator <RobocopyConfig> .Save(RobocopyConfigParameters.fullConfigFilePath, config);
     });
 }
コード例 #2
0
 public void Remove(string groupName)
 {
     SafeCall.Execute(() => {
         config.RemoveGroup(groupName);
         JsonConfigOperator <RobocopyConfig> .Save(RobocopyConfigParameters.fullConfigFilePath, config);
     });
 }
コード例 #3
0
        public void Rename(string groupName, string currentItemName, string newItemName)
        {
            var group = config.GetGroup(groupName);

            if (group != null)
            {
                // check if an backup item with the same new name has existed
                foreach (var backupItem in group.BackupItems)
                {
                    if (backupItem.BackupName == newItemName)
                    {
                        Console.WriteLine($"An backup item with the same new name has existed.");
                        return;
                    }
                }

                // do renaming
                var item = group.GetItem(currentItemName);
                if (item != null)
                {
                    item.BackupName = newItemName;
                }
                else
                {
                    Console.WriteLine($"Cannot find the specified backup item '{currentItemName}'");
                    return;
                }
            }
            else
            {
                Console.WriteLine($"The specified group '{groupName}' does not exist.");
            }

            JsonConfigOperator <RobocopyConfig> .Save(RobocopyConfigParameters.fullConfigFilePath, config);
        }
コード例 #4
0
 public void Add(string groupName)
 {
     SafeCall.Execute(() => {
         config.BackupGroups.Add(new BackupItemGroup {
             GroupName = groupName.Trim()
         });
         JsonConfigOperator <RobocopyConfig> .Save(RobocopyConfigParameters.fullConfigFilePath, config);
     });
 }
コード例 #5
0
        public void Remove(string groupName, string itemName)
        {
            var group = config.GetGroup(groupName);

            if (group != null)
            {
                group.BackupItems.Remove(group.GetItem(itemName));
            }
            else
            {
                Console.WriteLine($"The specified group '{groupName}' does not exist.");
            }

            JsonConfigOperator <RobocopyConfig> .Save(RobocopyConfigParameters.fullConfigFilePath, config);
        }
コード例 #6
0
        /// <summary>
        /// - If the specified item does not exist in the specified group, a new item will be created.
        /// - Multiple sources cannot point to the same target.
        /// </summary>
        /// <param name="fullBackupItemName">Backup item name with group prefix, e.g. SomeGroupName.SomeBackupName</param>
        /// <param name="source">Backup source</param>
        /// <param name="target">Backup target</param>
        public void Update(string groupName, string itemName, string source, string target)
        {
            if (!AreValidSourceAndTarget(source, target))
            {
                return;
            }

            var group = config.GetGroup(groupName);

            if (group != null)
            {
                // validate to make sure there is not any existing backup configured with the same target
                string lowerTarget = target.ToLower();
                foreach (var backupItem in group.BackupItems)
                {
                    // skip over the specified item, only apply validation to other items
                    if (backupItem.BackupName != itemName)
                    {
                        if (backupItem.Target.ToLower() == lowerTarget)
                        {
                            Console.WriteLine("A backup item with the same target has already existed.");
                            return;
                        }
                    }
                }

                // do update
                var item = group.GetItem(itemName);
                if (item != null)
                {
                    item.Source = source;
                    item.Target = target;
                }
                else
                {
                    Console.WriteLine($"The specified backup item '{itemName}' does not exist. A new backup item is created.");
                    group.BackupItems.Add(new BackupItem {
                        BackupName = itemName, Source = source, Target = target
                    });
                }
            }
            else
            {
                Console.WriteLine($"The specified group '{groupName}' does not exist.");
            }

            JsonConfigOperator <RobocopyConfig> .Save(RobocopyConfigParameters.fullConfigFilePath, config);
        }