Beispiel #1
0
        public CommandResult ReleaseLock(Guid lockID)
        {
            CommandResult commandResult = CommandResult.Failed_PrinterDoesNotHaveLock;

            lock (lock_sync)
            {
                if (lockStatus != PrinterConnection.LockStatus.Locked)
                {
                    if (lockStatus != PrinterConnection.LockStatus.Pending)
                    {
                        goto label_11;
                    }
                }
                if (this.lockID == lockID)
                {
                    lockStatus = PrinterConnection.LockStatus.Unlocked;
                    Info.synchronization.Locked = false;
                    clientID      = Guid.Empty;
                    lockID        = Guid.Empty;
                    commandResult = CommandResult.Success_LockReleased;
                }
                BaseController controllerSelf = ControllerSelf;
                if (controllerSelf != null)
                {
                    if (controllerSelf is FirmwareController firmwareController)
                    {
                        firmwareController.BoundsCheckingEnabled = true;
                    }
                }
            }
label_11:
            return(commandResult);
        }
Beispiel #2
0
        public void OnClientRemoved(Guid guid)
        {
            if (!(clientID == guid))
            {
                return;
            }

            lockStatus = PrinterConnection.LockStatus.Unlocked;
            Info.synchronization.Locked = false;
            clientID = Guid.Empty;
            lockID   = Guid.Empty;
        }
Beispiel #3
0
 private void InitConnection()
 {
     shared_shutdown               = new ThreadSafeVariable <bool>(false);
     internal_logger               = new Logger(shared_shutdown);
     printerInfo                   = new PrinterInfo();
     CurrentRPC_id.Value           = printerInfo.synchronization.LastCompletedRPCID = (uint)(SpoolerServer.RandomGenerator.Next() % byte.MaxValue);
     printerInfo.hardware.com_port = _safeSerialPort.PortName;
     Info.serial_number            = PrinterSerialNumber.Undefined;
     Status     = PrinterStatus.Uninitialized;
     lockID     = Guid.Empty;
     clientID   = Guid.Empty;
     lockStatus = PrinterConnection.LockStatus.Unlocked;
     lock_sync  = new object();
 }
Beispiel #4
0
        public CommandResult AcquireLock(Guid clientID)
        {
            lock (lock_sync)
            {
                if (IsPrinting && !IsPaused)
                {
                    return(CommandResult.Failed_CannotLockWhilePrinting);
                }

                if (lockStatus == PrinterConnection.LockStatus.Locked && !(this.clientID == clientID))
                {
                    return(CommandResult.Failed_PrinterAlreadyLocked);
                }

                this.clientID = clientID;
                lockID        = Guid.NewGuid();
                lockStatus    = PrinterConnection.LockStatus.Pending;
                return(CommandResult.Pending);
            }
        }
Beispiel #5
0
        private bool ProcessConnectedPrinter()
        {
            try
            {
                if (Status == PrinterStatus.Error_PrinterNotAlive)
                {
                    return(false);
                }

                if (!IsOpen)
                {
                    Status = PrinterStatus.Error_PrinterNotAlive;
                }

                BaseController controllerSelf = ControllerSelf;
                if (controllerSelf != null)
                {
                    controllerSelf.DoConnectionLogic();
                    if (!controllerSelf.IsWorking || Status == PrinterStatus.Firmware_PrintingPaused)
                    {
                        var num = CurrentRPC_id.Value;
                        if (num != 0U && (int)num != (int)Info.synchronization.LastCompletedRPCID)
                        {
                            Info.synchronization.LastCompletedRPCID = num;
                        }
                    }
                    else
                    {
                        lock (lockResetTimer)
                        {
                            if (lockResetTimer.IsRunning)
                            {
                                lockResetTimer.Restart();
                            }
                        }
                    }
                    if (lockStatus == PrinterConnection.LockStatus.Pending && Status != PrinterStatus.Connecting && (!controllerSelf.IsWorking && !controllerSelf.IsPrinting || Status == PrinterStatus.Firmware_PrintingPaused))
                    {
                        lockStatus = PrinterConnection.LockStatus.Locked;
                        Info.synchronization.Locked = true;
                        BroadcastServer.SendMessageToClient(clientID, new SpoolerMessage(MessageType.LockConfirmed, Info.serial_number, lockID.ToString()).Serialize());
                    }
                    if (controllerSelf.Idle && lockStatus == PrinterConnection.LockStatus.Locked)
                    {
                        lock (lockResetTimer)
                        {
                            if (!lockResetTimer.IsRunning)
                            {
                                lockResetTimer.Restart();
                            }

                            if (lockResetTimer.Elapsed.TotalSeconds > 30.0)
                            {
                                DoBreakLock();
                            }
                        }
                    }
                    else
                    {
                        lock (lockResetTimer)
                        {
                            if (lockResetTimer.IsRunning)
                            {
                                lockResetTimer.Stop();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.ToString().ToLower() != "unable to write program memory.  the serial port is not open.")
                {
                    ErrorLogger.LogException("PrinterConnection Exception", ex);
                }

                Shutdown();
                return(false);
            }
            return(true);
        }