示例#1
0
            //private bool _disposed;
            //private int count;

            public Client(ushort localPort, ZmqContext context, FtpServer ftpServer, string type)
            {
                if (context == null)
                {
                    throw new ApplicationException("创建Client时context为null");
                }

                if ("FileUpload" == type)
                {
                    OnFileDataReceived = OnFileUpload;
                }
                else if ("FileDownload" == type)
                {
                    OnFileDataReceived = onFileDownload;
                }
                else
                {
                    throw new ApplicationException("请求命令错误!");
                }

                _context   = context;
                _localPort = localPort;

                _ftpServer = ftpServer;
                _ftpServer.RegisterClient(this);
                RockContext.RegisterPort(_localPort);
            }
示例#2
0
        public void ListenToQueue(ReceivedDelegate receivedFunction, ShutDownDelegate shutdownFunction)
        {
            IModel channel = connection.CreateModel();

            channel.BasicQos(0, 1, false);

            channel.QueueDeclare(queue: queueName,
                                 durable: false,
                                 exclusive: false,
                                 autoDelete: false,
                                 arguments: null);

            EventingBasicConsumer eventingBasicConsumer = new EventingBasicConsumer(channel);

            eventingBasicConsumer.Received += (sender, basicDeliveryEventArgs) =>
            {
                try
                {
                    IBasicProperties basicProperties = basicDeliveryEventArgs.BasicProperties;
                    string           body            = Encoding.UTF8.GetString(basicDeliveryEventArgs.Body.ToArray());

                    if (receivedFunction(body))
                    {
                        channel.BasicAck(basicDeliveryEventArgs.DeliveryTag, false);
                    }
                    else
                    {
                        channel.BasicNack(basicDeliveryEventArgs.DeliveryTag, false, true);
                    }
                }
                catch (Exception)
                {
                    channel.BasicNack(basicDeliveryEventArgs.DeliveryTag, false, true);
                    throw;
                }
            };

            eventingBasicConsumer.Shutdown += (sender, shutdownEventArgs) =>
            {
                shutdownFunction();
            };

            channel.BasicConsume(queueName, false, eventingBasicConsumer);
        }
示例#3
0
 private void ResultReceived()
 {
     if (((this.mPrintMode != PrintStatus.Print) || ((this.mPrintMode == PrintStatus.Print) && (this.mPrintFlg == 0))) && ((Control) this.mSender).InvokeRequired)
     {
         ReceivedDelegate method = new ReceivedDelegate(this.ResultReceived);
         ((Control) this.mSender).Invoke(method, new object[0]);
     }
     else
     {
         try
         {
             if (this.mPrintMode == PrintStatus.DataviewPrint)
             {
                 Naccs.Common.Print.Print prt = new Naccs.Common.Print.Print {
                     PrintKey = this.mKey
                 };
                 this.PrinterSetting(prt);
                 prt.OnPrintEnd += new OnPrintEndEventHandler(this.PRT_OnPrintEnd);
                 prt.OwnerSender = this.mSender;
                 prt.printDataView(this.mData.Items, this.mPreviewFlg);
             }
             else
             {
                 Naccs.Common.Print.Print print2 = new Naccs.Common.Print.Print {
                     PrintDlgMode = this.mPrintFlg,
                     PrintKey = this.mKey,
                     TimeStamp = this.mData.TimeStamp
                 };
                 if (this.mData.Header.InputInfo.Trim().Length > 0)
                 {
                     print2.InputInfo = this.mData.Header.InputInfo;
                 }
                 if (this.mData.Header.ServerRecvTime.Trim().Length > 0)
                 {
                     print2.ServerRecvTime = this.mData.Header.ServerRecvTime.Replace(' ', '0');
                 }
                 if (this.mData.Contained == ContainedType.ReceiveOnly)
                 {
                     print2.Contained = 2;
                 }
                 else if (this.mData.Contained == ContainedType.SendOnly)
                 {
                     print2.Contained = 1;
                 }
                 else
                 {
                     print2.Contained = 0;
                 }
                 PathInfo info = PathInfo.CreateInstance();
                 print2.FontFilePath = info.SystemEnvironmentPath;
                 print2.ImportFontFiles = info.SystemEnvironmentPath + @"\NACCS_OCR.TTF";
                 print2.OcrFontName = "NACCS_OCR";
                 print2.OcrFontSize = 12f;
                 this.PrinterSetting(print2);
                 GStampSettings settings = GStampSettings.CreateInstance();
                 print2.IsWriteGStamp = settings.GStampInfo.GStampOn;
                 List<string> list = new List<string> {
                     settings.GStampInfo.TopItem,
                     settings.GStampInfo.DateItem,
                     settings.GStampInfo.UnderItem1,
                     settings.GStampInfo.UnderItem2,
                     settings.GStampInfo.UnderItem3
                 };
                 print2.GStampInfo = CommaText.ItemsToCommaText(list);
                 print2.GStampDateAlign = settings.GStampInfo.DateAlignment;
                 print2.OnPrintEnd += new OnPrintEndEventHandler(this.PRT_OnPrintEnd);
                 print2.CustomTemplatePath = this.mCustomTemplatePath;
                 SystemEnvironment environment = SystemEnvironment.CreateInstance();
                 print2.StampMarkText = environment.TerminalInfo.PrintStampMark;
                 print2.OwnerSender = this.mSender;
                 if (this.mJobConfig == null)
                 {
                     print2.execTextPrint(this.mData.Items, this.mPreviewFlg);
                 }
                 else if (this.mData.Style == JobStyle.combi)
                 {
                     this.mData.JobIndex = 1;
                     print2.printTemplate(this.mJobConfig, this.mData.SubItems, this.mPreviewFlg);
                 }
                 else
                 {
                     print2.printTemplate(this.mJobConfig, this.mData.Items, this.mPreviewFlg);
                 }
             }
         }
         catch (NaccsException exception)
         {
             this.OnThPrintError(exception, this.mKey, this.mPrintFlg);
         }
         catch (Exception exception2)
         {
             NaccsException sender = new NaccsException(Naccs.Common.MessageKind.Error, 0x261, exception2.Message);
             this.OnThPrintError(sender, this.mKey, this.mPrintFlg);
         }
     }
 }
示例#4
0
 private void ReceivedResponse(ComParameter data)
 {
     if (((Control) this.mRequestSender).InvokeRequired)
     {
         ReceivedDelegate method = new ReceivedDelegate(this.ReceivedResponse);
         ((Control) this.mRequestSender).Invoke(method, new object[] { data });
     }
     else
     {
         this.mTrace.WriteString(this.mTracekind, string.Format("# {0,-16} : status[{1}]", "ReceivedResponse", this.mStatus));
         if (this.mRequestAfterAbort)
         {
             WebException wex = new WebException(Resources.ResourceManager.GetString("HTTP01"), WebExceptionStatus.RequestCanceled);
             this.mIsTimeout = false;
             this.ErrorResponse(wex, true);
         }
         else
         {
             this.OnReceived(this, this.mSendkey, data);
         }
     }
 }