void webClient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { if (e.Error == null) { byte[] imageBytes = null; if (myImage != null) { //PngEncoder encoder = new smART .MVC.Silverlight.PngEncoder(); using (MemoryStream ms = new MemoryStream()) { var itImage = myImage.ToImage(); //ms = PngEncoder.Encode(itImage, 20, 30); //encoder.Encode(itImage, ms); imageBytes = ms.ToArray(); } } if (imageBytes == null) { imageBytes = new byte[100000]; } if (imageBytes != null) { string strBytes = Convert.ToBase64String(imageBytes); string dataString = string.Format("cameraInitiator={0}&id={1}&data={2}", this.CameraInitiator, this.Id, strBytes); byte[] postData = Encoding.UTF8.GetBytes(dataString); e.Result.Write(postData, 0, postData.Length); } e.Result.Close(); } }
//</Snippet14> //<Snippet15> private static void OpenWriteCallback2(Object sender, OpenWriteCompletedEventArgs e) { Stream body = null; StreamWriter s = null; try { body = (Stream)e.Result; s = new StreamWriter(body); s.AutoFlush = true; s.Write("This is content data to be sent to the server."); } finally { if (s != null) { s.Close(); } if (body != null) { body.Close(); } } }
//</Snippet12> //<Snippet13> private static void OpenWriteCallback(Object sender, OpenWriteCompletedEventArgs e) { System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState; Stream body = null; StreamWriter s = null; try { body = (Stream)e.Result; s = new StreamWriter(body); s.AutoFlush = true; s.Write("This is content data to be sent to the server."); } finally { if (s != null) { s.Close(); } if (body != null) { body.Close(); } // If this thread throws an exception, make sure that // you let the main application thread resume. waiter.Set(); } }
private void webClient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { if (e.Error == null) { #region DEPRECATED //byte[] imageBytes = null; //if (myImage != null) //{ // PngEncoder encoder = new PngEncoder(); // using (MemoryStream ms = new MemoryStream()) // { // var itImage = myImage.ToImage(); // encoder.Encode(itImage, ms); // imageBytes = ms.ToArray(); // } //} //if (imageBytes == null) imageBytes = new byte[100000]; //if (imageBytes != null) //{ // string strBytes = Convert.ToBase64String(imageBytes); // string dataString = string.Format("cameraInitiator={0}&id={1}&data={2}", this.CameraInitiator, this.ReferenceID, strBytes); // byte[] postData = Encoding.UTF8.GetBytes(dataString); // e.Result.Write(postData, 0, postData.Length); //} #endregion byte[] postData = Encoding.UTF8.GetBytes(e.UserState.ToString()); e.Result.Write(postData, 0, postData.Length); e.Result.Close(); } }
private void FireWriteCompleted(OpenWriteCompletedEventArgs e) { if (WriteCompleted != null) { var state = (object[])e.UserState; WriteCompleted(this, new WriteCompletedEventArgs(e.Error, state[1], e.Cancelled)); } }
private static void client_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { #if Debug Debug.WriteLine("Methode: WebClient.OpenWriteCompleted"); Debug.WriteLine(e.ToString()); Debug.WriteLine("#####################################"); #endif }
protected virtual void OnOpenWriteCompleted(OpenWriteCompletedEventArgs args) { CompleteAsync(); if (OpenWriteCompleted != null) { OpenWriteCompleted(this, args); } }
// </snippet7> // <snippet8> protected override void OnOpenWriteCompleted(OpenWriteCompletedEventArgs e) { // Here you can perform any custom actions before the event is raised // and event handlers are called... base.OnOpenWriteCompleted(e); // Here you can perform any post event actions... }
private void webClient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { if (e.Error == null) { byte[] postData = Encoding.UTF8.GetBytes(e.UserState.ToString()); e.Result.Write(postData, 0, postData.Length); e.Result.Close(); } }
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(); } }
async void write_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { if (e.Error == null) { progressbar.Value = 100; progressbar.Visibility = Visibility.Collapsed; MessageBox.Show("OPENED"); await writeAsync(e.Result); } else { MessageBoxResult msg_box = MessageBox.Show(e.Error.Message + "Server Ne repond Pas", "Do you want to Retry", MessageBoxButton.OKCancel); } }
void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { if (e.Error == null) { UploadFile f = _files.SingleOrDefault(m => m.Name == e.UserState as string); if (f != null) { Stream outputStream = e.Result; outputStream.Write(f.FileContent, 0, f.FileContent.Length); outputStream.Close(); f.FileContent = null; f.FileStoreUrl = "/FileStore/" + f.Name; f.UploadPercentage = 100; f.Loaded = true; } } }
//将文件数据流发送到服务器上 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) { //将图片数据流发送到服务器上 e.UserState即为需要上传的客户端的流 Stream clientStream = e.UserState as Stream; clientStream.Position = 0; Stream serverStream = e.Result; byte[] buffer = new byte[4096]; int readcount = 0; //将需要上传的流读取到指定的字节数组中 while ((readcount = clientStream.Read(buffer, 0, buffer.Length)) > 0) { //将指定的字节数组写入到目标地址的流 serverStream.Write(buffer, 0, readcount); } serverStream.Close(); clientStream.Close(); }
private void client_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { if (e.Error != null || e.Cancelled) { FireWriteCompleted(e); } else { ThreadPool.QueueUserWorkItem(nil => { var state = (object[])e.UserState; var fileInfo = (FileInfo)state[0]; Stream fileStream = fileInfo.OpenRead(); try { var buffer = new byte[4096]; double writtenSize = 0; long fileSize = fileInfo.Length; while (!canceled && writtenSize < fileSize) { int i = fileStream.Read(buffer, 0, buffer.Length); e.Result.Write(buffer, 0, i); writtenSize += i; FireProgressUpdated(writtenSize / fileSize, state[1]); } FireWriteCompleted(null, state[1]); } catch (Exception ex) { FireWriteCompleted(ex, state[1]); } finally { e.Result.Close(); fileStream.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); } } } }
private void openWriteCompleted(object sender, OpenWriteCompletedEventArgs e) { request.Content.CopyTo(e.Result); e.Result.Close(); }
/// <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) { if (OpenWriteCompleted != null) OpenWriteCompleted (this, args); }