コード例 #1
0
            public TestEnvironment(string rfctag, string rfctag2)
            {
                _folder = new TemporaryFolder("WritingSystemsInoptionListFileHelper");
                var pathtoOptionsListFile1 = Path.Combine(_folder.Path, "test1.xml");

                _optionListFile = new IO.TempFile(String.Format(_optionListFileContent, rfctag, rfctag2));
                _optionListFile.MoveTo(pathtoOptionsListFile1);
            }
コード例 #2
0
            public TestEnvironment(string liftFileContent)
            {
                _folder = new TemporaryFolder("WritingSystemsInLiftFileHelper");
                var pathtoLiftFile1 = Path.Combine(_folder.Path, "test1.lift");

                _liftFile1 = new IO.TempFile(liftFileContent);
                _liftFile1.MoveTo(pathtoLiftFile1);
                Helper = new WritingSystemsInLiftFileHelper(WritingSystems, _liftFile1.Path);
            }
コード例 #3
0
        public void ReplaceWritingSystemId(string oldId, string newId)
        {
            var fileToBeWrittenTo = new IO.TempFile();
            var reader            = XmlReader.Create(_liftFilePath, Xml.CanonicalXmlSettings.CreateXmlReaderSettings());
            var writer            = XmlWriter.Create(fileToBeWrittenTo.Path, Xml.CanonicalXmlSettings.CreateXmlWriterSettings());

            //System.Diagnostics.Process.Start(fileToBeWrittenTo.Path);
            try
            {
                bool readerMovedByXmlDocument = false;
                while (readerMovedByXmlDocument || reader.Read())
                {
                    readerMovedByXmlDocument = false;
                    var xmldoc = new XmlDocument();
                    //We load up the header and entry nodes individually as XmlDocuments and replace the writing systems
                    //This is not as fast as pure reader writers, but as this is not a frequent operation, that is ok and
                    //it is MUCH easier to code than a statemachine using readers and writers only.
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "header")
                    {
                        var headerFragment = xmldoc.ReadNode(reader);
                        readerMovedByXmlDocument = true;
                        GetNodeWithWritingSystemIdsReplaced(oldId, newId, headerFragment);
                        headerFragment.WriteTo(writer);
                    }
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "entry")
                    {
                        var entryFragment = xmldoc.ReadNode(reader);
                        readerMovedByXmlDocument = true;
                        GetNodeWithWritingSystemIdsReplaced(oldId, newId, entryFragment);
                        entryFragment.WriteTo(writer);
                    }
                    else
                    {
                        writer.WriteNodeShallow(reader);
                    }
                    //writer.Flush();
                }
            }
            finally
            {
                reader.Close();
                writer.Close();
            }
            File.Delete(_liftFilePath);
            fileToBeWrittenTo.MoveTo(_liftFilePath);
        }
コード例 #4
0
        public void DeleteWritingSystemId(string id)
        {
            var fileToBeWrittenTo = new IO.TempFile();
            var reader            = XmlReader.Create(_liftFilePath, Xml.CanonicalXmlSettings.CreateXmlReaderSettings());
            var writer            = XmlWriter.Create(fileToBeWrittenTo.Path, Xml.CanonicalXmlSettings.CreateXmlWriterSettings());

            //System.Diagnostics.Process.Start(fileToBeWrittenTo.Path);
            try
            {
                bool readerMovedByXmlDocument = false;
                while (readerMovedByXmlDocument || reader.Read())
                {
                    readerMovedByXmlDocument = false;
                    var xmldoc = new XmlDocument();
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "entry")
                    {
                        var entryFragment = xmldoc.ReadNode(reader);
                        readerMovedByXmlDocument = true;
                        var nodesWithLangId = entryFragment.SelectNodes(String.Format("//*[@lang='{0}']", id));
                        if (nodesWithLangId != null)
                        {
                            foreach (XmlNode node in nodesWithLangId)
                            {
                                var parent = node.SelectSingleNode("parent::*");
                                if (node.Name == "gloss")
                                {
                                    parent.RemoveChild(node);
                                }
                                else
                                {
                                    var siblingNodes =
                                        node.SelectNodes("following-sibling::form | preceding-sibling::form");
                                    if (siblingNodes.Count == 0)
                                    {
                                        var grandParent = parent.SelectSingleNode("parent::*");
                                        grandParent.RemoveChild(parent);
                                    }
                                    else
                                    {
                                        parent.RemoveChild(node);
                                    }
                                }
                            }
                        }
                        entryFragment.WriteTo(writer);
                    }
                    else
                    {
                        writer.WriteNodeShallow(reader);
                    }
                    //writer.Flush();
                }
            }
            finally
            {
                reader.Close();
                writer.Close();
            }
            File.Delete(_liftFilePath);
            fileToBeWrittenTo.MoveTo(_liftFilePath);
        }