Пример #1
0
        public List <string> Invoke(List <string> fileIds)
        {
            try
            {
                using (DriveService driveService = DriveService.Create())
                {
                    var untrashStreams = new List <API.DriveService.UntrashStream>();

                    foreach (string fileId in fileIds)
                    {
                        FileInfo fileInfo = driveService.GetFile(fileId);

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

                        var untrashStream = new API.DriveService.UntrashStream();

                        untrashStream.Init(fileInfo);

                        untrashStream.Visible = false;

                        untrashStreams.Add(untrashStream);
                    }

                    driveService.UntrashFiles(untrashStreams);

                    while (true)
                    {
                        bool finished = true;

                        for (int i = 0; i < untrashStreams.Count; i++)
                        {
                            API.DriveService.UntrashStream untrashStream = untrashStreams[i];

                            if (!untrashStream.Finished)
                            {
                                finished = false;
                                break;
                            }
                        }

                        if (finished)
                        {
                            break;
                        }

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

                    var untrashedFileIds = new List <string>();

                    foreach (DriveService.UntrashStream untrashStream in untrashStreams)
                    {
                        if (untrashStream.Completed)
                        {
                            untrashedFileIds.Add(untrashStream.FileId);
                        }
                        else if (untrashStream.Cancelled)
                        {
                        }
                        else if (untrashStream.Failed)
                        {
                            throw new LogException("Untrash could not complete - " + untrashStream.ExceptionMessage, true, true);
                        }
                    }

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

                return(null);
            }
        }
        public List<string> Invoke(List<string> fileIds)
        {
            try
              {
            using (DriveService driveService = DriveService.Create())
            {
              var untrashStreams = new List<API.DriveService.UntrashStream>();

              foreach (string fileId in fileIds)
              {
            FileInfo fileInfo = driveService.GetFile(fileId);

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

            var untrashStream = new API.DriveService.UntrashStream();

            untrashStream.Init(fileInfo);

            untrashStream.Visible = false;

            untrashStreams.Add(untrashStream);
              }

              driveService.UntrashFiles(untrashStreams);

              while (true)
              {
            bool finished = true;

            for (int i = 0; i < untrashStreams.Count; i++)
            {
              API.DriveService.UntrashStream untrashStream = untrashStreams[i];

              if (!untrashStream.Finished)
              {
                finished = false;
                break;
              }
            }

            if (finished)
            {
              break;
            }

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

              var untrashedFileIds = new List<string>();

              foreach (DriveService.UntrashStream untrashStream in untrashStreams)
              {
            if (untrashStream.Completed)
            {
              untrashedFileIds.Add(untrashStream.FileId);
            }
            else if (untrashStream.Cancelled)
            {
            }
            else if (untrashStream.Failed)
            {
              throw new LogException("Untrash could not complete - " + untrashStream.ExceptionMessage, true, true);
            }
              }

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

            return null;
              }
        }