示例#1
0
 internal bool ExcludeFile(FileInfo file)
 {
     if (ContainsSearchForFiles)
     {
         return(ExcludeFiles.Any(f => file.Name.Contains(f)));
     }
     else
     {
         return(ExcludeFiles.Contains(file.Name));
     }
 }
示例#2
0
        private IEnumerable <string> GetExlusionPatterns()
        {
            IEnumerable <string> patterns = ExcludeFiles.Select(
                e => Utils.ConvertToRegexPattern(e.ItemSpec)) ?? Enumerable.Empty <string>();

            foreach (string pattern in patterns)
            {
                Log.LogMessage(MessageImportance.Low, $"Adding exclusion pattern: {pattern}");
            }

            return(patterns);
        }
示例#3
0
        public IEnumerable <SlimFileInfo> EnumerateFiles(string filePath, string pattern = "*", SearchOption option = SearchOption.AllDirectories)
        {
            Files = Directory.EnumerateFiles(filePath, pattern, option)
                    .Select(x => new SlimFileInfo(x, filePath));

            // Exclude files under specified directories (respect directory structure)
            if (ExcludeDirectories != null && ExcludeDirectories.Any())
            {
                Files = Files.Where(x => !ExcludeDirectories.Any(y => x.MultiplatformRelativeDirectory.StartsWith(y)));
            }

            // Exclude specified name files (Just matching filename, ignore directory structure.)
            if (ExcludeFiles != null && ExcludeFiles.Any())
            {
                Files = Files.Where(x => !ExcludeFiles.Contains(x.FileName));
            }
            return(Files);
        }
示例#4
0
        private void AddFilesToTargetAndRecurse(string absPath, string relPath, List <string> ExcludeFiles = null, List <string> ExcludeFolders = null, bool Optional = false)
        {
            if (ExcludeFiles == null)
            {
                ExcludeFiles = new List <string>();
            }
            ExcludeFiles.Add(@".*\.lastcodeanalysissucceeded");
            if (!Program.YamlData.Deploy.Debug)
            {
                ExcludeFiles.Add(@".*\.pdb");
            }
            ExcludeFiles.Add(@".*\.d\.ts");
            if (ExcludeFolders == null)
            {
                ExcludeFolders = new List <string>();
            }
            ExcludeFolders.Add(@"\.git");

            if (File.Exists(Path.Combine(absPath, DONTDEPLOY)))
            {
                return;
            }

            if (!Directory.Exists(absPath))
            {
                if (Optional)
                {
                    return;
                }
                throw new Error($"Folder {absPath} does not exist");
            }

            string[] files = Directory.GetFiles(absPath);
            foreach (string file in files)
            {
                bool   exclude  = false;
                string filename = Path.GetFileName(file);
                foreach (string excludeFile in ExcludeFiles)
                {
                    if (LikeString(filename, excludeFile))
                    {
                        exclude = true;
                        break;
                    }
                }
                if (!exclude)
                {
                    Console.WriteLine("Copying {0}", file);

                    // Check for minimal length (most files should be > 0 (or > 3 Unicode)
                    long length = new System.IO.FileInfo(file).Length;
                    if (length <= 3 && !file.Contains("node_modules\\") && !file.Contains("node_modules/"))
                    {
                        if ((file.EndsWith(".ts") && !file.EndsWith(".d.ts")) || file.EndsWith(".css") || file.EndsWith(".js"))
                        {
                            throw new Error($"File {file} is empty");
                        }
                    }
                    // Check for stray .js and .css files without filelistJS/CSS.txt in Addons folder
                    if (file.EndsWith(".css") && ((!file.Contains(@"/node_modules/") && file.Contains(@"/Addons/")) || (!file.Contains(@"\\node_modules\\") && file.Contains(@"\\Addons\\"))))
                    {
                        string dir       = file;
                        int    maxLevels = 3;
                        for (; ;)
                        {
                            dir = Path.GetDirectoryName(dir);
                            if (File.Exists(Path.Combine(dir, "filelistCSS.txt")))
                            {
                                break;
                            }
                            --maxLevels;
                            if (maxLevels == 0)
                            {
                                throw new Error($"File {file} found without filelistCSS.txt");
                            }
                        }
                    }
                    if (file.EndsWith(".js") && ((!file.Contains(@"/node_modules/") && file.Contains(@"/Addons/")) || (!file.Contains(@"\node_modules\") && file.Contains(@"\Addons\"))))
                    {
                        string dir       = file;
                        int    maxLevels = 3;
                        for (; ;)
                        {
                            dir = Path.GetDirectoryName(dir);
                            if (File.Exists(Path.Combine(dir, "filelistJS.txt")))
                            {
                                break;
                            }
                            --maxLevels;
                            if (maxLevels == 0)
                            {
                                throw new Error($"File {file} found without FilelistJS.txt");
                            }
                        }
                    }

                    string relFile    = Path.Combine(relPath, filename);
                    string searchFile = BackupZipFile.CleanFileName(relFile);//$$$$verify
                    if (BackupTargetZip != null)
                    {
                        bool found = (from e in BackupTargetZip.Entries where e.RelativeName == searchFile select e).Any();
                        if (!found)
                        {
                            BackupTargetZip.AddFile(file, relFile);
                        }
                    }
                    if (BackupTargetFolder != null)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(BackupTargetFolder, relFile)));
                        File.Copy(file, Path.Combine(BackupTargetFolder, relFile));
                    }
                }
            }
            string[] dirs = Directory.GetDirectories(absPath);
            foreach (string dir in dirs)
            {
                bool   exclude = false;
                string folder  = Path.GetFileName(dir);
                if (ExcludeFolders != null)
                {
                    foreach (string excludeFolder in ExcludeFolders)
                    {
                        if (LikeString(folder, excludeFolder))
                        {
                            exclude = true;
                            break;
                        }
                    }
                }
                if (!exclude)
                {
                    Console.WriteLine("Copying folder {0}", folder);
                    AddFilesToTargetAndRecurse(dir, Path.Combine(relPath, folder), ExcludeFiles, ExcludeFolders);
                }
            }
            if (files.Length == 0 && dirs.Length == 0)
            {
                // no files or folders, just add the folder in the ZIP file
                // some modules/data providers check folder existence to determine whether the module is installed
                if (BackupTargetZip != null)
                {
                    //$$$$BackupTargetZip.AddDirectoryByName(relPath);
                }
                if (BackupTargetFolder != null)
                {
                    string absFolder = Path.Combine(BackupTargetFolder, relPath);
                    Directory.CreateDirectory(absFolder);
                }
            }
        }
示例#5
0
        public void AddItem(VssProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            else if (project.Database != Database)
            {
                throw new ArgumentException("Project database mismatch", "project");
            }

            rootProjects.AddLast(project);

            PathMatcher exclusionMatcher = null;

            if (!string.IsNullOrEmpty(ExcludeFiles))
            {
                var excludeFileArray = ExcludeFiles.Split(
                    new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                exclusionMatcher = new PathMatcher(excludeFileArray);
            }

            workQueue.AddLast(delegate(object work)
            {
                logger.WriteSectionSeparator();
                LogStatus(work, "Building revision list");

                logger.WriteLine("Root project: {0}", project.Path);
                logger.WriteLine("Excluded files: {0}", ExcludeFiles);

                var excludedProjects = 0;
                var excludedFiles    = 0;
                var stopwatch        = Stopwatch.StartNew();
                VssUtil.RecurseItems(project,
                                     delegate(VssProject subproject)
                {
                    if (workQueue.IsAborting)
                    {
                        return(RecursionStatus.Abort);
                    }

                    var path = subproject.Path;
                    if (exclusionMatcher != null && exclusionMatcher.Matches(path))
                    {
                        logger.WriteLine("Excluding project {0}", path);
                        ++excludedProjects;
                        return(RecursionStatus.Skip);
                    }

                    ProcessItem(subproject, path, exclusionMatcher);
                    ++projectCount;
                    return(RecursionStatus.Continue);
                },
                                     delegate(VssProject subproject, VssFile file)
                {
                    if (workQueue.IsAborting)
                    {
                        return(RecursionStatus.Abort);
                    }

                    var path = file.GetPath(subproject);
                    if (exclusionMatcher != null && exclusionMatcher.Matches(path))
                    {
                        logger.WriteLine("Excluding file {0}", path);
                        ++excludedFiles;
                        return(RecursionStatus.Skip);
                    }

                    // only process shared files once (projects are never shared)
                    if (!ProcessedFiles.Contains(file.PhysicalName))
                    {
                        ProcessedFiles.Add(file.PhysicalName);
                        ProcessItem(file, path, exclusionMatcher);
                        ++fileCount;
                    }
                    return(RecursionStatus.Continue);
                });
                stopwatch.Stop();

                logger.WriteSectionSeparator();
                logger.WriteLine("Analysis complete in {0:HH:mm:ss}", new DateTime(stopwatch.ElapsedTicks));
                logger.WriteLine("Projects: {0} ({1} excluded)", projectCount, excludedProjects);
                logger.WriteLine("Files: {0} ({1} excluded)", fileCount, excludedFiles);
                logger.WriteLine("Revisions: {0}", revisionCount);
            });
        }
        /// <summary>
        /// 生成控制器
        /// </summary>
        public void BuildControllers()
        {
            JsEncryption jsEncryption = new JsEncryption();

            if (string.IsNullOrEmpty(InFolderPath))
            {
                throw new ArgumentNullException("FolderPath");
            }
            if (string.IsNullOrEmpty(OutFolderPath))
            {
                throw new ArgumentNullException("OutFolderPath");
            }
            if (string.IsNullOrEmpty(NameSpace))
            {
                throw new ArgumentNullException("NameSpace");
            }
            if (string.IsNullOrEmpty(ControllerName))
            {
                throw new ArgumentNullException("ControllerName");
            }

            var setting = this;

            if (setting.InFolderPath.EndsWith("\\") == false)
            {
                setting.InFolderPath += "\\";
            }
            if (setting.OutFolderPath.EndsWith("\\") == false)
            {
                setting.OutFolderPath += "\\";
            }

            var jseFile = new List <string>();

            foreach (var item in JsEncryptionFiles)
            {
                jseFile.Add(Path.GetFullPath(item));
            }


            var files = Directory.GetFiles(setting.InFolderPath, "*.*", SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; i++)
            {
                var file = files[i];
                if (ExcludeFileSuffixs != null && ExcludeFileSuffixs.Count > 0)
                {
                    var isExclude = false;
                    foreach (var suffix in ExcludeFileSuffixs)
                    {
                        if (file.EndsWith(suffix))
                        {
                            isExclude = true; break;
                        }
                    }
                    if (isExclude)
                    {
                        continue;
                    }
                }
                if (ExcludeFiles != null && ExcludeFiles.Count > 0)
                {
                    if (ExcludeFiles.Contains(Path.GetFileName(file)))
                    {
                        continue;
                    }
                }

                Console.WriteLine("Load:" + file);
                var bytes = File.ReadAllBytes(file);

                WwwRootFile wwwRootFile = new WwwRootFile()
                {
                    FilePath = file,
                    //FileContent = Convert.ToBase64String(bytes),
                    FileHash = HashUtil.GetMd5String(bytes),
                    FileName = Path.GetFileName(file),
                };
                if (jseFile.Contains(file) && file.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
                {
                    wwwRootFile.FileContent = wwwRootFile.GetFileContent(bytes, file, CompressionType);
                    if (string.IsNullOrWhiteSpace(wwwRootFile.FileContent) == false)
                    {
                        var c = Encoding.UTF8.GetString(bytes);
                        var t = jsEncryption.BuildTemplate(c);
                        c = Convert.ToBase64String(Encoding.UTF8.GetBytes(t));
                        wwwRootFile.FileContent = c;
                    }
                }
                else
                {
                    wwwRootFile.FileContent = wwwRootFile.GetFileContent(bytes, file, CompressionType);
                }
                wwwRootFile.FileMime   = wwwRootFile.GetFileMime(file);
                wwwRootFile.FileUrl    = file.Substring(setting.InFolderPath.Length).Replace("\\", "/").TrimStart('/');
                wwwRootFile.FileMethod =
                    Regex.Replace(wwwRootFile.FileUrl,
                                  "[^0-9_a-zA-Z\u4E00-\u9FCB\u3400-\u4DB5\u20000-\u2A6D6\u2A700-\u2B734\u2B740-\u2B81D\u3007]", "_");


                var txt = setting.Template;
                if (i == 0)
                {
                    if (CompressionType == "gzip")
                    {
                        txt = setting.gzipFirstTemplate;
                    }
                    else
                    {
                        txt = setting.brFirstTemplate;
                    }
                }
                txt = txt.Replace("{NameSpace}", setting.NameSpace);
                txt = txt.Replace("{ControllerName}", setting.ControllerName);
                txt = txt.Replace("{FileUrl}", wwwRootFile.FileUrl);
                txt = txt.Replace("{FileMethod}", wwwRootFile.FileMethod);
                txt = txt.Replace("{FileHash}", wwwRootFile.FileHash);
                txt = txt.Replace("{FileContent}", wwwRootFile.FileContent);
                txt = txt.Replace("{FileMime}", wwwRootFile.FileMime);

                var outPath = file.Replace(setting.InFolderPath, setting.OutFolderPath) + ".cs";
                Directory.CreateDirectory(Path.GetDirectoryName(outPath));

                File.WriteAllText(outPath, txt);
                Console.WriteLine("Out:" + outPath);
            }
        }
示例#7
0
        internal string Parse()
        {
            var options = new StringBuilder();

            #region Set Options

            if (OnlyCopyArchiveFiles)
            {
                options.Append(ONLY_COPY_ARCHIVE_FILES);
            }
            if (OnlyCopyArchiveFilesAndResetArchiveFlag)
            {
                options.Append(ONLY_COPY_ARCHIVE_FILES_AND_RESET_ARCHIVE_FLAG);
            }
            if (!IncludeAttributes.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(INCLUDE_ATTRIBUTES, IncludeAttributes.CleanOptionInput()));
            }
            if (!ExcludeAttributes.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(EXCLUDE_ATTRIBUTES, ExcludeAttributes.CleanOptionInput()));
            }
            if (!ExcludeFiles.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(EXCLUDE_FILES, ExcludeFiles));
            }
            if (!ExcludeDirectories.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(EXCLUDE_DIRECTORIES, ExcludeDirectories));
            }
            if (ExcludeChanged)
            {
                options.Append(EXCLUDE_CHANGED);
            }
            if (ExcludeNewer)
            {
                options.Append(EXCLUDE_NEWER);
            }
            if (ExcludeOlder)
            {
                options.Append(EXCLUDE_OLDER);
            }
            if (ExcludeExtra)
            {
                options.Append(EXCLUDE_EXTRA);
            }
            if (ExcludeLonely)
            {
                options.Append(EXCLUDE_LONELY);
            }
            if (IncludeSame)
            {
                options.Append(INCLUDE_SAME);
            }
            if (IncludeTweaked)
            {
                options.Append(INCLUDE_TWEAKED);
            }
            if (MaxFileSize > 0)
            {
                options.Append(string.Format(MAX_FILE_SIZE, MaxFileSize));
            }
            if (MinFileSize > 0)
            {
                options.Append(string.Format(MIN_FILE_SIZE, MinFileSize));
            }
            if (!MaxFileAge.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MAX_FILE_AGE, MaxFileAge.CleanOptionInput()));
            }
            if (!MinFileAge.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MIN_FILE_AGE, MinFileAge.CleanOptionInput()));
            }
            if (!MaxLastAccessDate.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MAX_LAST_ACCESS_DATE, MaxLastAccessDate.CleanOptionInput()));
            }
            if (!MinLastAccessDate.IsNullOrWhiteSpace())
            {
                options.Append(string.Format(MIN_LAST_ACCESS_DATE, MinLastAccessDate.CleanOptionInput()));
            }
            if (ExcludeJunctionPoints)
            {
                options.Append(EXCLUDE_JUNCTION_POINTS);
            }
            if (ExcludeJunctionPointsForDirectories)
            {
                options.Append(EXCLUDE_JUNCTION_POINTS_FOR_DIRECTORIES);
            }
            if (ExcludeJunctionPointsForFiles)
            {
                options.Append(EXCLUDE_JUNCTION_POINTS_FOR_FILES);
            }
            if (UseFatFileTimes)
            {
                options.Append(USE_FAT_FILE_TIMES);
            }
            if (CompensateForDstDifference)
            {
                options.Append(COMPENSATE_FOR_DST_DIFFERENCE);
            }

            #endregion Set Options

            return(options.ToString());
        }
示例#8
0
        static void EvaluateArguments(string[] args)
        {
            // BucketName=nantokakantokabucket
            BucketName = args.Where(x => x.StartsWith(ArgumentType.BucketName.ToString(), StringComparison.InvariantCultureIgnoreCase))
                         .SelectMany(x => x.SplitEx("="))
                         .LastOrDefault()
                         ?? GetEnvValueString(ArgumentType.BucketName, EnvType.S3Sync_BucketName);

            // LocalRoot=c:\hogemoge
            LocalRoot = args.Where(x => x.StartsWith(ArgumentType.LocalRoot.ToString(), StringComparison.InvariantCultureIgnoreCase))
                        .SelectMany(x => x.SplitEx("="))
                        .LastOrDefault()
                        ?? GetEnvValueString(ArgumentType.LocalRoot, EnvType.S3Sync_LocalRoot);

            // KeyPrefix=image
            KeyPrefix = args.Where(x => x.StartsWith(ArgumentType.KeyPrefix.ToString(), StringComparison.InvariantCultureIgnoreCase))
                        .SelectMany(x => x.SplitEx("="))
                        .LastOrDefault()
                        ?.TrimEnd('/')
                        ?? GetEnvValueString(ArgumentType.KeyPrefix, EnvType.S3Sync_KeyPrefix);

            // IgnoreKeyPrefix=image
            IgnoreKeyPrefix = args.Where(x => x.StartsWith(ArgumentType.IgnoreKeyPrefix.ToString(), StringComparison.InvariantCultureIgnoreCase))
                              .SelectMany(x => x.SplitEx("="))
                              .LastOrDefault()
                              ?.TrimEnd('/')
                              ?? GetEnvValueString(ArgumentType.IgnoreKeyPrefix, EnvType.S3Sync_IgnoreKeyPrefix);

            // ExcludeFiles=hogemoge,fugafuga
            ExcludeFiles = args.Where(x => x.StartsWith(ArgumentType.ExcludeFiles.ToString(), StringComparison.InvariantCultureIgnoreCase))
                           .SelectMany(x => x.SplitEx("="))
                           .LastOrDefault()
                           ?.SplitEx(",")
                           .Select(x => x.Trim())
                           .ToArray()
                           ?? GetEnvValueString(ArgumentType.ExcludeFiles, EnvType.S3Sync_ExcludeFiles)
                           ?.SplitEx(",");

            // ExcludeDirectories=hogemoge,fugafuga
            ExcludeDirectories = args.Where(x => x.StartsWith(ArgumentType.ExcludeDirectories.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                 .SelectMany(x => x.SplitEx("="))
                                 .LastOrDefault()
                                 ?.SplitEx(",")
                                 ?.Select(x => x.Trim())
                                 .ToArray()
                                 ?? GetEnvValueString(ArgumentType.ExcludeDirectories, EnvType.S3Sync_ExcludeDirectories)
                                 ?.SplitEx(",");

            // Silent=false
            Silent = bool.Parse(args.Where(x => x.StartsWith(ArgumentType.Silent.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                .SelectMany(x => x.SplitEx("="))
                                .Where(x => string.Equals(x, "true", StringComparison.InvariantCultureIgnoreCase) || string.Equals(x, "false", StringComparison.InvariantCultureIgnoreCase))
                                .LastOrDefault()
                                ?.Trim()
                                ?? GetEnvValueString(ArgumentType.Silent, EnvType.S3Sync_Silent)
                                ?? "false");

            // CredentialProfile=ProfileName
            CredentialProfile = args.Where(x => x.StartsWith(ArgumentType.CredentialProfile.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                .SelectMany(x => x.SplitEx("="))
                                .LastOrDefault()
                                ?.Trim()
                                ?? GetEnvValueString(ArgumentType.CredentialProfile, EnvType.S3Sync_CredentialProfile);

            // DryRun=true
            Option.DryRun = bool.Parse(args.Where(x => x.StartsWith(ArgumentType.DryRun.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                       .SelectMany(x => x.SplitEx("="))
                                       .Where(x => string.Equals(x, "true", StringComparison.InvariantCultureIgnoreCase) || string.Equals(x, "false", StringComparison.InvariantCultureIgnoreCase))
                                       .LastOrDefault()
                                       ?.Trim()
                                       ?? GetEnvValueString(ArgumentType.DryRun, EnvType.S3Sync_DryRun)
                                       ?? "true");

            // ContentType=application/json
            Option.ContentType = args.Where(x => x.StartsWith(ArgumentType.ContentType.ToString(), StringComparison.InvariantCultureIgnoreCase))
                                 .SelectMany(x => x.SplitEx("="))
                                 .LastOrDefault()
                                 ?.TrimEnd('/')
                                 ?? GetEnvValueString(ArgumentType.ContentType, EnvType.S3Sync_ContentType);

            // Region=us-east-1
            Option.Region = args.Where(x => x.StartsWith(ArgumentType.Region.ToString(), StringComparison.InvariantCultureIgnoreCase))
                            .SelectMany(x => x.SplitEx("="))
                            .LastOrDefault()
                            ?.TrimEnd('/')
                            ?? GetEnvValueString(ArgumentType.Region, EnvType.S3Sync_Region);

            // Show Arguments
            Log($"{nameof(BucketName)} : {BucketName}");
            Log($"{nameof(LocalRoot)} : {LocalRoot}");
            Log($"{nameof(KeyPrefix)} : {KeyPrefix}");
            Log($"{nameof(IgnoreKeyPrefix)} : {IgnoreKeyPrefix}");
            Log($"{nameof(ExcludeFiles)} : {ExcludeFiles?.ToJoinedString(",")}");
            Log($"{nameof(ExcludeDirectories)} : {ExcludeDirectories?.ToJoinedString(",")}");
            Log($"{nameof(Silent)} : {Silent}");
            Log($"{nameof(CredentialProfile)} : {CredentialProfile}");
            Log($"{nameof(Option.DryRun)} : {Option.DryRun}");
            Log($"{nameof(Option.ContentType)} : {Option.ContentType}");
            Log($"{nameof(Option.Region)} : {Option.Region}");

            // Validate Required arguments
            if (string.IsNullOrWhiteSpace(BucketName))
            {
                Error("Please pass arguments. See detail followings.");
                PrintHelp();
                throw new NullReferenceException(nameof(BucketName));
            }

            if (string.IsNullOrWhiteSpace(LocalRoot))
            {
                Error("Please pass arguments. See detail followings.");
                PrintHelp();
                throw new NullReferenceException(nameof(LocalRoot));
            }
        }