public void Init() { var Path = System.IO.Path.GetDirectoryName(System.IO.Path.Combine(this.Path, Filename)); var ProjectFiles = System.IO.Directory.EnumerateFiles(Path, "*.xaml", System.IO.SearchOption.AllDirectories).OrderBy((x) => x).ToArray(); Workflows = new System.Collections.ObjectModel.ObservableCollection <IWorkflow>(); foreach (string file in ProjectFiles) { Workflows.Add(Workflow.FromFile(this, file)); } //return Workflows.ToArray(); }
private void LoadFilesFromDisk(string folder) { if (string.IsNullOrEmpty(folder)) { folder = Path; } var Files = System.IO.Directory.EnumerateFiles(folder, "*.*", System.IO.SearchOption.AllDirectories).OrderBy((x) => x).ToArray(); foreach (string file in Files) { if (System.IO.Path.GetExtension(file).ToLower() == ".xaml") { Workflows.Add(Workflow.FromFile(this, file)); } else if (System.IO.Path.GetExtension(file).ToLower() == ".json") { var json = System.IO.File.ReadAllText(file); Detector _d = JsonConvert.DeserializeObject <Detector>(json); if (!string.IsNullOrEmpty(_d._id)) { var exists = RobotInstance.instance.Detectors.FindById(_d._id); if (exists != null) { _d._id = null; } else { _d.isLocalOnly = true; } } if (string.IsNullOrEmpty(_d._id)) { _d._id = Guid.NewGuid().ToString(); } _d.isDirty = true; _d.Start(true); Detectors.Add(_d); } } }
public async Task LoadFileFromDisk(string file) { if (System.IO.Path.GetExtension(file).ToLower() == ".xaml") { var wf = Workflow.FromFile(this, file); wf.projectid = _id; wf._acl = _acl; await wf.Save(); } else if (System.IO.Path.GetExtension(file).ToLower() == ".json") { var json = System.IO.File.ReadAllText(file); JObject o = null; try { o = JObject.Parse(json); } catch (Exception ex) { Log.Warning("Error parsing " + file); Log.Error(ex.Message); return; } if (!o.ContainsKey("_type")) { Log.Warning("skipping " + file + " missing _type field"); return; } var _type = o.Value <string>("_type"); if (_type == "workitemqueue") { var _wiq = JsonConvert.DeserializeObject <WorkitemQueue>(json); _wiq.projectid = _id; _wiq._acl = _acl; _wiq.isDirty = true; _wiq.projectid = _id; if (!string.IsNullOrEmpty(_wiq._id)) { var exists = RobotInstance.instance.dbWorkItemQueues.FindById(_wiq._id); if (exists == null) { exists = RobotInstance.instance.dbWorkItemQueues.Find(x => x.name.ToLower() == _wiq.name.ToLower()).FirstOrDefault(); } else { if (string.IsNullOrEmpty(exists.name)) { exists.name = ""; } if (exists.name.ToLower() != _wiq.name.ToLower()) { _wiq._id = null; exists = null; } } if (exists != null) { Log.Warning("Skipping workitem queeu " + exists.name + " it already exists"); return; } else { _wiq.isLocalOnly = true; } } _wiq.isDirty = true; if (global.webSocketClient != null && global.webSocketClient.user != null && global.webSocketClient.isConnected) { if (_wiq.isLocalOnly || string.IsNullOrEmpty(_wiq._id)) { await _wiq.Save(true); } else { await _wiq.Save(); } } else if (!string.IsNullOrEmpty(Config.local.wsurl)) { System.Windows.MessageBox.Show("Not connected to " + Config.local.wsurl + " so cannot validate WorkItemQueue, removing queue from import"); } else { await _wiq.Save(true); } Log.Output("Adding workitem queue " + _wiq.name); } if (_type == "detector") { var _d = JsonConvert.DeserializeObject <Detector>(json); if (!string.IsNullOrEmpty(_d._id)) { var exists = RobotInstance.instance.dbDetectors.FindById(_d._id); if (exists != null) { _d._id = null; } else { _d.isLocalOnly = true; } } if (string.IsNullOrEmpty(_d._id)) { _d._id = Guid.NewGuid().ToString(); } _d.projectid = _id; _d._acl = _acl; _d.isDirty = true; _d.projectid = _id; _d.Start(true); Detectors.Add(_d); Log.Output("Adding detector " + _d.name); } if (_type == "workflow") { var _wf = JsonConvert.DeserializeObject <Workflow>(json); var exists = RobotInstance.instance.dbWorkflows.FindById(_wf._id); _wf.projectid = _id; if (exists == null) { exists = RobotInstance.instance.dbWorkflows.Find(x => x.ProjectAndName.ToLower() == _wf.ProjectAndName.ToLower()).FirstOrDefault(); } else { if (exists.ProjectAndName.ToLower() != _wf.ProjectAndName.ToLower()) { _wf._id = null; exists = null; } } if (exists != null) { Log.Warning("Skipping workitem queeu " + exists.name + " it already exists"); return; } else { _wf.isLocalOnly = true; } //if (!string.IsNullOrEmpty(_wf._id)) //{ // var exists = RobotInstance.instance.Workflows.Where(x => x._id == _wf._id).FirstOrDefault(); // if (exists != null) { _wf._id = null; } else { _wf.isLocalOnly = true; } //} if (string.IsNullOrEmpty(_wf._id)) { _wf._id = Guid.NewGuid().ToString(); } _wf.isDirty = true; _wf.projectid = _id; _wf._acl = _acl; await _wf.Save(); Log.Output("Adding workflow " + _wf.name); } } }