public async Task GitPullFromRepositoryAsync(string repositoryPath, string localDir, string branch, CancellationToken cancel = default) { string gitUrl = this.Settings.GitLabBaseUrl._CombineUrl(repositoryPath + ".git").ToString(); gitUrl = gitUrl._ReplaceStr("https://", $"https://*****:*****@"); await Lfs.CreateDirectoryAsync(localDir); // localDir ディレクトリに .git ディレクトリは存在するか? string dotgitDir = localDir._CombinePath(".git"); bool init = false; StrDictionary <string> envVars = new StrDictionary <string>(); // empty config string emptyCfgPath = Env.MyLocalTempDir._CombinePath("empty.txt"); using (await Lock1.LockWithAwait(cancel)) { if (await Lfs.IsFileExistsAsync(emptyCfgPath, cancel) == false) { await Lfs.WriteStringToFileAsync(emptyCfgPath, "\n\n", cancel : cancel); } } envVars.Add("GIT_CONFIG_GLOBAL", emptyCfgPath); envVars.Add("GIT_CONFIG_SYSTEM", emptyCfgPath); if (await Lfs.IsDirectoryExistsAsync(dotgitDir, cancel)) { try { // update を試みる await EasyExec.ExecAsync(this.GitExe, $"pull origin {branch}", localDir, cancel : cancel, additionalEnvVars : envVars); } catch (Exception ex) { ex._Error(); init = true; } } else { init = true; } if (init) { // 初期化する await Lfs.DeleteDirectoryAsync(localDir, true, cancel : cancel, forcefulUseInternalRecursiveDelete : true); // git clone をする await EasyExec.ExecAsync(this.GitExe, $"clone {gitUrl} {localDir}", cancel : cancel, additionalEnvVars : envVars); // update を試みる await EasyExec.ExecAsync(this.GitExe, $"pull origin {branch}", localDir, cancel : cancel, additionalEnvVars : envVars); } }
protected static StrDictionary ParseMime(IEnumerator enumerator, byte[] data) { StrDictionary table = new StrDictionary(); string name = null; string val = null; int startpos = 0; int endpos = 0; bool gettingval = false; while (enumerator.MoveNext()) { if ((byte)enumerator.Current == 13) { // no name specified -> end of header (presumably \r\n\r\n) if (startpos == endpos && !gettingval) { enumerator.MoveNext(); return(table); } val = Encoding.UTF8.GetString(data, startpos, endpos - startpos); if (!table.ContainsKey(name)) { table.Add(name, val); } startpos = endpos + 2; gettingval = false; } else if ((byte)enumerator.Current == 58) //: { if (!gettingval) { gettingval = true; name = Encoding.UTF8.GetString(data, startpos, endpos - startpos); startpos = endpos + 2; enumerator.MoveNext(); endpos++; } } endpos++; } return(table); }
public static void ParseQuery(string query, StrDictionary sd) { string[] pairs = query.Split(new char[] { '&' }); foreach (string p in pairs) { string[] kv = p.Split(new char[] { '=' }); if (kv.Length < 2) continue; sd.Add(kv[0], System.Web.HttpUtility.UrlDecode(kv[1])); } }
private void ParseAttr(XmlReader r,out StrDictionary sd) { sd = new StrDictionary(); StringBuilder sz = new StringBuilder(); while(r.MoveToNextAttribute()) { //r.GetAttribute() //r.AttributeCount sd.Add(r.Name, r.Value); } r.MoveToElement(); }
static StrDictionary ReadConfig() { XmlReaderSettings s = new XmlReaderSettings(); s.CloseInput = true; s.IgnoreComments = true; s.IgnoreWhitespace = true; XmlReader r = XmlReader.Create("config.xml", s); StrDictionary config = new StrDictionary(); try { while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { if (r.Name == "config") { if (r.HasAttributes) { config.Add("server", r.GetAttribute("server")); config.Add("dbname", r.GetAttribute("dbname")); } } else if (r.Name == "table") { if (r.HasAttributes) { config.Add(r.GetAttribute("name"), r.ReadString()); //r.MoveToElement(); } } } } } catch (System.Exception ex) { //MessageBox.Show(ex.Message); GlobalVar.Log.LogError(ex.Message, "SyncThread-ReadConfig"); } finally { if (r != null) r.Close(); } return config; }