Exemple #1
0
        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, info =>
            {
                switch (info)
                {
                case FileInfo fileInfo:
                    return(FileLock.IsLockFile(fileInfo) || fileInfo.Extension.EndsWith("binlog"));

                default:
                    return(false);
                }
            });

            Package copy;

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

            return(copy);
        }