Esempio n. 1
0
        public static async Task Parse(IProgress <ParseProgress> progress)
        {
            var outDir = ((App.Current.MainWindow as MainWindow).DataContext as MainVM).OutPath;
            var groups = DCT.DataCenter.Root.Children.GroupBy(x => x.Name);
            var count  = groups.Count();
            var g      = 0;
            var dc     = DCT.GetDataCenter();

            foreach (var group in groups)
            {
                await Task.Run(async() =>
                {
                    var pi          = new ParseProgress();
                    pi.CurrentGroup = group.Key;

                    string dir2, format;
                    if (group.Count() > 1)
                    {
                        dir2   = outDir + "/" + group.Key + "/";
                        format = "{0}-{1}.json";
                    }
                    else
                    {
                        dir2   = outDir + "/";
                        format = "{0}.json";
                    }

                    g++;
                    pi.OverallProgress = g / (float)count;

                    var i            = 0;
                    var objectsCount = group.Count();
                    foreach (var mainObject in group)
                    {
                        await Task.Run(async() =>
                        {
                            var values = dc.GetValues(mainObject, x => x.Value);
                            var json   = JsonConvert.SerializeObject(values, Formatting.Indented);
                            var fName  = string.Format(format, mainObject.Name, i);
                            var path   = Utils.GetOutput(dir2 + fName);
                            File.WriteAllText(path, json);
                            i++;

                            pi.CurrentFile   = fName;
                            pi.GroupProgress = i / (float)objectsCount;
                            progress.Report(pi);
                        });
                    }
                });
            }
        }
Esempio n. 2
0
        public async static Task Parse(IProgress <ParseProgress> progress)
        {
            var dc     = DCT.GetDataCenter();
            var groups = DCT.DataCenter.Root.Children.GroupBy(x => x.Name);
            var count  = groups.Count();
            var g      = 0;
            var outDir = ((App.Current.MainWindow as MainWindow).DataContext as MainVM).OutPath;

            foreach (var group in groups)
            {
                await Task.Run(async() =>
                {
                    var pi          = new ParseProgress();
                    pi.CurrentGroup = group.Key;
                    string dir2, format;
                    if (group.Count() > 1)
                    {
                        dir2   = outDir + "/" + group.Key + "/";
                        format = "{0}-{1}.xml";
                    }
                    else
                    {
                        dir2   = outDir + "/";
                        format = "{0}.xml";
                    }

                    g++;
                    pi.OverallProgress = g / (float)count;
                    Directory.CreateDirectory(dir2);
                    int i            = 0;
                    var objectsCount = group.Count();
                    foreach (var mainObject in group)
                    {
                        await Task.Run(() =>
                        {
                            var element = ConvertToXElement(mainObject);
                            var fName   = string.Format(format, mainObject.Name, i);
                            var path    = dir2 + fName;
                            element.Save(path);
                            i++;
                            pi.CurrentFile   = fName;
                            pi.GroupProgress = i / (float)objectsCount;
                            progress.Report(pi);
                            //Console.WriteLine($"[{i / (float)group.Count():P2}]\tCurrent: {fName}");
                        });
                    }
                });
            }
        }