Ejemplo n.º 1
0
            protected override void Start()
            {
                try
                {
                    if (Status != StatusType.Queued)
                    {
                        throw new Exception("Stream has not been queued.");
                    }

                    base.Start();

                    _FileInfo = _DriveService.GetFile(FileId);

                    if (_FileInfo == null)
                    {
                        throw new Exception("File '" + FileId + "' no longer exists.");
                    }

                    Lock();

                    using (API.DriveService.Connection connection = API.DriveService.Connection.Create())
                    {
                        FilesResource.TrashRequest request = connection.Service.Files.Trash(FileId);

                        request.Fields = API.DriveService.RequestFields.FileFields;

                        _CancellationTokenSource = new System.Threading.CancellationTokenSource();

                        System.Threading.Tasks.Task <File> task = request.ExecuteAsync(_CancellationTokenSource.Token);

                        if (task.IsCompleted)
                        {
                            DriveService_ProgressChanged(task);
                        }
                        else
                        {
                            task.ContinueWith(thisTask => DriveService_ProgressChanged(thisTask));
                        }
                    }
                }
                catch (Exception exception)
                {
                    try
                    {
                        _Status           = StatusType.Failed;
                        _ExceptionMessage = exception.Message;

                        DriveService_ProgressChanged(StatusType.Failed, exception);
                    }
                    catch
                    {
                        Debugger.Break();
                    }

                    Log.Error(exception);
                }
            }
Ejemplo n.º 2
0
        public override void DeleteFile(File file)
        {
            if (!file.Parent.Equals(this))
            {
                throw new ArgumentException("The specified directory could not be found");
            }

            GoogleDriveFile googleDriveFile = file as GoogleDriveFile;

            if (storage.UseTrash)
            {
                FilesResource.TrashRequest request = storage.Service.Files.Trash(googleDriveFile.file.Id);
                request.Execute();
            }
            else
            {
                FilesResource.DeleteRequest request = storage.Service.Files.Delete(googleDriveFile.file.Id);
                request.Execute();
            }
        }
Ejemplo n.º 3
0
        public override void DeleteDirectory(Directory directory)
        {
            if (!directory.Parent.Equals(this))
            {
                throw new ArgumentException("The specified directory could not be found");
            }

            GoogleDriveDirectory googleDriveDirectory = directory as GoogleDriveDirectory;

            if (storage.UseTrash)
            {
                FilesResource.TrashRequest request = storage.Service.Files.Trash(googleDriveDirectory.folder.Id);
                request.Execute();
            }
            else
            {
                FilesResource.DeleteRequest request = storage.Service.Files.Delete(googleDriveDirectory.folder.Id);
                request.Execute();
            }
        }