Пример #1
0
        internal static bool SaveSprints(ObservableCollection <UISprint> sprints)
        {
            Logger.Logger.Log.Info("Saving sprints...");

            var ret = false;

            var newSprints = new Sprints()
            {
                List = sprints.Select(x => new Sprint()
                {
                    Guid    = x.Guid.Equals(Guid.Empty) ? Guid.NewGuid() : x.Guid,
                    Number  = x.Number,
                    Name    = x.Name,
                    Version = x.Version,
                    Excels  = x.Root.Nodes != null ? x.Root.Nodes.Select(e =>
                                                                         new Excel()
                    {
                        Name        = e.Name,
                        Description = e.Description,
                        Nodes       = e.Nodes != null ? e.Nodes.Select(tab =>
                                                                       new Tab()
                        {
                            Name        = tab.Name,
                            Description = tab.Description,
                            Nodes       = tab.Nodes != null ? tab.Nodes.Select(table =>
                                                                               new DbTable()
                            {
                                Name        = table.Name,
                                Description = table.Description,
                                Nodes       = table.Nodes != null ? table.Nodes.Select(column =>
                                                                                       new DbColumn()
                                {
                                    Name        = column.Name,
                                    Description = column.Description
                                }
                                                                                       ).ToList() : new List <DbColumn>()
                            }
                                                                               ).ToList() : new List <DbTable>()
                        }
                                                                       ).ToList() : new List <Tab>()
                    }
                                                                         ).ToList() : new List <Excel>()
                }).ToList()
            };

            var ix = 0;

            foreach (var s in sprints)
            {
                var obsTables = s.DbSchemaTables;
                newSprints.List[ix].DbSchemaTables = DbSchemaHelper.ConvertDbSchemaTables(obsTables);

                ix++;
            }

            //var exePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            //var dataPath = string.Format("{0}\\Data", exePath);
            var data = FoldersHelper.DataPath; //string.Format("{0}\\sprints.json", dataPath);

            var json = JsonConvert.SerializeObject(newSprints, Formatting.Indented);
            var fi   = new FileInfo(data);

            try
            {
                using (var stream = fi.CreateText())
                {
                    stream.Write(json);
                }
                ret = true;
                Logger.Logger.Log.Info("Saving sprints -> SUCCESS!");
                return(ret);
            } catch (Exception ex)
            {
                Logger.Logger.Log.Error("Error saving sprints...", ex);
                ret = false;
                return(ret);
            }
        }
Пример #2
0
        //public static List<Sprint> LoadSprints()
        //{
        //    var list = new List<Sprint>();
        //    var exePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
        //    var dataPath = string.Format("{0}\\Data", exePath);

        //    var data = string.Format("{0}\\sprints.json", dataPath);
        //    var fi = new FileInfo(data);

        //    using (var stream = fi.OpenText())
        //    {
        //        var json = stream.ReadToEnd();
        //        var rr = JsonConvert.DeserializeObject<Sprints>(json).List;
        //        list = rr;
        //    }

        //    return list;

        //}

        public static bool Load(ref ObservableCollection <UISprint> sprints, IEventAggregator evAgg, MainViewModel viewModel, DatabaseSchemaViewModel dataViewModel)
        {
            Logger.Logger.Log.Info("Loading sprints...");

            var ret = false;

            //var exePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            //var dataPath = string.Format("{0}\\Data", exePath);

            var data = FoldersHelper.DataPath; // string.Format("{0}\\sprints.json", dataPath);
            var di   = new DirectoryInfo(FoldersHelper.DataFolder);

            if (!di.Exists)
            {
                di.Create();
            }

            var fi = new FileInfo(data);

            try
            {
                using (var stream = fi.OpenText())
                {
                    var json = stream.ReadToEnd();
                    var rr   = JsonConvert.DeserializeObject <Sprints>(json);

                    foreach (var s in rr.List)
                    {
                        var nodeRoot = new NodeRoot(evAgg, viewModel);
                        var sprint   = new UISprint(evAgg, sprints, nodeRoot, viewModel, dataViewModel)
                        {
                            Guid = s.Guid, Number = s.Number, Name = s.Name, Version = s.Version
                        };
                        sprint.DbSchemaTables = DbSchemaHelper.ConvertDbSchemaTables(s.DbSchemaTables);
                        sprints.Add(sprint);

                        var result = new ObservableCollection <NodeExcel>();
                        nodeRoot.Nodes = result;
                        if (s.Excels == null)
                        {
                            continue;
                        }
                        foreach (var r in s.Excels)
                        {
                            var ne = new NodeExcel(evAgg, nodeRoot, viewModel)
                            {
                                Name = r.Name, Description = r.Description
                            };
                            result.Add(ne);
                            ne.Nodes = new ObservableCollection <NodeTab>();
                            if (r.Nodes == null)
                            {
                                continue;
                            }
                            foreach (var t in r.Nodes)
                            {
                                var nt = new NodeTab(evAgg, ne, viewModel)
                                {
                                    Name = t.Name, Description = t.Description
                                };
                                ne.Nodes.Add(nt);
                                nt.Nodes = new ObservableCollection <NodeDbTable>();
                                if (t.Nodes == null)
                                {
                                    continue;
                                }
                                foreach (var table in t.Nodes)
                                {
                                    var ntable = new NodeDbTable(evAgg, nt, viewModel)
                                    {
                                        Name = table.Name, Description = table.Description
                                    };
                                    nt.Nodes.Add(ntable);
                                    ntable.Nodes = new ObservableCollection <NodeDbColumn>();
                                    if (table.Nodes == null)
                                    {
                                        continue;
                                    }
                                    foreach (var c in table.Nodes)
                                    {
                                        var nc = new NodeDbColumn(evAgg, ntable, viewModel)
                                        {
                                            Name = c.Name, Description = c.Description
                                        };
                                        ntable.Nodes.Add(nc);
                                    }
                                }
                            }
                        }
                    }
                }
                ret = true;
                Logger.Logger.Log.Info("Loading sprints -> SUCCESS!");
                return(ret);
            }
            catch (Exception ex)
            {
                Logger.Logger.Log.Error("Error loading sprints...", ex);
                ret = false;

                Logger.Logger.Log.Info("Creating sprints ...");

                try
                {
                    using (var s = fi.CreateText())
                    {
                        var sss = "{ \"List\": [ { \"Number\": 0, \"Name\": \"Sprint 0\", \"Version\": \"0.0.0.0\" } ] }";
                        s.Write(sss);
                    }

                    Logger.Logger.Log.Info("Creating sprints -> SUCCESS!");
                    // again ->
                    return(Load(ref sprints, evAgg, viewModel, dataViewModel));
                }
                catch (Exception ex2)
                {
                    Logger.Logger.Log.Error("Error creating sprints data file...", ex2);
                }

                return(ret);
            }
        }