Inheritance: System.ComponentModel.AsyncCompletedEventArgs
Exemplo n.º 1
1
        void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (e.Cancelled || e.Error != null)
            {
                return;
            }

            int width = 200;
            int height = 200;

            if (e.UserState != null)
            {
                FlickrNet.Photo photo = (FlickrNet.Photo)e.UserState;

                width = photo.SmallWidth.HasValue ? photo.SmallWidth.Value : width;
                height = photo.SmallHeight.HasValue ? photo.SmallHeight.Value : height;
            }

            byte[] imageData = e.Result;
            PictureBox pictureBox = new PictureBox();
            pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox.Size = new Size(width, height);

            using (MemoryStream stream = new MemoryStream(imageData))
            {
                pictureBox.Image = Image.FromStream(stream);
            }

            progressBar1.PerformStep();

            flowLayoutPanel1.Controls.Add(pictureBox);
        }
Exemplo n.º 2
0
		void mClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
		{

			RunOnUiThread(() =>
				{
					string json = Encoding.UTF8.GetString(e.Result);
					if (json == "Sem Registro")
					{
						lProduto = new List<RegistroProdutos>();
						mProdutoAdapter = new ProdutosViewAdapter(this, Resource.Layout.ProdutosListItem, lProduto);
						lstProdutoView.Adapter = mProdutoAdapter;

						AlertDialog.Builder builder = new AlertDialog.Builder(this);
						builder.SetMessage("Seleção sem Registro");
						builder.SetCancelable(false);
						builder.SetPositiveButton("OK", delegate {builder.Dispose(); });
						builder.Show();
						return;

					} else {

						lProduto = JsonConvert.DeserializeObject<List<RegistroProdutos>>(json);
						mProdutoAdapter = new ProdutosViewAdapter(this, Resource.Layout.ProdutosListItem, lProduto);
						lstProdutoView.Adapter = mProdutoAdapter;
						mProgressBar.Visibility = ViewStates.Gone;
					}
				});
		} 
Exemplo n.º 3
0
        private void cl_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            var lab = e.UserState as Label;

            if (e.Cancelled)
            {
                if (lab != null)
                {
                    lab.Text = LanguageHolder.Instance()[WordEnum.CANCEL_BY_USER];
                }
                return;
            }

            if (e.Error != null)
            {
                if (lab != null)
                {
                    lab.Text = LanguageHolder.Instance()[WordEnum.PROBLEM_WITH_INTERNET];
                }
                return;
            }
            byte[] data = e.Result;

            RefreshNews0(lab, data);
        }
        private void Completed(object sender, DownloadDataCompletedEventArgs e)
        {
            int major, minor, build;

            var raw = e.Result;
            var file = Encoding.UTF8.GetString(raw);
            var regex = new Regex(@"#define _AppVersion ""(\d+)\.(\d+)\.(\d+)""");
            var match = regex.Match(file);

            if (match.Groups.Count == 4)
            {
                if (Int32.TryParse(match.Groups[1].ToString(), out major) &&
                    Int32.TryParse(match.Groups[2].ToString(), out minor) &&
                    Int32.TryParse(match.Groups[3].ToString(), out build))
                {
                    var verRemote = new Version(major, minor, build);
                    var assembly = Assembly.GetExecutingAssembly();
                    var verLocal = assembly.GetName().Version;

                    if (verRemote > verLocal)
                        textUpdate.Text = String.Format(Properties.Resources.UpdateAvailable0,
                            verRemote.ToString());
                    else
                        textUpdate.Text = Properties.Resources.NoUpdateAvailable;
                }
                else
                    textUpdate.Text = Properties.Resources.CheckFailed;
            }
            else
                textUpdate.Text = Properties.Resources.CheckFailed; ;
        }
Exemplo n.º 5
0
 private static void DownloadCompleted(IRuntime runtime, int caller, DownloadDataCompletedEventArgs e)
 {
     // item 255
     if (e.Cancelled) {
     // item 258
     runtime.SendMessage(
         caller,
         Cancel,
         null,
         0
     );
     } else {
     // item 259
     if (e.Error == null) {
         // item 262
         runtime.SendMessage(
             caller,
             CallResult.Completed,
             e.Result,
             0
         );
     } else {
         // item 261
         runtime.SendMessage(
             caller,
             CallResult.Error,
             e.Error,
             0
         );
     }
     }
 }
 private void webClient_DownloadRssCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     if (!e.Cancelled)
     {
         try
         {
             if (e.Error != null)
             {
                 throw e.Error;
             }
             else
             {
                 toolStripStatusLabel1.Text = "";
                 RssListViewItem r = e.UserState as RssListViewItem;
                 r.channel = new RssChannel(new MemoryStream(e.Result));
                 if (r.channel.Image.Url != null && Uri.IsWellFormedUriString(r.channel.Image.Url, UriKind.Absolute) && !FeedImageList.Images.ContainsKey(r.Name))
                 {
                     imageWebClient.CancelAsync();
                     imageWebClient.DownloadDataAsync(new Uri(r.channel.Image.Url), r);
                 }
                 FillListView(r.channel);
             }
         }
         catch (Exception ee)
         {
             HandleException(ee);
         }
     }
 }
Exemplo n.º 7
0
        private void OnDownloadComplete(object sender, DownloadDataCompletedEventArgs e)
        {
            try
            {

                if (!e.Cancelled)
                {
                    while (File.Exists(Destination))
                    {
                        string[] temp = Destination.Split('.');
                        Destination = temp[0] + "_." + temp[1];
                    }
                    BinaryWriter bw = new BinaryWriter(new FileStream(Destination, FileMode.CreateNew));
                    bw.Write(e.Result);
                    bw.Close();
                }
                CallProcess(new ExcutionResult(ResultFlag.Result, "", "Download complete :\r\n" + Destination));
                DownloadCmdList.Remove(this);
            }catch(Exception ex)
            {
                CallProcess(new ExcutionResult(ResultFlag.Error, "", "Download Error :\r\n" + ex.ToString()));
                DownloadCmdList.Remove(this);

            }
        }
        static void OnImageReady(object sender, DownloadDataCompletedEventArgs e)
        {
            AsyncImage d = e.UserState as AsyncImage;

            if (d == null)
                return;

            if (e.Error != null)
            {
                d.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(a =>
                {
                    d.Source = null;
                    d.Visibility = Visibility.Collapsed;
                    return null;
                }), null);
                return;
            }

            byte[] data = e.Result;
            if (data == null)
                return;

            d.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(a =>
            {
                MemoryStream stream = new MemoryStream(data);
                BitmapImage imageSource = new BitmapImage();
                imageSource.BeginInit();
                imageSource.StreamSource = stream;
                imageSource.EndInit();
                d.Source = imageSource;

                return null;
            }), null);
        }
Exemplo n.º 9
0
        private void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                GoEnd(WordEnum.CANCEL_BY_USER);
                return;
            }

            if (e.Error != null)
            {
                if (e.Error is WebException)
                {
                    GoEnd(WordEnum.PROBLEM_WITH_INTERNET);
                    return;
                }
                else
                {
                    _log.Info("Exception: while downloading list: " + e.Error.Message, e.Error);

                    GoEnd(WordEnum.ERROR_DOWNLOAD_LIST);
                    return;
                }
            }

            if (e.Result == null)
            {
                GoEnd(WordEnum.PROBLEM_WITH_SERVER);
                return;
            }

            GoNextStep(e.Result);
        }
Exemplo n.º 10
0
        private void downloader_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            //progressBar1.Value = (int)e.BytesReceived;
            //progressBar1.Maximum = (int)e.TotalBytesToReceive;
            //this.lblPercent.Text = String.Format("已完成 {0}%  {1} 字节/{2} 字节", progressBar1.Value * 100 / progressBar1.Maximum, progressBar1.Value, progressBar1.Maximum);

            byte[] fileBytes = e.Result;
            FileItem fileItem = e.UserState as FileItem;
            string currentFolder = Application.StartupPath;
            var tempFolderInfo = Directory.CreateDirectory(currentFolder + "\\" + Constants.TEMP_DIRECTORY_FOR_DOWNLOAD);

            // use a temporary download location in case something goes wrong, we don't want to
            // corrupt the program and make it unusable without making the user manually delete files.
            string temporaryFilePath = tempFolderInfo.FullName + "\\" + fileItem.FileName;
            System.IO.File.WriteAllBytes(temporaryFilePath, fileBytes);

            //copy file
            if (File.Exists(tempFolderInfo + "\\" + fileItem.FileName))
            {
                File.Copy(tempFolderInfo + "\\" + fileItem.FileName, currentFolder + "\\" + fileItem.FileName, true);
            }
            //Thread.Sleep(3000);
            // delete temp directory
            Directory.Delete(currentFolder + "\\" + Constants.TEMP_DIRECTORY_FOR_DOWNLOAD, true);
            this.Close();
        }
Exemplo n.º 11
0
        private void OnDownloadCompleted(object sender, DownloadDataCompletedEventArgs eventArgs)
        {
            if (eventArgs.Error != null)
            {
                throw eventArgs.Error;
            }

            string file = Path.Combine(Application.StartupPath, DownloadUrl.Split('/')[DownloadUrl.Split('/').Length - 1]);

            File.WriteAllBytes(file, eventArgs.Result);

            string batch = string.Format(
                "@echo off{1}" +
                "TASKKILL /F /PID {0}{1}" +
                "PING 1.1.1.1 -n 1 -w 2000 >NUL{1}" +
                "DEL %2{1}" +
                "MOVE %1 %2{1}" +
                "%2{1}" +
                "DEL %1{1}" +
                "DEL %3", Process.GetCurrentProcess().Id, Environment.NewLine);
            string batchFile = Path.Combine(Application.StartupPath, "update.bat");

            File.WriteAllText(batchFile, batch);

            ProcessStartInfo info = new ProcessStartInfo(batchFile,
                string.Format("\"{0}\" \"{1}\" \"{2}\"", file, Application.ExecutablePath, batchFile))
                                        {CreateNoWindow = true, UseShellExecute = false};
            Process.Start(info);
        }
Exemplo n.º 12
0
		void mClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
		{

			RunOnUiThread(() =>
				{
					string json = Encoding.UTF8.GetString(e.Result);
					if ((json == "Usuario ou Senha nao encontrado") || (json == "Usuario ou Senha sem preenchimento"))
					{

						AlertDialog.Builder builder = new AlertDialog.Builder(this);
						builder.SetMessage(json);
						builder.SetCancelable(false);
						builder.SetPositiveButton("OK", delegate {builder.Dispose(); });
						builder.Show();
						return;

					} else {
						
						lUsuario = JsonConvert.DeserializeObject<List<RegistroUsuario>>(json);

						AlertCenter.Default.BackgroundColor = Color.White;
						AlertCenter.Default.PostMessage ("Seja Bem Vindo", lUsuario[0].nome,Resource.Drawable.Icon);

						StartActivity(typeof(MenuPrincipal));
						this.Finish();
					}
				});
		} 
		void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
		{
			try // if we get a bad result we can get a target invocation exception. In that case just don't show anything
			{
				byte[] raw = e.Result;
				Stream stream = new MemoryStream(raw);
				ImageBuffer unScaledImage = new ImageBuffer(10, 10, 32, new BlenderBGRA());
				StaticData.Instance.LoadImageData(stream, unScaledImage);
				// If the source image (the one we downloaded) is more than twice as big as our dest image.
				while (unScaledImage.Width > Image.Width * 2)
				{
					// The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
					// So we scale as many times as we need to to get the Image to be the right size.
					// If this were going to be a non-uniform scale we could do the x and y separately to get better results.
					ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender);
					halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
					unScaledImage = halfImage;
				}
				Image.NewGraphics2D().Render(unScaledImage, 0, 0, 0, Image.Width / (double)unScaledImage.Width, Image.Height / (double)unScaledImage.Height);
				Image.MarkImageChanged();
				Invalidate();

				if (LoadComplete != null)
				{
					LoadComplete(this, null);
				}
			}
			catch (Exception)
			{
				GuiWidget.BreakInDebugger();
			}
		}
Exemplo n.º 14
0
 void _wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     if (!e.Cancelled && e.Error == null)
     {
         _owner.LoadCompleted(e.Result, e.UserState as string);
     }
 }
Exemplo n.º 15
0
        void CheckForCertUpdates_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            try
            {
                Exception ex = e.Error;
                if (ex is WebException)
                {
                    main.Log.Error("Cert Update: Unable to reach server for updates - " + ex.Message);
                }
                else
                {
                    byte[] bytesCert = e.Result;
                    if (bytesCert.Length > 0)
                    {
                        File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + lastCertFile, bytesCert);
                        main.SetCertFile(lastCertFile);
                        main.Load("cert");
                    }
                }

            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is System.Reflection.TargetInvocationException)
                {
                    main.Log.Error("Link Update: Unable to reach server for updates - " + ex.InnerException.Message);
                }
                else
                {
                    main.Log.Error("Link Update: non-connection error - " + ex.Message);
                }
            }

        }
Exemplo n.º 16
0
        public static string GZipUtf8ResultToString(DownloadDataCompletedEventArgs e)
        {
            if(e.Cancelled || (e.Error != null) || (e.Result == null))
                return null;

            MemoryStream msZipped = new MemoryStream(e.Result);
            GZipStream gz = new GZipStream(msZipped, CompressionMode.Decompress);
            BinaryReader br = new BinaryReader(gz);
            MemoryStream msUTF8 = new MemoryStream();

            while(true)
            {
                byte[] pb = null;

                try { pb = br.ReadBytes(4096); }
                catch(Exception) { }

                if((pb == null) || (pb.Length == 0)) break;

                msUTF8.Write(pb, 0, pb.Length);
            }

            br.Close();
            gz.Close();
            msZipped.Close();

            return Encoding.UTF8.GetString(msUTF8.ToArray());
        }
Exemplo n.º 17
0
        void snapshot_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            mainForm.statusBar.Value = 0;
            if (e.Error != null) {
                MessageBox.Show(e.Error.Message);
            }
            byte[] webPage = { };
            webPage = e.Result;

            String lineArray = Encoding.UTF8.GetString(webPage);
            String[] lines = lineArray.Split(new Char[] { });
            int i = 0;
            bool b = false;
            while (b != true) {
                if (lines[i].Contains("assets") & lines[i].Contains("minecraft.jar")) {
                    mainForm.link = lines[i];
                    mainForm.link = mainForm.link.Substring(6, mainForm.link.Length - 6); // Remove first 6.
                    mainForm.link = mainForm.link.Substring(0, mainForm.link.IndexOf("\""));
                    String[] mysplit = mainForm.link.Split('/');
                    mainForm.version = mysplit[3];
                    b = true;
                }
                i++;
            }

            Download download = new Download(mainForm);
            download.downloadAndInstall();
        }
        /// <summary>Occurs when an asynchronous data download operation completes.</summary>
        protected override void OnDownloadDataCompleted(DownloadDataCompletedEventArgs e)
        {
            // Reset the Stopwatch
            p_Stopwatch.Reset();

            // Continue processing the event as usual
            base.OnDownloadDataCompleted(e);
        }
Exemplo n.º 19
0
 private void Completed(object sender, DownloadDataCompletedEventArgs e)
 {
     DelegateStatusTextAktualisieren textAktualisieren = new DelegateStatusTextAktualisieren(AktualisiereStatus);
     txtStatus.Invoke(textAktualisieren, "Download abgeschlossen");
     File.WriteAllBytes(Directory.GetCurrentDirectory() + "/UpdatePacket.zip", e.Result);
     txtStatus.Invoke(textAktualisieren, "Das Update wurde als \"UpdatePacket.zip\" gespeichert.");
     Updatefertig = true;
 }
        private void OnWebClientOnDownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            var webClient = (WebClient) sender;

            webClient.DownloadProgressChanged -= OnWebClientOnDownloadProgressChanged;
            webClient.DownloadDataCompleted -= OnWebClientOnDownloadDataCompleted;

            DownloadCompleted.SafeInvoke(this);
        }
Exemplo n.º 21
0
        public void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs downloadDataCompletedEventArgs)
        {
            var client = new WebClient();
            client.Proxy = null;
            client.DownloadStringCompleted += client_DownloadString;

            listBox1.Items.Clear();
            client.DownloadStringAsync(new Uri(GetAddress));
        }
Exemplo n.º 22
0
 void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     if (e.Error != null || e.Cancelled || e.Result == null) {
         Trace.TraceError("{0} failed {1}", Name, e.Error);
         Finish(false);
     } else {
         Result = e.Result;
         Trace.TraceInformation("{0} Completed - {1}", Name, Utils.PrintByteLength(Result.Length));
         Finish(true);
     }
 }
Exemplo n.º 23
0
 private void DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     Handle handle = (Handle)e.UserState;
     Debug.Assert(!m_idleClients.Contains(handle.client));
     handle.complete = true;
     m_idleClients.Add(handle.client);
     if (e.Cancelled || e.Error != null)
         handle.onComplete(handle.uri, null, ErrorMessage(e), handle.userData);
     else
         handle.onComplete(handle.uri, e.Result, null, handle.userData);
 }
Exemplo n.º 24
0
 private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     if (e.Error != null)
         Program.Database.FailedDatabases.Add(Tuple.Create((string)e.UserState, e.Error));
     else {
         using (var ms = new System.IO.MemoryStream(e.Result)) {
             var db = StreamDeskDatabase.OpenDatabase(ms, System.IO.Path.GetExtension((string) e.UserState));
             db.TagInformation = (string) e.UserState;
             Program.Database.ActiveDatabases.Add(db);
         }
     }
 }
Exemplo n.º 25
0
        void m_CheckUpdates_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            const string VERSION_ID_START = "&gt;&gt; Current Version:";
            const string VERSION_ID_END = " &lt;&lt;";

            if (!e.Cancelled)
            {
                if (e.Error != null)
                {
                    MessageBox.Show("Cannot contact the site for updates!", Application.ProductName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    // Encoding.ASCII.GetString(e.Result, 0, e.Result.Length).Split(new string[] { "\n" }, StringSplitOptions.None)
                    try
                    {
                        string[] sResult = Encoding.ASCII.GetString(e.Result, 0, e.Result.Length).Split(new string[] { "\n" }, StringSplitOptions.None);
                        string sWithData = null;

                        for (int i = 0; i < sResult.Length; i++)
                        {
                            if (sResult[i].IndexOf(VERSION_ID_START) != -1)
                            {
                                sWithData = sResult[i];
                                break;
                            }
                        }

                        if (sWithData != null)
                        {
                            int iFound = sWithData.IndexOf(VERSION_ID_START);

                            if (iFound > 0)
                            {
                                iFound += VERSION_ID_START.Length;
                                sWithData = sWithData.Substring(iFound, sWithData.IndexOf(VERSION_ID_END) - iFound);
                                CheckUpdate(sWithData.Trim());
                            }
                        }
                    }
                    catch
                    {

                    }
                }
            }

            // -------------------------------------
            this.Cursor = Cursors.Default;
            this.btnUpdates.Text = BTNUPDATE_UNCLICK;
            this.btnUpdates.Enabled = true;
        }
Exemplo n.º 26
0
 private void FTPDownloadCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     HandleCurrentFile(e.Result);
     if (SetupFiles.Count > 0)
     {
         var file = SetupFiles.Dequeue();
         CurrentFile = file;
         DownloadFile(file.Filename);
     } else
     {
         MessageBox.Show("Done!");
     }
 }
Exemplo n.º 27
0
 void wcl_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs args)
 {
     pbDownload.Value = 100;
     Text = string.Format("Загрузка завершена");
     if (args.Cancelled)
         MessageBox.Show("Отменено");
     else if (args.Error != null)
         throw args.Error;
     else
     {
         result=args.Result;
     }
     Close();
 }
Exemplo n.º 28
0
 private void WebClientDownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     var ms = new MemoryStream(e.Result);
     try
     {
         var image = Image.FromStream(ms);
         ms.Close();
         _imageReady(image);
     }
     catch
     {
         _imageReady(null);
     }
 }
Exemplo n.º 29
0
        private void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                SetDefaultClouds();
                return;
            }

            var image = new BitmapImage();
            image.BeginInit();
            image.StreamSource = new MemoryStream(e.Result);
            image.EndInit();

            Clouds = MaterialHelper.CreateImageMaterial(image, 0.5);
        }
Exemplo n.º 30
0
 // Method called when web request has fully retrieved events as Json data
 private void WebClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
 {
     Activity.RunOnUiThread(() =>
     {
         var imageBytes = e.Result;
         if (imageBytes != null && imageBytes.Length > 0)
         {
             Bitmap imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
             mProfilePic.SetImageBitmap(imageBitmap);
         } else
         {
             Console.WriteLine("IS NULL!!!!!");
         }
     });
 }
Exemplo n.º 31
0
 protected virtual void OnDownloadDataCompleted(DownloadDataCompletedEventArgs e)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 32
0
 void client_DownloadDataCompleted(object sender, System.Net.DownloadDataCompletedEventArgs e)
 {
     this.OnDownloadCompleted(this, e);
 }
Exemplo n.º 33
0
 private void Webclient_DownloadDataCompleted(object sender, System.Net.DownloadDataCompletedEventArgs e)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 34
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void wc_DownloadDataCompleted2(object sender, System.Net.DownloadDataCompletedEventArgs e)
 {
 }
 protected virtual new void OnDownloadDataCompleted(DownloadDataCompletedEventArgs e)
 {
 }