static void Main(string[] args) { Console.WriteLine("Multi-Cloud Example"); while (true) { var client = new GoogleDriveClient( name: "GoogleAccount", applicationName: "Multi-Cloud Example", credentialJsonFile: "credential.json" ); var files = client.GetFiles(null); if (files != null) { foreach (var file in files) { Console.WriteLine($"> {file.Name}"); } } // client.Dispose(); Console.WriteLine("Any key to restart..."); Console.ReadKey(); } }
/// <summary> /// Creates a new instance of the GoogleDrive storage handler. /// </summary> public GoogleDriveStorageHandler() { //Create a new Google Drive OAuth2Client. _client = new GoogleDriveClient(); _api = new GDriveApiHelper(_client); LastErrorMessage = "Operation Completed Successfully"; }
public static void ClassInitialize(TestContext testContext) { if (!GlobalTestSettings.RunNetworkTests) { return; } string tokenFilePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "SyncProTesting", "GoogleDriveTestingToken.json"); if (!File.Exists(tokenFilePath)) { throw new FileNotFoundException("Token file was not present at path " + tokenFilePath); } string tokenContent = File.ReadAllText(tokenFilePath); var token = JsonConvert.DeserializeObject <TokenResponse>(tokenContent); if (!token.IsEncrypted) { // The token file is NOT encrypted. Immediately encrypt and save the file back to disk // for security before using it. token.Protect(); tokenContent = JsonConvert.SerializeObject(token, Formatting.Indented); File.WriteAllText(tokenFilePath, tokenContent); } // The token file on disk is encrypted. Decrypt the values for in-memory use. token.Unprotect(); using (GoogleDriveClient client = new GoogleDriveClient(token)) { client.TokenRefreshed += (sender, args) => { //token = new TokenResponseEx(args.NewToken); //token.Protect(); //tokenContent = JsonConvert.SerializeObject(token, Formatting.Indented); //File.WriteAllText(tokenFilePath, tokenContent); //token.Unprotect(); // The token was refreshed, so save a protected copy of the token to the token file. token = args.NewToken; token.SaveProtectedToken(tokenFilePath); }; client.GetUserInformation().Wait(); } //testContext.Properties["CurrentToken"] = token; GoogleDriveTests.classCurrentToken = token; }
static async Task Main(string[] args) { var proxy = new WebProxy("127.0.0.1", 8008); var client = new GoogleDriveClient(proxy); // https://accounts.google.com/o/oauth2/auth?client_id=645529619299.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive await client.Auth("4/..."); // Console.WriteLine(client.AccessToken); // Console.WriteLine(client.RefreshToken); // client.RefreshToken = "1//..."; // await client.GetAccessTokenFromRefreshToken(); var uploadFileResponse = await client.UploadFile("input.mp4", "video/mp4", "MyPerfectVideo.mp4", true); var fileId = uploadFileResponse["id"].Value <string>(); await client.UpdateFileProperty(fileId, "description", "My perfect description"); await client.GetFileInfo(fileId); }
private void initialize() { var client = new GoogleDriveClient(GOOGLE_DRIVE_EMAIL, GOOGLE_DRIVE_CERT_PATH); client.CreateDirectory(ROOT_ID, ROOT.Trim('/')); }
public ViewModel() { _clients = new Dictionary <string, ICloudClient>(); var refreshRoot = new Action(() => { Files.Clear(); foreach (var client in _clients) { var googleFiles = client.Value.GetFiles(null); googleFiles.Select(x => new File { Name = x.Name, Id = x.Id, IsFolder = x.IsFolder, ParentId = x.ParentId, AccountName = client.Key }) .ToList() .ForEach(x => Files.Add(x)); } }); var addAccount = new Action <Account>(account => { if (_clients.ContainsKey(account.Name)) { return; } Accounts.Add(account); var client = new GoogleDriveClient( name: account.Name, applicationName: "CloudPlot", credentialJsonFile: "credential.json"); _clients[account.Name] = client; refreshRoot(); }); AddAccount = ReactiveCommand.Create( execute: () => { var newAccounts = new List <Account>(); var view = new NewAccount.View { ViewModel = new NewAccount.ViewModel(newAccounts) }; view.ShowDialog(); if (!newAccounts.Any()) { return; } newAccounts.ForEach(x => addAccount(x)); }); RemoveAccount = ReactiveCommand.Create( canExecute: this.WhenAny(x => x.SelectedAccount, selectedAccount => selectedAccount != null), execute: () => { if (SelectedAccount == null) { return; } _clients[SelectedAccount.Name].Dispose(); _clients.Remove(SelectedAccount.Name); var toRemove = Files?.Where(x => x.AccountName == SelectedAccount.Name).ToList(); toRemove?.ForEach(x => Files.Remove(x)); Accounts.Remove(SelectedAccount); } ); GoUp = ReactiveCommand.Create( execute: () => { if (!_parents.Any()) { return; } var parent = _parents.Pop(); if (_parents.Any()) { Files.Clear(); var googleFiles = _clients[_currentAccount].GetFiles(parent); googleFiles.Select(x => new File { Name = x.Name, Id = x.Id, IsFolder = x.IsFolder, ParentId = x.ParentId, AccountName = _currentAccount }) .ToList() .ForEach(x => Files.Add(x)); return; } refreshRoot(); } ); }
public void BasicSyncLocalToGoogleDrive() { if (!GlobalTestSettings.RunNetworkTests) { Assert.Inconclusive(GlobalTestSettings.NetworkTestsDisabledMessage); } TokenResponse currentToken = this.GetCurrentToken(); using (GoogleDriveClient client = new GoogleDriveClient(currentToken)) { var res12 = client.GetItemById("0B781VIRHEt3xeDM2UkVZcDFaUTQ").Result; //var info = client.GetUserInformation().Result; var res = client.GetChildItems(new GoogleDriveAdapterItem(new Item() { Id = "0B781VIRHEt3xNGtvMUppbnpPRVk" }, null, null)).Result; } // Assert.Inconclusive("TODO"); //string testRootPath = Path.Combine(this.TestContext.TestLogsDir, this.TestContext.TestName); //Directory.CreateDirectory(testRootPath); //string syncSourcePath = Path.Combine(testRootPath, "Source"); //Directory.CreateDirectory(syncSourcePath); //// Create temp files/folders //List<string> syncFileList = new List<string> // { // TestHelper.CreateDirectory(syncSourcePath, "dir1"), // TestHelper.CreateFile(syncSourcePath, "dir1\\file1.txt"), // TestHelper.CreateFile(syncSourcePath, "dir1\\file2.txt"), // TestHelper.CreateFile(syncSourcePath, "dir1\\file3.txt"), // TestHelper.CreateDirectory(syncSourcePath, "dir2"), // TestHelper.CreateFile(syncSourcePath, "dir2\\file1.txt"), // TestHelper.CreateFile(syncSourcePath, "dir2\\file2.txt"), // TestHelper.CreateFile(syncSourcePath, "dir2\\file3.txt") // }; //TokenResponse currentToken = this.GetCurrentToken(); //Guid remoteTestFolderName = Guid.NewGuid(); //Item remoteTestFolder = CreateOneDriveTestDirectory(currentToken, remoteTestFolderName.ToString("D")).Result; //SyncRelationship newRelationship = this.SetupRelationship(testRootPath, syncSourcePath, remoteTestFolder); //ManualResetEvent evt = new ManualResetEvent(false); //SyncJob run1 = new SyncJob(newRelationship); //run1.SyncFinished += (sender, args) => { evt.Set(); }; //run1.Start(); //evt.WaitOne(); //Assert.IsTrue(run1.HasFinished); //Assert.AreEqual(syncFileList.Count, run1.AnalyzeResult.EntryResults.Count); //OneDriveAdapter oneDriveAdapter = // newRelationship.Adapters.First(a => !a.Configuration.IsOriginator) as OneDriveAdapter; //OneDriveClient client = new OneDriveClient(this.GetCurrentToken()); //foreach (string syncFile in syncFileList.Where(f => f.EndsWith(".txt"))) //{ // string localPath = Path.Combine(syncSourcePath, syncFile); // using (var sha1 = new SHA1Managed()) // { // byte[] content = File.ReadAllBytes(localPath); // byte[] localFileHash = sha1.ComputeHash(content); // var entryResult = run1.AnalyzeResult.EntryResults.FirstOrDefault( // r => r.Entry.GetRelativePath(newRelationship, "\\") == syncFile); // Assert.IsNotNull(entryResult); // byte[] databaseHash = entryResult.Entry.Sha1Hash; // Assert.AreEqual( // TestHelper.HashToHex(localFileHash), // TestHelper.HashToHex(databaseHash), // "Local file hash does not match database hash."); // Pre.Assert(oneDriveAdapter != null, "oneDriveAdapter != null"); // var adapterEntry = // entryResult.Entry.AdapterEntries.First(e => e.AdapterId == oneDriveAdapter.Configuration.Id); // string itemId = OneDriveAdapter.UniqueIdToItemId(adapterEntry.AdapterEntryId); // var item = client.GetItemByItemIdAsync(itemId); // var oneDriveHash = "0x" + item.Result.File.Hashes.Sha1Hash; // Assert.AreEqual( // TestHelper.HashToHex(localFileHash), // oneDriveHash, // "Local file hash does not match OneDrive hash."); // } //} }
public GDriveApiHelper(GoogleDriveClient client) { _client = client; }