Esempio n. 1
0
        public void GoPoemBegining()
        {
            PoemLine curLine = this.CurrentLine;

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

                    SetOneLine(curLine);
                }
                else
                {
                    Poem curPoem = curLine.ParentPoem;

                    bool isFirstLine = curPoem.IsFirstLine(curLine);

                    if (!isFirstLine)
                    {
                        SetOneLine(curPoem.GetFirstLine());
                    }
                }
            }
        }
Esempio n. 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());
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void SetCurrentLine(Poem poem)
        {
            PoemLine line = poem.GetFirstLine();

            if (CurrentLine != line)
            {
                SetOneLine(line);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void GetRandomLine(Poem poem)
        {
            PoemLine result = null;

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

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

                result = poem.GetLineByIndex(randomIndex);
            }

            SetOneLine(result);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public void GetRandomPoem()
        {
            PoemLine result = null;

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

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

                Poem randomPoem = systemAccumulation.GetPoemByIndex(randomPoemIndex);

                result = randomPoem.GetFirstLine();
            }

            SetOneLine(result);
        }
Esempio n. 9
0
        public void GetRandomPoemPart(Poem poem)
        {
            PoemLine result = null;

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

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

                PoemPart poemPart = poem.Parts[randomIndex];

                result = poemPart.GetFirstLine();
            }

            SetOneLine(result);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        private static Poem CreatePoemFromXml(XmlNode itemPoem)
        {
            Poem result = new Poem();

            XmlAttribute attr;

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

            XmlNode nodeParts = itemPoem[objNamePoemPartCollection];

            if (nodeParts != null)
            {
                foreach (XmlNode itemPart in nodeParts)
                {
                    PoemPart poemPart = CreatePoemPartFromXml(itemPart);

                    result.Parts.Add(poemPart);
                }
            }
            else
            {
                XmlNode nodeLines = itemPoem[xmlNodeNamePoemLineCollection];
                if (nodeLines != null)
                {
                    foreach (XmlNode itemLine in nodeLines)
                    {
                        PoemLine poemLine = CreatePoemLineFromXml(itemLine);

                        result.Lines.Add(poemLine);
                    }
                }
            }

            return(result);
        }
        private static Collection <Poem> GetPoemsFromText(string poemCollectionText)
        {
            Collection <Poem> result = new Collection <Poem>();

            string[] splitPoems = poemCollectionText.Split(new string[] { PoemSplitter }, StringSplitOptions.RemoveEmptyEntries);

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

                Poem newPoem = new Poem();
                newPoem.Name = name;

                result.Add(newPoem);

                if (text.Contains(PoemPartSplitter))
                {
                    Collection <PoemPart> poems = GetPoemParts(text);
                    foreach (PoemPart itemPart in poems)
                    {
                        newPoem.Parts.Add(itemPart);
                    }
                }
                else
                {
                    Collection <PoemLine> poems = GetLines(text);
                    foreach (PoemLine item in poems)
                    {
                        newPoem.Lines.Add(item);
                    }
                }
            }


            return(result);
        }
Esempio n. 13
0
        private static XmlNode CreatePoemNode(Poem poem, XmlDocument saXmlFile)
        {
            XmlNode result = saXmlFile.CreateElement(xmlNodeNamePoem);

            XmlAttribute attr;

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

            if (poem.Parts.Count > 0)
            {
                XmlNode nodeParts = saXmlFile.CreateElement(objNamePoemPartCollection);
                result.AppendChild(nodeParts);

                foreach (PoemPart part in poem.Parts)
                {
                    XmlNode node = CreatePoemPartNode(part, saXmlFile);

                    nodeParts.AppendChild(node);
                }
            }
            else if (poem.Lines.Count > 0)
            {
                XmlNode nodeLines = saXmlFile.CreateElement(xmlNodeNamePoemLineCollection);
                result.AppendChild(nodeLines);

                foreach (PoemLine poemLine in poem.Lines)
                {
                    XmlNode node = CreatePoemLineNode(poemLine, saXmlFile);

                    nodeLines.AppendChild(node);
                }
            }

            return(result);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        private PoemLine GenerateNextPoem(PoemLine currentLine, bool forward)
        {
            Poem nextPoem = this.mySAIterator.GetNextPoem(currentLine.ParentPoem, forward);

            return(nextPoem.GetFirstLine());
        }