public void SetCurrentLineByID(PoemLineIdentifier curLine) { PoemLine line = systemAccumulation.GetLineByID(curLine); if (line != null) { SetOneLine(line); } }
internal PoemLineIdentifier GetID() { PoemLineIdentifier result = new PoemLineIdentifier(); result.LineString = this.Line; PoemPart curPoemPart = this.ParentPoemPart; Poem curPoem = this.ParentPoem; result.PoemName = curPoem.Name; result.PoemFirstLine = curPoem.GetFirstLine().Line; PoemLinesCollection collLines = null; if (curPoemPart != null) { collLines = curPoemPart.Lines; result.PoemPartName = curPoemPart.Name; result.PoemPartFirstLine = curPoemPart.GetFirstLine().Line; result.PoemPartIndex = curPoem.Parts.IndexOf(curPoemPart); } else { collLines = curPoem.Lines; } result.LineIndex = collLines.IndexOf(this); SABlockPart curBlockPart = curPoem.ParentBlockPart; SABlock curBlock = curPoem.ParentBlock; result.BlockName = curBlock.Name; result.BlockIndex = curBlock.ParentSA.Blocks.IndexOf(curBlock); PoemCollection collPoems = null; if (curBlockPart != null) { collPoems = curBlockPart.Poems; result.BlockPartName = curBlockPart.Name; result.BlockPartFirstLine = curBlockPart.GetFirstLine().Line; result.BlockPartIndex = curBlock.Parts.IndexOf(curBlockPart); } else { collPoems = curBlock.Poems; } result.PoemIndex = collPoems.IndexOf(curPoem); return(result); }
internal PoemLine GetLineByID(PoemLineIdentifier lineId) { SABlock block = null; if (!string.IsNullOrEmpty(lineId.BlockName)) { SABlock[] searchBlocks = this.GetBlockByName(lineId.BlockName); if (searchBlocks.Length == 1) { block = searchBlocks[0]; } else if (searchBlocks.Length > 1) { foreach (SABlock item in searchBlocks) { if (this.Blocks.IndexOf(item) == lineId.BlockIndex) { block = item; break; } } } } if (block == null) { return(null); } PoemCollection poemColl = null; if (!string.IsNullOrEmpty(lineId.BlockPartFirstLine) && lineId.BlockPartIndex.HasValue) { SABlockPart[] searchBlockParts = block.GetPartsByFirstLine(lineId.BlockPartFirstLine); if (searchBlockParts.Length == 1) { poemColl = searchBlockParts[0].Poems; } else if (searchBlockParts.Length > 1) { foreach (SABlockPart item in searchBlockParts) { if (block.Parts.IndexOf(item) == lineId.BlockPartIndex) { poemColl = item.Poems; break; } } } } else { poemColl = block.Poems; } if (poemColl == null) { return(null); } Poem poem = null; if (!string.IsNullOrEmpty(lineId.PoemFirstLine) && lineId.PoemIndex.HasValue) { Poem[] searchBlockParts = poemColl.GetPoemsByFirstLine(lineId.PoemFirstLine); if (searchBlockParts.Length == 1) { poem = searchBlockParts[0]; } else if (searchBlockParts.Length > 1) { foreach (Poem item in searchBlockParts) { if (poemColl.IndexOf(item) == lineId.PoemIndex) { poem = item; break; } } } } if (poem == null) { return(null); } PoemLinesCollection linesColl = null; if (!string.IsNullOrEmpty(lineId.PoemPartFirstLine) && lineId.PoemPartIndex.HasValue) { PoemPart[] searchBlockParts = poem.GetPartsByFirstLine(lineId.PoemPartFirstLine); if (searchBlockParts.Length == 1) { linesColl = searchBlockParts[0].Lines; } else if (searchBlockParts.Length > 1) { foreach (PoemPart item in searchBlockParts) { if (poem.Parts.IndexOf(item) == lineId.PoemPartIndex) { linesColl = item.Lines; break; } } } } else { linesColl = poem.Lines; } if (linesColl == null) { return(null); } PoemLine line = null; if (!string.IsNullOrEmpty(lineId.LineString) && lineId.LineIndex.HasValue) { PoemLine[] searchBlockParts = linesColl.GetPoemsByFirstLine(lineId.LineString); if (searchBlockParts.Length == 1) { line = searchBlockParts[0]; } else if (searchBlockParts.Length > 1) { foreach (PoemLine item in searchBlockParts) { if (linesColl.IndexOf(item) == lineId.LineIndex) { line = item; break; } } } } if (line == null) { return(null); } return(line); }
internal static PoemLineIdentifier CreateFromXmlNode(XmlNode node) { PoemLineIdentifier result = new PoemLineIdentifier(); XmlAttribute attr; // Блок. attr = node.Attributes[attrBlockName]; if (attr != null) { result.BlockName = attr.Value; } attr = node.Attributes[attrBlockIndex]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { int tempInt; if (int.TryParse(attr.Value, out tempInt)) { result.BlockIndex = tempInt; } } // Часть блока attr = node.Attributes[attrBlockPartName]; if (attr != null) { result.BlockPartName = attr.Value; } attr = node.Attributes[attrBlockPartFirstLine]; if (attr != null) { result.BlockPartFirstLine = attr.Value; } attr = node.Attributes[attrBlockPartIndex]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { int tempInt; if (int.TryParse(attr.Value, out tempInt)) { result.BlockPartIndex = tempInt; } } // Стих attr = node.Attributes[attrPoemName]; if (attr != null) { result.PoemName = attr.Value; } attr = node.Attributes[attrPoemFirstLine]; if (attr != null) { result.PoemFirstLine = attr.Value; } attr = node.Attributes[attrPoemIndex]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { int tempInt; if (int.TryParse(attr.Value, out tempInt)) { result.PoemIndex = tempInt; } } // Часть стиха attr = node.Attributes[attrPoemPartName]; if (attr != null) { result.PoemPartName = attr.Value; } attr = node.Attributes[attrPoemPartFirstLine]; if (attr != null) { result.PoemPartFirstLine = attr.Value; } attr = node.Attributes[attrPoemPartIndex]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { int tempInt; if (int.TryParse(attr.Value, out tempInt)) { result.PoemPartIndex = tempInt; } } // Строка attr = node.Attributes[attrLineString]; if (attr != null) { result.LineString = attr.Value; } attr = node.Attributes[attrLineIndex]; if (attr != null && !string.IsNullOrEmpty(attr.Value)) { int tempInt; if (int.TryParse(attr.Value, out tempInt)) { result.LineIndex = tempInt; } } return(result); }
//public void LoadConfigurationFromFile(string fileName) //{ // if (!File.Exists(fileName)) // { // return; // } // XmlDocument saXmlFile = new XmlDocument(); // saXmlFile.Load(fileName); // XmlNode node = saXmlFile[objName]; // if (node != null) // { // LoadConfigurationFromNode(node); // } //} public void LoadConfigurationFromNode(XmlNode nodeControllerConfig) { //{ // XmlNode nodeCurrentPosition = nodeControllerConfig[objCurrentPosition]; // if (nodeCurrentPosition != null && nodeCurrentPosition.ChildNodes.Count == 1) // { // PoemLineIdentifier lineId = PoemLineIdentifier.CreateFromXmlNode(nodeCurrentPosition.ChildNodes[0]); // PoemLine line = systemAccumulation.GetLineByID(lineId); // if (line != null) // { // selectedLines.Clear(); // selectedLines.Add(line); // } // } //} { this.selectedLines.Clear(); XmlNode nodeSelectedLines = nodeControllerConfig[objSelectedLines]; if (nodeSelectedLines != null) { foreach (XmlNode node in nodeSelectedLines) { PoemLineIdentifier lineId = PoemLineIdentifier.CreateFromXmlNode(node); if (lineId != null) { PoemLine line = systemAccumulation.GetLineByID(lineId); if (line != null) { bool addLine = true; if (this.selectedLines.Count > 0) { PoemLine lastLine = selectedLines[selectedLines.Count - 1]; PoemLine nextLine = mySAIterator.GetNextLine(lastLine, true); addLine = nextLine == line; } else { addLine = true; } if (addLine) { this.selectedLines.Add(line); } } } } } while (this.selectedLines.Count > this.selectedLinesCount) { this.selectedLines.RemoveAt(0); } } { this.HistoryPreviousLines.Clear(); XmlNode nodePreviousLines = nodeControllerConfig[objHistoryPreviousLines]; if (nodePreviousLines != null) { foreach (XmlNode node in nodePreviousLines) { PoemLineIdentifier lineId = PoemLineIdentifier.CreateFromXmlNode(node); if (lineId != null) { PoemLine line = systemAccumulation.GetLineByID(lineId); if (line != null) { this.HistoryPreviousLines.Add(line); } } } } while (HistoryPreviousLines.Count > maxHistoryElement) { HistoryPreviousLines.RemoveAt(HistoryPreviousLines.Count - 1); } } { this.HistoryNextLines.Clear(); XmlNode nodeNextLines = nodeControllerConfig[objHistoryNextLines]; if (nodeNextLines != null) { foreach (XmlNode node in nodeNextLines) { PoemLineIdentifier lineId = PoemLineIdentifier.CreateFromXmlNode(node); if (lineId != null) { PoemLine line = systemAccumulation.GetLineByID(lineId); if (line != null) { this.HistoryNextLines.Add(line); } } } } } OnCurrentLineChanged(); OnHistoryChanged(); }
//public void SaveConfiguration(string fileName) //{ // XmlDocument xmlFile = new XmlDocument(); // xmlFile.AppendChild(xmlFile.CreateXmlDeclaration("1.0", "utf-8", "yes")); // XmlNode root = CreateXmlNode(xmlFile); // xmlFile.AppendChild(root); // xmlFile.Save(fileName); //} public XmlNode CreateXmlNode(XmlDocument xmlFile) { XmlNode nodeControllerConfig = xmlFile.CreateElement(objName); //{ // PoemLine curLine = this.CurrentLine; // if (curLine != null) // { // PoemLineIdentifier lineId = curLine.GetID(); // if (lineId != null) // { // XmlNode nodeCurrentPosition = xmlFile.CreateElement(objCurrentPosition); // nodeControllerConfig.AppendChild(nodeCurrentPosition); // nodeCurrentPosition.AppendChild(lineId.CreateNode(xmlFile)); // } // } //} { XmlNode nodeSelectedLines = xmlFile.CreateElement(objSelectedLines); nodeControllerConfig.AppendChild(nodeSelectedLines); foreach (PoemLine line in this.selectedLines) { PoemLineIdentifier lineId = line.GetID(); if (lineId != null) { nodeSelectedLines.AppendChild(lineId.CreateNode(xmlFile)); } } } { XmlNode nodePreviousLines = xmlFile.CreateElement(objHistoryPreviousLines); nodeControllerConfig.AppendChild(nodePreviousLines); foreach (PoemLine line in this.HistoryPreviousLines) { PoemLineIdentifier lineId = line.GetID(); if (lineId != null) { nodePreviousLines.AppendChild(lineId.CreateNode(xmlFile)); } } } { XmlNode nodeNextLines = xmlFile.CreateElement(objHistoryNextLines); nodeControllerConfig.AppendChild(nodeNextLines); foreach (PoemLine line in this.HistoryNextLines) { PoemLineIdentifier lineId = line.GetID(); if (lineId != null) { nodeNextLines.AppendChild(lineId.CreateNode(xmlFile)); } } } return(nodeControllerConfig); }