Пример #1
0
 private void Send(IAsyncResult res)
 {
     if (!C.Work || !Work)
     {
         return;
     }
     C.Send(new KeepAliveC5A());
     Thread.Sleep(5000);
     async.BeginInvoke(null, null, null);
 }
Пример #2
0
            private void SetComplete(Exception ex, int bytesRead)
            {
                lock (locker)
                {
                    if (isCompleted)
                    {
                        return;
                    }

                    isCompleted    = true;
                    asyncException = ex;
                    this.bytesRead = bytesRead;
                    // If the wait handle isn't null, we should set the event
                    // rather than fire a callback
                    if (asyncWaitHandle != null)
                    {
                        asyncWaitHandle.Set();
                    }
                }
                // If we have a callback method, invoke it
                if (userCallback != null)
                {
                    userCallback.BeginInvoke(this, null, null);
                }
            }
Пример #3
0
        private void StartReceivingData()
        {
            fLastDataAction = DateTime.Now.Ticks;

            fActive = true;
            fMyListener.MyExtasysTCPServer.OnClientConnect(this);
            try
            {
                fConnection.BeginReceive(fReadBuffer, 0, fReadBufferSize, SocketFlags.None, new AsyncCallback(StreamReceiver), null);
                if (fConnection.SendTimeout > 0)
                {
                    AsyncCallback call = new AsyncCallback(CheckConnectionTimeOut);
                    call.BeginInvoke(null, call, null);
                }
            }
            catch (ArgumentNullException argumentNullException) // Buffer is a null reference.
            {
                DisconnectMe();
            }
            catch (SocketException socketException) // An error occurred when attempting to access the socket.
            {
                DisconnectMe();
            }
            catch (ObjectDisposedException objectDisposedException) // Socket has been closed.
            {
                DisconnectMe();
            }
            catch (ArgumentOutOfRangeException argumentOutOfRangeException) // Offset is less than 0.
            {
                DisconnectMe();
            }
            catch (Exception ex)
            {
            }
        }
Пример #4
0
        BeginWrite(byte [] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (!CanWrite)
            {
                throw new NotSupportedException("This stream does not support writing");
            }

            // Creating a class derived from Stream that doesn't override BeginWrite
            // shows that it actually calls Write and does everything synchronously except
            // when invoking the callback, which is done from the ThreadPool.
            // Just put this in the Write override:
            //  Console.WriteLine ("Write");
            //  Console.WriteLine (Environment.StackTrace);
            //	Thread.Sleep (10000);

            StreamAsyncResult result = new StreamAsyncResult(state);

            try {
                Write(buffer, offset, count);
                result.SetComplete(null);
            } catch (Exception e) {
                result.SetComplete(e);
            }

            if (callback != null)
            {
                callback.BeginInvoke(result, null, null);
            }

            return(result);
        }
Пример #5
0
        /// <include file='doc\Stream.uex' path='docs/doc[@for="Stream.BeginWrite"]/*' />
        public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
        {
            if (!CanWrite)
            {
                __Error.WriteNotSupported();
            }

            // To avoid a race with a stream's position pointer & generating race
            // conditions with internal buffer indexes in our own streams that
            // don't natively support async IO operations when there are multiple
            // async requests outstanding, we will block the application's main
            // thread and do the IO synchronously.
            SynchronousAsyncResult asyncResult = new SynchronousAsyncResult(state, true);

            try {
                Write(buffer, offset, count);
                asyncResult._isCompleted = true;
                asyncResult._waitHandle.Set();
            }
            catch (IOException e) {
                asyncResult._exception = e;
            }

            if (callback != null)
            {
                callback.BeginInvoke(asyncResult, null, null);
            }

            return(asyncResult);
        }
Пример #6
0
        public void BeginInvokeTest()
        {
            AsyncCallback c = delegate { };

            Assert.Throws <NotSupportedException> (() => c.BeginInvoke(null, null, null), "#1");
            Assert.Throws <NotSupportedException> (() => c.EndInvoke(null), "#2");
        }
Пример #7
0
 public void OnCompletedAsync()
 {
     IsCompleted = true;
     if (Cb != null)
     {
         Cb.BeginInvoke(this, result => Cb.EndInvoke(result), null);
     }
 }
Пример #8
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback,
                                               object state)
        {
            _event.Reset();
            AsyncRes res = new AsyncRes(buffer, offset, count);

            callback.BeginInvoke(res, null, state);
            return(res);
        }
Пример #9
0
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// asynccallback.BeginInvoke(ar, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this AsyncCallback asynccallback, IAsyncResult ar, AsyncCallback callback)
        {
            if (asynccallback == null)
            {
                throw new ArgumentNullException("asynccallback");
            }

            return(asynccallback.BeginInvoke(ar, callback, null));
        }
Пример #10
0
 internal void CompleteRequest(long resultCode)
 {
     Result = resultCode;
     _timeStarted.Stop();
     _asyncWaitHandle.Set();
     if (_callback != null)
     {
         _callback.BeginInvoke(this, ar => _callback.EndInvoke(ar), null);
     }
 }
Пример #11
0
 internal static IAsyncResult DoBeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state, byte[] messageBytes)
 {
    for (int i = 0; i < messageBytes.Length; i++)
    {
       buffer[i] = messageBytes[i];
    }
    var ar = MockRepository.GenerateStub<IAsyncResult>();
    ar.Stub(x => x.AsyncState).Return(state);
    callback.BeginInvoke(ar, null, null);
    return ar;
 }
Пример #12
0
        internal static IAsyncResult DoBeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state, byte[] messageBytes)
        {
            for (int i = 0; i < messageBytes.Length; i++)
            {
                buffer[i] = messageBytes[i];
            }
            var ar = MockRepository.GenerateStub <IAsyncResult>();

            ar.Stub(x => x.AsyncState).Return(state);
            callback.BeginInvoke(ar, null, null);
            return(ar);
        }
Пример #13
0
        internal void Complete()
        {
            lock (_sync) {
                if (_completed)
                {
                    return;
                }

                _completed = true;

                if (_waitHandle != null)
                {
                    _waitHandle.Set();
                }

                if (_callback != null)
                {
                    _callback.BeginInvoke(this, ar => _callback.EndInvoke(ar), null);
                }
            }
        }
Пример #14
0
        public void Set()
        {
            if (_event.IsSet)
            {
                return;
            }

            _event.Set();

            if (_callback != null)
            {
                _callback.BeginInvoke(this, OnAsyncCallbackComplete, null);
            }
        }
Пример #15
0
        public void Complete()
        {
            lock (_locker)
            {
                if (_completed)
                {
                    return;
                }

                _completed = true;
                _handle?.Set();

                Callback?.BeginInvoke(this, null, null);
            }
        }
Пример #16
0
 public void Complete()
 {
     lock (locker)
     {
         if (!completed)
         {
             completed = true;
             if (handle != null)
             {
                 handle.Set();
             }
             if (Callback != null)
             {
                 Callback.BeginInvoke(this, null, null);
             }
         }
     }
 }
Пример #17
0
 public void SetComplete(Exception ex)
 {
     lock (locker)
     {
         if (!completed)
         {
             completed = true;
             if (handle != null)
             {
                 handle.Set();
             }
             if (_userCallback != null)
             {
                 _userCallback.BeginInvoke(this, null, null);
             }
             _asyncException = ex;
         }
     }
 }
Пример #18
0
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object state)
 {
     if (_nextLength < 1)
     {
         CustomeAsyncResult customeAsyncResult = new CustomeAsyncResult(state);
         customeAsyncResult.RealRecvSize     = (-1);
         customeAsyncResult.IsCompleted      = (true);
         customeAsyncResult.RecvBuffer       = (buffer);
         customeAsyncResult.RecvLength       = (count);
         customeAsyncResult.RecvOffset       = (offset);
         customeAsyncResult.UserCallbackFunc = (asyncCallback);
         ((AutoResetEvent)customeAsyncResult.AsyncWaitHandle).Set();
         if (asyncCallback != null)
         {
             asyncCallback.BeginInvoke(customeAsyncResult, null, null);
         }
         return(customeAsyncResult);
     }
     return(_base.BeginRead(buffer, offset, count, asyncCallback, state));
 }
Пример #19
0
 private void SetComplete(Exception ex, byte[] resultingBuffer)
 {
     lock (locker)
     {
         if (!completed)
         {
             completed        = true;
             _asyncException  = ex;
             _resultingBuffer = resultingBuffer;
             if (handle != null)
             {
                 handle.Set();
             }
             if (_userCallback != null)
             {
                 _userCallback.BeginInvoke(this, null, null);
             }
         }
     }
 }
Пример #20
0
            private void SetComplete(Exception ex, int bytesRead)
            {
                lock (locker) {
                    if (completed)
                    {
                        return;
                    }

                    completed       = true;
                    _asyncException = ex;
                    _bytesRead      = bytesRead;
                    if (handle != null)
                    {
                        handle.Set();
                    }
                }
                if (_userCallback != null)
                {
                    _userCallback.BeginInvoke(this, null, null);
                }
            }
Пример #21
0
        public void Complete()
        {
            lock (_locker)
            {
                if (_completed)
                {
                    return;
                }

                _completed = true;
                if (_handle != null)
                {
                    _handle.Set();
                }

                if (_callback != null)
                {
                    _callback.BeginInvoke(this, null, null);
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Set async operation as completed.
        /// </summary>
        public void SetComplete()
        {
            lock (_lock)
            {
                if (_isDisposed)
                {
                    return;
                }
                if (!_isCompleted)
                {
                    _isCompleted = true;
                    _callback?.BeginInvoke(this, delegate(IAsyncResult ar)
                    {
                        _callback.EndInvoke(ar);
                    }, null);

                    if (!_waitHandle.Set())
                    {
                        throw new KsiException("WaitHandle completion failed.");
                    }
                }
            }
        }
Пример #23
0
        /// <summary>Begins an asynchronous write operation.</summary>
        /// <returns>An IAsyncResult that represents the asynchronous write, which could still be pending.</returns>
        /// <param name="buffer">The buffer to write data from. </param>
        /// <param name="offset">The byte offset in <paramref name="buffer" /> from which to begin writing. </param>
        /// <param name="count">The maximum number of bytes to write. </param>
        /// <param name="callback">An optional asynchronous callback, to be called when the write is complete. </param>
        /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests. </param>
        /// <exception cref="T:System.IO.IOException">Attempted an asynchronous write past the end of the stream, or a disk error occurs. </exception>
        /// <exception cref="T:System.ArgumentException">One or more of the arguments is invalid. </exception>
        /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
        /// <exception cref="T:System.NotSupportedException">The current Stream implementation does not support the write operation. </exception>
        /// <filterpriority>2</filterpriority>
        public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (!this.CanWrite)
            {
                throw new NotSupportedException("This stream does not support writing");
            }
            StreamAsyncResult streamAsyncResult = new StreamAsyncResult(state);

            try
            {
                this.Write(buffer, offset, count);
                streamAsyncResult.SetComplete(null);
            }
            catch (Exception complete)
            {
                streamAsyncResult.SetComplete(complete);
            }
            if (callback != null)
            {
                callback.BeginInvoke(streamAsyncResult, null, null);
            }
            return(streamAsyncResult);
        }
Пример #24
0
        private void Connection_Disconnected(object sender, EventArgs e)
        {
            if (Enabled)
            {
                Status = ReloginStatus.Relogin;
                ReloginEventArgs args = new ReloginEventArgs(LastLoginTime, ReloginInterval, ReconnectInterval);
                if (OnReconnect != null)
                {
                    OnReconnect(this, args);
                }

                Sleep         = args.Sleep;
                NextLoginTime = args.NextLoginTime;

                asyncRelogin.BeginInvoke(null, null, null);

                ReconnectCount++;
            }
            else
            {
                Status = ReloginStatus.Disconnected;
            }
        }
Пример #25
0
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback,
                                        object state)
 {
     _event.Reset();
     AsyncRes res = new AsyncRes(buffer, offset, count);
     callback.BeginInvoke(res, null, state);
     return res;
 }
        /// <summary>
        /// This method is called after the transport-server handshake is confirmed. This method starts the listening process.
        /// </summary>
        /// <param name="context">The transport context.</param>
        /// <param name="job">The job.</param>
        /// <param name="Data">The request/response data.</param>
        /// <returns>Returns false is the listening process has started successfully.</returns>
        public override bool ListenConfirm(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data)
        {
            TransportContextTCPIP tcpContext = context as TransportContextTCPIP;
            if (tcpContext == null)
            {
                Data.Response.Status = CH.HTTPCodes.ServiceUnavailable_503;
                return true;
            }

            Uri location = tcpContext.Location;
            //Ok, validate the IP address
            IPAddress address;
            if (!IPAddress.TryParse(location.Host, out address))
            {
                if (location.Host.ToLowerInvariant() != "localhost")
                {
                    Data.Response.Status = CH.HTTPCodes.BadRequest_400;
                    Data.Response.Substatus = string.Format("Location '{0}' is not a valid listening address.", location.Host);
                    return true;
                }
                address = IPAddress.Loopback;
            }

            IPEndPoint EndPoint = new IPEndPoint(address, location.Port);

            try
            {
                Socket listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                //We need to start listening on the appropriate ports and IP addresses
                listeningSocket.Bind(EndPoint);

                //Start the socket listening, the cnLISTENQUEUE is the number of items we allow
                //in the connection queue
                listeningSocket.Listen(tcpContext.ListenerQueueLength);

                //tcpContext.LocalEndPoint = EndPoint;
                tcpContext.ActiveSocket = listeningSocket;

                //Ok, we need to shunt off the listening duties to another thread so that we can returns to
                //the server on this thread.


                AsyncCallback startListening = new AsyncCallback(tcpContext.ListenerStart);

                startListening.BeginInvoke(null, null, null);

                Data.Response.Status = CH.HTTPCodes.OK_200;
                return false;

            }
            catch (SocketException socex)
            {
                Data.Response.Status = CH.HTTPCodes.BadRequest_400;
                Data.Response.Substatus = string.Format("The socket threw an exception {0}:{1} ({2})", socex.ErrorCode, socex.SocketErrorCode, socex.Message);
                return true;
            }
            catch (ObjectDisposedException obex)
            {
                Data.Response.Status = CH.HTTPCodes.InternalServerError_500;
                Data.Response.Substatus = string.Format("The socket threw an object disposed exception {0}", obex.Message);
                return true;
            }
            catch (Exception ex)
            {
                Data.Response.Status = CH.HTTPCodes.InternalServerError_500;
                Data.Response.Substatus = string.Format("An unhandeled exception was caught {0}/{1}", ex.GetType().ToString(), ex.Message);
                return true;
            }

        }
Пример #27
0
        private void StartReceivingData()
        {
            fLastDataAction = DateTime.Now.Ticks;

            fActive = true;
            fMyListener.MyExtasysTCPServer.OnClientConnect(this);
            try
            {
                fConnection.BeginReceive(fReadBuffer, 0, fReadBufferSize, SocketFlags.None, new AsyncCallback(StreamReceiver), null);
                if (fConnection.SendTimeout > 0)
                {
                    AsyncCallback call = new AsyncCallback(CheckConnectionTimeOut);
                    call.BeginInvoke(null, call, null);
                }
            }
            catch (ArgumentNullException argumentNullException) // Buffer is a null reference. 
            {
                DisconnectMe();
            }
            catch (SocketException socketException) // An error occurred when attempting to access the socket.
            {
                DisconnectMe();
            }
            catch (ObjectDisposedException objectDisposedException) // Socket has been closed.
            {
                DisconnectMe();
            }
            catch (ArgumentOutOfRangeException argumentOutOfRangeException) // Offset is less than 0.
            {
                DisconnectMe();
            }
            catch (Exception ex)
            {
            }
        }
Пример #28
0
        private IAsyncResult BeginPagesListRequest(object sender, EventArgs e, AsyncCallback cb, object state)
        {
            IAsyncResult  ar    = null;
            List <string> pages = new List <string>();

            try {
                if (lstWiki.SelectedValue.ToUpperInvariant() == "MEDIA")
                {
                    //Download all namespaces
                    string url = txtWikiUrl.Text + "?title=Special:Allpages&namespace=0";

                    List <string> namespaces = GetNamespaces(PageRequest(url));

                    //Download list of pages
                    for (int k = 0; k < namespaces.Count; k = k + 2)
                    {
                        string pageText = PageRequest(txtWikiUrl.Text + "?title=Special:Allpages&namespace=" + namespaces[k]);

                        Regex allPagesTable = new Regex(@"(?<=(\<table\ class=\'allpageslist\'([^>])*?)\>)(.|\s)+?(?=(\<\/table\>))");
                        Match table         = allPagesTable.Match(pageText);
                        if (table.Success)
                        {
                            string tableStr     = table.Value;
                            Regex  allPagesData = new Regex(@"(?<=(\<a([^>])*?)\>)(.|\s)+?(?=(\<\/a\>))");
                            Match  data         = allPagesData.Match(tableStr);
                            int    i            = 2;
                            while (data.Success)
                            {
                                i++;
                                if (i == 3)
                                {
                                    pages.AddRange(PartialList(PageRequest(txtWikiUrl.Text + "?title=Special:Allpages&from=" + data.Value + "&namespace=" + namespaces[k]), namespaces[k + 1]));
                                    i = 0;
                                }
                                tableStr = tableStr.Substring(data.Index + data.Length + 5);
                                data     = allPagesData.Match(tableStr);
                            }
                        }
                        else
                        {
                            pages.AddRange(PartialList(pageText, namespaces[k + 1]));
                        }
                    }
                }
                else
                {
                    string pageText = null;
                    if (txtWikiUrl.Text.EndsWith("/"))
                    {
                        pageText = PageRequest(txtWikiUrl.Text + @"search.aspx?search=&namespace=%5BAll%5D");
                    }
                    else
                    {
                        pageText = PageRequest(txtWikiUrl.Text + @"/search.aspx?search=&namespace=%5BAll%5D");
                    }

                    Regex pageTitle = new Regex(@"<div class='searchHitHead'>(.|\s)+?</div>");
                    Match match     = pageTitle.Match(pageText);
                    while (match.Success)
                    {
                        pages.Add(match.Value.Substring(37, match.Value.IndexOf('"', 37) - 37));
                        match = pageTitle.Match(pageText, match.Index + match.Length - 1);
                    }
                }
                pageList.Items.Clear();

                for (int i = 0; i < pages.Count; i++)
                {
                    pageList.Items.Add(new ListItem(pages[i], pages[i]));
                    pageList.Items[i].Selected = true;
                }
                if (pages.Count > 1000)
                {
                    pageList.Visible     = false;
                    pageList_div.Visible = false;
                    lblPageList.Text     = "Too many pages. Click Translate button to import whole wiki.";
                }
                else
                {
                    pageList.Visible     = true;
                    pageList_div.Visible = true;
                    lblPageList.Text     = "To exclude pages, uselect them";
                }
            }
            catch (WebException) {
                pageList.Visible        = false;
                pageList_div.Visible    = false;
                btnTranslateAll.Visible = false;
                lblPageList.Text        = "Web Exception";
            }

            return(cb.BeginInvoke(ar, cb, null));
        }
Пример #29
0
        private IAsyncResult PageDownload(object sender, EventArgs e, AsyncCallback ac, object state)
        {
            IAsyncResult ar = null;

            return(ac.BeginInvoke(ar, ac, null));
        }
Пример #30
0
		private IAsyncResult PageDownload(object sender, EventArgs e, AsyncCallback ac, object state) {
			IAsyncResult ar = null;
			return ac.BeginInvoke(ar, ac, null);
		}
Пример #31
0
		private IAsyncResult BeginPagesListRequest(object sender, EventArgs e, AsyncCallback cb, object state) {
			IAsyncResult ar = null;
			List<string> pages = new List<string>();
			try {
				if(lstWiki.SelectedValue.ToUpperInvariant() == "MEDIA") {
					//Download all namespaces
					string url = txtWikiUrl.Text + "?title=Special:Allpages&namespace=0";

					List<string> namespaces = GetNamespaces(PageRequest(url));

					//Download list of pages
					for(int k = 0; k < namespaces.Count; k = k + 2) {
						string pageText = PageRequest(txtWikiUrl.Text + "?title=Special:Allpages&namespace=" + namespaces[k]);

						Regex allPagesTable = new Regex(@"(?<=(\<table\ class=\'allpageslist\'([^>])*?)\>)(.|\s)+?(?=(\<\/table\>))");
						Match table = allPagesTable.Match(pageText);
						if(table.Success) {
							string tableStr = table.Value;
							Regex allPagesData = new Regex(@"(?<=(\<a([^>])*?)\>)(.|\s)+?(?=(\<\/a\>))");
							Match data = allPagesData.Match(tableStr);
							int i = 2;
							while(data.Success) {
								i++;
								if(i == 3) {
									pages.AddRange(PartialList(PageRequest(txtWikiUrl.Text + "?title=Special:Allpages&from=" + data.Value + "&namespace=" + namespaces[k]), namespaces[k + 1]));
									i = 0;
								}
								tableStr = tableStr.Substring(data.Index + data.Length + 5);
								data = allPagesData.Match(tableStr);
							}
						}
						else
							pages.AddRange(PartialList(pageText, namespaces[k + 1]));
					}
				}
				else {
					string pageText = null;
					if(txtWikiUrl.Text.EndsWith("/")) pageText = PageRequest(txtWikiUrl.Text + @"search.aspx?search=&namespace=%5BAll%5D");
					else pageText = PageRequest(txtWikiUrl.Text + @"/search.aspx?search=&namespace=%5BAll%5D");
					Regex pageTitle = new Regex(@"<div class='searchHitHead'>(.|\s)+?</div>");
					Match match = pageTitle.Match(pageText);
					while(match.Success) {
						pages.Add(match.Value.Substring(37, match.Value.IndexOf('"', 37) - 37));
						match = pageTitle.Match(pageText, match.Index + match.Length - 1);
					}
				}
				pageList.Items.Clear();

				for(int i = 0; i < pages.Count; i++) {
					pageList.Items.Add(new ListItem(pages[i], pages[i]));
					pageList.Items[i].Selected = true;
				}
				if(pages.Count > 1000) {
					pageList.Visible = false;
					pageList_div.Visible = false;
					lblPageList.Text = "Too many pages. Click Translate button to import whole wiki.";
				}
				else {
					pageList.Visible = true;
					pageList_div.Visible = true;
					lblPageList.Text = "To exclude pages, uselect them";
				}
			}
			catch(WebException) {
				pageList.Visible = false;
				pageList_div.Visible = false;
				btnTranslateAll.Visible = false;
				lblPageList.Text = "Web Exception";
			}

			return cb.BeginInvoke(ar, cb, null);
		}
Пример #32
0
        /// <summary>
        /// 打印领料单
        /// </summary>
        /// <param name="main"></param>
        /// <param name="list"></param>
        public void SendIOPrint(WH_IOMain main, IEnumerable <WH_IOItem> list)
        {
            string        path     = HttpContext.Current.Server.MapPath("~/CrReport/Rpt_Ticket_Picking.rpt");
            AsyncCallback callback = delegate
            {
                ReportDocument rptDocument = new ReportDocument();
                rptDocument.Load(path);
                QX.BLL.Bll_Comm comInstance = new QX.BLL.Bll_Comm();



                //ParameterDiscreteValue crParameterDiscreteValue;
                //ParameterField crParameterField;
                //ParameterFields crParameterFields;


                //crParameterFields = new ParameterFields();

                ////工程名称
                //crParameterDiscreteValue = new ParameterDiscreteValue();
                //crParameterDiscreteValue.Value = main.WHIOM_Code;
                //crParameterField = new ParameterField();
                //crParameterField.ParameterFieldName = "WHIOM_Code";
                //crParameterField.CurrentValues.Add(crParameterDiscreteValue);
                //crParameterFields.Add(crParameterField);


                ////工程名称
                //crParameterDiscreteValue = new ParameterDiscreteValue();
                //crParameterDiscreteValue.Value = main.WHIOM_RDate;
                //crParameterField = new ParameterField();
                //crParameterField.ParameterFieldName = "WHIOM_RDate";
                //crParameterField.CurrentValues.Add(crParameterDiscreteValue);
                //crParameterFields.Add(crParameterField);

                ////工程名称
                //crParameterDiscreteValue = new ParameterDiscreteValue();
                //crParameterDiscreteValue.Value = main.WHIOM_Department;
                //crParameterField = new ParameterField();
                //crParameterField.ParameterFieldName = "WHIOM_Code";
                //crParameterField.CurrentValues.Add(crParameterDiscreteValue);
                //crParameterFields.Add(crParameterField);


                ////工程名称
                //crParameterDiscreteValue = new ParameterDiscreteValue();
                //crParameterDiscreteValue.Value = main.WHIOM_Owner;
                //crParameterField = new ParameterField();
                //crParameterField.ParameterFieldName = "WHIOM_Owner";
                //crParameterField.CurrentValues.Add(crParameterDiscreteValue);
                //crParameterFields.Add(crParameterField);


                //crParameterDiscreteValue = new ParameterDiscreteValue();
                //crParameterDiscreteValue.Value = main.WHIOM_BOwner;
                //crParameterField = new ParameterField();
                //crParameterField.ParameterFieldName = "WHIOM_BOwner";
                //crParameterField.CurrentValues.Add(crParameterDiscreteValue);
                //crParameterFields.Add(crParameterField);

                ////foreach (ParameterField p in crParameterFields)
                ////{
                ////    rptDocument.SetParameterValue(p.ParameterFieldName, p.CurrentValues[0]);
                ////}

                System.Data.DataTable dt = new System.Data.DataTable();
                dt = comInstance.ListViewData(string.Format("select * from VRpt_IOItem where WHIOI_MainCode='{0}'", main.WHIOM_Code));
                rptDocument.SetDataSource(list);

                rptDocument.SetParameterValue("WHIOM_Department", main.WHIOM_Department);
                rptDocument.SetParameterValue("WHIOM_Code", main.WHIOM_Code);
                rptDocument.SetParameterValue("WHIOM_Owner", main.WHIOM_Owner);
                rptDocument.SetParameterValue("WHIOM_BOwner", main.WHIOM_BOwner);
                rptDocument.SetParameterValue("WHIOM_RDate", main.WHIOM_RDate);

                rptDocument.PrintToPrinter(1, false, 0, 0); //开始打印所有页
            };

            callback.BeginInvoke(null, null, null);
        }
Пример #33
0
		BeginWrite (byte [] buffer, int offset, int count, AsyncCallback callback, object state)
		{
			if (!CanWrite)
				throw new NotSupportedException ("This stream does not support writing");
	
			// Creating a class derived from Stream that doesn't override BeginWrite
			// shows that it actually calls Write and does everything synchronously except
			// when invoking the callback, which is done from the ThreadPool.
			// Just put this in the Write override:
			// 	Console.WriteLine ("Write");
			// 	Console.WriteLine (Environment.StackTrace);
			//	Thread.Sleep (10000);

			StreamAsyncResult result = new StreamAsyncResult (state);
			try {
				Write (buffer, offset, count);
				result.SetComplete (null);
			} catch (Exception e) {
				result.SetComplete (e);
			}

			if (callback != null)
				callback.BeginInvoke (result, null, null);

			return result;
		}
Пример #34
0
 /// <summary>
 /// 发送数据到指定终端
 /// </summary>
 /// <param name="sendObj"></param>
 /// <param name="_sendCallback">发送后的回调函数</param>
 public void Send(SendClientObject sendObj,AsyncCallback _sendCallback)
 {
     lock (sendObj.stateObject.sendLockObj)
     {
         var data = sendObj.txData.GetData();
         try
         {
             sendObj.stateObject.workSocket.BeginSend(data, 0, data.Length, SocketFlags.None, p =>
             {
                 try
                 {
                     sendObj.stateObject.workSocket.EndSend(p);
                     sendObj.IsSendOK = true;
                 }
                 catch(Exception ex) {
                     sendObj.IsSendOK = false;
                     sendObj.ErrMsg = ex.Message;
                     if (ClientErrorEvent != null)
                     {
                         ClientErrorEvent.BeginInvoke(sendObj.stateObject, ex.Message, null, null);
                     }
                 }
                 if (_sendCallback != null)
                 {
                     _sendCallback.BeginInvoke((IAsyncResult)sendObj, null, null);
                 }
             }, sendObj);
         }
         catch (Exception ex)
         {
             sendObj.IsSendOK = false;
             sendObj.ErrMsg = ex.Message;
             if (ClientErrorEvent != null)
             {
                 ClientErrorEvent.BeginInvoke(sendObj.stateObject, ex.Message, null, null);
             }
             if (_sendCallback != null)
             {
                 _sendCallback.BeginInvoke((IAsyncResult)sendObj, null, null);
             }
         }
     }
 }
Пример #35
0
        /// <include file='doc\Stream.uex' path='docs/doc[@for="Stream.BeginWrite"]/*' />
        public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
        {
            if (!CanWrite) __Error.WriteNotSupported();

            // To avoid a race with a stream's position pointer & generating race 
            // conditions with internal buffer indexes in our own streams that 
            // don't natively support async IO operations when there are multiple 
            // async requests outstanding, we will block the application's main
            // thread and do the IO synchronously.  
            SynchronousAsyncResult asyncResult = new SynchronousAsyncResult(state, true);
            try {
                Write(buffer, offset, count);
                asyncResult._isCompleted = true;
                asyncResult._waitHandle.Set();
            }
            catch (IOException e) {
                asyncResult._exception = e;
            }
            
            if (callback != null)
                callback.BeginInvoke(asyncResult, null, null);

            return asyncResult;
        }