Пример #1
0
        private static SABlockPart CreateBlockPartFromXml(XmlNode itemPart)
        {
            SABlockPart result = new SABlockPart();

            XmlAttribute attr;

            attr = itemPart.Attributes[xmlFieldName];
            if (attr != null)
            {
                result.Name = attr.Value;
            }

            XmlNode nodePoems = itemPart[xmlNodeNamePoemCollection];

            if (nodePoems != null)
            {
                foreach (XmlNode itemPoem in nodePoems)
                {
                    Poem poem = CreatePoemFromXml(itemPoem);

                    result.Poems.Add(poem);
                }
            }

            return(result);
        }
Пример #2
0
        public string GetFullInfo()
        {
            StringBuilder strBuilder = new StringBuilder();

            PoemPart    curPoemPart  = this.ParentPoemPart;
            Poem        curPoem      = this.ParentPoem;
            SABlockPart curBlockPart = curPoem.ParentBlockPart;
            SABlock     curBlock     = curPoem.ParentBlock;

            strBuilder.AppendFormat("Блок: {0}", curBlock.ToString());

            if (curBlockPart != null)
            {
                strBuilder.AppendLine();
                strBuilder.AppendFormat("Часть блока: {0}", curBlockPart.ToString());
            }

            strBuilder.AppendLine();
            strBuilder.AppendFormat("Стих: {0}", curPoem.ToString());

            if (curPoemPart != null)
            {
                strBuilder.AppendLine();
                strBuilder.AppendFormat("Часть стиха: {0}", curPoemPart.ToString());
            }

            return(strBuilder.ToString());
        }
Пример #3
0
        private static Collection <SABlockPart> GetBlockParts(string fullText)
        {
            Collection <SABlockPart> result = new Collection <SABlockPart>();

            string[] splitBlockParts = fullText.Trim('\n').Split(new string[] { BlockSplitter }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string itemText in splitBlockParts)
            {
                string name = string.Empty;
                string text = CutName(itemText, out name);

                SABlockPart blockPart = new SABlockPart();
                blockPart.Name = name;

                result.Add(blockPart);

                Collection <Poem> poems = GetPoemsFromText(text);
                foreach (Poem item in poems)
                {
                    blockPart.Poems.Add(item);
                }
            }

            return(result);
        }
Пример #4
0
        internal SABlockPart[] GetPartsByFirstLine(string firstLine)
        {
            int count = 0;

            foreach (SABlockPart item in this.Parts)
            {
                string itemFirstLine = item.GetFirstLine().Line;

                if (string.Compare(itemFirstLine, firstLine, true) == 0)
                {
                    count++;
                }
            }

            SABlockPart[] result = new SABlockPart[count];

            count = 0;

            foreach (SABlockPart item in this.Parts)
            {
                string itemFirstLine = item.GetFirstLine().Line;

                if (string.Compare(itemFirstLine, firstLine, true) == 0)
                {
                    result[count] = item;
                    count++;
                }
            }

            return(result);
        }
Пример #5
0
        public void SetCurrentLine(SABlockPart blockPart)
        {
            PoemLine line = blockPart.GetFirstLine();

            if (CurrentLine != line)
            {
                SetOneLine(line);
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        private PoemLine GenerateNextBlockPart(PoemLine currentLine, bool forward)
        {
            if (currentLine.ParentPoem.ParentBlockPart != null)
            {
                SABlockPart nextPart = this.mySAIterator.GetNextBlockPart(currentLine.ParentPoem.ParentBlockPart, forward);
                if (nextPart != null)
                {
                    return(nextPart.GetFirstLine());
                }
            }

            return(GenerateNextBlock(currentLine, forward));
        }
Пример #8
0
        public void GetRandomLine(SABlockPart blockPart)
        {
            PoemLine result = null;

            if (blockPart != null)
            {
                int lineCount = blockPart.LinesCount;

                int randomIndex = CommonOperations.rnd.Next(lineCount);

                result = blockPart.GetLineByIndex(randomIndex);
            }

            SetOneLine(result);
        }
Пример #9
0
        public void GetRandomBlockPart(SABlock block)
        {
            PoemLine result = null;

            if (block != null && block.Parts.Count > 0)
            {
                int partsCount = block.Parts.Count;

                int randomIndex = CommonOperations.rnd.Next(partsCount);

                SABlockPart blockPart = block.Parts[randomIndex];

                result = blockPart.GetFirstLine();
            }

            SetOneLine(result);
        }
Пример #10
0
        public void GetRandomPoem(SABlockPart blockPart)
        {
            PoemLine result = null;

            if (blockPart != null)
            {
                int poemCount = blockPart.PoemCount;

                int randomPoemIndex = CommonOperations.rnd.Next(poemCount);

                Poem randomPoem = blockPart.GetPoemByIndex(randomPoemIndex);

                result = randomPoem.GetFirstLine();
            }

            SetOneLine(result);
        }
Пример #11
0
        private static SABlock CreateBlockFromXml(XmlNode node)
        {
            SABlock result = new SABlock();

            XmlAttribute attr;

            attr = node.Attributes[xmlFieldName];
            if (attr != null)
            {
                result.Name = attr.Value;
            }

            attr = node.Attributes[xmlFieldAuthor];
            if (attr != null)
            {
                result.Author = attr.Value;
            }

            XmlNode nodeParts = node[xmlNodeNameSABlockPartCollection];

            if (nodeParts != null)
            {
                foreach (XmlNode itemPart in nodeParts)
                {
                    SABlockPart part = CreateBlockPartFromXml(itemPart);

                    result.Parts.Add(part);
                }
            }
            else
            {
                XmlNode nodePoems = node[xmlNodeNamePoemCollection];
                if (nodePoems != null)
                {
                    foreach (XmlNode itemPoem in nodePoems)
                    {
                        Poem poem = CreatePoemFromXml(itemPoem);

                        result.Poems.Add(poem);
                    }
                }
            }

            return(result);
        }
Пример #12
0
        public void GoBlockPartBegining()
        {
            PoemLine curLine = this.CurrentLine;

            if (systemAccumulation != null)
            {
                if (curLine == null)
                {
                    curLine = systemAccumulation.GetFirstLine();

                    SetOneLine(curLine);
                }
                else
                {
                    SABlockPart curBlockPart = curLine.ParentPoem.ParentBlockPart;
                    SABlock     curBlock     = curLine.ParentPoem.ParentBlock;

                    if (curBlockPart != null)
                    {
                        bool isFirstLine = curBlockPart.IsFirstLine(curLine);

                        if (!isFirstLine)
                        {
                            SetOneLine(curBlockPart.GetFirstLine());
                        }
                    }
                    else
                    {
                        bool isFirstLine = curBlock.IsFirstLine(curLine);

                        if (!isFirstLine)
                        {
                            SetOneLine(curBlock.GetFirstLine());
                        }
                    }
                }
            }
        }
Пример #13
0
        private static XmlNode CreateBlockPartNode(SABlockPart part, XmlDocument saXmlFile)
        {
            XmlNode result = saXmlFile.CreateElement(xmlNodeNameSABlockPart);

            XmlAttribute attr;

            attr = saXmlFile.CreateAttribute(xmlFieldName);
            result.Attributes.Append(attr);
            attr.Value = part.Name;

            XmlNode nodePoems = saXmlFile.CreateElement(xmlNodeNamePoemCollection);

            result.AppendChild(nodePoems);

            foreach (Poem poem in part.Poems)
            {
                XmlNode node = CreatePoemNode(poem, saXmlFile);

                nodePoems.AppendChild(node);
            }

            return(result);
        }