public static void CreateFolder(IItemNode node) { string Email = node.GetRoot.RootType.Email; DriveAPIv2 gdclient = GetAPIv2(Email); string parent_id = ""; try { List <IItemNode> listnode = node.GetFullPath(); Monitor.Enter(sync_createfolder); int i; for (i = listnode.Count - 1; i > 0; i--) { if (!string.IsNullOrEmpty(listnode[i].Info.ID)) { parent_id = listnode[i].Info.ID; break; } } i++; bool create = false; for (; i < listnode.Count; i++) { if (!create) { List <IItemNode> listsearchnode = Search("'" + parent_id + "' in parents" + " and trashed=false" + " and title='" + listnode[i].Info.Name.Replace("'", "\\'") + "'" + " and mimeType = 'application/vnd.google-apps.folder'", Email).Convert(node); if (listsearchnode.Count == 0) { create = true; } else { parent_id = listnode[i].Info.ID = listsearchnode[0].Info.ID; } } if (create) { Drivev2_File metadata = new Drivev2_File() { title = listnode[i].Info.Name }; metadata.parents = new List <Drivev2_Parent>() { new Drivev2_Parent() { id = parent_id } }; Drivev2_File folder = gdclient.Extend.CreateFolder(metadata); parent_id = listnode[i].Info.ID = folder.id; } } } finally { Monitor.Exit(sync_createfolder); } }
static void TestDrive2Copy() { //file 0Bx154iMNwuyWUUJEUTNRMnAwc0k folder 0B2T-102UejylQmwxSnFGN3RsLWM DriveAPIv2 v2 = GetAPIv2(email_gd); Drivev2_File f = v2.Files.Copy("0Bx154iMNwuyWUUJEUTNRMnAwc0k", "0B2T-102UejylQmwxSnFGN3RsLWM"); return; }
internal static DriveAPIv2 GetAPIv2(string Email, GD_LimitExceededDelegate LimitExceeded = null) { DriveAPIv2 gdclient = new DriveAPIv2(GetToken(Email)); if (LimitExceeded != null) { gdclient.LimitExceeded += LimitExceeded; } return(gdclient); }
static void Drive2Checkquotas() { DriveAPIv2 v2 = GetAPIv2(email_gd); //var about = v2.About.Get(); //string about_string = JsonConvert.SerializeObject(about, JsonSetting._settings_serialize); var file = v2.Files.Patch("0B2T-102UejylMXZpbUwtUU13c2c"); string file_string = JsonConvert.SerializeObject(file, JsonSetting._settings_serialize); return; }
public static List <Drivev2_File> Search(string query, string Email, string pageToken = null) { DriveAPIv2 gdclient = GetAPIv2(Email); Drivev2_Files_list list = gdclient.Files.List(en, query, pageToken); if (!string.IsNullOrEmpty(list.nextPageToken)) { list.items.AddRange(Search(query, Email, list.nextPageToken)); } return(list.items); }
public static bool ReNameItem(IItemNode node, string newname) { DriveAPIv2 gdclient = GetAPIv2(node.GetRoot.RootType.Email); Drivev2_File response = gdclient.Files.Patch(node.Info.ID, new Drivev2_File() { title = newname }); if (response.title == newname) { return(true); } else { return(false); } }
private void Oauth_gd_TokenCallBack(string token_) { if (!string.IsNullOrEmpty(token_)) { TokenGoogleDrive token = JsonConvert.DeserializeObject <TokenGoogleDrive>(token_); if (token.IsError) { throw new Exception("Accesstoken:" + token.access_token + ",RefreshToken:" + token.refresh_token); } string token_text = JsonConvert.SerializeObject(token); DriveAPIv2 client = new DriveAPIv2(token); Drivev2_About about = client.About.Get(); SaveToken(about.user.emailAddress, token_text, CloudType.GoogleDrive); } else { throw new Exception("Oauth token GD failed."); } }
//trash/delete public static bool File_trash(IItemNode node, bool Permanently) { DriveAPIv2 gdclient = GetAPIv2(node.GetRoot.RootType.Email); if (node == node.GetRoot) { throw new Exception("Can't delete root."); } if (Permanently) { gdclient.Files.Delete(node.Info.ID); return(true); } else { gdclient.Files.Trash(node.Info.ID); return(true); } }
void Transfer(TransferItem item) { #if DEBUG Console.WriteLine("Transfer items:" + item.From.node.GetFullPathString()); #endif int buffer_length = 32; //default int.TryParse(AppSetting.settings.GetSettingsAsString(SettingsKey.BufferSize), out buffer_length); //get buffer_length from setting item.buffer = item.From.node.GetRoot.RootType.Type == CloudType.Mega ? new byte[buffer_length * 2048] : new byte[buffer_length * 1024]; //create buffer ItemNode rootnodeto = item.To.node.GetRoot; item.byteread = 0; //this.group.items[x].UploadID = "";//resume item.SizeWasTransfer = item.OldTransfer = item.SaveSizeTransferSuccess; //resume item.DataSource.Error = string.Empty; //clear error item.TimeStamp = CurrentMillis.Millis; switch (rootnodeto.GetRoot.RootType.Type) { case CloudType.LocalDisk: #region LocalDisk ItemsTransferWork.Add(new TransferBytes(item, this)); return; #endregion case CloudType.Dropbox: #region Dropbox int chunksizedb = 25;//default 25Mb int.TryParse(AppSetting.settings.GetSettingsAsString(SettingsKey.Dropbox_ChunksSize), out chunksizedb); item.ChunkUploadSize = chunksizedb * 1024 * 1024; DropboxRequestAPIv2 DropboxClient = Dropbox.GetAPIv2(rootnodeto.GetRoot.RootType.Email); if (string.IsNullOrEmpty(item.UploadID))//create upload id { item.byteread = item.From.stream.Read(item.buffer, 0, item.buffer.Length); IDropbox_Request_UploadSessionAppend session = DropboxClient.upload_session_start(item.buffer, item.byteread); item.UploadID = session.session_id; item.SizeWasTransfer += item.byteread; } ItemsTransferWork.Add(new TransferBytes(item, DropboxClient)); return; #endregion case CloudType.GoogleDrive: #region GoogleDrive DriveAPIv2 gdclient = GoogleDrive.GetAPIv2(rootnodeto.GetRoot.RootType.Email); GoogleDrive.CreateFolder(item.To.node.Parent); int chunksizeGD = 5;//default int.TryParse(AppSetting.settings.GetSettingsAsString(SettingsKey.GD_ChunksSize), out chunksizeGD); item.ChunkUploadSize = chunksizeGD * 1024 * 1024; if (string.IsNullOrEmpty(item.UploadID))//create upload id { if (string.IsNullOrEmpty(item.To.node.Parent.Info.ID)) { throw new Exception("Can't get root id."); } string parentid = item.To.node.Parent.Info.ID; string mimeType = Get_mimeType.Get_mimeType_From_FileExtension(item.To.node.GetExtension()); Drivev2_File f_metadata = new Drivev2_File() { title = item.From.node.Info.Name, mimeType = mimeType }; f_metadata.parents = new List <Drivev2_Parent>() { new Drivev2_Parent() { id = parentid } }; item.UploadID = gdclient.Files.Insert_Resumable_GetUploadID(f_metadata, mimeType, item.From.node.Info.Size); } ItemsTransferWork.Add(new TransferBytes(item, gdclient)); return; #endregion case CloudType.Mega: #region Mega MegaApiClient MegaClient = MegaNz.GetClient(rootnodeto.GetRoot.RootType.Email); item.buffer = new byte[128 * 1024]; if (string.IsNullOrEmpty(item.UploadID)) //create upload id { MegaNz.AutoCreateFolder(item.To.node.Parent); //auto create folder item.UploadID = MegaClient.RequestUrlUpload(item.From.node.Info.Size); //Make Upload url } item.From.stream = MegaApiClient.MakeEncryptStreamForUpload(item.From.stream, item.From.node.Info.Size, item.dataCryptoMega); //make encrypt stream from file ItemsTransferWork.Add(new TransferBytes(item, MegaClient)); return; #endregion } }
public static Drivev2_File GetMetadataItem(IItemNode node) { DriveAPIv2 client = GetAPIv2(node.GetRoot.RootType.Email); return(client.Files.Patch(node.Info.ID, null)); }
public static Stream GetFileStream(IItemNode node, long Startpos = -1, long endpos = -1) { DriveAPIv2 gdclient = GetAPIv2(node.GetRoot.RootType.Email); return(gdclient.Files.Get(node.Info.ID, Startpos, endpos)); }