コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: jashif/resxmanager
        private async void LoadAn()
        {
            StorageFile fullrestfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///resxfile.txt"));

            string fulltext = await FileIO.ReadTextAsync(fullrestfile);

            Xml2CSharp.Root rt = new Xml2CSharp.Root();
            rt.replace = "hi";
            rt.Data    = new List <Xml2CSharp.Data>();

            StorageFile restfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///values-" + lancode.Text + "/strings.xml"));

            string text = await FileIO.ReadTextAsync(restfile);

            var eles = XDocument.Parse(text).Descendants("string");

            prg.Maximum = wrroot.Data.Count;
            int i = 0;

            foreach (var vl in wrroot.Data)
            {
                Xml2CSharp.Data dt = new Xml2CSharp.Data();
                dt       = vl;
                dt.Space = "preserve";
                var val = eles.Where(x => x.Attribute("name").Value == vl.AId).FirstOrDefault()?.Value;
                if (val != null)
                {
                    dt.Value = val;
                }
                else
                {
                    dt.Value = await Translate(vl.Value);

                    await Task.Delay(100);
                }
                prg.Value = i;
                t1.Text   = dt.Name;
                t2.Text   = dt.Value;
                i++;

                rt.Data.Add(dt);
            }
            var serialisedxml = Xml2CSharp.XMLUtil.Serialize(rt);

            var    xml   = XElement.Parse(serialisedxml).Elements("data").Select(x => x.ToString());
            string dtxml = "";

            foreach (var x in xml)
            {
                dtxml += x;
            }
            fulltext = fulltext.Replace("<replace>", dtxml);
            var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(lancode.Text + "-IN", CreationCollisionOption.ReplaceExisting);

            StorageFile reswfile = await folder.CreateFileAsync("Resources.resw", CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteTextAsync(reswfile, fulltext);
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: jashif/resxmanager
        private async void Load()
        {
            try
            {
                StorageFile restfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///resxfile.txt"));

                string text = await FileIO.ReadTextAsync(restfile);

                Xml2CSharp.Root root2 = new Xml2CSharp.Root();
                StorageFile     file  = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Resx.xml"));

                root2.Data = new List <Xml2CSharp.Data>();
                var stream = await file.OpenStreamForReadAsync();

                Xml2CSharp.Root root = Xml2CSharp.XMLUtil.DeSerialize(stream) as Xml2CSharp.Root;
                prg.Maximum = root.Data.Count;
                int i = 0;
                foreach (var rt in root.Data)
                {
                    Xml2CSharp.Data dt = new Xml2CSharp.Data();
                    dt.Name = rt.Name;

                    root2.Data.Add(dt);
                    dt.Value = await Translate(rt.Value);

                    dt.Space   = "preserve";
                    dt.Comment = rt.Value;
                    prg.Value  = i;
                    t1.Text    = rt.Value;
                    t2.Text    = dt.Value;
                    i++;
                    await Task.Delay(100);
                }
                root2.replace = "hi";
                //<replace>hi</replace>
                //   root2.Resheader = root.Resheader;
                //root2.Schema = root.Schema;
                var serialisedxml = Xml2CSharp.XMLUtil.Serialize(root2);

                var    xml   = XElement.Parse(serialisedxml).Elements("data").Select(x => x.ToString());
                string dtxml = "";
                foreach (var x in xml)
                {
                    dtxml += x;
                }
                text = text.Replace("<replace>", dtxml);
                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(lancode.Text + "-IN");

                StorageFile reswfile = await folder.CreateFileAsync("Resources.resw");

                await FileIO.WriteTextAsync(reswfile, text);
            }
            catch (Exception ex)
            {
                // throw;
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: jashif/resxmanager
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Xml2CSharp.Root merged = new Xml2CSharp.Root();
            merged.Data = new List <Xml2CSharp.Data>();

            StorageFile wfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Resx.xml"));

            var stream = await wfile.OpenStreamForReadAsync();

            wrroot = Xml2CSharp.XMLUtil.DeSerialize(stream) as Xml2CSharp.Root;

            andrdatas = new List <Xml2CSharp.Data>();
            var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///values/strings.xml"));

            var data = await FileIO.ReadTextAsync(file);


            var eles = XDocument.Parse(data).Descendants("string");

            foreach (var el in eles)
            {
                Xml2CSharp.Data dt = new Xml2CSharp.Data();
                dt.Name    = el.Attribute("name").Value.ToString();
                dt.AId     = el.Attribute("name").Value.ToString();
                dt.Space   = "reserve";
                dt.Value   = el.Value;
                dt.Comment = el.Value;
                if (wrroot.Data.Where(x => x.Name.ToLower() == el.Attribute("name").Value.ToLower()).Count() != 0)
                {
                    if (wrroot.Data.Where(x => x.Value.ToLower() == el.Value.ToLower()).Count() == 0)
                    {
                        var item = wrroot.Data.FirstOrDefault(x => x.Name.ToLower() == el.Attribute("name").Value.ToLower());
                        wrroot.Data[wrroot.Data.IndexOf(item)].AId = dt.AId;
                        item.Value = dt.Value;
                        item.AId   = dt.AId;
                    }
                    else
                    {
                        var item = wrroot.Data.FirstOrDefault(x => x.Name.ToLower() == el.Attribute("name").Value.ToLower());
                        wrroot.Data[wrroot.Data.IndexOf(item)].AId = dt.AId;
                        item.AId = dt.AId;
                    }
                }
                else
                {
                    if (wrroot.Data.Where(x => x.Value.ToLower() == el.Value.ToLower()).Count() == 0)
                    {
                        wrroot.Data.Add(dt);
                    }
                    else
                    {
                        var item = wrroot.Data.FirstOrDefault(x => x.Value.ToLower() == el.Value.ToLower());
                        wrroot.Data[wrroot.Data.IndexOf(item)].AId = dt.AId;
                        item.AId = dt.AId;
                    }
                }

                andrdatas.Add(dt);
            }
        }