コード例 #1
0
    public static ITask UpdateIndexFromFilesInFolderTask(SPath folderWithFiles, SPath indexFileToGenerate, SPath?indexTemplate = null)
    {
        Index?templateIndex = null;

        if (indexTemplate.HasValue && indexTemplate.Value.FileExists())
        {
            templateIndex = Index.Load(indexTemplate);
        }
        folderWithFiles = folderWithFiles.MakeAbsolute();
        var dt = DateTimeOffset.Now.Date.ToString("yyyyMMdd");
        TaskQueue <Asset> hashTask = new TaskQueue <Asset>(TaskManager)
        {
            Message = "Calculating hashes..."
        };

        foreach (var file in folderWithFiles.Files())
        {
            Asset asset = default;

            if ((templateIndex?.Assets.Any(x => x.Filename == file.FileName)) ?? false)
            {
                var templateAsset = templateIndex.Value.Assets.First(x => x.Filename == file.FileName);
                asset.LocalPath = file;
                asset.Path      = templateAsset.Path;
                asset.Url       = templateAsset.Url.Combine("assets")
                                  .Combine(dt)
                                  .Combine(file.FileName);
                asset.NeedsUnzip = templateAsset.NeedsUnzip;
            }
            else
            {
                asset.LocalPath  = file;
                asset.Path       = file.FileNameWithoutExtension.ToSPath();
                asset.NeedsUnzip = file.ExtensionWithDot == ".zip" ? true : false;
                asset.Url        = $"{DefaultWebServerUrl}:{DefaultWebServerPort}/assets/{dt}/{file.FileName}";
            }

            hashTask.Queue(new FuncTask <Asset, Asset>(TaskManager, (_, x) => {
                x.Hash      = x.LocalPath.ToMD5();
                x.LocalPath = default;
                return(x);
            },
                                                       () => asset)
            {
                Message = file.FileName
            });
コード例 #2
0
        private void UpdateLocalBranches(Dictionary <string, ConfigBranch> branches, SPath path, IEnumerable <ConfigBranch> configBranches, string prefix)
        {
            foreach (var file in path.Files())
            {
                var branchName = prefix + file.FileName;
                var branch     =
                    configBranches.Where(x => x.Name == branchName).Select(x => x as ConfigBranch?).FirstOrDefault();
                if (!branch.HasValue)
                {
                    branch = new ConfigBranch(branchName);
                }
                branches.Add(branchName, branch.Value);
            }

            foreach (var dir in path.Directories())
            {
                UpdateLocalBranches(branches, dir, configBranches, prefix + dir.FileName + "/");
            }
        }