コード例 #1
0
        public static async Task <GoogleFileList> Get(GoogleDrive drive, GoogleFile folder, FileList fileList, DriveService service, CancellationToken token)
        {
            var ret = new GoogleFileList(drive);

            foreach (var googleFile in fileList.Items.Select(file => new GoogleFile(drive, file)))
            {
                if (googleFile.IsFolder)
                {
                    googleFile.hasChildren = await HasSubfoldersAsync(googleFile, service, token);
                }
                ret.files.Add(googleFile);
            }
            return(ret);
        }
コード例 #2
0
ファイル: GoogleDrive.cs プロジェクト: fiftin/oblqo
        internal async Task <DriveFile> UploadFileAsync(System.IO.Stream stream, string fileName,
                                                        GoogleFile destFolder, IList <Property> props, CancellationToken token)
        {
            var service = await GetServiceAsync(token);

            var file = new File
            {
                Properties = props,
                Title      = fileName,
                Parents    = new List <ParentReference>
                {
                    new ParentReference {
                        Id = destFolder == null ? RootId : destFolder.Id
                    }
                }
            };
            ImageFormat imageType;

            System.IO.Stream scaled;

            if (!ImageMaxSize.IsEmpty && TryGetImageType(fileName, out imageType))
            {
                var image = await Task.Run(() => Image.FromStream(stream));

                scaled = await ScaleImageAsync(image, imageType, token);
            }
            else
            {
                scaled = stream;
            }

            var observed = new ObserverStream(scaled);

            observed.PositionChanged += (sender, e) => { };
            var request = service.Files.Insert(file, observed, "");
            var result  = await request.UploadAsync(token);

            if (result.Status == UploadStatus.Failed)
            {
                throw new Exception(result.Exception.Message);
            }
            return(new GoogleFile(this, request.ResponseBody));
        }
コード例 #3
0
ファイル: GoogleDrive.cs プロジェクト: fiftin/oblqo
        internal async Task<DriveFile> UploadFileAsync(System.IO.Stream stream, string fileName,
            GoogleFile destFolder, IList<Property> props, CancellationToken token)
        {
            var service = await GetServiceAsync(token);
            var file = new File
            {
                Properties = props,
                Title = fileName,
                Parents = new List<ParentReference>
                        {
                            new ParentReference {Id = destFolder == null ? RootId : destFolder.Id}
                        }
            };
            ImageFormat imageType;
            System.IO.Stream scaled;

            if (!ImageMaxSize.IsEmpty && TryGetImageType(fileName, out imageType))
            {
                var image = await Task.Run(() => Image.FromStream(stream));
                scaled = await ScaleImageAsync(image, imageType, token);
            } else
            {
                scaled = stream;
            }

            var observed = new ObserverStream(scaled);
            observed.PositionChanged += (sender, e) => { };
            var request = service.Files.Insert(file, observed, "");
            var result = await request.UploadAsync(token);
            if (result.Status == UploadStatus.Failed)
            {
                throw new Exception(result.Exception.Message);
            }
            return new GoogleFile(this, request.ResponseBody);
        }