public static void IsDrawBackgroundImageTest(bool isDraw) { var instance = new EditorIniData(); var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var errorOccured = false; try { instance.IsDrawBackgroundImage = isDraw; } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーが発生しないこと Assert.IsFalse(errorOccured); var setValue = instance.IsDrawBackgroundImage; // セットした値と取得した値が一致すること Assert.IsTrue(setValue.Equals(isDraw)); // 意図したとおりプロパティ変更通知が発火していること Assert.AreEqual(changedPropertyList.Count, 1); Assert.IsTrue(changedPropertyList[0].Equals(nameof(EditorIniData.IsDrawBackgroundImage))); }
public static void SystemDbWindowPositionTest(WindowPosition position) { var instance = new EditorIniData(); var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var errorOccured = false; try { instance.SystemDbWindowPosition = position; } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーが発生しないこと Assert.IsFalse(errorOccured); var setValue = instance.SystemDbWindowPosition; // セットした値と取得した値が一致すること Assert.IsTrue(setValue.Equals(position)); // 意図したとおりプロパティ変更通知が発火していること Assert.AreEqual(changedPropertyList.Count, 1); Assert.IsTrue(changedPropertyList[0].Equals(nameof(EditorIniData.SystemDbWindowPosition))); }
public EditorIniData GetEditorData() { EditorIniData data = new EditorIniData(this.TemplateIndex); foreach (TableBlock block in this.Blocks) { data.Blocks.Add(block.Block); } return(data); }
public TableData(EditorIniData data) { this.Blocks = new List <TableBlock>(); this.TemplateIndex = data.TemplateIndex; this.MaxId = data.Blocks.Count; for (int i = 0; i < this.MaxId; ++i) { this.Blocks.Add(new TableBlock(i, i, data.Blocks[i], this.TemplateIndex)); } }
public ArchetypeManager(string file, int templateIndex) { if (file == null) { return; } FileManager fileManager = new FileManager(file); EditorIniData iniContent = fileManager.Read(FileEncoding.Automatic, templateIndex); this.CreateContentTable(iniContent.Blocks); }
public void Copy() { EditorIniData data = new EditorIniData(this.Data.TemplateIndex); foreach (TableBlock tableData in this.objectListView1.SelectedObjects) { data.Blocks.Add(tableData.Block); } Clipboard.Copy(data, typeof(EditorIniData)); this.OnDocumentChanged(this); }
public void Paste() { EditorIniData editorData = (EditorIniData)Clipboard.Paste(typeof(EditorIniData)); if (editorData.TemplateIndex == this.Data.TemplateIndex) { int id = this.GetNewBlockId(); List <TableBlock> blocks = new List <TableBlock>(); for (int i = 0; i < editorData.Blocks.Count; ++i) { blocks.Add(new TableBlock(id + i, this.Data.MaxId++, editorData.Blocks[i], this.Data.TemplateIndex)); } this.AddBlocks(blocks); } }
public static void SerializeTest() { var target = new EditorIniData { BackupType = ProjectBackupType.FiveTimes, }; var changedPropertyList = new List <string>(); target.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var clone = DeepCloner.DeepClone(target); Assert.IsTrue(clone.Equals(target)); // プロパティ変更通知が発火していないこと Assert.AreEqual(changedPropertyList.Count, 0); }
public FrmTableEditor(int templateIndex, string file) { FrmTableEditor.Instance = this; this.InitializeComponent(); this.LoadIcons(); this.undoManager.DataChanged += this.UndoManagerDataChanged; Helper.Settings.LoadTemplates(); if (file != null) { FileManager fileManager = new FileManager(file) { ReadWriteComments = true, // always read comments }; EditorIniData iniContent = fileManager.Read(FileEncoding.Automatic, templateIndex); this.Data = new TableData(iniContent); this.isBini = fileManager.IsBini; this.SetFile(file); } else { this.Data = new TableData { TemplateIndex = templateIndex }; this.SetFile(string.Empty); } this.SetTheme(); SimpleDropSink dropSink = this.objectListView1.DropSink as SimpleDropSink; if (dropSink != null) { dropSink.CanDropBetween = true; dropSink.CanDropOnItem = false; } this.RefreshSettings(); }
public static void FileIOTest(string inputFileName, string outputFileName) { var dir = Path.GetDirectoryName($@"{EditorIniDataTestItemGenerator.TestWorkRootDir}\{outputFileName}"); dir.CreateDirectoryIfNeed(); var reader = new EditorIniFileReader( $@"{EditorIniDataTestItemGenerator.TestWorkRootDir}\{inputFileName}"); EditorIniData data = null; var isSuccessRead = false; try { data = reader.ReadAsync().GetAwaiter().GetResult(); isSuccessRead = true; } catch (Exception ex) { logger.Exception(ex); } Assert.IsTrue(isSuccessRead); var writer = new EditorIniFileWriter( $@"{EditorIniDataTestItemGenerator.TestWorkRootDir}\{outputFileName}"); var isSuccessWrite = false; try { writer.WriteAsync(data).GetAwaiter().GetResult(); isSuccessWrite = true; } catch (Exception ex) { logger.Exception(ex); } Assert.IsTrue(isSuccessWrite); Console.WriteLine( $@"Written FilePath : {EditorIniDataTestItemGenerator.TestWorkRootDir}\{outputFileName}"); }
private static void Common(EditorIniData resultData, string readFileName) { var filePath = $@"{CommonFileTestItemGenerator.TestWorkRootDir}\{readFileName}"; var reader = new EditorIniFileReader(filePath); EditorIniData readData = null; var readResult = false; var errorMessage = ""; try { readData = reader.ReadSync(); readResult = true; } catch (Exception ex) { logger.Exception(ex); errorMessage = ex.Message; } // 正しく読めること if (!readResult) { throw new InvalidOperationException( $"Error Occured. Message : {errorMessage}"); } Assert.NotNull(readData); Console.WriteLine("Read Test Clear."); // 意図したデータと一致すること var propertyInfos = typeof(EditorIniData).GetProperties(); foreach (var propertyInfo in propertyInfos) { var readPropertyValue = propertyInfo.GetValue(readData); var answerPropertyValue = propertyInfo.GetValue(resultData); Assert.AreEqual(readPropertyValue, answerPropertyValue); } }
public static void NotCopyExtListTest(ExtensionList list, bool isError) { var instance = new EditorIniData(); var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var errorOccured = false; try { instance.NotCopyExtList = list; } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーフラグが一致すること Assert.AreEqual(errorOccured, isError); if (!errorOccured) { var setValue = instance.NotCopyExtList; // セットした値と取得した値が一致すること Assert.IsTrue(setValue.Equals(list)); } // 意図したとおりプロパティ変更通知が発火していること if (errorOccured) { Assert.AreEqual(changedPropertyList.Count, 0); } else { Assert.AreEqual(changedPropertyList.Count, 1); Assert.IsTrue(changedPropertyList[0].Equals(nameof(EditorIniData.NotCopyExtList))); } }
public static void ValidateTest(string testItemCode, bool answer) { var instance = new EditorIniData(); switch (testItemCode) { case "Success": // 初期状態 = 正常な状態 break; case "DuplicateShortCutKeyList": instance.ShortCutKeyList[0] = EventCommandShortCutKey.A; instance.ShortCutKeyList[1] = EventCommandShortCutKey.A; break; case "SetValueNotUseShortCutKeyList": instance.ShortCutKeyList[19] = EventCommandShortCutKey.A; break; default: Assert.Fail(); break; } var result = instance.Validate(out var errorMsg); // 結果が意図した値と一致すること Assert.AreEqual(result, answer); // チェックOKの場合は以降のテスト不要 if (result) { return; } // エラーメッセージが格納されていること Assert.IsNotEmpty(errorMsg); logger.Debug(errorMsg); }
public static void CommandPositionListTest(bool isNull, bool isError) { var instance = new EditorIniData(); var changedPropertyList = new List <string>(); instance.PropertyChanged += (sender, args) => { changedPropertyList.Add(args.PropertyName); }; var item = isNull ? null : new ShortCutPositionList(); var errorOccured = false; try { instance.CommandPositionList = item; } catch (Exception ex) { logger.Exception(ex); errorOccured = true; } // エラーフラグが一致すること Assert.AreEqual(errorOccured, isError); if (errorOccured) { return; } Assert.NotNull(item); var setValue = instance.CommandPositionList; // セットした値と取得した値が一致すること Assert.IsTrue(setValue.Equals(item)); // 意図したとおりプロパティ変更通知が発火していること Assert.AreEqual(changedPropertyList.Count, 1); Assert.IsTrue(changedPropertyList[0].Equals(nameof(EditorIniData.CommandPositionList))); }
public static void WriteSyncTest(EditorIniData outputDat, string outputFileName) { Path.GetDirectoryName(outputFileName).CreateDirectoryIfNeed(); var writer = new EditorIniFileWriter(outputFileName); var isSuccess = false; var errorMessage = ""; try { writer.WriteSync(outputDat); isSuccess = true; } catch (Exception e) { errorMessage = e.Message; } // 出力成功すること if (!isSuccess) { throw new InvalidOperationException( $"Error message: {errorMessage}"); } // デバッグログにファイルの内容を出力 logger.Debug("Outputファイル内容出力開始"); var outputTextLines = File.ReadAllLines(outputFileName); foreach (var outputTextLine in outputTextLines) { logger.Debug(outputTextLine); } logger.Debug("Outputファイル内容出力完了"); Assert.True(true); }
private static EditorIniData GetEditorData(List <IniBlock> iniData, int templateFileIndex) { #if DEBUG Stopwatch st = new Stopwatch(); st.Start(); #endif EditorIniData editorData = new EditorIniData(templateFileIndex); Template.File templateFile = Helper.Template.Data.Files[templateFileIndex]; // loop each ini block foreach (IniBlock iniBlock in iniData) { Template.Block templateBlock; int templateBlockIndex; // get template block based on ini block name if (templateFile.Blocks.TryGetValue(iniBlock.Name, out templateBlock, out templateBlockIndex)) { EditorIniBlock editorBlock = new EditorIniBlock(templateBlock.Name, templateBlockIndex) { Comments = iniBlock.Comments }; // loop each template option for (int j = 0; j < templateBlock.Options.Count; ++j) { // handle nested options Template.Option childTemplateOption = null; if (j < templateBlock.Options.Count - 1 && templateBlock.Options[j + 1].Parent != null) { // next option is child of current option childTemplateOption = templateBlock.Options[j + 1]; } Template.Option templateOption = templateBlock.Options[j]; EditorIniOption editorOption = new EditorIniOption(templateOption.Name, j); // get ini options based on all possible template option names List <IniOption> iniOptions; iniBlock.Options.TryGetValue(templateOption.Name, out iniOptions); // search for options with alternative names if (templateOption.RenameFrom != null) { string[] namesFromRename = templateOption.RenameFrom.Split(new[] { ',' }); for (int nameIndex = 0; nameIndex < namesFromRename.Length; ++nameIndex) { List <IniOption> alternativeOptions; if (iniBlock.Options.TryGetValue(namesFromRename[nameIndex], out alternativeOptions)) { iniOptions.AddRange(alternativeOptions); // stop searching after we found the first option group with the correct name break; } } } if (iniOptions != null) { // h is used to start again at last child option in order to provide better performance int h = 0; if (templateOption.Multiple) { // loop each ini option for (int k = 0; k < iniOptions.Count; ++k) { List <object> editorChildOptions = null; List <IniOption> iniChildOptions; // get ini options of child based on child's template option name if (childTemplateOption != null && iniBlock.Options.TryGetValue(childTemplateOption.Name, out iniChildOptions)) { editorOption.ChildTemplateIndex = j + 1; editorOption.ChildName = childTemplateOption.Name; editorChildOptions = new List <object>(); // loop each ini option of child for (; h < iniChildOptions.Count; ++h) { IniOption childOption = iniChildOptions[h]; if (k < iniOptions.Count - 1 && childOption.Index > iniOptions[k + 1].Index) { break; } if (childOption.Index > iniOptions[k].Index) { editorChildOptions.Add(childOption.Value); } } } // add entry of multiple option editorOption.Values.Add(new EditorIniEntry(iniOptions[k].Value, editorChildOptions)); } } else { // single option if (iniOptions.Count > 0) { if (iniOptions[0].Value.Length > 0) { // just add the last option (Freelancer like) if aviable to prevent multiple options which should be single editorOption.Values.Add(new EditorIniEntry(iniOptions[iniOptions.Count - 1].Value)); } else { // use '=' for options which dont have values and are simply defined when using the option key followed by a colon equal editorOption.Values.Add(new EditorIniEntry("=")); } } } // add option editorBlock.Options.Add(editorOption); } else { // add empty option based on template editorBlock.Options.Add(new EditorIniOption(templateOption.Name, j)); } // set index of main option (value displayed in table view) if (templateBlock.Identifier != null && templateBlock.Identifier.Equals(editorBlock.Options[editorBlock.Options.Count - 1].Name, StringComparison.OrdinalIgnoreCase)) { editorBlock.MainOptionIndex = editorBlock.Options.Count - 1; } // ignore next option because we already added it as children to the current option if (childTemplateOption != null) { ++j; } } // add block editorData.Blocks.Add(editorBlock); } } #if DEBUG st.Stop(); Debug.WriteLine("typecast data: " + st.ElapsedMilliseconds + "ms"); #endif return(editorData); }
public void Write(EditorIniData data) { // save data List <IniBlock> newData = new List <IniBlock>(); foreach (EditorIniBlock block in data.Blocks) { IniOptions newBlock = new IniOptions(); foreach (EditorIniOption option in block.Options) { if (option.Values.Count > 0) { List <IniOption> newOption = new List <IniOption>(); foreach (EditorIniEntry entry in option.Values) { string optionValue = entry.Value.ToString(); if (optionValue == "=") { // use an empty value for options which dont have values and are simply defined when using the option key followed by a colon equal newOption.Add(new IniOption { Value = string.Empty }); } else { newOption.Add(new IniOption { Value = optionValue }); } // add suboptions as options with defined parent if (entry.SubOptions != null) { for (int k = 0; k < entry.SubOptions.Count; ++k) { newOption.Add( new IniOption { Value = entry.SubOptions[k].ToString(), Parent = option.ChildName }); } } } newBlock.Add(option.Name, newOption); } } newData.Add(new IniBlock { Name = block.Name, Options = newBlock, Comments = block.Comments, }); } // if (IsBINI) // { // BINIManager biniManager = new BINIManager(File); // biniManager.Data = newData; // biniManager.Write(); // } // else // { IniManager iniManager = new IniManager(this.File) { WriteEmptyLine = this.WriteEmptyLine, WriteSpaces = this.WriteSpaces, ReadWriteComments = this.ReadWriteComments, }; iniManager.Write(newData); // } }