Пример #1
0
        public async void Handle(TaskStartEvent message)
        {
            if (message.obj is FileModel)
            {
                FileModel objModel = (FileModel)message.obj;
                if (message.type == TaskStartEventType.DOWNLOAD)
                {
                    try
                    {
                        events.Publish(new TaskAddNumEvent(1));
                        objModel.startTimer();
                        await downloadfile((FileModel)message.obj, objModel.localPath);

                        events.Publish(new TaskEvent(objModel, TaskEventType.DOWNLOADCOMPELETED));
                    }
                    catch (Exception ex)
                    {
                        if (ex is System.Threading.Tasks.TaskCanceledException)
                        {
                            events.Publish(new TaskEvent(objModel, TaskEventType.DOWNLOADCANCEL));
                        }
                        else
                        {
                            windowManager.ShowMetroMessageBox(ex.Message, "Error",
                                                              MessageBoxButton.OK);
                        }
                    }
                }
                else
                {
                    try
                    {
                        events.Publish(new TaskAddNumEvent(1));
                        objModel.startTimer();
                        await uploadSingleFile(objModel);

                        events.Publish(new TaskEvent(objModel, TaskEventType.UPLOADCOMPELETED));
                        await refresh();
                    }
                    catch (Exception ex)
                    {
                        if (ex is System.Threading.Tasks.TaskCanceledException)
                        {
                            events.Publish(new TaskEvent(objModel, TaskEventType.UPLOADCANCEL));
                            folderListModel.deleteFile(objModel.bucketName, objModel.key);
                        }
                        else
                        {
                            windowManager.ShowMetroMessageBox(ex.Message, "Error",
                                                              MessageBoxButton.OK);
                        }
                    }
                }
            }
            else
            {
                FolderModel objModel = (FolderModel)message.obj;
                if (message.type == TaskStartEventType.DOWNLOAD)
                {
                    try
                    {
                        events.Publish(new TaskAddNumEvent(1));
                        ((FolderModel)objModel).startTimer();
                        await downloadFolder((FolderModel)objModel, objModel.localPath);

                        events.Publish(new TaskEvent(objModel, TaskEventType.DOWNLOADCOMPELETED));
                    }
                    catch (Exception ex)
                    {
                        if (ex is System.Threading.Tasks.TaskCanceledException)
                        {
                            events.Publish(new TaskEvent(objModel, TaskEventType.DOWNLOADCANCEL));
                        }
                        else
                        {
                            windowManager.ShowMetroMessageBox(ex.Message, "Error",
                                                              MessageBoxButton.OK);
                        }
                    }
                }
                else
                {
                    try
                    {
                        events.Publish(new TaskAddNumEvent(1));
                        objModel.startTimer();
                        await createFolders(objModel, objModel.localPath);
                        await uploadFolder(objModel);

                        events.Publish(new TaskEvent(objModel, TaskEventType.UPLOADCOMPELETED));
                        await refresh();
                    }
                    catch (Exception ex)
                    {
                        if (ex is System.Threading.Tasks.TaskCanceledException)
                        {
                            events.Publish(new TaskEvent(objModel, TaskEventType.UPLOADCANCEL));
                            folderListModel.deleteFolder(objModel.bucketName, objModel.key);
                        }
                        else
                        {
                            windowManager.ShowMetroMessageBox(ex.Message, "Error",
                                                              MessageBoxButton.OK);
                        }
                    }
                }
            }
        }