/// <inheritdoc /> /// <summary> /// Action to execute when the trigger occurs /// </summary> protected override void OnAction() { var status = OnFetchStatus?.Invoke(); try { if (status == null) { return; } var now = Core.Now; var filename = FileNameFormat .Replace("{yyyy}", now.ToString("yyyy")) .Replace("{MM}", now.ToString("MM")) .Replace("{dd}", now.ToString("dd")) .Replace("{HH}", now.ToString("HH")) .Replace("{mm}", now.ToString("mm")); var filePath = SPath.Combine(AppContext.BaseDirectory, Path, filename); var folder = SPath.GetDirectoryName(filePath); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } Serializer.SerializeToFile(status, filePath); } catch (Exception ex) { Core.Log.Write(ex); } }
public Drwg(string fileNameWithPath) : this() { NamingFormats = new DrwgNamingFormat().GetDrwgNamingFormatListExceptOther(); FileNameWithPath = fileNameWithPath; FileName = Path.GetFileName(FileNameWithPath); //Test to see if there are multiple matches for filenames -> meaning multiple regex matches -> should be only one match if (TestFormatsForMultipleMatches(FileName) > 1) { throw new Exception($"Filename {FileName} matched multiple Regex patterns! Must only match one!"); } //Analyze file name and find the format Format = DetermineFormat(FileName); //Find the correct analyzing format if (Format == FileNameFormat.Other) { Dnf = new DrwgNamingFormat.Other(); } else { Dnf = NamingFormats.Where(x => x.Format == Format).FirstOrDefault(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Exposes the method to update a Paratext ssf file. /// </summary> /// <param name="ssf">Stream for Paratext SSF that already exists.</param> /// <param name="format">the prefix, scheme, suffix, extension</param> /// <param name="sShortName">The short name of the Paratext project</param> /// <param name="styleSheetFile">The style sheet file.</param> /// <param name="projPath">The path where the project is located</param> /// <param name="ws">The HVO of the writing system for the current export.</param> /// ------------------------------------------------------------------------------------ public XmlDocument UpdateSsfFile(TextReader ssf, FileNameFormat format, string sShortName, string styleSheetFile, string projPath, int ws) { CheckDisposed(); return(m_ParatextSsfFileAccessor.UpdateSsfFile(ssf, format, sShortName, styleSheetFile, projPath, ws)); }
public static string FormatFileName(int resIndex, string dateFormat) { var fileName = FileNameFormat.Replace("{S}", GetSceneName()); fileName = fileName.Replace("{P}", PlayerSettings.productName); fileName = fileName.Replace("{R}", reslist[resIndex]); fileName = fileName.Replace("{D}", DateTime.Now.ToString(dateFormat).Replace("-", ".")); fileName = fileName.Replace("{T}", DateTime.Now.ToString(TimeFormat == 0 ? "HH-mm-ss" : "hh-mm-ss tt")); fileName = fileName.Replace("{U}", DateTime.Now.Ticks.ToString()); return(fileName); }
public static string FormatFileName(int resIndex, string dateFormat) { string fileName = FileNameFormat.Replace("{S}", GetSceneName()); fileName = fileName.Replace("{P}", PlayerSettings.productName); fileName = fileName.Replace("{R}", reslist[resIndex]); fileName = fileName.Replace("{D}", System.DateTime.Now.ToString(dateFormat)); fileName = fileName.Replace("{T}", System.DateTime.Now.ToString("HH-mm-ss")); fileName = fileName.Replace("{U}", System.DateTime.Now.Ticks.ToString()); return(fileName); }
public FileNameControlViewModel(FileNameFormat format, ContentType type) { this.ContentType = type; this.FileNameFormat = new FileNameFormat(format); this.FileNameFormat.PropertyChanged += Format_PropertyChanged; this.FileNameFormat.EpisodeFormat.PropertyChanged += Format_PropertyChanged; this.FileNameFormat.Format.CollectionChanged += Format_CollectionChanged; foreach (FileNamePortion portion in this.FileNameFormat.Format) { portion.PropertyChanged += Format_PropertyChanged; } UpdatePreview(); }
/// <summary> /// ファイル名フォーマット種別に従いファイル名を作成する。 /// </summary> /// <param name="format">ファイル名フォーマット種別。</param> /// <param name="charaName">キャラ名。</param> /// <param name="talkText">トークテキスト。</param> /// <returns>ファイル名。拡張子なし。</returns> public static string MakeFileName( FileNameFormat format, string charaName, string talkText) { if (charaName == null) { throw new ArgumentNullException(nameof(charaName)); } var chara = MakeFileNamePart(charaName, MaxFileNamePartFromCharaNameLength); var text = MakeFileNamePart(talkText, MaxFileNamePartFromTextLength); var time = DateTime.Now.ToString("yyMMdd_HHmmss"); string name; switch (format) { case FileNameFormat.Text: name = text; break; case FileNameFormat.DateTimeText: name = string.Join("_", time, text); break; case FileNameFormat.NameText: name = string.Join("_", chara, text); break; case FileNameFormat.DateTimeNameText: name = string.Join("_", time, chara, text); break; case FileNameFormat.TextInNameDirectory: name = Path.Combine(chara, text); break; case FileNameFormat.DateTimeTextInNameDirectory: name = Path.Combine(chara, string.Join("_", time, text)); break; default: throw new InvalidEnumArgumentException( nameof(format), (int)format, format.GetType()); } return(name); }
public void UpdateParatextSsfFile_SameFolderAndSpec() { m_scr.Versification = 0; // Should default to English IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; // The existing file has Exodus and Matthew. string existingSsf = @"<ScriptureText>" + Environment.NewLine + @"<Book_EXO>Exodus</Book_EXO>" + Environment.NewLine + @"<Book_MAT>Matthew</Book_MAT>" + Environment.NewLine + @"<BooksPresent>010000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000</BooksPresent>" + Environment.NewLine + @"<ChapterMarker>c</ChapterMarker>" + Environment.NewLine + @"<Copyright></Copyright>" + Environment.NewLine + @"<Directory>C:\My Paratext Projects\dummy</Directory>" + Environment.NewLine + @"<DotAll>No</DotAll>" + Environment.NewLine + @"<Editable>T</Editable>" + Environment.NewLine + @"<Encoding>" + ParatextSsfFileAccessor.kUnicodeEncoding + "</Encoding>" + Environment.NewLine + @"<FileNameChapterNumberForm></FileNameChapterNumberForm>" + Environment.NewLine + @"<FileNameForm>41MAT</FileNameForm>" + Environment.NewLine + @"<FileNamePostPart>suf.ext</FileNamePostPart>" + Environment.NewLine + @"<FileNamePrePart>pre</FileNamePrePart>" + Environment.NewLine + @"<FullName>My project Name</FullName>" + Environment.NewLine + @"<Language>Gumbasian</Language>" + Environment.NewLine + @"<LeftToRight>" + (vernWs.RightToLeftScript ? "F" : "T") + "</LeftToRight>" + Environment.NewLine + @"<MatchCase>No</MatchCase>" + Environment.NewLine + @"<Name>dummy</Name>" + Environment.NewLine + @"<ResourceText>F</ResourceText>" + Environment.NewLine + @"<RunFromCD>F</RunFromCD>" + Environment.NewLine + @"<ShowReferences>No</ShowReferences>" + Environment.NewLine + @"<StyleSheet>dontOverWriteMe.sty</StyleSheet>" + Environment.NewLine + @"<VerseMarker>v</VerseMarker>" + Environment.NewLine + @"<Versification>2</Versification>" + Environment.NewLine + "<Naming PrePart=\"pre\" PostPart=\"suf.ext\" BookNameForm=\"41MAT\"></Naming>" + Environment.NewLine + @"<AssociatedLexicalProject>" + Cache.ProjectId.PipeHandle + @"</AssociatedLexicalProject>" + Environment.NewLine + @"</ScriptureText>"; FileNameFormat fileNameFormat = new FileNameFormat("pre", FileNameFormat.SchemeFormat.NNBBB, "suf", "ext"); XmlDocument resultSSF; m_filter.Add(new IScrBook[] { m_book } ); using (StringReader sr = new StringReader(existingSsf)) { resultSSF = m_exporter.ParatextSsfFileAccessor.UpdateSsfFile(sr, fileNameFormat, "dummy", "styFile.sty", @"C:\My Paratext Projects\dummy", vernWs.Handle); } // Verify the .ssf contents Dictionary<string, string> expectedSsfEntries = new Dictionary<string, string>(); expectedSsfEntries["AssociatedLexicalProject"] = Cache.ProjectId.PipeHandle; expectedSsfEntries["Book_EXO"] = "Exodus"; expectedSsfEntries["Book_MAT"] = "Matthew"; expectedSsfEntries["BooksPresent"] = "110000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000"; expectedSsfEntries["ChapterMarker"] = "c"; expectedSsfEntries["Copyright"] = string.Empty; expectedSsfEntries["Directory"] = @"C:\My Paratext Projects\dummy"; expectedSsfEntries["DotAll"] = "No"; expectedSsfEntries["Editable"] = "T"; expectedSsfEntries["Encoding"] = ParatextSsfFileAccessor.kUnicodeEncoding; expectedSsfEntries["FileNameChapterNumberForm"] = string.Empty; expectedSsfEntries["FileNameForm"] = "41MAT"; expectedSsfEntries["FileNamePostPart"] = "suf.ext"; expectedSsfEntries["FileNamePrePart"] = "pre"; expectedSsfEntries["FullName"] = "My project Name"; expectedSsfEntries["Language"] = "French"; expectedSsfEntries["LeftToRight"] = (vernWs.RightToLeftScript ? "F" : "T"); expectedSsfEntries["MatchCase"] = "No"; expectedSsfEntries["Name"] = "dummy"; expectedSsfEntries["ResourceText"] = "F"; expectedSsfEntries["RunFromCD"] = "F"; expectedSsfEntries["ShowReferences"] = "No"; expectedSsfEntries["StyleSheet"] = "dontOverWriteMe.sty"; // Don't overwrite the .sty expectedSsfEntries["VerseMarker"] = "v"; expectedSsfEntries["Versification"] = "2"; // Don't overwrite the versification. expectedSsfEntries["Naming"] = string.Empty; Assert.AreEqual(1, resultSSF.ChildNodes.Count, "Only node in document should be ScriptureText"); XmlNode contents = resultSSF.SelectSingleNode("ScriptureText"); Assert.AreEqual(expectedSsfEntries.Count, contents.ChildNodes.Count); foreach (string expectedElement in expectedSsfEntries.Keys) { XmlNode node = contents.SelectSingleNode(expectedElement); Assert.IsNotNull(node); Assert.AreEqual(expectedSsfEntries[expectedElement], node.InnerText); } // Check the Naiming node (only node that uses attributes) XmlNode namingNode = contents.SelectSingleNode("Naming"); Assert.IsNotNull(namingNode); Assert.AreEqual("pre", namingNode.Attributes.GetNamedItem("PrePart").Value); Assert.AreEqual("suf.ext", namingNode.Attributes.GetNamedItem("PostPart").Value); Assert.AreEqual("41MAT", namingNode.Attributes.GetNamedItem("BookNameForm").Value); }
public void WriteParatextSsfFile_SeptuagintVersification() { m_scr.Versification = ScrVers.Septuagint; IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; using (DummyFileWriter writer = new DummyFileWriter()) { FileNameFormat fileNameFormat = new FileNameFormat("pre", FileNameFormat.SchemeFormat.NNBBB, "suf", "ext"); m_exporter.ParatextSsfFileAccessor.SaveSsfFile(fileNameFormat, "dummy", "styFile.sty", @"C:\My Paratext Projects\dummy", writer, Cache.DefaultVernWs); // Verify the .ssf file string[] expectedSsf = new string[] { @"<ScriptureText>", @"<BooksPresent>100000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000</BooksPresent>", @"<Copyright></Copyright>", @"<Directory>C:\My Paratext Projects\dummy</Directory>", @"<Editable>T</Editable>", @"<Encoding>" + ParatextSsfFileAccessor.kUnicodeEncoding + "</Encoding>", @"<FileNameForm>41MAT</FileNameForm>", @"<FileNamePostPart>suf.ext</FileNamePostPart>", @"<FileNamePrePart>pre</FileNamePrePart>", @"<FullName>" + Cache.ProjectId.Name + "</FullName>", @"<Language>French</Language>", @"<LeftToRight>" + (vernWs.RightToLeftScript ? "F" : "T") + "</LeftToRight>", @"<Name>dummy</Name>", @"<StyleSheet>styFile.sty</StyleSheet>", @"<Versification>2</Versification>", // Septuagint "<Naming PrePart=\"pre\" PostPart=\"suf.ext\" BookNameForm=\"41MAT\"></Naming>", @"</ScriptureText>" }; writer.VerifyOutput(expectedSsf); } }
public void UpdateParatextSsfFile_MissingStylsheetSpecInOrig() { IWritingSystem vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; // The existing file has Exodus and Matthew. string existingSsf = @"<ScriptureText>" + Environment.NewLine + @"<BooksPresent>010000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000</BooksPresent>" + Environment.NewLine + @"<Directory>C:\My Paratext Projects\dummy</Directory>" + Environment.NewLine + @"<Editable>T</Editable>" + Environment.NewLine + @"<Encoding>" + ParatextSsfFileAccessor.kUnicodeEncoding + "</Encoding>" + Environment.NewLine + @"<FileNameForm>41MAT</FileNameForm>" + Environment.NewLine + @"<FileNamePostPart>suf.ext</FileNamePostPart>" + Environment.NewLine + @"<FileNamePrePart>pre</FileNamePrePart>" + Environment.NewLine + @"<FullName>My project Name</FullName>" + Environment.NewLine + @"<Language>Gumbasian</Language>" + Environment.NewLine + @"<LeftToRight>" + (vernWs.RightToLeftScript ? "F" : "T") + "</LeftToRight>" + Environment.NewLine + @"<Name>dummy</Name>" + Environment.NewLine + @"<Versification>4</Versification>" + Environment.NewLine + "<Naming PrePart=\"pre\" PostPart=\"suf.ext\" BookNameForm=\"41MAT\"></Naming>" + Environment.NewLine + @"</ScriptureText>"; FileNameFormat fileNameFormat = new FileNameFormat("pre", FileNameFormat.SchemeFormat.NNBBB, "suf", "ext"); XmlDocument resultSSF; m_filter.Add(new IScrBook[] { m_book }); using (StringReader sr = new StringReader(existingSsf)) { resultSSF = m_exporter.ParatextSsfFileAccessor.UpdateSsfFile(sr, fileNameFormat, "dummy", "styFile.sty", @"C:\My Paratext Projects\dummy", vernWs.Handle); } // Verify the .ssf contents Dictionary<string, string> expectedSsfEntries = new Dictionary<string, string>(); expectedSsfEntries["BooksPresent"] = "110000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000"; expectedSsfEntries["Directory"] = @"C:\My Paratext Projects\dummy"; expectedSsfEntries["Editable"] = "T"; expectedSsfEntries["Encoding"] = ParatextSsfFileAccessor.kUnicodeEncoding; expectedSsfEntries["FileNameForm"] = "41MAT"; expectedSsfEntries["FileNamePostPart"] = "suf.ext"; expectedSsfEntries["FileNamePrePart"] = "pre"; expectedSsfEntries["FullName"] = "My project Name"; expectedSsfEntries["Language"] = "French"; expectedSsfEntries["LeftToRight"] = (vernWs.RightToLeftScript ? "F" : "T"); expectedSsfEntries["Name"] = "dummy"; expectedSsfEntries["StyleSheet"] = "styFile.sty"; expectedSsfEntries["Versification"] = "4"; expectedSsfEntries["Naming"] = string.Empty; Assert.AreEqual(1, resultSSF.ChildNodes.Count, "Only node in document should be ScriptureText"); XmlNode contents = resultSSF.SelectSingleNode("ScriptureText"); Assert.AreEqual(expectedSsfEntries.Count, contents.ChildNodes.Count); foreach (string expectedElement in expectedSsfEntries.Keys) { XmlNode node = contents.SelectSingleNode(expectedElement); Assert.IsNotNull(node); Assert.AreEqual(expectedSsfEntries[expectedElement], node.InnerText); } // Check the Naming node (only node that uses attributes) XmlNode namingNode = contents.SelectSingleNode("Naming"); Assert.IsNotNull(namingNode); Assert.AreEqual("pre", namingNode.Attributes.GetNamedItem("PrePart").Value); Assert.AreEqual("suf.ext", namingNode.Attributes.GetNamedItem("PostPart").Value); Assert.AreEqual("41MAT", namingNode.Attributes.GetNamedItem("BookNameForm").Value); }
/// <summary> /// Opinionated configuration of NLog /// </summary> /// <param name="appFolder"></param> public static void ConfigureNLog(DirectoryInfo logFolder, string filePrefix = "", FileNameFormat fileNameFormat = FileNameFormat.ShortDate) { if (!string.IsNullOrEmpty(filePrefix) && !filePrefix.EndsWith("-")) filePrefix += "-"; Console.Error.WriteLine($"Configuring NLog with folder {logFolder.FullName} and prefix {filePrefix}"); if (!logFolder.Exists) { logFolder.Create(); } var config = new LoggingConfiguration(); string filenameSuffix; switch (fileNameFormat) { case FileNameFormat.Simple: filenameSuffix = ""; break; case FileNameFormat.ShortDate: default: filenameSuffix = ".${shortdate}"; break; } var microsoftFileTarget = new FileTarget("microsoft") { FileName = $@"{logFolder.FullName}/{filePrefix}microsoft{filenameSuffix}.log", Layout = @"${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger} ${message} ${exception}" }; config.AddTarget(microsoftFileTarget); config.AddRuleForAllLevels(microsoftFileTarget, "Microsoft.*", true); config.AddRuleForAllLevels(microsoftFileTarget, "System.Net.Http.HttpClient.*", true); var consoleTarget = new ColoredConsoleTarget("console") { Layout = @"${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger:shortName=true} ${message} ${exception}" }; consoleTarget.RowHighlightingRules.Add( new ConsoleRowHighlightingRule { Condition = ConditionParser.ParseExpression("level == LogLevel.Debug"), ForegroundColor = ConsoleOutputColor.DarkCyan }); consoleTarget.RowHighlightingRules.Add( new ConsoleRowHighlightingRule { Condition = ConditionParser.ParseExpression("level == LogLevel.Trace"), ForegroundColor = ConsoleOutputColor.DarkCyan }); config.AddTarget(consoleTarget); config.AddRuleForAllLevels(consoleTarget); var fileTarget = new FileTarget("file") { FileName = $@"{logFolder.FullName}/{filePrefix}general{filenameSuffix}.log", Layout = @"${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger:shortName=true} ${message} ${exception}" }; config.AddTarget(fileTarget); config.AddRuleForAllLevels(fileTarget); var errorFileTarget = new FileTarget("errorFileTarget") { FileName = $@"{logFolder.FullName}/error{filenameSuffix}.log", Layout = @"${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger:shortName=true} ${message} ${exception}" }; config.AddTarget(errorFileTarget); config.AddRuleForOneLevel(global::NLog.LogLevel.Fatal, errorFileTarget); config.AddRuleForOneLevel(global::NLog.LogLevel.Error, errorFileTarget); config.AddRuleForOneLevel(global::NLog.LogLevel.Warn, errorFileTarget); if (System.Diagnostics.Debugger.IsAttached) { var debuggerTarget = new DebuggerTarget("debugger") { Layout = @"${date:format=HH\:mm\:ss} ${level:uppercase=true} ${logger:shortName=true} ${message} ${exception}" }; config.AddTarget(debuggerTarget); config.AddRuleForAllLevels(debuggerTarget); } LogManager.Configuration = config; }
void SaveResultToFile() { if (string.IsNullOrEmpty(FileNameSpliter)) { LoggerHelper.Logger.Info(nameof(FileNameSpliter) + " should not be null or empty"); return; } if (string.IsNullOrEmpty(FileNameFormat)) { LoggerHelper.Logger.Info(nameof(FileNameFormat) + " should not be null or empty"); return; } if (string.IsNullOrEmpty(SingerNameSpliter)) { LoggerHelper.Logger.Info(nameof(SingerNameSpliter) + " should not be null or empty"); return; } IsSaving = true; try { var formarts = FileNameFormat.Split(" ", StringSplitOptions.RemoveEmptyEntries); var parts = GetParts(formarts); foreach (var music in MusicFiles) { try { var fileName = music.FileInfo.Name.Remove(music.FileInfo.Name.LastIndexOf(".")); var nameParts = fileName.Split(FileNameSpliter, StringSplitOptions.RemoveEmptyEntries).Where(u => !string.IsNullOrWhiteSpace(u)).Select(u => u.Trim()).ToArray(); if (parts.Count == nameParts.Length) { music.SelectedSongInfo = new SongDocument(); for (int i = 0; i < nameParts.Length; i++) { switch (parts[i]) { case Part.Title: if (OverrideRawValue || string.IsNullOrWhiteSpace(music.TagInfo.Tag.Title)) { music.SelectedSongInfo.SongTitle = nameParts[i]; } break; case Part.Singer: if (OverrideRawValue || music.TagInfo.Tag.Performers.Length == 0) { music.SelectedSongInfo.SingerNames = string.Join( Constants.Separater, nameParts[i] .Split(SingerNameSpliter, StringSplitOptions.RemoveEmptyEntries) .Where(u => !string.IsNullOrEmpty(u))); } break; case Part.Album: if (OverrideRawValue || string.IsNullOrWhiteSpace(music.TagInfo.Tag.Album)) { music.SelectedSongInfo.Album = nameParts[i]; } break; default: throw new NotImplementedException(); } } music.SaveResultToFileCommand.Execute(null); } else { LoggerHelper.Logger.Warn("Skip file {File} due to not meet the formats", music.FileInfo.Name); } } catch (Exception ex) { LoggerHelper.Logger.Error(ex, "Error occur in {method}", nameof(SaveResultToFile)); } } } catch (Exception ex) { LoggerHelper.Logger.Error(ex, "Error occur in {method}", nameof(SaveResultToFile)); } IsSaving = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Exposes the method to update a Paratext ssf file. /// </summary> /// <param name="ssf">Stream for Paratext SSF that already exists.</param> /// <param name="format">the prefix, scheme, suffix, extension</param> /// <param name="sShortName">The short name of the Paratext project</param> /// <param name="styleSheetFile">The style sheet file.</param> /// <param name="projPath">The path where the project is located</param> /// <param name="ws">The HVO of the writing system for the current export.</param> /// ------------------------------------------------------------------------------------ public XmlDocument UpdateSsfFile(TextReader ssf, FileNameFormat format, string sShortName, string styleSheetFile, string projPath, int ws) { CheckDisposed(); return m_ParatextSsfFileAccessor.UpdateSsfFile(ssf, format, sShortName, styleSheetFile, projPath, ws); }