コード例 #1
0
 private static void RenameFile(String fileId, String newTitle)
 {
     try
     {
         Google.Apis.Drive.v2.DriveService service = GetService_v2();
         Google.Apis.Drive.v2.Data.File    file    = new Google.Apis.Drive.v2.Data.File();
         file.Title = newTitle;
         // Rename the file.
         Google.Apis.Drive.v2.FilesResource.PatchRequest request = service.Files.Patch(file, fileId);
         Google.Apis.Drive.v2.Data.File updatedFile = request.Execute();
         //return updatedFile;
     }
     catch (Exception e)
     {
         Console.WriteLine("An error occurred: " + e.Message);
         //return null;
     }
 }
コード例 #2
0
            protected void DriveService_ProgressChanged(IUploadProgress uploadProgress)
            {
                try
                {
                    var       status           = StatusType.NotStarted;
                    long      bytesProcessed   = uploadProgress.BytesSent;
                    long      totalBytes       = FileSize;
                    Exception processException = uploadProgress.Exception;

                    if (uploadProgress.Status == UploadStatus.Completed)
                    {
                        status = StatusType.Completed;
                    }
                    else if (uploadProgress.Status == UploadStatus.Uploading)
                    {
                        status = StatusType.Processing;
                    }
                    else if (uploadProgress.Status == UploadStatus.Failed)
                    {
                        status = StatusType.Failed;
                    }
                    else
                    {
                        status = StatusType.Starting;
                    }

                    UpdateProgress(status, bytesProcessed, totalBytes, processException);

                    if (Processed)
                    {
                        try
                        {
                            if (Completed)
                            {
                                _LastWriteTime = API.DriveService.GetFileLastWriteTime(FilePath);

                                DateTime modifiedDate = _FileInfo.ModifiedDate;

                                if (!API.DriveService.IsDateTimeEqual(_LastWriteTime, modifiedDate))
                                {
                                    try
                                    {
                                        _LastWriteTime = API.DriveService.SetFileLastWriteTime(FilePath, modifiedDate);
                                    }
                                    catch (Exception exception)
                                    {
                                        Log.Error(exception, false, false);

                                        System.Threading.Thread.Sleep(500);
                                    }
                                }

                                if (!API.DriveService.IsDateTimeEqual(_LastWriteTime, modifiedDate))
                                {
                                    try
                                    {
                                        using (API.DriveService.Connection connection = API.DriveService.Connection.Create())
                                        {
                                            File file = _FileInfo._file;

                                            file.ModifiedDate = _LastWriteTime.ToUniversalTime();

                                            Google.Apis.Drive.v2.FilesResource.UpdateRequest updateRequest =
                                                connection.Service.Files.Update(file, file.Id);

                                            updateRequest.SetModifiedDate = true;

                                            _FileInfo._file = updateRequest.Execute();

                                            modifiedDate = _FileInfo.ModifiedDate;
                                        }
                                    }
                                    catch (Exception exception)
                                    {
                                        Log.Error(exception, false, false);

                                        System.Threading.Thread.Sleep(500);
                                    }
                                }

                                if (!API.DriveService.IsDateTimeEqual(_LastWriteTime, modifiedDate))
                                {
                                    try
                                    {
                                        using (API.DriveService.Connection connection = API.DriveService.Connection.Create())
                                        {
                                            File file = _FileInfo._file;

                                            file.ModifiedDate = _LastWriteTime.ToUniversalTime();

                                            Google.Apis.Drive.v2.FilesResource.PatchRequest patchRequest = connection.Service.Files.Patch(
                                                file,
                                                file
                                                .Id);

                                            patchRequest.SetModifiedDate = true;

                                            _FileInfo._file = patchRequest.Execute();

                                            modifiedDate = _FileInfo.ModifiedDate;
                                        }
                                    }
                                    catch (Exception exception)
                                    {
                                        Log.Error(exception, false, false);

                                        System.Threading.Thread.Sleep(500);
                                    }
                                }

                                if (!API.DriveService.IsDateTimeEqual(_LastWriteTime, modifiedDate))
                                {
                                    // hopefully at least this will keep the upload process from firing off
                                    _FileInfo._file.ModifiedDate = _LastWriteTime.ToUniversalTime();
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            Log.Error(exception, false);

                            if (!Failed)
                            {
                                _ExceptionMessage = exception.Message;
                                _Status           = StatusType.Failed;
                            }
                        }
                    }

                    InvokeOnProgressEvent();
                }
                catch (Exception exception)
                {
                    Log.Error(exception, false);
                }
            }