/// <summary> ///根据本地文件解析出能使用的NPC公司数据 /// </summary> public static void ReadAndParseNpcCorpGroup() { var @default = YamlTools.Read <Dictionary <int, NpcCorporations> >("Resources/npcCorporations.yaml"); //YamlFilter.NpcCorporations(@default, out var @new); FPS.FileReader.Read("Resources/npcCorporations.txt", out string contents); // 反转字典,用于反向构造映射关系 Dictionary <string, int> @neww = new Dictionary <string, int>(); foreach (var n in @default) { if ([email protected](n.Value.nameID.zh)) { @neww.Add(n.Value.nameID.zh, n.Key); } } var strs = contents.Split('\n'); Dictionary <int, NewNpcCorporations> tmncc = new Dictionary <int, NewNpcCorporations>(); List <TmpNc> tmncs = new List <TmpNc>(); // nc用来存txt解析出来的数据 // ncc用来构造新模板实例 bool title = true; int tmncsIndex = 0; for (int i = 0; i < strs.Length; i++) { var name = strs[i].Replace("\r", ""); if (title) { title = false; tmncs.Add(new TmpNc(name)); continue; } if (name.Contains("//")) { title = true; tmncsIndex++; continue; } tmncs[tmncsIndex].AddSub(name, 0); } int tmnccIndex = 0; foreach (var n in tmncs) { var tmnc = new NewNpcCorporations(tmnccIndex, n.name); tmncc.Add(tmnccIndex, tmnc); foreach (var n1 in n.subs) { @neww.TryGetValue(n1.Key, out int id); tmnc.AddSub(new NewNpcCorporations(id, n1.Key)); } tmnccIndex++; } YamlTools.Write(tmncc, "Resources/newNpcCorporations.yaml"); }
static void Main(string[] args) { try { string Root = null; #if DEBUG Root = Path.GetFullPath(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, @"..\..\..\..\", @"HMZ-Software\wwwroot\Blog")); #else Root = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"HMZ-Software\wwwroot\Blog")); #endif //Here we used the GetCurrentDirectory because the working directory is set via Azure Pipelines. string Domain = "https://www.hamzialsheikh.tk"; Console.WriteLine("Cleaning up..."); FileOps.CleanSite(Root); Console.WriteLine("Building the Markdig pipeline and compiling posts if they exist..."); var PostDocuments = MarkupCompilerFactory.GetOrCreate().CompileMarkdown(Root); string MainSiteDataPath = Path.Combine(Root, "Site"); Console.WriteLine("Creating the necessary directories if they're not already created..."); Directory.CreateDirectory(Path.Combine(MainSiteDataPath, "Metadata")); Directory.CreateDirectory(Path.Combine(MainSiteDataPath, "Site")); Console.WriteLine("Writing the compiled data to files in a form of .html and .yml..."); foreach (var Document in PostDocuments) { using (StreamWriter markdownStreamWriter = File.CreateText(Path.Combine(MainSiteDataPath, Document.Yaml.FileName) + ".html")) { markdownStreamWriter.Write(Document.Markdown); } using (StreamWriter yamlStreamWriter1 = File.CreateText(Path.Combine(MainSiteDataPath, Document.Yaml.FileName) + ".yml")) { yamlStreamWriter1.Write(YamlTools.SerializeYaml(Document.Yaml)); } } var YamlMetadata = PostDocuments.Select(p => p.Yaml).ToList(); Console.WriteLine("Constructing blog metadata..."); MetadataTool.ConstructMetadata(Root, YamlMetadata); Console.WriteLine("Building \"Robots.txt\"..."); Seo.ConstructRobots(Domain, YamlMetadata, Root.Substring(0, Root.LastIndexOf('\\') + 1)); Console.WriteLine("Building \"Sitemap.xml\"..."); Seo.ConstructSitemap(Domain, YamlMetadata, Root.Substring(0, Root.LastIndexOf('\\') + 1)); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public async Task <BlogPostDocument> ProcessPostAsync(string Name) { return(new BlogPostDocument() { Html = await HttpClient.GetStringAsync($"/Blog/Site/{Name}.html"), Yaml = YamlTools .DeserializeYaml(await HttpClient.GetStringAsync($"Blog/Site/{Name}.yml")) }); }
public IEnumerable <BlogPostDocument> CompileMarkdown(string Root) { var PostDirectory = Path.Combine(Root, "Posts"); //Grab Markdown files var Paths = Directory.GetFiles(PostDirectory, "*.md"); if (Paths.Length == 0) { Console.WriteLine($"No posts found in {PostDirectory}!"); Environment.Exit(0); } List <BlogPostDocument> Docs = new List <BlogPostDocument>(); using (StringWriter stringWriter = new StringWriter()) { HtmlRenderer htmlRenderer = new HtmlRenderer(stringWriter); MarkdownPipeline.Setup(htmlRenderer); foreach (var Path in Paths) { var markdown = File.ReadAllText(Path); MarkdownDocument Document = Markdown.Parse(markdown, MarkdownPipeline); //Get yaml metadata var yamlBlock = Document.Descendants <YamlFrontMatterBlock>().FirstOrDefault(); if (yamlBlock == null) { throw new Exception($"File with path {Path} has no Yaml metadata!"); } string yaml = markdown.Substring(yamlBlock.Span.Start, yamlBlock.Span.Length); YamlMetadata yamlMetadata = YamlTools.DeserializeYaml(yaml); htmlRenderer.Render(Document); stringWriter.Flush(); string FileName = Path.Substring(Path.LastIndexOf('\\') + 1); FileName = FileName.Remove(FileName.LastIndexOf('.')); yamlMetadata.FileName = FileName; Docs.Add(new BlogPostDocument { Yaml = yamlMetadata, Markdown = stringWriter.ToString() }); } } return(Docs); }
/// <summary> /// 读取本地yaml配置文件 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <param name="onComplete">读取完毕后存入数据库</param> public static void ReadYaml <T>(string path, Action <T> onComplete) { try { onComplete?.Invoke(YamlTools.Read <T>(path)); } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); } }
public static void StartOAHelper(String path) { ProperNameController pnc = new ProperNameController(); Task.WaitAll( Directory.GetFiles(Directory.CreateDirectory(path).FullName, "*.yaml").Select(e => Task.Factory.StartNew(() => { try { var configdict = YamlTools.getResultMapFromYaml(e); foreach (String config in DataTools.getYamlArray(configdict.GetValueOrDefault("configs"))) { var aconfigdict = YamlTools.getResultMapFromYaml(config); aconfigdict.ToArray(); List <EmailValidatorConfigCol> emailValidatorConfigCols = new List <EmailValidatorConfigCol>(); foreach (String consolidation in DataTools.getYamlArray(aconfigdict.GetValueOrDefault("consolidationConfigs"))) { var aconsolidationConfig = YamlTools.getNodeMapFromYaml(consolidation); var aconsolidation = YamlTools.getResultMapFromYaml(consolidation); foreach (var vaddic in aconsolidationConfig["validation"].AllNodes.Where(n => n.NodeType == YamlNodeType.Mapping).Select(n => ((YamlMappingNode)n).Children.Select(entry => new KeyValuePair <string, string>(entry.Key.ToString(), entry.Value.ToString())).ToDictionary(prop => prop.Key, prop => prop.Value))) { //vaddic.ToArray(); emailValidatorConfigCols.Add(new EmailValidatorConfigCol(vaddic["macroSnippet"], vaddic["version"], vaddic.GetValueOrDefault("sheetName")) { new EmailValidatorConfig { ID = vaddic["path"], criteria = YamlTools.getResultMapFromYaml(vaddic["path"]), rejFolder = aconsolidation.GetValueOrDefault("rejfolder") ?? aconfigdict.GetValueOrDefault("rejFolder"), rejTemplate = new FileInfo(aconsolidation["rejTemplate"]), rejEmails = aconfigdict.GetValueOrDefault("rejRecipients")?.Split(";"), ResultMap = YamlTools.getResultMapFromYaml(aconfigdict.GetValueOrDefault("emailresponseMappingPath")), continueOnReject = aconsolidation.GetValueOrDefault("continueOnReject") == "true", rejectOnInvalid = aconsolidation.GetValueOrDefault("rejectOnInvalid") == "true", sucEmails = aconfigdict.GetValueOrDefault("sucRecipients")?.Split(";"), sucTemplate = String.IsNullOrWhiteSpace(aconsolidation.GetValueOrDefault("successTemplate"))?null:new FileInfo(aconsolidation["successTemplate"]), useCustomValidation = vaddic.GetValueOrDefault("useCustomValidation") == "true" } }); } } new MailStoreProcessor() { pnc = pnc }.process(new MailStoreConfig() { storename = configdict["mailStore"], rejfolder = aconfigdict["rejFolder"], savemailpath = aconfigdict.GetValueOrDefault("savemailpath") ?? configdict.GetValueOrDefault("savemailpath"), infolder = aconfigdict["inFolder"], sucfolder = aconfigdict["sucFolder"], validColsCol = emailValidatorConfigCols, sentonbehalf = aconfigdict.GetValueOrDefault("sentonbehalf") ?? configdict.GetValueOrDefault("sentonbehalf"), sucTemplate = new FileInfo(aconfigdict["successTemplate"]), retfolder = aconfigdict.GetValueOrDefault("returnFolder") ?? configdict.GetValueOrDefault("returnFolder"), restricter = aconfigdict["restricter"] ?? configdict.GetValueOrDefault("restricter") }, null, null); } } catch (Exception ex) { Logger.Log($"[{e}]{ex}"); Lasterror = ex; Lasterror.HelpLink = e; } }) ).ToArray()); }
/// <summary> /// 本地配置文件修改翻译,typeIDs /// </summary> public static void ReadYaml_FilterToNewTypeID() { try { var @default = YamlTools.Read <Dictionary <int, TypeID> >("Resources/typeIDs.yaml"); System.Windows.MessageBox.Show(@default.Count.ToString()); YamlFilter.TypeIDs(@default, out var @new); YamlTools.Write(@new, "Resources/newTypeIDs.yaml"); } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); } }
protected IDictionary <string, IEnumerable <KeyValuePair <string, string> > > getBindMaps(ValidResultConfig vrc) { Dictionary <string, IEnumerable <KeyValuePair <string, string> > > bindmaps = new Dictionary <string, IEnumerable <KeyValuePair <string, string> > >(); bindmaps.Add(XCDconfigsEnum.resultMap.ToString(), YamlTools.getResultKVFromYaml(vrc.resultMappingPath)); bindmaps.Add(XCDconfigsEnum.IAFormatFields.ToString(), YamlTools.getResultKVFromYaml(vrc.IAFormatFields)); bindmaps.Add(XCDconfigsEnum.dataResultValMapping.ToString(), YamlTools.getResultKVFromYaml(vrc.resultValMappingPath)); return(bindmaps); }
/// <summary> /// 写星域星系,只负责主要的 /// </summary> public static void WriteYaml_RegionGalaxy() { Dictionary <int, Galaxy> gxyFuerge = new Dictionary <int, Galaxy> { { 30000142, new Galaxy(30000142, "吉他") }, { 30000144, new Galaxy(30000144, "皮尔米特") } }; Dictionary <int, Galaxy> gxyDelve = new Dictionary <int, Galaxy> { { 30004759, new Galaxy(30004759, "1DQ-A") } }; List <Region> regions = new List <Region>() { { new Region(10000002, "伏尔戈", gxyFuerge) }, { new Region(10000060, "绝地之域", gxyDelve) } }; YamlTools.Write(regions, "Resources/regionGalaxy.yaml"); }
public async Task <YamlMetadata> ProcessPostMetadataAsync(string Name) { return(YamlTools .DeserializeYaml(await HttpClient.GetStringAsync($"/Blog/Site/{Name}.yml"))); }
/// <summary> /// 本地配置文件修改翻译,蓝图消耗 /// </summary> public static void ReadYaml_FilterToNewBlueprints() { // 读取原始数据 // 一级原始数据解析,反向产物存储,由蓝图ID key->实例 ,构造二级字典,produce-.实例,这个过程中实例引用不变,最佳新字典存储 // 由正向字典数据,consumer追加蓝图实例,作为子节点实例,构造新树,保存新的实例 // 读取解析 try { var db = LocalConfigLoadManager.GetConfigClass <TypeIDDBClass>(); var @default = YamlTools.Read <Dictionary <int, Buleprints> >("Resources/blueprints.yaml"); Dictionary <int, Buleprints> productsR = new Dictionary <int, Buleprints>(); // 反转产出与蓝图 foreach (var blue in @default) { if (blue.Value.activities.manufacturing != null) { if (db.TypeIDs.ContainsKey(blue.Key)) { var id = blue.Value.activities.manufacturing.products[0].typeID; if (db.TryGet(id, out NewTypeID value)) { if (!productsR.ContainsKey(id)) { productsR.Add(id, blue.Value); } } } } } Dictionary <int, NewBuleprints> @new = new Dictionary <int, NewBuleprints>(); foreach (var blue in productsR.Values) { var manufact = blue.activities.manufacturing; if (manufact == null) { continue; } NewBuleprints nb = new NewBuleprints(); nb.costProduct = new List <Products>(); nb.costProductMap = new List <int>(); nb.costmineral = new List <Products>(); nb.product = new Products(); nb.product.id = manufact.products[0].typeID; nb.product.count = manufact.products[0].quantity; nb.blueprintTypeID = blue.blueprintTypeID; db.TryGet(nb.product.id, out string pname); nb.product.name = pname; db.TryGet(nb.blueprintTypeID, out string bname); nb.name = bname; if (manufact.materials == null) { @new.Add(blue.blueprintTypeID, nb); continue; } foreach (var co in manufact.materials) { db.TryGet(co.typeID, out string cname); productsR.TryGetValue(co.typeID, out var bp); // 这里需要注意一点,有些原材料是矿石,需要单独处理 if (bp == null) { nb.costmineral.Add(new Products(co.typeID, cname, co.quantity)); } else { nb.costProduct.Add(new Products(co.typeID, cname, co.quantity)); nb.costProductMap.Add(bp.blueprintTypeID); } } @new.Add(blue.blueprintTypeID, nb); } System.Windows.MessageBox.Show(@new.Count.ToString()); YamlTools.Write(@new, "Resources/newBlueprints.yaml"); } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); } }