private async void HandleDeleteUploadQueueItemCommand(UploadQueueItem item) { //TODO: fix this //await App.Sync.Delete(item.Filename); await RefreshUploadQueue(); }
private async Task UploadItem(UploadQueueItem uploadQueueItem, DataChunkSize dataChunkSize) { if (uploadQueueItem.Title.Trim().Length == 0) { App.TaskDialogShow("오류", "입력에 오류가 있습니다.", "영상 제목은 반드시 채워져야 합니다.", TaskDialogIcon.Error, TaskDialogCommonButtonFlags.OK); return; } string itemName = $"{uploadQueueItem.Title}({Path.GetFileName ( HttpUtility.UrlDecode ( uploadQueueItem.FileName.AbsolutePath ) )})"; switch (await uploadQueueItem.UploadStart(dataChunkSize)) { case UploadResult.Succeed: switch (uploadQueueItem.UploadingStatus) { case UploadingStatus.UploadCompleted: NotificatorManager.Notify("안내", $"{itemName}에 대한 업로드를 성공했습니다.", NotifyType.CustomType1); break; case UploadingStatus.UpdateComplete: NotificatorManager.Notify("안내", $"{itemName}에 대한 업데이트를 성공했습니다.", NotifyType.CustomType1); break; case UploadingStatus.UploadFailed: NotificatorManager.Notify("안내", $"{itemName}에 대한 업로드를 실패했습니다.", NotifyType.Warning); break; case UploadingStatus.UpdateFailed: NotificatorManager.Notify("안내", $"{itemName}에 대한 업데이트를 실패했습니다.", NotifyType.Warning); break; } break; case UploadResult.UploadCanceled: NotificatorManager.Notify("안내", $"{itemName}에 대한 업로드가 중단됐습니다.\n업로드 재개가 가능합니다.", NotifyType.Warning); break; case UploadResult.AlreadyUploading: NotificatorManager.Notify("오류", $"{itemName}은 이미 업로드가 시작되었습니다.", NotifyType.Error); break; case UploadResult.FailedUploadRequest: NotificatorManager.Notify("오류", $"{itemName}의 업로드 요청을 시작할 수 없었습니다.", NotifyType.Error); break; case UploadResult.CannotStartUpload: NotificatorManager.Notify("오류", $"{itemName}의 업로드 작업을 시작할 수 없었습니다.", NotifyType.Error); break; } }
public void TestUploadQueueItem() { // Get the receive queue using (var queue = GetUniqueMessageQueue()) { var queueItem = new UploadQueueItem( calledApplicationEntityTitle: "Test1", callingApplicationEntityTitle: "Test2", associationFolderPath: "Test4", rootDicomFolderPath: "Test6", associationGuid: Guid.NewGuid(), associationDateTime: DateTime.UtcNow) { DequeueCount = 9 }; TransactionalEnqueue(queue, queueItem); var item = TransactionalDequeue <UploadQueueItem>(queue); Assert.IsNotNull(item); AssertAllProperties(queueItem, item); } }
private void SetThumbnailImage(UploadQueueItem uploadQueueItem, BitmapSource bitmapSource) { if (bitmapSource == null || uploadQueueItem == null) { return; } if (Math.Abs((bitmapSource.PixelWidth / ( double )bitmapSource.PixelHeight) - (16 / 9.0)) >= float.Epsilon) { var result = App.TaskDialogShow("알림", "이미지 크기가 16:9 비율이어야 합니다.", "클립보드 이미지 크기 비율이 16:9인지 확인해주세요.\nYouTube 권장 크기는 1280 * 720입니다.", TaskDialogIcon.Warning, TaskDialogCommonButtonFlags.OK, "레터박스 추가", "잘라내기", "늘리기").Button; if (result != 0) { var blackBrush = new SolidColorBrush(Colors.Black); blackBrush.Freeze(); RenderTargetBitmap bmp = new RenderTargetBitmap(1280, 720, 96, 96, PixelFormats.Default); Grid container = new Grid() { Width = 1280, Height = 720, Background = blackBrush }; Image image = new Image() { Source = bitmapSource, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; switch (result) { case 1: image.Stretch = Stretch.Uniform; break; case 2: image.Stretch = Stretch.UniformToFill; break; case 3: image.Stretch = Stretch.Fill; break; } container.Children.Add(image); container.Measure(new Size(1280, 720)); container.Arrange(new Rect(0, 0, 1280, 720)); bmp.Render(container); bmp.Freeze(); bitmapSource = bmp; } else { return; } } uploadQueueItem.Thumbnail = bitmapSource; }
/// <summary> /// Shorthand for creating an association status log entry. /// </summary> /// <param name="associationStatus">Association status.</param> /// <param name="information">Freeform information about log item.</param> /// <param name="queueItemBase">Queue item base.</param> /// <param name="deleteQueueItem">Delete queue item.</param> /// <param name="downloadQueueItem">Download queue item.</param> /// <param name="downloadProgress">Download progress.</param> /// <param name="downloadError">Download error.</param> /// <param name="pushQueueItem">Push queue item.</param> /// <param name="uploadQueueItem">Upload queue item.</param> /// <param name="segmentationId">Segmentation id.</param> /// <param name="modelId">Model id.</param> /// <param name="destination">Destination.</param> /// <param name="path">Path.</param> /// <param name="failedDicomTags">String formatted list of failed DICOM tags.</param> /// <param name="dicomDataReceiverProgress">Receiver progress.</param> /// <returns>New LogEntry of type SegmentationStatus.</returns> public static LogEntry Create( AssociationStatus associationStatus, string information = null, QueueItemBase queueItemBase = null, DeleteQueueItem deleteQueueItem = null, DownloadQueueItem downloadQueueItem = null, int?downloadProgress = null, string downloadError = null, PushQueueItem pushQueueItem = null, UploadQueueItem uploadQueueItem = null, string segmentationId = null, string modelId = null, (string ipAddress, string title, int port)?destination = null,
/// <summary> /// Method for when data is received. Used for adding a received folder onto the message queue /// when the association is closed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The progress update.</param> private void DataReceiver_DataReceived(object sender, DicomDataReceiverProgressEventArgs e) { var queueItem = new UploadQueueItem( calledApplicationEntityTitle: e.DicomAssociation?.CalledAE, callingApplicationEntityTitle: e.DicomAssociation?.CallingAE, associationFolderPath: e.FolderPath, rootDicomFolderPath: e.RootFolderPath, associationGuid: e.AssociationId, associationDateTime: e.SocketConnectionDateTime); if (e.ProgressCode == DicomReceiveProgressCode.AssociationReleased || e.ProgressCode == DicomReceiveProgressCode.TransferAborted) { // Send a log event LogInformation(LogEntry.Create(AssociationStatus.DicomAssociationClosed, uploadQueueItem: queueItem, dicomDataReceiverProgress: CreateReceiveProperties(e))); // If no data has been received, we do not need to add to the message queue. // An example of a no data received scenario is a Dicom echo. if (!e.AnyDataReceived) { return; } using (var transaction = CreateQueueTransaction(_uploadQueuePath)) { BeginMessageQueueTransaction(transaction); try { // Add the receive queue item onto the queue. // No retry logic as if the method fails, retrying will not help EnqueueMessage(queueItem, _uploadQueuePath, transaction); transaction.Commit(); } // This should never happen unless someone has manually changed the queue configuration #pragma warning disable CA1031 // Do not catch general exception types catch (Exception exception) #pragma warning restore CA1031 // Do not catch general exception types { transaction.Abort(); LogError(LogEntry.Create(AssociationStatus.ReceiveEnqueueError, uploadQueueItem: queueItem), exception); } } } else if (e.ProgressCode == DicomReceiveProgressCode.FileReceived || e.ProgressCode == DicomReceiveProgressCode.ConnectionClosed || e.ProgressCode == DicomReceiveProgressCode.AssociationEstablished) { LogInformation(LogEntry.Create(AssociationStatus.FileReceived, uploadQueueItem: queueItem, dicomDataReceiverProgress: CreateReceiveProperties(e))); } else if (e.ProgressCode == DicomReceiveProgressCode.AssociationEstablished) { LogInformation(LogEntry.Create(AssociationStatus.DicomAssociationOpened, uploadQueueItem: queueItem, dicomDataReceiverProgress: CreateReceiveProperties(e))); } else if (e.ProgressCode == DicomReceiveProgressCode.Echo) { LogInformation(LogEntry.Create(AssociationStatus.DicomEcho, uploadQueueItem: queueItem, dicomDataReceiverProgress: CreateReceiveProperties(e))); } else { LogError(LogEntry.Create(AssociationStatus.ReceiveUploadError, uploadQueueItem: queueItem, dicomDataReceiverProgress: CreateReceiveProperties(e)), new ReceiveServiceException("Cannot add to upload queue")); } }
private void AddItem(string filename) { if (!YouTubeSession.IsAlreadyAuthorized) { return; } bool alreadyAdded = false; Uri filenameUri = new Uri(filename); foreach (var item in uploadQueueListBox.ItemsSource as IList <UploadQueueItem> ) { if (item.FileName.AbsolutePath == filenameUri.AbsolutePath) { alreadyAdded = true; break; } } if (alreadyAdded) { return; } string itemName = Path.GetFileName(filename); UploadQueueItem queueItem; try { queueItem = new UploadQueueItem(YouTubeSession, filename) { PrivacyStatus = ( PrivacyStatus )comboBoxDefaultPrivacyStatus.SelectedIndex }; } catch (ArgumentException) { NotificatorManager.Notify("오류", $"{itemName}의 업로드할 파일의 크기는 64GB를 넘길 수 없습니다.", NotifyType.Error); return; } catch (IOException) { NotificatorManager.Notify("오류", $"{itemName}의 영상 파일에 접근할 수 없었습니다.", NotifyType.Error); return; } // 업로드 성공 queueItem.Completed += (sender, e) => { if (DeleteWhenComplete) { File.Delete(System.Web.HttpUtility.UrlDecode((sender as UploadQueueItem).FileName.AbsolutePath)); } if (HaltWhenAllCompleted) { var list = uploadQueueListBox.ItemsSource as IList <UploadQueueItem>; bool incompleted = false; foreach (var i in list) { if (i.UploadingStatus == UploadingStatus.UploadCompleted || i.UploadingStatus == UploadingStatus.UpdateComplete) { continue; } incompleted = true; break; } if (!incompleted) { Dispatcher.BeginInvoke(new Action(() => { new HaltWindow().ShowDialog(); })); } } }; // 업로드 실패 queueItem.Failed += async(sender, e) => { if ((sender as UploadQueueItem).UploadingStatus == UploadingStatus.UploadCompleted || (sender as UploadQueueItem).UploadingStatus == UploadingStatus.UpdateComplete || (sender as UploadQueueItem).UploadingStatus == UploadingStatus.UploadCanceled) { return; } if ((sender as UploadQueueItem).IsManuallyPaused) { return; } if (!HaltWhenAllCompleted && !RetryWhenCanceled) { return; } int sec = 0; switch (option.Options.RetryDelayIndex) { case 0: sec = 0; break; case 1: sec = 5; break; case 2: sec = 10; break; case 3: sec = 15; break; case 4: sec = 30; break; case 5: sec = 60; break; } if (sec != 0) { await Task.Delay(1000 *sec); } if (!HaltWhenAllCompleted && !RetryWhenCanceled) { return; } var uploadState = (sender as UploadQueueItem).UploadingStatus; if (uploadState == UploadingStatus.Uploading || uploadState == UploadingStatus.UploadCompleted || uploadState == UploadingStatus.UpdateComplete) { return; } await(sender as UploadQueueItem).UploadStart(); }; // 업로드 중 queueItem.Uploading += (sender, e) => { Dispatcher.BeginInvoke(new Action(() => { double totalProgress = 0; bool thereIsFailedItem = false; int totalCount = 0; foreach (var item in uploadQueueListBox.ItemsSource as ObservableCollection <UploadQueueItem> ) { if (item.UploadingStatus == UploadingStatus.UploadFailed || item.UploadingStatus == UploadingStatus.UpdateFailed) { thereIsFailedItem = true; } else if (item.UploadingStatus == UploadingStatus.Queued) { continue; } totalProgress += item.Progress; ++totalCount; } TaskbarItemInfo.ProgressState = thereIsFailedItem ? TaskbarItemProgressState.Paused : TaskbarItemProgressState.Normal; TaskbarItemInfo.ProgressValue = totalProgress / totalCount; })); }; (uploadQueueListBox.ItemsSource as IList <UploadQueueItem>).Add(queueItem); }