private void OpenFile(string file) { _RecentFileList.AddToRecentList(file); Pat.Project proj = null; if (System.IO.Path.GetExtension(file) == ".pat") { proj = ProjectGenerater.Generate(file); } else if (System.IO.Path.GetExtension(file) == ".patproj") { proj = ProjectSerializer.OpenProject(file); } else { MessageBox.Show("Unknown file extension."); } if (proj != null) { _Editor.Project = proj; } SetupToolbarEnabled(); openFileDialog1.FileName = ""; }
public void TestLoadStartingRule() { IProjectNode p = ProjectSerializer.LoadString("StartingRule root 200\r\nStartingRule root2\r\nStartingRule root3", null, null); Assert.AreEqual(3, p.Children.Count); IProjectNode sr = p.Children[0]; Assert.AreEqual(ProjectNodeType.StartingRuleDeclaration, sr.NodeType); StartingRuleNode srn = sr as StartingRuleNode; Assert.AreEqual("root", srn.Name); Assert.AreEqual(200, srn.Amount); sr = p.Children[1]; Assert.AreEqual(ProjectNodeType.StartingRuleDeclaration, sr.NodeType); srn = sr as StartingRuleNode; Assert.AreEqual("root2", srn.Name); Assert.AreEqual(100, srn.Amount); sr = p.Children[2]; Assert.AreEqual(ProjectNodeType.StartingRuleDeclaration, sr.NodeType); srn = sr as StartingRuleNode; Assert.AreEqual("root3", srn.Name); Assert.AreEqual(100, srn.Amount); }
private bool ReadTranslation(object context, TextReader reader, string line, ref int lineNumber) { if (line == "}") { return(false); } if (string.IsNullOrEmpty(line)) { return(true); } List <string> tokens = ProjectSerializer.ReadTokens(line); int translatepos = tokens.IndexOf("=>"); if (translatepos == -1) { Project.Warnings.Add(string.Format("Line {0}: Missing => in Translate directive.", lineNumber)); } else if (translatepos == 0) { Project.Warnings.Add(string.Format("Line {0}: Missing source tokens in Translate directive.", lineNumber)); } else { _stringmapping.Add(tokens.GetRange(0, translatepos).ToArray(), tokens.GetRange(translatepos + 1, tokens.Count - translatepos - 1).ToArray()); } return(true); }
public override void LoadCommand(Project project, System.IO.TextReader reader, string line, ref int lineNumber) { base.LoadCommand(project, reader, line, ref lineNumber); List <string> parts = ProjectSerializer.ReadTokens(line); if (parts.Count == 2) { if (!int.TryParse(parts[1], out _StartIndex)) { project.Warnings.Add(string.Format("Line {0}: Substring command requires an integer as its first argument.", m_lineNumber)); } } else if (parts.Count == 3) { if (!int.TryParse(parts[1], out _StartIndex)) { project.Warnings.Add(string.Format("Line {0}: Substring command requires an integer as its first argument.", m_lineNumber)); } if (!int.TryParse(parts[2], out _EndIndex)) { project.Warnings.Add(string.Format("Line {0}: Substring command requires an integer as its second argument.", m_lineNumber)); } } else { project.Warnings.Add(string.Format("Line {0}: Substring command requires one or two integer arguments.", m_lineNumber)); } }
public override void LoadCommand(Project project, System.IO.TextReader reader, string line, ref int lineNumber) { base.LoadCommand(project, reader, line, ref lineNumber); List <string> parts = ProjectSerializer.ReadTokens(line); if (parts[parts.Count - 1] != "{") { project.Warnings.Add(string.Format("Line {0}: The Random command requires a {{ at the end of the line.", lineNumber)); } else { parts.RemoveAt(0); parts.RemoveAt(parts.Count - 1); if (parts.Count == 0) { if (ProjectSerializer.ReadLines(new object[] { project, Commands }, reader, ProjectSerializer.ParseWeightedCommands, ref lineNumber)) { project.Warnings.Add(string.Format("Line {0}: The Random command is not closed correctly.", lineNumber)); } } else { project.Warnings.Add(string.Format("Line {0}: The Random command must have no arguments.", lineNumber)); } } }
public void TestLoadRuleWithLoop() { IProjectNode p = ProjectSerializer.LoadString("rule root {\r\n\tloop 1 2 {\r\n\t\tliteral a\r\n\t}\r\n}\r\n", null, null); Assert.AreEqual(1, p.Children.Count, "Didn't find the rule."); IProjectNode rule = p.Children[0]; Assert.AreEqual(ProjectNodeType.RuleDeclaration, rule.NodeType); RuleNode rn = rule as RuleNode; Assert.IsNotNull(rn); Assert.AreEqual(1, rn.Children.Count, "Didn't find the command block."); Assert.AreEqual("root", rn.Name); CommandBlockNode cbn = rn.Children[0] as CommandBlockNode; Assert.IsNotNull(cbn); Assert.AreEqual(1, cbn.Children.Count); Whee.WordBuilder.Model.Commands.CommandBase cb = cbn.Children[0] as Whee.WordBuilder.Model.Commands.CommandBase; Assert.IsInstanceOfType(typeof(Whee.WordBuilder.Model.Commands.LoopCommand), cb); Assert.AreEqual(1, cb.Children.Count); }
public void TestLoadCommand() { IProjectNode project = ProjectSerializer.LoadString("rule root {\nliteral a\n}\n", null, null); LiteralCommand cmd = (LiteralCommand)(project.Children[0].Children[0].Children[0]); Assert.AreEqual("a", cmd.Literal); }
public void TestLoadCommand() { IProjectNode project = ProjectSerializer.LoadString("rule root {\napply {\ntoken a\n}\n}\n", null, null); ApplyCommand cmd = (ApplyCommand)(project.Children[0].Children[0].Children[0]); Assert.AreEqual(1, cmd.Commands.Count); }
public void TestBrokenTranslationMissingArrow() { ProjectSerializer ps = new ProjectSerializer("a b c\n", null, null); TranslationNode tn = new TranslationNode(ps); Assert.IsFalse(tn.Successful); }
protected override byte[] SerializeWith(Project project, ProjectSerializer serializer) { var xmlSerializer = serializer as ProjectXmlSerializer; xmlSerializer !.BeforeSerialize += BeforeSerialize; return(base.SerializeWith(project, serializer)); }
public void SetUp() { _sources = new List <Source>(); _dataTypes = new List <Type>(); _columns = new List <Column>(); _rows = new List <Row>(); _filters = new List <Filter>(); _views = new List <View>(); _project = new Project() { Sources = _sources, Columns = _columns, Rows = _rows, Filters = _filters, Views = _views }; _xProject = new XElement("project"); _xSources = new XElement("sources"); _xColumns = new XElement("columns"); _xRows = new XElement("rows"); _xFilters = new XElement("filters"); _xViews = new XElement("views"); _xProject.Add(_xSources, _xColumns, _xRows, _xFilters, _xViews); _mockSourceSerializer = new Mock <ISourceSetSerializer>(); _mockSourceSerializer.Setup(p => p.Serialize(_sources)).Returns(_xSources); _mockSourceSerializer.Setup(p => p.Deserialize(_xSources)).Returns(_sources); _mockColumnDataTypeSerializer = new Mock <IColumnDataTypeSerializer>(); _mockColumnDataTypeSerializer.Setup(p => p.Deserialize(_xColumns)).Returns(_dataTypes); _mockColumnSerializer = new Mock <IColumnSetSerializer>(); _mockColumnSerializer.Setup(p => p.Serialize(_columns)).Returns(_xColumns); _mockColumnSerializer.Setup(p => p.Deserialize(_xColumns, _rows)).Returns(_columns); _mockRowSerializer = new Mock <IRowSetSerializer>(); _mockRowSerializer.Setup(p => p.Serialize(_rows, _columns)).Returns(_xRows); _mockRowSerializer.Setup(p => p.Deserialize(_xRows, _dataTypes)).Returns(_rows); _mockFilterSerializer = new Mock <IFilterSetSerializer>(); _mockFilterSerializer.Setup(p => p.Serialize(_filters)).Returns(_xFilters); _mockFilterSerializer.Setup(p => p.Deserialize(_xFilters, _columns)).Returns(_filters); _mockViewSerializer = new Mock <IViewSetSerializer>(); _mockViewSerializer.Setup(p => p.Serialize(_views)).Returns(_xViews); _mockViewSerializer.Setup(p => p.Deserialize(_xViews, _columns)).Returns(_views); _serializer = new ProjectSerializer( _mockSourceSerializer.Object, _mockColumnDataTypeSerializer.Object, _mockColumnSerializer.Object, _mockRowSerializer.Object, _mockFilterSerializer.Object, _mockViewSerializer.Object); }
/// <summary> /// Save the project changes held by this database if this project is dirty. /// If no changes are pending, this is a noop. /// </summary> public void save(ProjectSerializer serializer) { if (IsDirty) { Project.Logger.Info("Saving {Database}", Name); serialize(serializer); IsDirty = false; } }
public void TestLoadCommand() { IProjectNode project = ProjectSerializer.LoadString("rule root {\nbranch plural Plural-Form\n}\n", null, null); BranchCommand cmd = (BranchCommand)(project.Children[0].Children[0].Children[0]); Assert.AreEqual("plural", cmd.Name); Assert.AreEqual("Plural-Form", cmd.Rule); }
public override void WriteCommand(System.IO.TextWriter writer) { writer.WriteLine("Translate {"); foreach (string[] key in _stringmapping.Keys) { writer.WriteLine("{0} => {1}", ProjectSerializer.SecureList(key), ProjectSerializer.SecureList(_stringmapping[key])); } writer.WriteLine("}"); }
public void TestLoadProject() { IProjectNode p = ProjectSerializer.LoadString("", null, null); Assert.IsNotNull(p); Assert.AreEqual(0, p.Index); Assert.AreEqual(ProjectNodeType.Root, p.NodeType); Assert.IsEmpty(p.Children); }
public void TestWorkingTranslation() { ProjectSerializer ps = new ProjectSerializer("a b c => d e f\n", null, null); TranslationNode tn = new TranslationNode(ps); Assert.IsTrue(tn.Successful); Assert.AreEqual(new string[] { "a", "b", "c" }, tn.Source.ToArray()); Assert.AreEqual(new string[] { "d", "e", "f" }, tn.Destination.ToArray()); }
private void toolStripButtonSaveAs_Click(object sender, EventArgs e) { if (saveFileDialogSave.ShowDialog() == DialogResult.OK) { ProjectSerializer.SaveProject(_Editor.Project, saveFileDialogSave.FileName); _Editor.Project.FilePath = saveFileDialogSave.FileName; saveFileDialogSave.FileName = ""; } }
public void SimpleTreeSetup() { _topProject = new Project { GroupId = "a", ArtifactId = "a" }; _secondProject = new Project { GroupId = "b", ArtifactId = "b" }; _serializerMock = new Mock <IProjectSerializerWithUpdate>(); _readerMock = new Mock <IProjectReader>(); _writerMock = new Mock <IProjectWriter>(); var realSerializer = new ProjectSerializer(new DataFactory()); _topProjectContent = realSerializer.Serialize(_topProject); _serializerMock.Setup(s => s.Deserialize(_topProjectContent)).Returns(_topProject); _topFolder = "top"; _secondFolderName = "second"; _topProjectPath = "top\\pom.xml"; _secondProjectPath = "top\\second\\pom.xml"; _fileIOMock = new Mock <IFileSystemAccess>(); _fileIOMock.Setup(io => io.GetFullPath(It.IsAny <string>())).Returns((string s) => s); // load tree _fileIOMock.Setup(io => io.ReadAllText(_topProjectPath)).Returns(_topProjectContent); _fileIOMock.Setup(io => io.IsFileExist(_topProjectPath)).Returns(true); _fileIOMock.Setup(io => io.IsFileExist(_secondProjectPath)).Returns(true); // scan for files _fileIOMock.Setup(io => io.IsDirectoryExist(_topFolder)).Returns(true); _fileIOMock.Setup(io => io.GetFiles(_topFolder, "pom.xml", SearchOption.AllDirectories)) .Returns(new[] { _topProjectPath, _secondProjectPath }); Mock <IPathCalculator> path = new Mock <IPathCalculator>(); FullPath topFullPath = new FullPath(_topProjectPath); FullPath seconFullPath = new FullPath(_secondProjectPath); path.Setup(p => p.TryResolveModulePath(topFullPath, _secondFolderName, out seconFullPath)).Returns(true); _readerMock.Setup(l => l.ReadProject(_topProjectPath)).Returns(_topProject); _readerMock.Setup(l => l.ReadProject(_secondProjectPath)).Returns(_secondProject); _loader = new ProjectTreeLoader(_fileIOMock.Object, _readerMock.Object, _writerMock.Object, path.Object, new NoLog()); }
public override void LoadCommand(Project project, System.IO.TextReader reader, string line, ref int lineNumber) { base.LoadCommand(project, reader, line, ref lineNumber); List <string> parts = ProjectSerializer.ReadTokens(line); if (parts.Count != 2) { project.Warnings.Add(string.Format("Line {0}: The PreLit command requires 1 argument.", lineNumber)); } else { _Literal = parts[1]; } }
private Coroutine Serialize(string path, BoolFlag errorFlag, bool handleCompletion = true) { DatabaseManager.Instance.ResetProgress(); ProgressDialog.Instance.Show("Сохранение проекта"); var completeFlag = new BoolFlag(); var task = new Task(async() => { try { await ProjectSerializer.Serialize(path); } catch (Exception ex) { await new WaitForUpdate(); if (!DatabaseManager.Instance.IsConnected) { DatabaseManager.Instance.Connect(); } errorFlag.Flag = true; completeFlag.Flag = true; ProgressDialog.Instance.Hide(); ErrorDialog.Instance.ShowError("Не удалось сохранить проект.", ex); return; } _project.Path = FileExplorer.Instance.LastResult; _project.WasChanged = false; await new WaitForUpdate(); errorFlag.Flag = false; completeFlag.Flag = true; if (handleCompletion) { ProgressDialog.Instance.Hide(); PopupManager.Instance.PopSuccess("Проект успешно сохранен"); } }); task.Start(); return(StartCoroutine(FlagRoutine(completeFlag))); }
public void TestLoadTokenSet() { IProjectNode p = ProjectSerializer.LoadString("tokens consonants b c d", null, null); IProjectNode c = p.Children[0]; Assert.AreEqual(0, c.Index); Assert.AreEqual(ProjectNodeType.TokenSetDeclaration, c.NodeType); TokenSetNode tsn = c as TokenSetNode; Assert.AreEqual("consonants", tsn.Name); Assert.AreEqual(3, tsn.Tokens.Count); }
public void TestIndentationLevelVerification() { Mockery mockery = new Mockery(); IProjectNode pn = mockery.NewMock <IProjectNode>(); ProjectSerializer ps = new ProjectSerializer("\tged\r\n\t hest \r\n\tnejj\r\n", null, null); ps.SpacesIndent = 2; Token t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t", t.Text); t = ps.ReadTextToken(pn); Assert.AreEqual(TokenType.Text, t.Type); Assert.AreEqual("ged", t.Text); t = ps.ReadLineBreakToken(pn); t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t ", t.Text); Assert.AreEqual(2, ps.GetIndentationLevel(t.Text)); t = ps.ReadTextToken(pn); Assert.AreEqual(TokenType.Text, t.Type); Assert.AreEqual("hest", t.Text); t = ps.ReadLineBreakToken(pn); t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t", t.Text); Assert.AreEqual(1, ps.GetIndentationLevel(t.Text)); ps.RollBackToken(t); t = ps.ReadIndentationToken(pn); Assert.AreEqual(TokenType.Indentation, t.Type); Assert.AreEqual("\t", t.Text); Assert.AreEqual(1, ps.GetIndentationLevel(t.Text)); }
public ISolution OpenSolution(string fileOrFolderName, bool loadDisconnectedProjects) { IFileSystemAccess fileIo = new FileSystemAccess(); IDataFactory factory = new DataFactory(); IProjectSerializerWithUpdate serializer = new ProjectSerializer(factory); IProjectLoader projectLoader = new ProjectLoader(fileIo, serializer, Log); var pathCalculator = new PathCalculator(fileIo); var loader = new ProjectTreeLoader(fileIo, projectLoader, projectLoader, pathCalculator, Log); IExternalModulesLoader externalModulesLoader = new ExternalModulesLoader(fileIo); var solution = new Solution(fileIo, loader, externalModulesLoader); solution.Open(fileOrFolderName, loadDisconnectedProjects); return(solution); }
public override void LoadCommand(Project project, System.IO.TextReader reader, string line, ref int lineNumber) { base.LoadCommand(project, reader, line, ref lineNumber); List <string> parts = ProjectSerializer.ReadTokens(line); if (parts.Count == 1) { _Amount = 1; } else if (parts.Count == 2) { if (!int.TryParse(parts[1], out _Amount)) { project.Warnings.Add(string.Format("Line {0}: Drop command requires a positive integer as its second argument.", m_lineNumber)); } } }
public override void LoadCommand(Project project, System.IO.TextReader reader, string line, ref int lineNumber) { base.LoadCommand(project, reader, line, ref lineNumber); List <string> parts = ProjectSerializer.ReadTokens(line); if (parts.Count == 2 && parts[1] == "{") { if (ProjectSerializer.ReadLines(project, reader, ReadTranslation, ref lineNumber)) { project.Warnings.Add(string.Format("Line {0}: The Translate command is not closed correctly.", lineNumber)); } } else { project.Warnings.Add(string.Format("Line {0}: The Translate command requires a {{} at the end of the line.", lineNumber)); } }
private Coroutine Deserialize(string path, BoolFlag errorFlag) { DatabaseManager.Instance.ResetProgress(); ProgressDialog.Instance.Show("Восстановление проекта"); var completeFlag = new BoolFlag(); var persistentPath = Application.persistentDataPath; var temporaryPath = Application.temporaryCachePath; var task = new Task(async() => { try { await ProjectSerializer.Deserialize(path, persistentPath, temporaryPath); } catch (Exception ex) { await new WaitForUpdate(); errorFlag.Flag = true; completeFlag.Flag = true; ProgressDialog.Instance.Hide(); ErrorDialog.Instance.ShowError("Не удалось восстановить проект.", ex); return; } await new WaitForUpdate(); errorFlag.Flag = false; completeFlag.Flag = true; _project.Path = FileExplorer.Instance.LastResult; _project.WasChanged = false; ProgressDialog.Instance.Hide(); PopupManager.Instance.PopSuccess("Проект успешно восстановлен"); }); task.Start(); return(StartCoroutine(FlagRoutine(completeFlag))); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (saveFileDialog.ShowDialog() == DialogResult.OK) { if (File.Exists(saveFileDialog.FileName)) { File.Delete(saveFileDialog.FileName); } ProjectSerializer projectSerializer = new ProjectSerializer(); foreach (IRADElement radElement in RADElements) { projectSerializer.radElements.Add(new RADElementSerializer(radElement.RADType, radElement.Serialize())); } File.WriteAllText(saveFileDialog.FileName, JsonConvert.SerializeObject(projectSerializer)); } }
public void TestLineNumber() { Mockery mockery = new Mockery(); IProjectNode pn = mockery.NewMock <IProjectNode>(); ProjectSerializer ps = new ProjectSerializer("a\r\nb;\n\nc", null, null); Token t = ps.ReadTextToken(pn); Assert.AreEqual(1, t.LineNumber); Token newLine = ps.ReadLineBreakToken(pn); t = ps.ReadTextToken(pn); Assert.AreEqual(2, t.LineNumber); newLine = ps.ReadLineBreakToken(pn); t = ps.ReadTextToken(pn); Assert.AreEqual(4, t.LineNumber); }
public override void LoadCommand(Project project, System.IO.TextReader reader, string line, ref int lineNumber) { base.LoadCommand(project, reader, line, ref lineNumber); List <string> parts = ProjectSerializer.ReadTokens(line); if (parts[parts.Count - 1] != "{") { project.Warnings.Add(string.Format("Line {0}: The Loop command requires a {{ at the end of the line.", lineNumber)); } else { parts.RemoveAt(0); parts.RemoveAt(parts.Count - 1); if (parts.Count > 0) { int reps; foreach (string rep in parts) { if (int.TryParse(rep, out reps)) { Repetitions.Add(reps); } else { project.Warnings.Add(string.Format("Line {0}: The loop command requires all arguments to be numeric. '{1}' is not.", lineNumber, rep)); } } if (ProjectSerializer.ReadLines(new object[] { project, Commands }, reader, ProjectSerializer.ParseCommands, ref lineNumber)) { project.Warnings.Add(string.Format("Line {0}: The loop command is not closed correctly.", lineNumber)); } } else { project.Warnings.Add(string.Format("Line {0}: The loop command must have one or more numeric arguments.", lineNumber)); } } }
public override void LoadCommand(Project project, System.IO.TextReader reader, string line, ref int lineNumber) { base.LoadCommand(project, reader, line, ref lineNumber); List <string> parts = ProjectSerializer.ReadTokens(line); if (parts.Count == 1) { _Index = -1; } else if (parts.Count == 2) { if (!int.TryParse(parts[1], out _Index)) { project.Warnings.Add(string.Format("Line {0}: The capitalize command requires the first argument to be an integer.", lineNumber)); } } else { project.Warnings.Add(string.Format("Line {0}: The capitalize command requires zero or one argument.", lineNumber)); } }
public void Init() { testPath = @"C:\projectSquared\test\"; serializer = new ProjectSerializer(testPath); }