Пример #1
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());
        }
Пример #2
0
        public static SA CreateSAFromXml(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(null);
            }

            SA result = new SA();

            XmlDocument saXmlFile = new XmlDocument();

            saXmlFile.Load(fileName);

            XmlNode node = saXmlFile[xmlNodeNameSA];

            if (node != null)
            {
                XmlAttribute attr;

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

                    foreach (XmlNode item in node.ChildNodes)
                    {
                        SABlock block = CreateBlockFromXml(item);

                        result.Blocks.Add(block);
                    }
                }
            }

            return(result);
        }
Пример #3
0
        private static SABlock CreateNewBlock(string fileName)
        {
            SABlock block = new SABlock();

            Regex regexName = new Regex(regexNamePattern);

            if (regexName.IsMatch(fileName))
            {
                Match match = regexName.Match(fileName);
                block.Name = match.Groups["Name"].Value;

                block.Author = match.Groups["Author"].Value;

                string rankString = match.Groups["Rank"].Value;
                int    temp;
                if (int.TryParse(rankString, out temp))
                {
                    block.Rank = temp;
                }
            }

            if (string.IsNullOrEmpty(block.Name))
            {
                block.Name = fileName;
            }

            return(block);
        }
Пример #4
0
        internal SABlock[] GetBlockByName(string name)
        {
            int count = 0;

            foreach (SABlock block in this.Blocks)
            {
                if (string.Compare(block.Name, name, true) == 0)
                {
                    count++;
                }
            }

            SABlock[] result = new SABlock[count];

            count = 0;

            foreach (SABlock block in this.Blocks)
            {
                if (string.Compare(block.Name, name, true) == 0)
                {
                    result[count] = block;
                    count++;
                }
            }

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

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

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

                    bool isFirstLine = curBlock.IsFirstLine(curLine);

                    if (!isFirstLine)
                    {
                        SetOneLine(curBlock.GetFirstLine());
                    }
                }
            }
        }
Пример #6
0
        public void SetCurrentLine(SABlock block)
        {
            PoemLine line = block.GetFirstLine();

            if (CurrentLine != line)
            {
                SetOneLine(line);
            }
        }
Пример #7
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);
        }
Пример #8
0
        internal static Collection <SABlock> GetBlocksFromRTFFiles(Collection <FileInfo> selectedFiles)
        {
            Collection <SABlock> result = new Collection <SABlock>();

            using (RichTextBox rTB = new RichTextBox())
            {
                string tempDirName = GetTemporaryDirectoryName();

                DirectoryInfo tempDir = new DirectoryInfo(tempDirName);

                tempDir.Create();

                foreach (FileInfo file in selectedFiles)
                {
                    if (file.Exists)
                    {
                        string  fileName = Path.GetFileNameWithoutExtension(file.Name);
                        SABlock block    = CreateNewBlock(fileName);

                        string tempFileName = Path.Combine(tempDir.FullName, file.Name);

                        file.CopyTo(tempFileName);

                        rTB.LoadFile(tempFileName);
                        DeleteComments(rTB);

                        string text = rTB.Text;

                        if (text.Contains(BlockSplitter))
                        {
                            Collection <SABlockPart> newBlockParts = GetBlockParts(text);

                            foreach (SABlockPart itemBlockPart in newBlockParts)
                            {
                                block.Parts.Add(itemBlockPart);
                            }
                        }
                        else
                        {
                            Collection <Poem> poems = GetPoemsFromText(text);
                            foreach (Poem item in poems)
                            {
                                block.Poems.Add(item);
                            }
                        }

                        result.Add(block);
                    }
                }

                tempDir.Delete(true);
            }

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

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

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

                result = block.GetLineByIndex(randomIndex);
            }

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

            if (systemAccumulation != null)
            {
                int blockCount = systemAccumulation.Blocks.Count;

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

                SABlock block = systemAccumulation.Blocks[randomIndex];

                result = block.GetFirstLine();
            }

            SetOneLine(result);
        }
Пример #11
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);
        }
Пример #12
0
        public void GetRandomPoem(SABlock block)
        {
            PoemLine result = null;

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

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

                Poem randomPoem = block.GetPoemByIndex(randomPoemIndex);

                result = randomPoem.GetFirstLine();
            }

            SetOneLine(result);
        }
Пример #13
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);
        }
Пример #14
0
        private static XmlNode CreateBlockNode(SABlock block, XmlDocument saXmlFile)
        {
            XmlNode result = saXmlFile.CreateElement(xmlNodeNameSABlock);

            XmlAttribute attr;

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

            attr = saXmlFile.CreateAttribute(xmlFieldAuthor);
            result.Attributes.Append(attr);
            attr.Value = block.Author;

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

                foreach (SABlockPart part in block.Parts)
                {
                    XmlNode node = CreateBlockPartNode(part, saXmlFile);

                    nodeParts.AppendChild(node);
                }
            }
            else if (block.Poems.Count > 0)
            {
                XmlNode nodePoems = saXmlFile.CreateElement(xmlNodeNamePoemCollection);
                result.AppendChild(nodePoems);

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

                    nodePoems.AppendChild(node);
                }
            }

            return(result);
        }
Пример #15
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);
        }
Пример #16
0
        private PoemLine GenerateNextBlock(PoemLine currentLine, bool forward)
        {
            SABlock nextBlock = this.mySAIterator.GetNextBlock(currentLine.ParentPoem.ParentBlock, forward);

            return(nextBlock.GetFirstLine());
        }