protected virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs args) { CompleteAsync(); if (OpenWriteCompleted != null) { OpenWriteCompleted(this, args); } }
protected virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs args) { CompleteAsync(); OpenWriteCompletedEventHandler handler = OpenWriteCompleted; if (handler != null) { handler(this, args); } }
void m_downloadClient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { Stream outputStream = e.Result; byte[] fileContent = e.UserState as byte[]; outputStream.Write(fileContent, 0, fileContent.Length); outputStream.Close(); if (UploadCompleted != null) { UploadCompleted(); } }
private void OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs args) { FileInfo info; if (_fileQueue.Count > 0) lock (_baton) if (_fileQueue.Count > 0) info = _fileQueue.Dequeue(); else return; else return; using (Stream output = args.Result) using (FileStream input = info.OpenRead()) input.WriteTo(output, 4096); }
//将文件数据流发送到服务器上 void webclient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { // e.UserState - 需要上传的流(客户端流) Stream clientStream = e.UserState as Stream; // e.Result - 目标地址的流(服务端流) Stream serverStream = e.Result; byte[] buffer = new byte[clientStream.Length / 1024]; int readcount = 0; // clientStream.Read - 将需要上传的流读取到指定的字节数组中 while ((readcount = clientStream.Read(buffer, 0, buffer.Length)) > 0) { // serverStream.Write - 将指定的字节数组写入到目标地址的流 serverStream.Write(buffer, 0, readcount); } serverStream.Close(); clientStream.Close(); }
private void Client_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { bool raiseEvent = false; if (!_Dead) { if (!_Running) raiseEvent = true; // We are connected to the event queue _Running = true; } // Create an EventQueueGet request LLSDMap request = new LLSDMap(); request["ack"] = new LLSD(); request["done"] = LLSD.FromBoolean(false); byte[] postData = LLSDParser.SerializeXmlBytes(request); _Client.UploadDataAsync(_Client.Location, postData); if (raiseEvent) { SecondLife.DebugLogStatic("Capabilities event queue connected"); // The event queue is starting up for the first time if (OnConnected != null) { try { OnConnected(); } catch (Exception ex) { SecondLife.LogStatic(ex.ToString(), Helpers.LogLevel.Error); } } } }
/// <summary> /// Handler for writing out the request body if needed /// </summary> void SendHttpRequestOpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { EchoNestApiEventArgs args = null; Dictionary<string, object> state = (Dictionary<string, object>)e.UserState; string path = (string)state["path"]; object body = state["body"]; object userState = state["userState"]; Dictionary<string, string> parameters = (Dictionary<string, string>)state["parameters"]; HttpHelper h = (HttpHelper)sender; if (e.Cancelled) { args = new EchoNestApiEventArgs(e.Error, true, userState, null); } else if (e.Error == null) { try { using (var stream = e.Result) { parameters["data"] = JsonConvert.SerializeObject( body, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); StreamWriter writer = new StreamWriter(stream); writer.Write(CreateMultipartForm(parameters)); writer.Flush(); } h.OpenReadAsync(new Dictionary<string, object> { {"path", path}, {"userState", userState} }); return; } catch (Exception ex) { args = new EchoNestApiEventArgs(ex, h.HttpWebRequest.IsCancelled, userState, null); } } else { var ex = e.Error as WebExceptionWrapper; if (ex != null) { if (ex.GetResponse() != null) { h.OpenReadAsync(path); return; } } args = new EchoNestApiEventArgs(e.Error, false, userState, null); } OnCompleted(path, args); }
private void OpenWriteAsyncCallback(IAsyncResult result) { LazyAsyncResult result2 = (LazyAsyncResult) result; AsyncOperation asyncState = (AsyncOperation) result2.AsyncState; WebRequest asyncObject = (WebRequest) result2.AsyncObject; WebClientWriteStream stream = null; Exception exception = null; try { stream = new WebClientWriteStream(asyncObject.EndGetRequestStream(result), asyncObject, this); } catch (Exception exception2) { if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException)) { throw; } exception = exception2; if (!(exception2 is WebException) && !(exception2 is SecurityException)) { exception = new WebException(SR.GetString("net_webclient"), exception2); } } OpenWriteCompletedEventArgs eventArgs = new OpenWriteCompletedEventArgs(stream, exception, this.m_Cancelled, asyncState.UserSuppliedState); this.InvokeOperationCompleted(asyncState, this.openWriteOperationCompleted, eventArgs); }
protected virtual new void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e) { }
protected void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { // 要上传的文件 string fileNamePath = @"c:\ws\temp\Oraycn.RecordDemo.rar"; FileStream fs = new FileStream(fileNamePath, FileMode.Open, FileAccess.Read); BinaryReader r = new BinaryReader(fs, Encoding.UTF8); //int size = r.Read(buf, 0, bufSize); int bufSize = 10; int byteGet = 0; byte[] buf = new byte[bufSize]; //while ((byteGet = ms.Read(buf, 0, bufSize)) > 0)//循环读取,上传 while ((byteGet = r.Read(buf, 0, bufSize)) > 0)//循环读取,上传 { e.Result.Write(buf, 0, byteGet);//注意这里 } e.Result.Close();//关闭 r.Close();//关闭ms }
public void OpenWriteAsync(Uri address, string method, object userToken) { if(Logging.On)Logging.Enter(Logging.Web, this, "OpenWriteAsync", address +", "+method); if (address == null) throw new ArgumentNullException("address"); if (method == null) { method = MapToDefaultMethod(address); } InitWebClientAsync(); ClearWebClientState(); AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(userToken); m_AsyncOp = asyncOp; try { m_Method = method; WebRequest request = m_WebRequest = GetWebRequest(GetUri(address)); request.BeginGetRequestStream(new AsyncCallback(OpenWriteAsyncCallback), asyncOp); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } if (!(e is WebException || e is SecurityException)) { e = new WebException(SR.GetString(SR.net_webclient), e); } OpenWriteCompletedEventArgs eventArgs = new OpenWriteCompletedEventArgs(null, e, m_Cancelled, asyncOp.UserSuppliedState); InvokeOperationCompleted(asyncOp, openWriteOperationCompleted, eventArgs); } catch { Exception e = new WebException(SR.GetString(SR.net_webclient), new Exception(SR.GetString(SR.net_nonClsCompliantException))); OpenWriteCompletedEventArgs eventArgs = new OpenWriteCompletedEventArgs(null, e, m_Cancelled, asyncOp.UserSuppliedState); InvokeOperationCompleted(asyncOp, openWriteOperationCompleted, eventArgs); } if(Logging.On)Logging.Exit(Logging.Web, this, "OpenWriteAsync", null); }
private void OpenWriteAsyncCallback(IAsyncResult result) { LazyAsyncResult lazyAsyncResult = (LazyAsyncResult) result; AsyncOperation asyncOp = (AsyncOperation) lazyAsyncResult.AsyncState; WebRequest request = (WebRequest) lazyAsyncResult.AsyncObject; WebClientWriteStream stream = null; Exception exception = null; try { stream = new WebClientWriteStream(request.EndGetRequestStream(result), request, this); } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } exception = e; if (!(e is WebException || e is SecurityException)) { exception = new WebException(SR.GetString(SR.net_webclient), e); } } catch { exception = new WebException(SR.GetString(SR.net_webclient), new Exception(SR.GetString(SR.net_nonClsCompliantException))); } OpenWriteCompletedEventArgs eventArgs = new OpenWriteCompletedEventArgs(stream, exception, m_Cancelled, asyncOp.UserSuppliedState); InvokeOperationCompleted(asyncOp, openWriteOperationCompleted, eventArgs); }
protected virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e) { if (OpenWriteCompleted != null) { OpenWriteCompleted(this, e); } }
private void openWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { request.Content.CopyTo(e.Result); e.Result.Close(); }
protected virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e) { throw new NotImplementedException(); }
public static void webClient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { if (e.Error == null) { object[] objArr = e.UserState as object[]; byte[] fileContent = e.UserState as byte[]; Stream outputStream = e.Result; outputStream.Write(fileContent, 0, fileContent.Length); outputStream.Flush(); outputStream.Close(); string s = e.Result.ToString(); MessageBox.Show("Image has been uploaded successfully !"); } else { MessageBox.Show("There has been an error while uploading image. Please try again ...!!"); } }
private void OnWriteReady(object sender, OpenWriteCompletedEventArgs e) { byte[] fileChunk = e.UserState as byte[]; if (fileChunk != null) { Stream httpStream = e.Result; httpStream.Write(fileChunk, 0, fileChunk.Length); httpStream.Close(); } }
protected virtual new void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e) { }
private void Webclient_OpenWriteCompleted(object sender, System.Net.OpenWriteCompletedEventArgs e) { throw new NotImplementedException(); }
protected virtual void OnOpenWriteCompleted (OpenWriteCompletedEventArgs e) { CompleteAsync (); OpenWriteCompletedEventHandler handler = OpenWriteCompleted; if (handler != null) handler (this, e); }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// openwritecompletedeventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this OpenWriteCompletedEventHandler openwritecompletedeventhandler, Object sender, OpenWriteCompletedEventArgs e, AsyncCallback callback) { if(openwritecompletedeventhandler == null) throw new ArgumentNullException("openwritecompletedeventhandler"); return openwritecompletedeventhandler.BeginInvoke(sender, e, callback, null); }
protected virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs args) { CompleteAsync(); if (OpenWriteCompleted != null) OpenWriteCompleted(this, args); }
public void OpenWriteAsync(Uri address, string method, object userToken) { if (Logging.On) { Logging.Enter(Logging.Web, this, "OpenWriteAsync", address + ", " + method); } if (address == null) { throw new ArgumentNullException("address"); } if (method == null) { method = this.MapToDefaultMethod(address); } this.InitWebClientAsync(); this.ClearWebClientState(); AsyncOperation state = AsyncOperationManager.CreateOperation(userToken); this.m_AsyncOp = state; try { this.m_Method = method; (this.m_WebRequest = this.GetWebRequest(this.GetUri(address))).BeginGetRequestStream(new AsyncCallback(this.OpenWriteAsyncCallback), state); } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } if (!(exception is WebException) && !(exception is SecurityException)) { exception = new WebException(SR.GetString("net_webclient"), exception); } OpenWriteCompletedEventArgs eventArgs = new OpenWriteCompletedEventArgs(null, exception, this.m_Cancelled, state.UserSuppliedState); this.InvokeOperationCompleted(state, this.openWriteOperationCompleted, eventArgs); } if (Logging.On) { Logging.Exit(Logging.Web, this, "OpenWriteAsync", (string) null); } }