private void AddSignalToList(string user, string path, ICollection <Signal> signals) { Signal existingSignal; lock (signals) existingSignal = signals.FirstOrDefault(x => x.Name == path); var context = new ScriptingAppDomainContext(user, path, _signalsFolderPath); try { var signal = context.CreateSignal(); if (signal != null) { var newSignal = new Signal { Name = path, ID = signal.ID, State = signal.State, Parameters = signal.GetParameters(), Selections = signal.Selections }; if (existingSignal != null) { _signalStore.UpdateEntity(Path.Combine(_signalsFolderPath, user, path, signal.Name + FileExtensions.SIGNAL_CONFIG), newSignal); } else { lock (signals) signals.Add(newSignal); _signalStore.AddEntity(Path.Combine(_signalsFolderPath, user, path, signal.Name + FileExtensions.SIGNAL_CONFIG), newSignal); } } } catch (Exception ex) { Logger.Error("Failed to create new signal", ex); } finally { try { context.Dispose(); } catch (Exception ex) { Logger.Error("Failed to dispose signal context", ex); } } }
private SignalBase CreateSignalInstance(string userName, string signalName) { var signal = default(SignalBase); lock (_userWorkingSignals) { signal = _userWorkingSignals.FirstOrDefault(x => x.Name == signalName && x.Owner == userName); if (signal != null) { return(signal); } } var context = new ScriptingAppDomainContext(userName, signalName, _signalsFolderPath); try { signal = context.CreateSignal(); signal.Name = signalName; lock (_signalDomains) _signalDomains.Add(context); return(signal); } catch (Exception ex) { lock (_signalDomains) { if (signal != null) { _signalDomains.Remove(context); } } try { context.Dispose(); } catch (Exception disposingEx) { Logger.Error("Disposing error", disposingEx); } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Logger.Error(ex.Message, ex); return(null); } }
private void InitUserSignal(string user, string path) { var context = new ScriptingAppDomainContext(user, path, _signalsFolderPath); try { var signalBase = context.CreateSignal(); if (signalBase != null) { var signalList = new List <Signal>(); var signal = new Signal { Name = path, ID = signalBase.ID, State = signalBase.State, Parameters = signalBase.GetParameters(), Selections = signalBase.Selections }; signalList.Add(signal); lock (_userSignals) _userSignals.Add(user, signalList); _signalStore.AddEntity(Path.Combine(_signalsFolderPath, user, path, signalBase.Name + FileExtensions.SIGNAL_CONFIG), signal); } } catch (Exception ex) { Logger.Error("Failed to create new signal", ex); } finally { try { context.Dispose(); } catch (Exception ex) { Logger.Error("Failed to dispose signal context", ex); } } }
private string ValidateAndAddSignalToList(string login, string path) { try { lock (_userSignals) { if (_userSignals.TryGetValue(login, out var signals)) { var signalToRemove = signals.FirstOrDefault(i => i.Name == path); if (signalToRemove != null) { signals.Remove(signalToRemove); } } } var context = new ScriptingAppDomainContext(login, path, _signalsFolderPath); try { var signal = context.CreateSignal(); if (signal != null) { lock (_userSignals) { if (!_userSignals.ContainsKey(login)) { _userSignals.Add(login, new List <Signal>()); } _userSignals[login].Add(new Signal { Name = path, ID = signal.ID, State = signal.State, Parameters = signal.GetParameters(), Selections = signal.Selections }); } } } catch (Exception ex) { Logger.Error("Failed to create new signal", ex); return("Failed to create signal: " + path); } finally { try { context.Dispose(); } catch (Exception ex) { Logger.Error("Failed to dispose signal context", ex); } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } return(string.Empty); } catch (Exception ex) { Logger.Error("Failed to validate/create user signal", ex); return(ex.Message); } }