public ServerUploader(VectorDescription vectorDescription, CommandHandler cmd) { try { if (cmd != null) { cmd.EventFired += SendEvent; } var duplicates = vectorDescription._items.GroupBy(x => x.Descriptor).Where(x => x.Count() > 1).Select(x => x.Key); if (duplicates.Any()) { throw new Exception("Title of datapoint in vector was listed twice: " + string.Join(", ", duplicates)); } var loopName = IOconfFile.GetLoopName(); _signing = new Signing(loopName); vectorDescription.IOconf = IOconfFile.RawFile; _vectorDescription = vectorDescription; _plot = PlotConnection.Establish(loopName, _signing.GetPublicKey(), GetSignedVectorDescription(vectorDescription)).GetAwaiter().GetResult(); new Thread(() => this.LoopForever()).Start(); _cmd = cmd; cmd?.AddCommand("escape", Stop); } catch (Exception ex) { OnError("failed initializing uploader", ex); throw; } }
public Alerts(VectorDescription vectorDescription, CommandHandler cmd) : base() { _cmd = cmd; var cmdPlugins = new PluginsCommandHandler(cmd); Initialize(cmdPlugins, new PluginsLogger("Alerts")); cmdPlugins.AddCommand("removealert", RemoveAlert); _alerts = GetAlerts(vectorDescription, cmd); }
private byte[] GetSignedVectorDescription(VectorDescription vectorDescription) { var xmlserializer = new XmlSerializer(typeof(VectorDescription)); using var msXml = new MemoryStream(); xmlserializer.Serialize(msXml, vectorDescription); var buffer = msXml.ToArray(); return(SignAndCompress(buffer)); }
private List <IOconfAlert> GetAlerts(VectorDescription vectorDesc, CommandHandler cmd) { var alerts = IOconfFile.GetAlerts().ToList(); var alertsWithoutItem = alerts.Where(a => !vectorDesc.HasItem(a.Sensor)).ToList(); foreach (var alert in alertsWithoutItem) { logger.LogError($"ERROR in {Directory.GetCurrentDirectory()}\\IO.conf:{Environment.NewLine} Alert: {alert.Name} points to missing sensor: {alert.Sensor}"); } if (alertsWithoutItem.Count > 0) { throw new InvalidOperationException("Misconfigured alerts detected"); } if (alerts.Any(a => a.Command != default) && cmd == null) { throw new InvalidOperationException("Alert with command is configured, but command handler is not available to trigger it"); } return(alerts); }
public ServerUploader(VectorDescription vectorDescription) : this(vectorDescription, null) { }