public static bool SetWorkPath(string workPath, string name, string repo) { if (!string.IsNullOrEmpty(value: workPath)) { Config.workPath = workPath; } if (string.IsNullOrEmpty(value: name) || string.IsNullOrEmpty(value: repo)) { Config.name = ConfigurationManager.AppSettings[name : $"name{count}"]; Config.repo = ConfigurationManager.AppSettings[name : $"repo{count}"]; } else { Config.name = name; Config.repo = repo; } ID = ConfigurationManager.AppSettings[name : $"ID{count}"]; filter = Convert.ToBoolean(ConfigurationManager.AppSettings[name: $"filter{count}"]); if (string.IsNullOrEmpty(value: ID)) { url = $"https://raw.githubusercontent.com/{Config.name}/{Config.repo}/master/"; } else { url = $"https://gitlab.com/{Config.name}/{Config.repo}/raw/master/"; } if (!Directory.Exists(path: infoPath)) { Directory.CreateDirectory(path: infoPath); } SHAFile = Path.Combine(path1: infoPath, path2: $"version{count}.txt"); errorFile = Path.Combine(path1: infoPath, path2: $"error{count}.txt"); if (File.Exists(path: SHAFile)) { oldSHA = File.ReadAllText(path: SHAFile, encoding: Encoding.UTF8); } // The URL to Get the Latest SHA Key of Commit string temp; if (string.IsNullOrEmpty(value: ID)) { temp = $"https://api.github.com/repos/{Config.name}/{Config.repo}/branches/master"; newSHA = JsonConvert.DeserializeObject <RootObject>(value: MyHttp.GetHtmlContent(requestUriString: temp)).commit.commit.tree.sha; } else { temp = $"https://gitlab.com/api/v4/projects/{ID}/repository/branches/master"; newSHA = JsonConvert.DeserializeObject <Root>(value: MyHttp.GetHtmlContent(requestUriString: temp)).commit.id; } return(true); }
public static void MakeFileinfo(string SHA, ConcurrentDictionary <string, string> fileinfo) { if (string.IsNullOrEmpty(value: Config.ID)) { // The URL to Get the Filelist string temp = $"https://api.github.com/repos/{Config.name}/{Config.repo}/git/trees/{SHA}?recursive=1"; List <Tree> tree = JsonConvert.DeserializeObject <RootObject>(value: MyHttp.GetHtmlContent(requestUriString: temp)).tree; //所有文件 Parallel.ForEach(tree, index => { if (index.type == "blob") { string fileName = Path.GetFileName(path: index.path); if (fileName.EndsWith(value: "Thumbs.db", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: ".gitattributes", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: ".gitignore", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "LICENSE", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "appveyor.yml", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: ".travis.yml", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "circle.yml", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "README.md", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "web.config", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "update-push.bat", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "update-server.bat", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "desktop.ini", comparisonType: StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(value: "start.htm", comparisonType: StringComparison.OrdinalIgnoreCase) || index.path == Assembly.GetExecutingAssembly().Location || index.path == $"{Assembly.GetExecutingAssembly().Location}.config" ) { return; } fileinfo.TryAdd(key: index.path, value: index.sha); } }); } else { for (int i = 1; true; i++) { // The URL to Get the Filelist string temp = $"https://gitlab.com/api/v4/projects/{Config.ID}/repository/tree?ref={SHA}&recursive=1&page={i}&per_page=100"; string body = MyHttp.GetHtmlContent(requestUriString: temp); if (body == "[]") { break; } List <Root> root = JsonConvert.DeserializeObject <List <Root> >(value: body); //所有文件 Parallel.ForEach(root, index => { if (index.type == "blob") { if (index.name.EndsWith(value: "Thumbs.db", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: ".gitattributes", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: ".gitignore", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "LICENSE", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "appveyor.yml", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: ".travis.yml", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "circle.yml", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "README.md", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "web.config", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "update-push.bat", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "update-server.bat", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "desktop.ini", comparisonType: StringComparison.OrdinalIgnoreCase) || index.name.EndsWith(value: "start.htm", comparisonType: StringComparison.OrdinalIgnoreCase) || index.path == Assembly.GetExecutingAssembly().Location || index.path == $"{Assembly.GetExecutingAssembly().Location}.config" ) { return; } fileinfo.TryAdd(key: index.path, value: index.id); } }); } } }