コード例 #1
0
ファイル: CompareTask.cs プロジェクト: ARLM-Attic/clr-toolbox
        /// <summary>
        /// Loads tasks from a config repository.
        /// </summary>
        /// <param name="config">The config repository.</param>
        /// <returns>The loaded data.</returns>
        public static IEnumerable <CompareTask> FromConfig(IConfigRepository config,
                                                           bool activeOnly = true)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            foreach (var taskName in config.GetCategoryNames())
            {
                CompareTask newTask;
                try
                {
                    bool isActive;
                    config.TryGetValue <bool>(category: taskName,
                                              name: _CONFIG_NAME_IS_ACTIVE,
                                              value: out isActive,
                                              defaultVal: true);

                    if (activeOnly &&
                        isActive == false)
                    {
                        continue;
                    }

                    string displayName;
                    config.TryGetValue <string>(category: taskName,
                                                name: _CONFIG_NAME_TASKNAME,
                                                value: out displayName);

                    string source;
                    config.TryGetValue <string>(category: taskName,
                                                name: _CONFIG_NAME_SOURCE,
                                                value: out source);

                    string destination;
                    config.TryGetValue <string>(category: taskName,
                                                name: _CONFIG_NAME_DEST,
                                                value: out destination);

                    bool recursive;
                    config.TryGetValue <bool>(category: taskName,
                                              name: _CONFIG_NAME_RECURSIVE,
                                              value: out recursive,
                                              defaultVal: false);

                    string hash;
                    config.TryGetValue <string>(category: taskName,
                                                name: _CONFIG_NAME_HASH,
                                                value: out hash);

                    newTask             = new CompareTask();
                    newTask.Destination = destination;
                    newTask.DisplayName = string.IsNullOrWhiteSpace(displayName) ? taskName : displayName.Trim();
                    newTask.IsActive    = isActive;
                    newTask.Name        = taskName;
                    newTask.Recursive   = recursive;
                    newTask.Source      = source;

                    switch ((hash ?? string.Empty).ToLower().Trim())
                    {
                    case "":
                        break;

                    case "crc":
                    case "crc32":
                    case "crc-32":
                        newTask.Hash = typeof(Crc32);
                        break;

                    case "md5":
                    case "md-5":
                        newTask.Hash = typeof(MD5CryptoServiceProvider);
                        break;

                    case "sha1":
                    case "sha-1":
                        newTask.Hash = typeof(SHA1CryptoServiceProvider);
                        break;

                    case "sha256":
                    case "sha-256":
                        newTask.Hash = typeof(SHA256CryptoServiceProvider);
                        break;

                    case "sha384":
                    case "sha-384":
                        newTask.Hash = typeof(SHA384CryptoServiceProvider);
                        break;

                    case "sha512":
                    case "sha-512":
                        newTask.Hash = typeof(SHA512CryptoServiceProvider);
                        break;

                    default:
                        throw new NotSupportedException(hash);
                    }
                }
                catch
                {
                    newTask = null;
                }

                if (newTask != null)
                {
                    yield return(newTask);
                }
            }
        }
コード例 #2
0
 internal CompareProgress(CompareTask task)
 {
     this.Task = task;
 }