private bool ProcessHandshakingPrinter() { if (!DoInitialHandShaking()) { if (!serial_failed_list.ContainsKey(ComPort)) { PrinterConnection.ConnectAttemptData connectAttemptData; connectAttemptData.time = DateTime.Now; connectAttemptData.message_sent = false; serial_failed_list.TryAdd(ComPort, connectAttemptData); } else { if (serial_failed_list.TryGetValue(ComPort, out ConnectAttemptData comparisonValue) && ((DateTime.Now - comparisonValue.time).Seconds > 30 && !comparisonValue.message_sent)) { PrinterConnection.ConnectAttemptData newValue; newValue.time = comparisonValue.time; newValue.message_sent = true; serial_failed_list.TryUpdate(ComPort, newValue, comparisonValue); var spoolerMessage = new SpoolerMessage(MessageType.FirmwareErrorCyclePower, new PrinterSerialNumber("0000000000000000"), "null"); if (broadcastserver != null) { broadcastserver.BroadcastMessage(spoolerMessage.Serialize()); } } } IsAlive = false; } else if (serial_failed_list.ContainsKey(ComPort)) { serial_failed_list.TryRemove(ComPort, out ConnectAttemptData connectAttemptData); } return(IsAlive); }
public void BroadcastPluginMessage(SpoolerMessage message) { if (message.Type != MessageType.PluginMessage) { return; } if (clientID != Guid.Empty) { BroadcastServer.SendMessageToClient(clientID, message.Serialize()); } else { BroadcastServer.BroadcastMessage(message.Serialize()); } }