示例#1
0
        private void saveDataToJsonFile(bool original, string filename, XDocument doc)
        {
            string path = (original) ? (FolderDispatcher.OriginalPath()) : (FolderDispatcher.TranslationPath());

            System.IO.Stream stream;
            stream = File.Open(path + filename, FileMode.Create);
            var jsonWriter = JsonReaderWriterFactory.CreateJsonWriter(stream, Encoding.UTF8, true, true);

            jsonWriter.WriteStartDocument();
            jsonWriter.WriteStartElement("root");
            jsonWriter.WriteAttributeString("type", "object");

            IEnumerable <XElement> elements = doc.Root.Elements().ToList();

            foreach (XElement chapter in elements)
            {
                jsonWriter.WriteStartElement(chapter.Name.ToString());
                jsonWriter.WriteAttributeString("type", "object");
                foreach (XElement element in elements.Descendants())
                {
                    jsonWriter.WriteElementString(element.Name.ToString(), element.GetDefaultNamespace().ToString(), element.Value);
                }
            }
            jsonWriter.WriteEndDocument();
            jsonWriter.Flush();
            stream.Close();
        }
示例#2
0
        private void addJsonToManager(string filename)
        {
            string rusPath = FolderDispatcher.OriginalPath() + filename;
            string engPath = FolderDispatcher.TranslationPath() + filename;

            System.IO.Stream stream;

            // preparing original file to xml
            stream = File.Open(rusPath, FileMode.Open);
            var       jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, new System.Xml.XmlDictionaryReaderQuotas());
            XElement  root       = XElement.Load(jsonReader);
            XDocument doc        = new XDocument();

            doc.Add(root);
            XmlReader reader = doc.CreateReader();

            stream.Close();

            // preparing translated file to xml
            stream     = File.Open(engPath, FileMode.Open);
            jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, new System.Xml.XmlDictionaryReaderQuotas());
            root       = XElement.Load(jsonReader);
            XDocument engDoc = new XDocument();

            engDoc.Add(root);
            stream.Close();

            parseXmlFile(reader, engDoc, filename);
        }
示例#3
0
        private void addXmlToManager(string filename)
        {
            string    rusPath = FolderDispatcher.OriginalPath() + filename;
            string    engPath = FolderDispatcher.TranslationPath() + filename;
            XmlReader reader  = new XmlTextReader(rusPath);
            XDocument engDoc  = new XDocument();

            engDoc = XDocument.Load(engPath);
            parseXmlFile(reader, engDoc, filename);
        }
        public void SaveDataToFile(bool original)
        {
            string path = (original) ? (FolderDispatcher.OriginalPath()) : (FolderDispatcher.TranslationPath());

            foreach (CTextData text in textDict.Values)
            {
                string value = (original) ? (text.GetOriginalText()) : (text.GetTranslation(""));
                string file  = path + text.GetFilename();
                File.WriteAllText(file, value, Encoding.UTF8);
            }
        }
        public void AddFileToManager(string filename)
        {
            string rusPath = FolderDispatcher.OriginalPath() + filename;
            string engPath = FolderDispatcher.TranslationPath() + filename;

            string rus = File.ReadAllText(rusPath);
            string eng = File.ReadAllText(engPath);

            textDict.Add(id, new CTextData(filename, rus, eng));
            id++;
        }
示例#6
0
        public void SaveDataToFile(bool original)
        {
            string path = (original) ? (FolderDispatcher.OriginalPath()) : (FolderDispatcher.TranslationPath());
            bool   json = false;

            foreach (string file in CFileList.CheckedFiles)
            {
                XDocument doc = new XDocument();
                if (Path.GetExtension(file) == ".json")
                {
                    json = true;
                    XElement el = new XElement("root");
                    doc.Add(el);
                }
                else
                {
                    json = false;
                }

                if (!json)
                {
                    doc = XDocument.Load(path + file);
                    IEnumerable <XElement> del = doc.Root.Descendants().ToList();
                    del.Remove();
                    doc.Save(path + file);
                }

                foreach (CXmlData text in xmlDict.Values)
                {
                    if (text.GetFilename() != file)
                    {
                        continue;
                    }

                    XElement localPath = text.GetPath();
                    XElement noRoot    = localPath.Descendants().First();
                    string   value     = (original) ? (text.GetOriginalText()) : (text.GetTranslation("eng"));

                    XElement child = noRoot;
                    while (child.HasElements)
                    {
                        XName name = child.Descendants().First().Name;
                        child = child.Element(name);
                    }

                    child.SetValue(value);
                    doc.Root.Add(noRoot);
                }

                if (json)
                {
                    saveDataToJsonFile(original, file, doc);
                    continue;
                }
                else
                {
                    System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
                    settings.Encoding            = new UTF8Encoding(false);
                    settings.Indent              = true;
                    settings.OmitXmlDeclaration  = true;
                    settings.NewLineOnAttributes = false;
                    using (System.Xml.XmlWriter w = System.Xml.XmlWriter.Create(path + file, settings))
                    {
                        doc.Save(w);
                    }
                }
            }
        }