private void ProgressHandler(IUploadProgress obj, VideosResource.InsertMediaUpload video) { if (obj.Status == UploadStatus.Failed) { MessageBox.Show(obj.Exception.Message); foreach (var help in obj.Exception.Data.Values) { MessageBox.Show(help.ToString()); } } if (obj.Status == UploadStatus.Uploading) { Dispatcher.BeginInvoke( new Action(() => { for (int i = 0; i < UploadQueue.Items.Count; i++) { System.Windows.Controls.Border UploadEntry = UploadQueue.Items.GetItemAt(i) as System.Windows.Controls.Border; if (UploadEntry.FindChild <TextBlock>("Stats").Text.Contains(video.Body.Snippet.Title)) { UploadEntry.FindChild <ProgressBar>("Progress").Value = obj.BytesSent / filesize; string[] Stats = UploadEntry.FindChild <TextBlock>("Stats").Text.Split('\n'); DateTime StartTime = DateTime.Parse(Stats[2].Substring(12)); TimeSpan ElapsedTime = DateTime.Now - StartTime; TimeSpan RemainingTime = TimeSpan.FromTicks((long)(ElapsedTime.Ticks * (100 - (obj.BytesSent / filesize) * 100))); UploadEntry.FindChild <TextBlock>("Stats").Text = Stats[0] + "\n" + Math.Round(obj.BytesSent / filesize, 3) + "%\n" + Stats[2] + "\nFinished in:\t" + RemainingTime.ToString(@"dd\.hh\:mm\:ss"); } } }) ); } }
private void videosInsertRequest_ProgressChanged(IUploadProgress obj) { if (obj.Status == UploadStatus.Failed) { MessageBox.Show(obj.Exception.Message); foreach (var help in obj.Exception.Data.Values) { MessageBox.Show(help.ToString()); } } if (obj.Status == UploadStatus.Uploading) { Dispatcher.BeginInvoke( new Action(() => { System.Windows.Controls.Border UploadEntry = UploadQueue.Items.GetItemAt(0) as System.Windows.Controls.Border; UploadEntry.FindChild <ProgressBar>("Progress").Value = obj.BytesSent / filesize; string [] Stats = UploadEntry.FindChild <TextBlock>("Stats").Text.Split('\n'); DateTime StartTime = DateTime.Parse(Stats[2].Substring(12)); TimeSpan ElapsedTime = DateTime.Now - StartTime; TimeSpan RemainingTime = TimeSpan.FromTicks((long)(ElapsedTime.Ticks * (100 - (obj.BytesSent / filesize) * 100))); UploadEntry.FindChild <TextBlock>("Stats").Text = Stats[0] + "\n" + Math.Round(obj.BytesSent / filesize, 3) + "%\n" + Stats[2] + "\nFinished in:\t" + (int)RemainingTime.TotalHours + ":" + RemainingTime.ToString(@"mm\:ss"); }) ); } }
private void uploadRequest_ResponseReceived(Video obj) { Dispatcher.BeginInvoke( new Action(() => { for (int i = 0; i < UploadQueue.Items.Count; i++) { System.Windows.Controls.Border UploadEntry = UploadQueue.Items.GetItemAt(i) as System.Windows.Controls.Border; if (UploadEntry.FindChild <TextBlock>("Stats").Text.Contains(obj.Snippet.Title)) { UploadEntry.FindChild <ProgressBar>("Progress").Value = 100; string[] Stats = UploadEntry.FindChild <TextBlock>("Stats").Text.Split('\n'); UploadEntry.FindChild <TextBlock>("Stats").Text = Stats[0] + "\n100%\n" + Stats[2] + "\nFinished"; UploadEntry.FindChild <TextBlock>("VideoUri").Text = "http://youtube.com/watch?v=" + obj.Id; UploadEntry.FindChild <TextBlock>("VideoUri").MouseDown += new MouseButtonEventHandler((s, e) => VideoUri_MouseDown(s, e, obj)); } } }) ); }