Пример #1
0
        public FileInfo Invoke(string fileId)
        {
            try
            {
                if (String.IsNullOrEmpty(fileId))
                {
                    throw new Exception("Input parameter 'fileId' is null or empty (Cannot upload root directory).");
                }

                using (DriveService driveService = DriveService.Create())
                {
                    FileInfo fileInfo = driveService.GetFile(fileId);

                    if (fileInfo == null)
                    {
                        throw new Exception("File no longer exists.");
                    }

                    var uploadStream = new API.DriveService.UploadStream();

                    uploadStream.Init(fileInfo, null);

                    driveService.UploadFile(uploadStream);

                    while (!uploadStream.Finished)
                    {
                        System.Threading.Thread.Sleep(250);
                    }

                    if (uploadStream.Cancelled)
                    {
                        return(null);
                    }
                    if (uploadStream.Failed)
                    {
                        throw new LogException("Upload could not complete - " + uploadStream.ExceptionMessage, true, true);
                    }

                    fileInfo = uploadStream.FileInfo;

                    return(fileInfo);
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);

                return(null);
            }
        }
        public FileInfo Invoke(string fileId)
        {
            try
              {
            if (String.IsNullOrEmpty(fileId))
            {
              throw new Exception("Input parameter 'fileId' is null or empty (Cannot upload root directory).");
            }

            using (DriveService driveService = DriveService.Create())
            {
              FileInfo fileInfo = driveService.GetFile(fileId);

              if (fileInfo == null)
              {
            throw new Exception("File no longer exists.");
              }

              var uploadStream = new API.DriveService.UploadStream();

              uploadStream.Init(fileInfo, null);

              driveService.UploadFile(uploadStream);

              while (!uploadStream.Finished)
              {
            System.Threading.Thread.Sleep(250);
              }

              if (uploadStream.Cancelled)
              {
            return null;
              }
              if (uploadStream.Failed)
              {
            throw new LogException("Upload could not complete - " + uploadStream.ExceptionMessage, true, true);
              }

              fileInfo = uploadStream.FileInfo;

              return fileInfo;
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception);

            return null;
              }
        }