示例#1
0
        private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                executeCommandDelegate();
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
            }
        }
示例#2
0
 public BoltServerException(string message, ServerErrorCode error, MethodInfo action, string url)
     : base(message)
 {
     Error = error;
     Action = action;
     Url = url;
 }
示例#3
0
 private void FlushBuffer(bool throwPaperOut, bool throwOnBusy)
 {
     try
     {
         if (IsSerial)
         {
             // добавляем в буфер команду проверки статуса
             currCmd[cmdLen++] = 0x05;
             WriteToSerial();
         }
         else
         {
             WriteToParallel(throwPaperOut, throwOnBusy);
         }
     }
     catch (TimeoutException)
     {
         ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
     }
     catch (Exception E)
     {
         ErrorCode = new ServerErrorCode(this, E);
         // очистка буфера принтера
         try
         {
             Port.WriteByte(0x18);
         }
         catch
         {
         }
     }
 }
示例#4
0
        public override string this[int lineNumber]
        {
            set
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Success);
                if (value.Length == 0)
                {
                    return;
                }

                try
                {
                    Locate((byte)(lineNumber + 1));
                    if (!ErrorCode.Succeeded)
                    {
                        return;
                    }

                    byte[] nLine = Encoding.GetEncoding(CodePage).GetBytes(value.PadRight(DISPLAY_WIDTH, ' '));
                    Port.Write(nLine, 0, DISPLAY_WIDTH);
                }
                catch (TimeoutException)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
                }
                catch (Exception E)
                {
                    ErrorCode = new ServerErrorCode(this, E);
                }
            }
        }
示例#5
0
        protected override void OnCloseDocument(bool cutPaper)
        {
            try
            {
                using (var document = new PrintDocument())
                {
                    document.PrinterSettings.PrinterName = PortName;
                    document.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
                    document.PrintPage += new PrintPageEventHandler(document_PrintPage);

                    _yPos        = document.DefaultPageSettings.Bounds.Top;
                    _currentLine = 0;

                    document.Print();
                }
            }
            catch (InvalidPrinterException)
            {
                ErrorCode = new ServerErrorCode(this, 1, string.Format("Принтер с именем \"{0}\" не найден", PortName));
            }
            catch (Exception e)
            {
                ErrorCode = new ServerErrorCode(this, e);
            }
        }
示例#6
0
 public BoltServerException(ServerErrorCode error, string action, string url)
     : base($"Execution of action '{action}' failed on server with error '{error}'. Url - '{url}'")
 {
     ServerError = error;
     Action      = action;
     Url         = url;
 }
示例#7
0
        private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                executeCommandDelegate();

                if (_errorCode < 0x1000)
                {
                    ErrorCode = new ServerErrorCode(this, _errorCode, GetSpecificDescription(_errorCode));
                }
                else
                {
                    ErrorCode = new ServerErrorCode(this, (GeneralError)_errorCode);
                }
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
            }
        }
示例#8
0
 public BoltServerException(string message, ServerErrorCode error, string action, string url)
     : base(message)
 {
     ServerError = error;
     Action      = action;
     Url         = url;
 }
示例#9
0
 public BoltServerException(ServerErrorCode error, MethodInfo action, string url)
     : base($"Execution of action '{action.Name}' failed on server with error '{error}'. Url - '{url}'")
 {
     Error = error;
     Action = action;
     Url = url;
 }
        private bool WriteBuffer(byte[] nCmd, int nLen, bool checkStatus)
        {
            byte nRsp = 0;

            if (WriteBuffer(nCmd, nLen, out nRsp, checkStatus))
            {
                if ((nRsp & 0x04) == 0x04)  // mechanical error
                {
                    ErrorCode = new ServerErrorCode(this, 0x100, GetSpecificDescription(0x100));
                }
                else if ((nRsp & 0x20) == 0x20)  // unrecoverable error
                {
                    ErrorCode = new ServerErrorCode(this, 0x100, GetSpecificDescription(0x102));
                }
                else if ((nRsp & 0x40) == 0x40)  // auto-recoverable error
                {
                    ErrorCode = new ServerErrorCode(this, 0x100, GetSpecificDescription(0x103));
                }
                else
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Success);
                }
            }
            else
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }

            return(ErrorCode.Succeeded);
        }
示例#11
0
        /// <summary>
        /// Запись в последовательный порт
        /// </summary>
        private void WriteToSerial()
        {
            Port.DiscardBuffers();
            byte nRsp;
            int  bytesWritten = 0;
            int  maxBufferLen = 256;

            while (bytesWritten + maxBufferLen < cmdLen)
            {
                bytesWritten += Port.Write(currCmd, bytesWritten, maxBufferLen);
            }
            Port.Write(currCmd, bytesWritten, cmdLen - bytesWritten);

            nRsp = (byte)Port.ReadByte();

            if ((nRsp & 0x01) == 0x01)  // vertical parity error
            {
                ErrorCode = new ServerErrorCode(this, 0x100, GetSpecificDescription(0x100));
            }
            else if ((nRsp & 0x02) == 0x02)  // Framing error
            {
                ErrorCode = new ServerErrorCode(this, 0x101, GetSpecificDescription(0x101));
            }
            else if ((nRsp & 0x04) == 0x04)  // Printer mechanical error
            {
                ErrorCode = new ServerErrorCode(this, 0x102, GetSpecificDescription(0x102));
            }
            else
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            }
        }
示例#12
0
        // отмена документа
        private void CancelDocument(bool printerMode)
        {
            try
            {
                if (printerMode)
                {
                    CloseNonFiscalDocument(true);
                }
                else
                {
                    switch (_deviceProtocol.GetDeviceInfo().DocState)
                    {
                    case FiscalDocState.Closed:
                        // а если документ не открывался и режим принтера не включен,
                        // то скорее всего ничего еще не напечатано и отменять нечего
                        break;

                    case FiscalDocState.FreeDoc:
                        // закрытие произвольного документа
                        _deviceProtocol.ExecuteCommand("52");
                        break;

                    default:
                        // отмена фискального документа
                        _deviceProtocol.ExecuteCommand("17", true);
                        break;
                    }
                }
                _docOpened = false;
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout, _deviceProtocol.GetCommandDump());
            }
            catch (PrintableErrorException)
            {
                // ошибка печатающего устройства. документ не отменяется
                ErrorCode = new ServerErrorCode(this, 0x18, GetSpecificDescription(0x18), _deviceProtocol.GetCommandDump());
            }
            catch (DeviceErrorException E)
            {
                if (E.ErrorCode != 13)
                {
                    ErrorCode = new ServerErrorCode(this, E.ErrorCode, GetSpecificDescription(E.ErrorCode), _deviceProtocol.GetCommandDump());
                }
                _docOpened = false;
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
                if (!ErrorCode.Succeeded && Logger.DebugInfo && !string.IsNullOrEmpty(_deviceProtocol.DebugInfo))
                {
                    Logger.SaveDebugInfo(this, _deviceProtocol.DebugInfo);
                }
//                _deviceProtocol.ClearDebugInfo();
            }
        }
示例#13
0
        public override void SaveToEEPROM()
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            if ((DisplayLines[0].Length == 0) && (DisplayLines[1].Length == 0))
            {
                return;
            }

            try
            {
                this[0] = DisplayLines[0];
                this[1] = DisplayLines[1];

                // устанавливаем курсор в заданную позицию
                byte[] nCmd = new byte[5];
                nCmd[0] = EOT;
                nCmd[1] = SOH;
                nCmd[2] = Convert.ToByte('S');
                nCmd[3] = 0x31;
                nCmd[4] = ETB;
                Port.Write(nCmd, 0, 5);
                //                if(Port.ReadByte() == ACK)
                //                    ErrorCode = (short)ErrorCodes.e_success;
                //                else
                //                    ErrorCode = (short)ErrorCodes.e_timeout;
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
        }
示例#14
0
 private void WaitForNewSlip()
 {
     if (!IsSerial)
     {
         return;
     }
     try
     {
         byte nRsp;
         // дожидаемся появления бумаги
         do
         {
             System.Threading.Thread.Sleep(200);
             Port.WriteByte(0x04);
             nRsp = (byte)Port.ReadByte();
         }while ((nRsp & 0x80) != 0x80);
     }
     catch (TimeoutException)
     {
         ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
     }
     catch (Exception E)
     {
         ErrorCode = new ServerErrorCode(this, E);
     }
 }
示例#15
0
        protected override void OnOpenDocument(DocumentType docType, string cashierName, string cashierInn, string customerPhoneOrEmail)
        {
            ExecuteDriverCommand(delegate()
            {
                slipLineNo = 0;

                // устанавливаем режим печати: слип или лента
                ClearBuffer();
                WriteBuffer(0x1B, 0x2B, 0x41);
                WriteBuffer(this.PrinterNumber == PrinterNumber.MainPrinter ? (byte)0x30 : (byte)0x33);
                FlushBuffer(true, true);

                if (!PrintOnSlip)
                {
                    //                PrintHeader();
                    DrawGraphicHeader();
                }
                else
                {
                    // нет бумаги в подкладнике
                    byte slipStatusByte = GetStatusByte(0x04);
                    if ((slipStatusByte & 0x80) == 0)
                    {
                        ErrorCode = new ServerErrorCode(this, ERROR_NO_SLIP, GetSpecificDescription(ERROR_NO_SLIP));
                    }
                }

                docOpened = ErrorCode.Succeeded;
            });
        }
        protected override void OnCash(uint amount)
        {
            string printLine = "Сумма:";

            OnPrintString(printLine + Convert.ToString(amount / 100.0).PadLeft(PrinterInfo.TapeWidth.MainPrinter - printLine.Length), FontStyle.Regular);
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
        }
示例#17
0
 private void WaitForPrinting()
 {
     if (!IsSerial)
     {
         return;
     }
     try
     {
         byte nRsp;
         // дожидаемся освобождения буфера
         do
         {
             System.Threading.Thread.Sleep(200);
             Port.WriteByte(0x05);
             nRsp = (byte)Port.ReadByte();
         }while ((nRsp & 0x20) != 0x20);
     }
     catch (TimeoutException)
     {
         ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
     }
     catch (Exception E)
     {
         ErrorCode = new ServerErrorCode(this, E);
     }
 }
        private void OpenPort(EasyCommunicationPort port)
        {
            if (_portOpened)
            {
                return;
            }

            port.SetCommStateEvent += SetCommStateEventHandler;
            try
            {
                // дополнительные действия до открытия порта
                OnBeforeActivate();

                // открываем порт на заданной скорости
                port.BaudRate = _baudRate;
                port.Open();

                _portOpened = true;
            }
            catch (Win32Exception e)
            {
                // устанавливаем код ошибки
                ErrorCode = new ServerErrorCode(this, e);
                throw;
            }
            finally
            {
                port.SetCommStateEvent -= SetCommStateEventHandler;
            }
        }
        internal void IsNotMasterOrRecovering_should_return_expected_result(ServerErrorCode code, bool expectedResult)
        {
            _subject.Initialize();

            var result = _subject.IsNotMasterOrRecovering(code, null);

            result.Should().Be(expectedResult);
        }
示例#20
0
        internal void IsStateChangeError_should_return_expected_result(ServerErrorCode code, bool expectedResult)
        {
            _subject.Initialize();

            var result = _subject.IsStateChangeError(code, null);

            result.Should().Be(expectedResult);
        }
        protected override void OnOpenDocument(DocumentType docType, string cashierName, string cashierInn, string customerPhoneOrEmail)
        {
            OnPrintString("", FontStyle.Regular);
            OnPrintString("", FontStyle.Regular);
            if (DocumentHeader != null)
            {
                foreach (string s in DocumentHeader)
                {
                    OnPrintString(s, FontStyle.Regular);
                }
            }

            string headerString = string.Format("Кассир: {0}", cashierName).PadRight(PrinterInfo.TapeWidth.MainPrinter - 4);

            OnPrintString(headerString + "#" + docNo.ToString("d3"), FontStyle.Regular);
            switch (docType)
            {
            case DocumentType.Sale:
                OnPrintString("Продажа", FontStyle.Regular);
                break;

            case DocumentType.Refund:
                OnPrintString("Возврат", FontStyle.Regular);
                break;

            case DocumentType.PayingIn:
                OnPrintString("Внесение", FontStyle.Regular);
                break;

            case DocumentType.PayingOut:
                OnPrintString("Выплата", FontStyle.Regular);
                break;

            case DocumentType.SectionsReport:
                OnPrintString("Отчет по секциям", FontStyle.Regular);
                break;

            case DocumentType.XReport:
                OnPrintString("X-отчет", FontStyle.Regular);
                break;

            case DocumentType.ZReport:
                OnPrintString("Z-отчет", FontStyle.Regular);
                break;

            case DocumentType.Other:
                OnPrintString("Нефискальный документ", FontStyle.Regular);
                break;
            }

            OnPrintString(new string(Separator, PrinterInfo.TapeWidth.MainPrinter), FontStyle.Regular);

            openedShift    = true;
            docAmount      = 0;
            paymentAmount  = 0;
            openedDocument = true;
            ErrorCode      = new ServerErrorCode(this, GeneralError.Success);
        }
示例#22
0
        protected override PrinterStatusFlags OnQueryPrinterStatus(DevicesBase.Communicators.TcpCommunicator communicator)
        {
            PaperOutStatus poStatus      = PaperOutStatus.Present;
            bool           bDrawerOpened = false;
            bool           bPrinting     = false;

            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            return(new PrinterStatusFlags(bPrinting, poStatus, _openedDoc, bDrawerOpened));
        }
        public override void GetLifetime(out DateTime firstDate, out DateTime lastDate, out int firstShift, out int lastShift)
        {
            firstDate  = DateTime.Now;
            lastDate   = DateTime.Now;
            firstShift = 1;
            lastShift  = 9999;

            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
        }
        protected override void OnPrintString(string source, FontStyle style)
        {
            if (!System.IO.File.Exists(fileName))
            {
                System.IO.File.Create(fileName).Close();
            }

            System.IO.File.AppendAllText(fileName, (source.Length > PrinterInfo.TapeWidth.MainPrinter ? source.Substring(0, PrinterInfo.TapeWidth.MainPrinter) : source) + "\n", Encoding.Default);
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
        }
示例#25
0
        private void ExecuteDriverCommand(bool printerMode, ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                if (!IsPrim02)
                {
                    // проверяем текущий режим
                    if (_deviceProtocol.IsPrinterMode != printerMode)
                    {
                        // устанавливаем нужный режим
                        _deviceProtocol.IsPrinterMode = printerMode;
                    }
                }

                executeCommandDelegate();
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout, _deviceProtocol.GetCommandDump());
                if (_deviceProtocol.IsPrinterMode)
                {
                    _deviceProtocol.IsPrinterMode = false;
                }
            }
            catch (PrintableErrorException)
            {
                // Ошибка печатающего устройства. Документ не отменяется
                ErrorCode = new ServerErrorCode(this, 0x18, GetSpecificDescription(0x18), _deviceProtocol.GetCommandDump());
            }
            catch (DeviceErrorException E)
            {
                // Протокольная ошибка. Документ нужно попробовать отменить
                ErrorCode = new ServerErrorCode(this, E.ErrorCode, GetSpecificDescription(E.ErrorCode), _deviceProtocol.GetCommandDump());
                CancelDocument(_deviceProtocol.IsPrinterMode);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
                if (!ErrorCode.Succeeded && Logger.DebugInfo && !string.IsNullOrEmpty(_deviceProtocol.DebugInfo))
                {
                    Logger.SaveDebugInfo(this, _deviceProtocol.DebugInfo);
                }
//                _deviceProtocol.ClearDebugInfo();
            }
        }
        protected override void OnRegistration(string commentary, uint quantity, uint amount,
                                               byte section)
        {
            int regAmount = (int)(amount * quantity / 1000.0);

            docAmount += regAmount;

            string printLine = commentary;

            OnPrintString(printLine + string.Format("{0:f2}", regAmount / 100.0).PadLeft(PrinterInfo.TapeWidth.MainPrinter - printLine.Length), FontStyle.Regular);
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
        }
示例#27
0
        private bool IsShutdownError(ServerErrorCode errorCode)
        {
            switch (errorCode)
            {
            case ServerErrorCode.InterruptedAtShutdown:  // 1160
            case ServerErrorCode.ShutdownInProgress:     // 91
                return(true);

            default:
                return(false);
            }
        }
示例#28
0
        internal void IsNotMaster_should_return_expected_result_for_code(ServerErrorCode code, bool expectedResult)
        {
            _subject.Initialize();

            var result = _subject.IsNotMaster(code, null);

            result.Should().Be(expectedResult);
            if (result)
            {
                _subject.IsRecovering(code, null).Should().BeFalse();
            }
        }
        private void ExecuteDriverCommand(ExecuteCommandDelegate executeCommandDelegate)
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            try
            {
                if (!Active)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Inactive);
                    return;
                }

                executeCommandDelegate();
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                debugInfo.AppendLine();
                debugInfo.AppendLine("Full exception info:");
                debugInfo.AppendLine();

                var currentException = E;
                var level            = 0;
                do
                {
                    debugInfo.AppendFormat("[{0}]", level);
                    debugInfo.AppendLine();
                    debugInfo.AppendFormat("Exception: {0}", currentException.Message);
                    debugInfo.AppendFormat("Type: {0}", currentException.GetType());
                    debugInfo.AppendFormat("Stack trace: {0}", currentException.StackTrace);
                    debugInfo.AppendLine();

                    level++;
                    currentException = currentException.InnerException;
                }while (currentException != null);

                Logger.SaveDebugInfo(this, debugInfo.ToString());
                ClearDebugInfo();

                ErrorCode = new ServerErrorCode(this, E);
            }
            finally
            {
                if (!ErrorCode.Succeeded && Logger.DebugInfo && !string.IsNullOrEmpty(debugInfo.ToString()))
                {
                    Logger.SaveDebugInfo(this, debugInfo.ToString());
                }
                ClearDebugInfo();
            }
        }
示例#30
0
        public override string this[int lineNumber]
        {
            set
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Success);
                if (value.Length == 0)
                {
                    return;
                }

                try
                {
                    byte[] nCmd = Encoding.Default.GetBytes(new string(' ', 24));
                    DisplayLines[lineNumber] = value;

                    nCmd[0] = 0x1B;
                    nCmd[1] = 0x51;
                    if (lineNumber == 0)
                    {
                        nCmd[2] = 0x41;
                    }
                    else
                    {
                        nCmd[2] = 0x42;
                    }

                    byte[] nLine = Encoding.GetEncoding(866).GetBytes(value);
                    if (nLine.Length > DISPLAY_WIDTH)
                    {
                        Array.Copy(nLine, 0, nCmd, 3, DISPLAY_WIDTH);
                    }
                    else
                    {
                        Array.Copy(nLine, 0, nCmd, 3, nLine.Length);
                    }

                    nCmd[23] = 13;
                    Port.Write(nCmd, 0, 24);
                }
                catch (TimeoutException)
                {
                    ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
                }
                catch (Exception E)
                {
                    ErrorCode = new ServerErrorCode(this, E);
                }
            }
        }
示例#31
0
        public override void SaveToEEPROM()
        {
            ErrorCode = new ServerErrorCode(this, GeneralError.Success);
            if ((DisplayLines[0].Length == 0) && (DisplayLines[1].Length == 0))
            {
                return;
            }

            try
            {
                byte[] nCmd = Encoding.Default.GetBytes(new string(' ', 44));
                nCmd[0] = 0x0C;

                byte[] nLine = Encoding.GetEncoding(866).GetBytes(DisplayLines[0]);
                if (nLine.Length > 20)
                {
                    Array.Copy(nLine, 0, nCmd, 1, 20);
                }
                else
                {
                    Array.Copy(nLine, 0, nCmd, 1, nLine.Length);
                }

                nLine = Encoding.GetEncoding(866).GetBytes(DisplayLines[1]);
                if (nLine.Length > 20)
                {
                    Array.Copy(nLine, 0, nCmd, 21, 20);
                }
                else
                {
                    Array.Copy(nLine, 0, nCmd, 21, nLine.Length);
                }

                nCmd[41] = 0x1B;
                nCmd[42] = 0x53;
                nCmd[43] = 0x31;

                Port.Write(nCmd, 0, 44);
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
            catch (Exception E)
            {
                ErrorCode = new ServerErrorCode(this, E);
            }
        }
示例#32
0
        private void Locate(byte nLine)
        {
            byte[] nCmd = new byte[4];
            nCmd[0] = 0x1f;
            nCmd[1] = 0x24;
            nCmd[2] = 0x01;
            nCmd[3] = nLine;

            try
            {
                Port.Write(nCmd, 0, 4);
            }
            catch (TimeoutException)
            {
                ErrorCode = new ServerErrorCode(this, GeneralError.Timeout);
            }
        }
示例#33
0
 private void _OnWarningMessage(OscarSession sess, ServerErrorCode errorCode)
 {
     string msg = String.Format(_("Connection Warning: {0}"), errorCode);
     Session.AddTextToChat(_NetworkChat, "-!- " + msg);
 }
示例#34
0
文件: Main.cs 项目: pkt30/OscarLib
 private void sess_WarningMessage(Session sess, ServerErrorCode error)
 {
     Console.WriteLine("Warning: " + error);
 }
示例#35
0
文件: Main.cs 项目: pkt30/OscarLib
 private void sess_ErrorMessage(Session sess, ServerErrorCode error)
 {
     Console.WriteLine("Error: " + error);
 }
		public ServerExceptionAttribute(ServerErrorCode exceptionCode)
		{
			ExceptionCode = exceptionCode;
		}
 public ServerException(string message = "Un errore sconosciuto è accaduto nel server", ServerErrorCode err = ServerErrorCode.Default)
     : base(message)
 {
     this.__err_code = err;
 }
示例#38
0
 protected IEnumerable<string> getResponses()
 {
     bool completata = false;
     if(!Connected)
     {
         error_message = Properties.Messaggi.erroreConnessioneServer;
         error_code = ServerErrorCode.ConnessioneInterrotta;
         yield return null;
         yield break;
     }
     while (!completata) {
         //Prima linea con codice di errore
         string response = control_stream_reader.ReadLine();
         if (response == null)
         {
             error_message = Properties.Messaggi.erroreConnessioneServer;
             error_code = ServerErrorCode.ConnessioneInterrotta;
             control_stream_reader.Close();
             Connected = false;
             yield return null;
             yield break;
         }
         response = response.Trim();
         CommandErrorCode errorCode = (CommandErrorCode)Int32.Parse(response.Split(' ')[0]); //Extract code from response
         switch (errorCode)
         {
             case CommandErrorCode.OK:
                 completata = true;
                 do
                 {
                     response = control_stream_reader.ReadLine();
                     yield return response;
                 } while (response != null && response.Length > 0);
                 if (response == null)
                 {
                     error_message = Properties.Messaggi.erroreConnessioneServer;
                     error_code = ServerErrorCode.ConnessioneInterrotta;
                     control_stream_reader.Close();
                     Connected = false;
                     yield break;
                 }
                 break;
             case CommandErrorCode.OKIntermedio:
                 do
                 {
                     response = control_stream_reader.ReadLine();
                     yield return response;
                 } while (response != null && response.Length > 0);
                 if (response == null)
                 {
                     error_message = Properties.Messaggi.erroreConnessioneServer;
                     error_code = ServerErrorCode.ConnessioneInterrotta;
                     control_stream_reader.Close();
                     Connected = false;
                     yield break;
                 }
                 break;
             case CommandErrorCode.FormatoDatiErrato:
                 error_message = Properties.Messaggi.formatoDatiErrato;
                 error_code = ServerErrorCode.FormatoDatiErrato;
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 yield return null;
                 yield break;
             case CommandErrorCode.UtenteNonLoggato:
                 error_message = Properties.Messaggi.nonLoggato;
                 error_code = ServerErrorCode.UtenteNonLoggato;
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 yield return null;
                 yield break;
             case CommandErrorCode.FileEsistente:
                 error_message = Properties.Messaggi.fileEsistente;
                 error_code = ServerErrorCode.FileEsistente;
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 yield return null;
                 yield break;
             case CommandErrorCode.LimiteFileSuperato:
                 error_message = Properties.Messaggi.limiteFileSuperato;
                 error_code = ServerErrorCode.LimiteFileSuperato;
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 yield return null;
                 yield break;
             case CommandErrorCode.DatiIncompleti:
                 error_message = Properties.Messaggi.datiInconsistenti;
                 error_code = ServerErrorCode.DatiIncompleti;
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 yield return null;
                 yield break;
             case CommandErrorCode.DatiErrati:
                 error_message = Properties.Messaggi.datiErrati;
                 error_code = ServerErrorCode.DatiErrati;
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 yield return null;
                 yield break;
             case CommandErrorCode.MomentoSbagliato:
                 error_message = Properties.Messaggi.momentoSbagliato;
                 error_code = ServerErrorCode.MomentoSbagliato;
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 yield return null;
                 yield break;
             default:
                 do { response = control_stream_reader.ReadLine(); }
                 while (response != null && response.Length > 0);
                 throw new ServerException(Properties.Messaggi.erroreServer, ServerErrorCode.Default);
         }
     }
 }
示例#39
0
 public BoltServerException(string message, ServerErrorCode errorCode)
     : base(message)
 {
     Error = errorCode;
 }
示例#40
0
 public BoltServerException(string message, ServerErrorCode errorCode, Exception innerException)
     : base(message, innerException)
 {
     Error = errorCode;
 }
示例#41
0
文件: Session.cs 项目: pkt30/OscarLib
        /// <summary>
        /// Raises the <see cref="WarningMessage"/> event
        /// </summary>
        /// <param name="errorcode">A <see cref="ServerErrorCode"/> describing the warning</param>
        /// <param name="dp">The Datapacket of the transfer with the error</param>
        protected internal void OnWarning(ServerErrorCode errorcode, DataPacket dp)
        {
            // csammis:  Losing a secondary connection (chat room, icon downloader)
            // isn't cause for logging off the session...and setting LoggedIn to false
            // doesn't log off the session anyway.  Call .Logoff() for that.

            //if (errorcode == ServerErrorCode.LostSecondaryConnection)
            //    this.LoggedIn = false;

            if(dp != null)
            {
                Logging.WriteString("OnWarning: {0}, RequestId: {1}", errorcode.ToString(), dp.SNAC.RequestID);
            }

            if (this.WarningMessage != null)
            {
                this.WarningMessage(this, errorcode);
            }
        }
示例#42
0
文件: Session.cs 项目: pkt30/OscarLib
        /// <summary>
        /// Raises the <see cref="ErrorMessage"/> event or the <see cref="LoginFailed"/> event
        /// </summary>
        /// <param name="errorcode">A <see cref="ServerErrorCode"/> describing the error</param>
        /// <param name="dp">The Datapacket of the transfer with the error</param>
        /// <remarks>If the login process has not completed, <see cref="LoginFailed"/> is raised.
        /// Otherwise, <see cref="ErrorMessage"/> is raised.</remarks>
        protected internal void OnError(ServerErrorCode errorcode, DataPacket dp)
        {
            if (dp != null) {
                Logging.WriteString("OnError: {0}, RequestId: {1}", errorcode.ToString(), dp.SNAC.RequestID);
            }

            if (!_loggedin)
            {
                if (this.LoginFailed != null)
                {
                    if (errorcode == ServerErrorCode.LostBOSConnection)
                    {
                        this.LoggedIn = false;
                        this.LoginFailed(this, LoginErrorCode.CantReachBOSServer);
                    }
                    else
                        this.LoginFailed(this, LoginErrorCode.UnknownError);
                }
            }
            else
            {
                if (this.ErrorMessage != null)
                    this.ErrorMessage(this, errorcode);
            }
        }