private void DoAddExcel() { var newExcel = new NodeExcel(eventAgg, root); newExcel.AreDescsShown = AreDescsShown; NodesExcel.Insert(0, newExcel); }
private void DoAddExcel() { var newExcel = new NodeExcel(eventAgg, root, this); newExcel.AreDescsShown = AreDescsShown; if (NodesExcel == null) { NodesExcel = new ObservableCollection <IFulltext>(); } NodesExcel.Insert(0, newExcel); SelectedExcel = newExcel; newExcel.IsSelected = true; }
private void DoImport() { var exePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); var dataPath = string.Format("{0}\\Data", exePath); var data = string.Format("{0}\\data.json", dataPath); var guide = string.Format("{0}\\guide.txt", dataPath); var fi = new FileInfo(guide); if (fi.Exists) { using (var stream = fi.OpenText()) { var text = stream.ReadToEnd(); stream.Close(); var lines = text.Split('\n'); var nodeRoot = new NodeRoot(eventAgg, this) { Name = "ROOT", Description = "just help instance..." }; NodesExcel = new ObservableCollection <IFulltext>(); var masterDataNode = new NodeExcel(eventAgg, nodeRoot, this) { Name = "MasterData" }; nodeRoot.Nodes = new ObservableCollection <IFulltext>(); nodeRoot.Nodes.Add(masterDataNode); masterDataNode.Nodes = new ObservableCollection <IFulltext>(); NodesExcel.Add(masterDataNode); NodeTab tab = null; NodeDbTable dbTable = null; foreach (var l in lines) { if (string.IsNullOrEmpty(l) || string.IsNullOrWhiteSpace(l)) { continue; } if (l[0] == '#') { // starting... -> tab = new NodeTab(eventAgg, masterDataNode, this) { Name = l.Substring(1, l.IndexOf('-') - 2), Description = l.Substring(l.IndexOf('-') + 2) }; dbTable = new NodeDbTable(eventAgg, tab, this) { Name = l.Substring(1, l.IndexOf('-') - 2).Replace(" ", "") }; tab.Nodes = new ObservableCollection <IFulltext> { dbTable }; NodesExcel[0].Nodes.Add(tab); } else { var column = new NodeDbColumn(eventAgg, dbTable, this) { Name = (l.Substring(0, l.IndexOf('-') - 1)), Description = l.Substring(l.IndexOf('-') + 2) }; if (tab.Nodes[0].Nodes == null) { tab.Nodes[0].Nodes = new ObservableCollection <IFulltext>(); } tab.Nodes[0].Nodes.Add(column); } } } } }
//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); } }