private void ProcessMetapackage(string xmlData) { Console.WriteLine("Decoding XML: " + xmlData); SocketMessage message = SocketMessage.FromXml(xmlData); // Most should just be sent straight to backend. Some could possibly be processed already here. switch (message.MessageType) { case "BroadcastProgress": JObject progressBroadcast = new JObject(); progressBroadcast["MessageType"] = "ProgressUpdate"; progressBroadcast["Guid"] = message.Guid.Replace("-", "_"); // enables JS tokens from Guid progressBroadcast["Progress"] = message.Progress; Sessions.Broadcast(progressBroadcast.ToString()); break; default: // we're not handling here, send to backend FrontendLoop.SendMessageUpstream(message); break; } }
protected override void OnMessage(WebSocketSharp.MessageEventArgs e) { // Basically just echo whatever's sent here Console.WriteLine(" - a client says " + e.Data); JObject json = JObject.Parse(e.Data); string serverRequest = (string)json["ServerRequest"]; if (string.IsNullOrEmpty(serverRequest)) { // Not a server request, so just echo the contents to everybody Sessions.Broadcast(e.Data); } switch (serverRequest) { case "AddBitcoinAddress": FrontendLoop.AddBitcoinAddress((string)json["Address"]); break; case "Metapackage": ProcessMetapackage((string)json["XmlData"]); break; case "Ping": // TODO: Request heartbeat from backend // Sessions.Broadcast("{\"messageType\":\"Heartbeat\"}"); break; case "ConvertPdf": try { JArray pdfFilesArray = (JArray)json["PdfFiles"]; JArray pdfClientNamesArray = (JArray)json["ClientFileNames"]; List <RasterizationTarget> rasterizationTargets = new List <RasterizationTarget>(); for (int loop = 0; loop < pdfFilesArray.Count; loop++) { rasterizationTargets.Add(new RasterizationTarget { FullyQualifiedFileName = Document.StorageRoot + (string)pdfFilesArray[loop], ClientFileName = (string)pdfClientNamesArray[loop] }); } PdfProcessor pdfMaker = new PdfProcessor(); pdfMaker.RasterizationProgress += BroadcastGuidProgress; pdfMaker.RasterizeMany(rasterizationTargets.ToArray(), (string)json["Guid"], _authority.Person, _authority.Organization); } catch (Exception exc) { Sessions.Broadcast("{\"messageType\":\"Debug\",\"data\":\"Exception - " + exc.GetType() + " - " + exc.ToString().Replace("\"", "\\\"") + "\"}"); } break; case "ConvertPdfHires": // Send to backend JObject backendRequest = new JObject(); backendRequest["BackendRequest"] = "ConvertPdfHires"; backendRequest["DocumentId"] = json["DocumentId"]; FrontendLoop.SendMessageUpstream(backendRequest); break; default: // do nothing; break; } }