コード例 #1
0
 internal PrinterConnection GetPrinterConnection(PrinterSerialNumber serialnumber)
 {
     foreach (KeyValuePair <string, PrinterConnection> printer in connectionManager.printers)
     {
         PrinterConnection printerConnection = printer.Value;
         if (printerConnection.PrinterInfo.serial_number == serialnumber)
         {
             return(printerConnection);
         }
     }
     return(null);
 }
コード例 #2
0
        public int ConnectToPrinter(PrinterConnection serial_connection)
        {
            if (string.IsNullOrEmpty(serial_connection.ComPort))
            {
                return(0);
            }

            serial_connection.InternalLogger._onLog += new Logger.OnLogDel(PrinterLoggerCallback);
            serial_connection.InitializeController(broadcastserver);
            serial_connection.StartSerialProcessing();
            return(1);
        }
コード例 #3
0
        public string Serialize()
        {
            var str1 = "";

            if (connectionManager != null && connectionManager.printers != null)
            {
                lock (connectionManager.printers)
                {
                    foreach (KeyValuePair <string, PrinterConnection> printer in connectionManager.printers)
                    {
                        PrinterConnection printerConnection = printer.Value;
                        var str2 = (string)null;
                        try
                        {
                            if (printerConnection.PrinterInfo.serial_number != PrinterSerialNumber.Undefined)
                            {
                                if (printerConnection.PrinterInfo.Status != PrinterStatus.Uninitialized)
                                {
                                    if (printerConnection.PrinterInfo.Status != PrinterStatus.Connected)
                                    {
                                        if (printerConnection.PrinterInfo.Status != PrinterStatus.Error_PrinterNotAlive)
                                        {
                                            str2 = printerConnection.Serialize();
                                        }
                                    }
                                }
                            }
                        }
                        catch (InvalidOperationException ex)
                        {
                            str2 = null;
                        }
                        if (!string.IsNullOrEmpty(str2))
                        {
                            str1 += str2;
                        }
                    }
                }
                str1 += string.Format("<DeviceInstallDetected count=\"{0}\" />", WinUSBPrinterFinder.DeviceInstallDetected);
            }
            return("<SPOOLER__ALL/>" + str1);
        }
コード例 #4
0
        public override string OnClientMessage(Guid guid, string message)
        {
            try
            {
                if (message == "<CloseConnection/>")
                {
                    if (guid != MyGuid)
                    {
                        RemoveClient(guid);
                    }
                }
                else if (message.StartsWith("<RPC"))
                {
                    var call = new RPCInvoker.RPC();
                    call.Deserialize(message);
                    var str = (string)null;
                    var obj = (object)null;
                    try
                    {
                        if (call.serialnumber == null)
                        {
                            obj = rpc_invoker.CallMethod(call);
                        }
                        else
                        {
                            PrinterConnection printerConnection = GetPrinterConnection(call.serialnumber);
                            if (printerConnection != null)
                            {
                                if (call.callID != 0U)
                                {
                                    if ((int)call.callID == (int)current_processing_id.Value)
                                    {
                                        return(null);
                                    }

                                    current_processing_id.Value = call.callID;
                                }
                                CommandResult result;
                                if (call.name == "AcquireLock")
                                {
                                    result = printerConnection.AcquireLock(guid);
                                }
                                else if (call.name == "ReleaseLock")
                                {
                                    result = printerConnection.ReleaseLock(call.lockID);
                                }
                                else
                                {
                                    var flag = true;
                                    if (LockExceptionList.Contains(call.name))
                                    {
                                        flag = false;
                                    }

                                    result = printerConnection.VerifyLock(call.lockID);
                                    if (result == CommandResult.Failed_PrinterDoesNotHaveLock && call.name == "SendEmergencyStop" && printerConnection.IsWorking)
                                    {
                                        printerConnection.SendInterrupted(LockVerifyResultToSpoolerMessage(CommandResult.CommandInterruptedByM0, call.serialnumber, 0U));
                                    }

                                    if (result == CommandResult.Success || !flag)
                                    {
                                        obj = rpc_invoker.CallMethod(printerConnection, call);
                                        if (obj is CommandResult)
                                        {
                                            result = (CommandResult)obj;
                                            obj    = null;
                                        }
                                    }
                                }
                                if (call.callID != 0U)
                                {
                                    printerConnection.CurrentRPC_id.Value = call.callID;
                                }

                                str = LockVerifyResultToSpoolerMessage(result, call.serialnumber, call.callID);
                            }
                            else
                            {
                                str = new SpoolerMessage(MessageType.PrinterNotConnected, call.serialnumber, call.name).Serialize();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        str = new SpoolerMessage(MessageType.RPCError, ex.Message + "::" + call.name).Serialize();
                    }
                    if (str != null)
                    {
                        return("<SocketBroadcast>" + str + "</SocketBroadcast>");
                    }

                    if (obj != null)
                    {
                        if (obj is string)
                        {
                            return((string)obj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogException("Exception in SpoolerServer.OnClientMessage " + ex.Message, ex);
                return("FAIL");
            }
            return(null);
        }
コード例 #5
0
 public void RemovePrinter(PrinterConnection connection)
 {
     connection.Shutdown();
 }