コード例 #1
0
ファイル: Package.cs プロジェクト: zeroyou/try
        public static async Task <Package> Copy(
            Package fromPackage,
            string folderNameStartsWith       = null,
            bool isRebuildable                = false,
            IScheduler buildThrottleScheduler = null,
            DirectoryInfo parentDirectory     = null)
        {
            if (fromPackage == null)
            {
                throw new ArgumentNullException(nameof(fromPackage));
            }

            await fromPackage.EnsureReady(new Budget());

            folderNameStartsWith = folderNameStartsWith ?? fromPackage.Name;
            parentDirectory      = parentDirectory ?? fromPackage.Directory.Parent;

            var destination =
                CreateDirectory(folderNameStartsWith,
                                parentDirectory);

            fromPackage.Directory.CopyTo(destination);

            var binLogs = destination.GetFiles("*.binlog");

            foreach (var fileInfo in binLogs)
            {
                fileInfo.Delete();
            }

            Package copy;

            if (isRebuildable)
            {
                copy = new RebuildablePackage(directory: destination, name: destination.Name, buildThrottleScheduler: buildThrottleScheduler)
                {
                    IsDirectoryCreated = true
                };
            }
            else
            {
                copy = new NonrebuildablePackage(directory: destination, name: destination.Name, buildThrottleScheduler: buildThrottleScheduler)
                {
                    IsDirectoryCreated = true
                };
            }

            Log.Info(
                "Copied workspace {from} to {to}",
                fromPackage,
                copy);

            return(copy);
        }