public async Task Save(bool skipOnline = false) { await Save <Project>(skipOnline); foreach (var workflow in Workflows.ToList()) { if (workflow.projectid != _id) { workflow.projectid = _id; } await workflow.Save(skipOnline); } foreach (Detector detector in Detectors.ToList()) { if (detector.projectid != _id) { detector.projectid = _id; } await detector.Save(skipOnline); } foreach (WorkitemQueue wiq in WorkItemQueues.ToList()) { if (wiq.projectid != _id) { wiq.projectid = _id; } await wiq.Save(skipOnline); } GenericTools.RunUI(() => { if (System.Threading.Monitor.TryEnter(RobotInstance.instance.Projects, Config.local.thread_lock_timeout_seconds * 1000)) { try { var exists = RobotInstance.instance.Projects.FindById(_id); if (exists == null) { RobotInstance.instance.Projects.Add(this); } if (exists != null) { RobotInstance.instance.Projects.UpdateItem(exists, this); } } finally { System.Threading.Monitor.Exit(RobotInstance.instance.Projects); } } else { throw new LockNotReceivedException("Saving Project"); } }); }
public async Task Save() { await Save <Project>(); var wfs = Workflows.ToList(); var dts = Detectors.ToList(); foreach (var workflow in wfs) { workflow.projectid = _id; await workflow.Save(); } foreach (Detector detector in dts) { detector.projectid = _id; await detector.Save(); } }
public async Task Delete(bool skipOnline = false) { foreach (var wiq in WorkItemQueues.ToList()) { if (global.webSocketClient != null && global.webSocketClient.user != null && global.webSocketClient.isConnected) { try { await global.webSocketClient.DeleteWorkitemQueue(wiq, true); } catch (Exception ex) { if (!ex.Message.Contains("not found") && !ex.Message.Contains("denied")) { throw; } } GenericTools.RunUI(() => { RobotInstance.instance.dbWorkItemQueues.Delete(wiq._id); RobotInstance.instance.WorkItemQueues.Remove(wiq); }); } else if (!string.IsNullOrEmpty(Config.local.wsurl)) { System.Windows.MessageBox.Show("Not connected to " + Config.local.wsurl + " so cannot validate deletion of WorkItemQueue"); } else { await wiq.Delete(); } } foreach (var wf in Workflows.ToList()) { await wf.Delete(); } foreach (var d in Detectors.ToList()) { var _d = d as Detector; _d.Stop(); await _d.Delete(); } if (System.IO.Directory.Exists(Path)) { var Files = System.IO.Directory.EnumerateFiles(Path, "*.*", System.IO.SearchOption.AllDirectories).OrderBy((x) => x).ToArray(); foreach (var f in Files) { System.IO.File.Delete(f); } } if (global.isConnected && !skipOnline) { if (!string.IsNullOrEmpty(_id)) { await global.webSocketClient.DeleteOne("openrpa", this._id); } } try { if (System.IO.Directory.Exists(Path)) { System.IO.Directory.Delete(Path, true); } } catch (Exception ex) { Log.Error(ex.ToString()); } var exists = RobotInstance.instance.dbProjects.FindById(_id); if (exists != null) { RobotInstance.instance.dbProjects.Delete(_id); } GenericTools.RunUI(() => { if (System.Threading.Monitor.TryEnter(RobotInstance.instance.Projects, Config.local.thread_lock_timeout_seconds * 1000)) { try { RobotInstance.instance.Projects.Remove(this); } finally { System.Threading.Monitor.Exit(RobotInstance.instance.Projects); } } else { throw new LockNotReceivedException("Delete Project"); } }); }