private void Save(object sender, ElapsedEventArgs args) { try { var filename = SettingManager.Instance.Settings.CurrentProject.Replace(".json", string.Empty).ToLower(); StateManager.Instance.SaveStateBackup(filename, getNextFileIndex()); Talk.Info("'" + filename + "' backup saved."); } catch (Exception e) { Talk.Error("Backup save failed, error message: " + e.Message); } }
public void Update() { try { foreach (IFixtureUpdateHandler fuh in updateHandlers) { fuh.OnUpdate(this); } } catch (InvalidOperationException e) { Talk.Error("Fixture faild to update -> most likely on removal from the output: " + e.ToString()); } }
protected void WriteServerSentEvent( HttpListenerContext context, int status, string eventType, Dictionary <string, string> data) { var response = context.Response; // Check if connection isn't dead. if (!response.OutputStream.CanWrite) { Talk.Error("The '" + context.Request.RemoteEndPoint + "' has died for some reason. Removing this client."); CloseConnection(context); return; } // All good.. write some response. response.AddHeader("Access-Control-Allow-Origin", "*"); response.AddHeader("Cache-Control", "no-cache"); response.KeepAlive = true; response.StatusCode = status; response.ContentType = "text/event-stream"; if (data != null) { var eventData = Encoding.UTF8.GetBytes("event:" + eventType + "\n"); var dataData = Encoding.UTF8.GetBytes("data:" + GetSSEDataString(data)); var endData = Encoding.UTF8.GetBytes("\n\n"); response.OutputStream.Write(eventData, 0, eventData.Length); response.OutputStream.Write(dataData, 0, dataData.Length); response.OutputStream.Write(endData, 0, endData.Length); Talk.Info(String.Format("Sending event -> type: {0}, data: {1}", eventType, StringUtil.MapToString(data).Replace("\r", "").Replace("\n", "").Replace("\"", "").Replace("{", "\r\n{").Replace(",", "")) ); } else { response.OutputStream.Write(new byte[0], 0, 0); Talk.Info("Sending 'keep-alive' event stream to: " + context.Request.RemoteEndPoint.Address); } }
public void Start() { if (server != null) { try { server.Start(); Talk.Info("Started on port " + port); } catch (Exception e) { Talk.Error("Failed to start on port " + port + ". " + e.ToString()); return; } isRunning = true; new Thread(() => { while (isRunning) { var context = server.GetContext(); IHttpRequestHandler handler = null; Talk.Info("From: '" + context.Request.RemoteEndPoint.Address + ", Request => " + context.Request.Url); // get relative url cause handlers are sotred by relative keys var url = GetRealtiveUrl(context.Request.Url.ToString()); if (requestHandlers.TryGetValue(url, out handler)) { handler.HandleRequest(context); } else { new RestPrefixNotRegistredHandler().HandleRequest(context); } } }).Start(); } else { Talk.Warning("Not initialized. Server not started."); } }
public static void WriteFile(string path, bool relative, string data) { var dir = Path.GetDirectoryName(GetRelativePath() + path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (relative) { path = GetRelativePath() + path; } try { File.WriteAllText(path, data); Talk.Info(path + " written successfully."); } catch (Exception e) { Talk.Error(path + "write error => " + e.ToString()); } }
private void WriteOutput() { var copyIndex = 0; foreach (Fixture f in fixtures) { Array.Copy(f.DmxValues, 0, dmxValuesArray, copyIndex, f.DmxValues.Length); copyIndex += f.DmxValues.Length; } packets.Clear(); foreach (Port p in Ports) { var packet = new ArtNetDmxPacket(); packet.Physical = (byte)p.Net; packet.Universe = (byte)((p.SubNet * 16) + p.Universe); packets.Add(packet); } // copy data to packets copyIndex = 0; foreach (ArtNetDmxPacket pack in packets) { pack.DmxData = Utils.GetSubArray(dmxValuesArray, copyIndex, 510, 512).Select(x => (byte)x).ToArray(); copyIndex += 510; try { socket.SendTo(pack.ToArray(), new IPEndPoint(ipAddress, ArtNetSocket.Port)); } catch (Exception e) { Talk.Error(e.ToString()); } universeCounter++; } }