예제 #1
0
        public async Task <CloudFile> CreateFolderAsync(string folderName)
        {
            MyLogger.Assert(this.IsFolder);
            var folderCreator = new RestRequests.FileCreator(this.Id, folderName, true);
            //var request = (await Drive.GetDriveServiceAsync()).Files.Create(
            //    new Google.Apis.Drive.v3.Data.File
            //    {
            //        Name = folderName,
            //        Parents = new List<string> { this.Id },
            //        MimeType = Constants.FolderMimeType
            //    });
            ////MyLogger.Log($"Creating folder... {folderName} ({this.FullName})");
            //var result = await request.ExecuteAsync();
            ////var result = await new Func<Task<Google.Apis.Drive.v3.Data.File>, Task<Google.Apis.Drive.v3.Data.File>>((Task<Google.Apis.Drive.v3.Data.File> task) =>
            ////{
            ////    task.ContinueWith(t =>
            ////    {
            ////        // NotOnRanToCompletion - this code will be called if the upload fails
            ////        MyLogger.Log($"Failed to create folder:\r\n{t.Exception}");
            ////    }, TaskContinuationOptions.NotOnRanToCompletion);
            ////    task.ContinueWith(t =>
            ////    {
            ////        MyLogger.Log($"Folder created successfully: {folderName} ({this.FullName})");
            ////    });
            ////    return task;
            ////})();
            //MyLogger.Assert(result.Name == folderName);
            await folderCreator.Start();

            MyLogger.Assert(folderCreator.Result != null);
            var ans = new CloudFile(folderCreator.Result, folderName, true, this);

            return(ans);
        }
예제 #2
0
                protected override async Task StartPrivateAsync()
                {
                    Status = NetworkStatus.Networking;
                    try
                    {
                        OnTotalFoldersRemainChanged(1);
                        OnMessageAppended("Creating folder...");
                        var folderCreator = new RestRequests.FileCreator(cloudFolder.Id, folderName, true);
                        var eventHandler  = new MessageAppendedEventHandler((log) => { OnMessageAppended($"[Rest]{log}"); });
                        folderCreator.MessageAppended += eventHandler;
                        await folderCreator.Start();

                        folderCreator.MessageAppended -= eventHandler;
                        switch (folderCreator.Status)
                        {
                        case RestRequests.FileCreator.FileCreatorStatus.Completed:
                        {
                            CreatedCloudFolder = new CloudFile(folderCreator.Result, folderName, true, cloudFolder);
                            //CreatedCloudFolder = await cloudFolder.CreateFolderAsync(folderName);
                            OnMessageAppended("Folder created");
                            Status = NetworkStatus.Completed;
                            return;
                        }

                        case RestRequests.FileCreator.FileCreatorStatus.ErrorNeedRestart:
                        {
                            Status = NetworkStatus.ErrorNeedRestart;
                            return;
                        }

                        default:
                        {
                            throw new Exception($"Status: {Status}");
                        }
                        }
                    }
                    catch (Exception error)
                    {
                        OnMessageAppended(error.ToString());
                        Status = NetworkStatus.ErrorNeedRestart;
                        return;
                    }
                    finally
                    {
                        OnTotalFoldersRemainChanged(-1);
                    }
                }