Ejemplo n.º 1
0
        public static void Stop()
        {
            if (_licenseRequestPoller != null)
            {
                _licenseRequestPoller.Stop();

                PendingClientLicenseRequests.Clear();
                ActivedLicenses.Clear();
                AvailableLicenses.Clear();

                PendingLicensesChanged?.Invoke(null, null);
                AvailableLicensesChanged?.Invoke(null, null);

                if (!string.IsNullOrEmpty(UserProfileManager.UserProfile.LicenseServer_ServerName))
                {
                    var clientRemoveLicenseRequestAsEncodedXml   = new RemoveActiveClientLicenseRequest().ToEncodedXml();
                    var clientEncodedRemoveLicenseRequestMessage = new RemoveActiveClientLicenseRequestMessage();
                    clientEncodedRemoveLicenseRequestMessage.Message = clientRemoveLicenseRequestAsEncodedXml;
                    try
                    {
                        var ipAddresses = Dns.GetHostAddresses(UserProfileManager.UserProfile.LicenseServer_ServerName);
                        if (ipAddresses != null && ipAddresses.Length > 0)
                        {
                            foreach (var ipAddress in ipAddresses)
                            {
                                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                                {
                                    DAL.Managers.ConnectionManager.SendAsXML(clientEncodedRemoveLicenseRequestMessage, ipAddress, 11006);
                                    DAL.Managers.LoggingManager.WriteToLog("License Manager", "Remove active licenses from server", "Send to server: " + ipAddress.ToString());
                                }
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        DAL.Managers.LoggingManager.WriteToLog("License Manager Error", "Remove active licenses from server", "Send to server (" + exc.Message + ")");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static void OnTCPReceive(IAsyncResult ar)
        {
            try
            {
                Socket clientSocket = (Socket)ar.AsyncState;
                var    remoteIP     = new IPEndPoint(((IPEndPoint)clientSocket.RemoteEndPoint).Address, 11000);
                var    bytesRead    = clientSocket.EndReceive(ar);
                clientSocket.Close();

                var ms = new System.IO.MemoryStream(_byteData, 0, bytesRead);
                ms.Position = 0;
                var sr             = new StreamReader(ms);
                var streamAsString = sr.ReadToEnd();
                // streamAsString = streamAsString.Replace("<?", "<").Replace("?>", ">");
                if (streamAsString.StartsWith("<"))
                {
                    var xmlReader = new System.IO.StringReader(streamAsString);

                    if (streamAsString.Contains("<PrinterRemoteControllerQuery"))
                    {
                    }
                    else if (streamAsString.Contains("<PendingClientLicenseRequestMessage"))
                    {
                        var clientLicenseRequestMessage = (PendingClientLicenseRequestMessage.Deserialize(xmlReader));
                        var clientLicenseRequest        = clientLicenseRequestMessage.DecodeToXml();
                        clientLicenseRequest.IPAddress = remoteIP.ToString().Split(':')[0];
                        AtumClientLicenseRequest?.Invoke(clientLicenseRequest);
                    }
                    else if (streamAsString.Contains("<PendingClientLicenseResponseMessage"))
                    {
                        var clientLicenseResponseMessage = (PendingClientLicenseResponseMessage.Deserialize(xmlReader));
                        var clientLicenseResponse        = clientLicenseResponseMessage.DecodeToXml();
                        AtumClientLicenseResponse?.Invoke(clientLicenseResponse);
                    }
                    else if (streamAsString.Contains("<RemoveActiveClientLicenseRequest"))
                    {
                        var clientRemoveLicenseRequestMessage = (RemoveActiveClientLicenseRequestMessage.Deserialize(xmlReader));
                        var clientRemoveLicenseRequest        = clientRemoveLicenseRequestMessage.DecodeToXml();
                        AtumClientRemoveLicenseRequest?.Invoke(clientRemoveLicenseRequest);
                    }
                    //else if (streamAsString.Contains("<ArrayOfRemoteControlAction"))
                    //{
                    //    var serializer = new System.Xml.Serialization.XmlSerializer(typeof(RemoteControlActions));
                    //    var remoteControlActions = (RemoteControlActions)serializer.Deserialize(xmlReader);
                    //    remoteControlActions[0].RemoteHostIP = remoteIP.Address.ToString();
                    //    if (AtumPrinterRemoteControlActionReceived != null) AtumPrinterRemoteControlActionReceived(remoteControlActions[0]);

                    //}
                }
                else
                {
                    ms.Position = 0;
                    var remoteObject     = _binFormatter.Deserialize(ms);
                    var remoteObjectType = remoteObject.GetType().FullName;
                    LoggingManager.WriteToLog("TCP Listener", "Received", remoteObjectType);
                    switch (remoteObjectType)
                    {
                    case "Atum.DAL.Hardware.PrinterFirmwareResult":
                        AtumFirmwareResults?.Invoke((PrinterFirmwareResult)remoteObject);
                        break;

                    case "Atum.DAL.Hardware.PrinterFirmware":
                        AtumFirmwareQuery?.Invoke(remoteIP);
                        break;

                    case "Atum.DAL.Hardware.AtumV15Printer":
                        AtumPrinterReceived?.Invoke((AtumPrinter)remoteObject);
                        AtumPrinterV15Received?.Invoke((AtumPrinter)remoteObject);
                        break;

                    case "Atum.DAL.Print.PrintJob":
                        PrintJobReceived?.Invoke(remoteObject, null);
                        break;

                    case "Atum.DAL.Remoting.PrinterAction":
                        AtumPrinterActionReceived?.Invoke((PrinterAction)remoteObject);
                        break;

                    case "Atum.DAL.Hardware.PrinterControllerResult":
                        AtumFirmwareResults?.Invoke((PrinterFirmwareResult)remoteObject);
                        break;
                        //case "Atum.DAL.Remoting.RemoteControlActions":
                        //    var remoteAction = (RemoteControlActions)remoteObject;
                        //    if (remoteAction.Count > 0)
                        //    {
                        //        if (AtumPrinterRemoteControlActionReceived != null) AtumPrinterRemoteControlActionReceived(remoteAction[0]);
                        //    }
                        //    break;
                        //case "Atum.DAL.Remoting.RemoteControlDisplay":
                        //    var remoteDisplay = (RemoteControlDisplay)remoteObject;
                        //    if (AtumPrinterRemoteControlDisplayReceived != null) AtumPrinterRemoteControlDisplayReceived(remoteDisplay);
                        //    break;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }