コード例 #1
0
        public static SA CreateSAFromSingleRtfFile(string fileName)
        {
            SA result = new SA();

            result.Name = "Система Накопления";

            FileInfo file = new FileInfo(fileName);

            if (file.Exists)
            {
                Collection <FileInfo> selectedFiles = new Collection <FileInfo>();
                selectedFiles.Add(file);

                {
                    Collection <SABlock> blocks = GetBlocksFromRTFFiles(selectedFiles);

                    foreach (SABlock itemBlock in blocks)
                    {
                        if (itemBlock != null && (itemBlock.Poems.Count > 0 || itemBlock.Parts.Count > 0))
                        {
                            result.Blocks.Add(itemBlock);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #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 XmlNode CreateSANode(SA sa, XmlDocument saXmlFile)
        {
            XmlNode result = saXmlFile.CreateElement(xmlNodeNameSA);

            XmlAttribute attr;

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

            return(result);
        }
コード例 #4
0
        public static void CreateSAFile(string fileName, SA sa)
        {
            XmlDocument saXmlFile = new XmlDocument();

            saXmlFile.AppendChild(saXmlFile.CreateXmlDeclaration("1.0", "utf-8", "yes"));

            XmlNode root = CreateSANode(sa, saXmlFile);

            saXmlFile.AppendChild(root);

            foreach (SABlock item in sa.Blocks)
            {
                XmlNode node = CreateBlockNode(item, saXmlFile);

                root.AppendChild(node);
            }

            saXmlFile.Save(fileName);
        }
コード例 #5
0
        public static SA CreateSAFromRFTFiles(DirectoryInfo directory)
        {
            SA result = new SA();

            result.Name = "Система Накопления";

            if (directory.Exists)
            {
                FileInfo[] files = directory.GetFiles("*.rtf");

                Collection <FileInfo> selectedFiles = new Collection <FileInfo>();

                foreach (FileInfo itemFile in files)
                {
                    if (!itemFile.Name.StartsWith("!") && !itemFile.Name.StartsWith("~"))
                    {
                        selectedFiles.Add(itemFile);
                    }
                }

                if (selectedFiles.Count > 0)
                {
                    Collection <SABlock> blocks = GetBlocksFromRTFFiles(selectedFiles);

                    foreach (SABlock itemBlock in blocks)
                    {
                        if (itemBlock != null && (itemBlock.Poems.Count > 0 || itemBlock.Parts.Count > 0))
                        {
                            result.Blocks.Add(itemBlock);
                        }
                    }
                }
            }

            return(result);
        }