public async Task<bool> downloadFileAsync(CommonDescriptor cd) { OneDriveCommunicationParser odcp = new OneDriveCommunicationParser(); WindowsDownloadManager wdm = new WindowsDownloadManager(); var _oneDriveClient = InitializeAPI.oneDriveClient; //_oneDriveClient.AuthenticateAsync(); var fileId = cd.FileID; string extension = odcp.getExtension(cd.FileType); try { var contentStream = await _oneDriveClient.Drive.Items[fileId].Content.Request().GetAsync(); wdm.downloadFile((MemoryStream)contentStream, cd.FileName + extension); } catch (Exception e) { Console.WriteLine(e); return false; } return true; }
private bool moveCopyFile(CommonDescriptor fileToMove, CommonDescriptor folderDestination, bool destructive) { //move a file within this account to another place within this account. var _googleDriveService = InitializeAPI.googleDriveService; //get previous parents to remove var parentRequest = _googleDriveService.Files.Get(fileToMove.FileID); parentRequest.Fields = "parents"; var file = parentRequest.Execute(); //this will remove all parents var previousParents = string.Join(",", file.Parents); //move file to new folder //var updateRequest = _googleDriveService.Files.Update(new File(), cd.FileID); Google.Apis.Drive.v3.Data.File temp = new Google.Apis.Drive.v3.Data.File(); var updateRequest = _googleDriveService.Files.Update(temp, fileToMove.FileID); updateRequest.Fields = "id, parents"; updateRequest.AddParents = folderDestination.FileID; if (destructive) { //will only remove it from the previous parent if its a destructive call (moving), not copying. updateRequest.RemoveParents = previousParents; } file = updateRequest.Execute(); return(true); }
public async Task<bool> moveFileAsync(CommonDescriptor fileToMove, CommonDescriptor folderDestination) { var _oneDriveClient = InitializeAPI.oneDriveClient; //Move within 1D var newParentId = folderDestination.FileID; var fileId = fileToMove.FileID; var updateItem = new Item { ParentReference = new ItemReference { Id = newParentId } }; try { var itemWithUpdates = await _oneDriveClient .Drive .Items[fileId] .Request() .UpdateAsync(updateItem); } catch(Exception e) { return false; } return true; }
public async Task<bool> shareFileAsync(CommonDescriptor fileToShare) { var _oneDriveClient = InitializeAPI.oneDriveClient; var itemID = fileToShare.FileID; try { var request = _oneDriveClient.Drive.Items[itemID].CreateLink("edit").Request(); var result = await request.PostAsync(); var shareLink = result.Link; //the ability to send invitations is only in 'beta' and is not included in the SDK. //the only thing we can do is create a link that the user can send to people. //the link works, and they 'stack', that is if shared multiple times, many links (all valid) //will be created. The only way to remove them is to go into the one drive website and delete it manually. string message = "Here is the link to share the file " + fileToShare.FileName + ":\n " + shareLink.WebUrl; MessageBox.Show(message); //prompt is not showing the message } catch(Exception e) { return false; } return true; }
public void moveFileAsyncTest1() { CommonDescriptor cd = new CommonDescriptor(); cd.FileName = "Cheat Sheet Final"; cd.FileType = ".doc"; cd.FileID = "8FA41A1E5CF18E2B!1130"; CommonDescriptor folder = new CommonDescriptor(); folder.FileName = "Folder"; cd.FileType = "folder"; cd.FileID = "8FA41A1E5CF18E2B!696969"; var odc = new OneDriveCalls(); try { odc.moveFileAsync(cd, folder); } catch (Exception e) { Assert.Fail(); } }
public MainWindow(User user) { this.user = user; InitializeComponent(); this.Height = (SystemParameters.PrimaryScreenHeight); this.Width = (SystemParameters.PrimaryScreenWidth); this.menu1.Width = (SystemParameters.PrimaryScreenWidth); this.fileTreeMenu.Height = (SystemParameters.PrimaryScreenHeight) - 116; //82 this.pathBox.Width = (SystemParameters.PrimaryScreenWidth) - 198; this.scrollText.Width = (SystemParameters.PrimaryScreenWidth) - 198; this.folderView.Width = (SystemParameters.PrimaryScreenWidth) - 193; this.folderView.Height = (SystemParameters.PrimaryScreenHeight) - 200; // Test Code to show that generatePath works CommonDescriptor cd1 = new CommonDescriptor("gpname", "filetype", "filePath", "fileID", "accountType", new DateTime(1), 1); CommonDescriptor cd2 = new CommonDescriptor("pname", "filetype", "filePath", "fileID", "accountType", new DateTime(1), 1); CommonDescriptor cd3 = new CommonDescriptor("name", "filetype", "filePath", "fileID", "accountType", new DateTime(1), 1); Models.SupportClasses.TreeNode grandparentNode = new Models.SupportClasses.TreeNode(null, cd1); Models.SupportClasses.TreeNode parentNode = new Models.SupportClasses.TreeNode(grandparentNode, cd2); Models.SupportClasses.TreeNode node = new Models.SupportClasses.TreeNode(parentNode, cd3); generatePath(node, " "); // End generatePath testcode windowsDownloadManager = new WindowsDownloadManager(); windowsUploadManager = new WindowsUploadManager(); metaDataController = new MetaDataController(metaDataStorageLocation); //mimicLogin(); setButtonsClickable(false); }
public void CommonDescriptorTest() { string name, type, path, id, account; name = "name"; type = "type"; path = "path"; account = "acct"; DateTime date = DateTime.Now; long size = 1024;; id = "id"; CommonDescriptor con = new CommonDescriptor(name, type, path, id, account, date, size); CommonDescriptor cd = con; cd.FileName = name; cd.FileType = type; cd.FilePath = path; cd.LastModified = date; cd.FileSize = size; cd.FileID = id; Assert.AreEqual(cd, con); }
public List <string> uploadFiles(List <UploadInfo> toUpload, CommonDescriptor folderDestination) { List <string> newFileIDs = new List <string>(); var _googleDriveService = InitializeAPI.googleDriveService; GoogleDriveCommunicationParser gdcp = new GoogleDriveCommunicationParser(); FilesResource.CreateMediaUpload request; string mimeType, fileName; foreach (UploadInfo uInfo in toUpload) { //get the fileType using the gdcp conversion method. fileName = uInfo.getFileName(); mimeType = gdcp.getMimeType(fileName.Substring(fileName.IndexOf('.'))); Google.Apis.Drive.v3.Data.File fileMetaData = new Google.Apis.Drive.v3.Data.File(); fileMetaData.Name = fileName; fileMetaData.Parents = new List <string> { folderDestination.FileID }; request = _googleDriveService.Files.Create(fileMetaData, uInfo.getFileStream(), mimeType); request.Fields = "id"; request.Upload(); uInfo.getFileStream().Close(); newFileIDs.Add(request.ResponseBody.Id); } return(newFileIDs); }
public TreeNode(TreeNode parent, CommonDescriptor cd) { this.parent = parent; commonDescriptor = cd; children = new LinkedList <TreeNode>(); children.Clear(); }
public bool copyFile(CommonDescriptor fileToMove, CommonDescriptor folderDestination) { //copying currently just creates an identical pointer to the file in the new folder. //this means that a copy followed by a move will remove both pointers previously created b/c they are one in the same. //TODO: fix depends on what the user wants. //a) user wants two seperate files: Need to upload a 'new file' that has the contents of the old file //b) user wants two pointers to one file: Need to implement removeParent/AddParent methods to remove a specified parent, not all parents. return(moveCopyFile(fileToMove, folderDestination, false)); }
public bool shareFile(CommonDescriptor fileToShare, string role, string email, string optionalMessage) { try { Console.WriteLine("STARTED SHARING"); var _googleDriveService = InitializeAPI.googleDriveService; var batch = new BatchRequest(_googleDriveService); BatchRequest.OnResponse <Permission> callback = delegate( Permission permission, RequestError error, int index, System.Net.Http.HttpResponseMessage message) { if (error != null) { // Handle error Console.WriteLine(error.Message); } else { Console.WriteLine("Permission ID: " + permission.Id); } }; //TODO: launch the share window view, get the email address //shareWindow window = new shareWindow(); //window.Show(); //get the informaiton //TODO: replace these permissions with the permissions entered on the shareWindow Permission userPermission = new Permission(); userPermission.Type = "user"; userPermission.Role = role; //TODO. pick the correct role userPermission.EmailAddress = email; //TODO, enter the email address var request = _googleDriveService.Permissions.Create(userPermission, fileToShare.FileID); request.Fields = "id"; request.EmailMessage = optionalMessage; //TODO enter message batch.Queue(request, callback); var task = batch.ExecuteAsync(); } catch (Exception e) { //caught a bug Console.WriteLine(e.Message); } return(true); }
public void deleteCloudObjetTest() { try { string root = "L://TestingFolder"; CommonDescriptor cd = new CommonDescriptor("name", "ftype", "fpath", "fid", "acct", new DateTime(), 10); MetaDataController mc = new MetaDataController(root); mc.deleteCloudObjet(cd); } catch (Exception) { Assert.Fail(); } }
public bool deleteFile(CommonDescriptor cd) { try { var _googleDriveService = InitializeAPI.googleDriveService; var request = _googleDriveService.Files.Delete(cd.FileID); request.Execute(); } catch (Exception e) { //Something caused an error, delete did not occur. return(false); } return(true); }
public void downloadFileAsyncTest() { CommonDescriptor cd = new CommonDescriptor(); cd.FileName = "Future"; cd.FileID = "1-e2aWnKr5j9OlkwbXIMv9E6xj4lBfH9DDNp_3hzLrEQ"; cd.FileType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; try { gdc.downloadFileAsync(cd); } catch (Exception e) { Assert.Inconclusive(); } }
public void deleteFileAsyncTest1() { CommonDescriptor cd = new CommonDescriptor(); cd.FileName = "Cheat Sheet Final"; cd.FileType = ".doc"; cd.FileID = "8FA41A1E5CF18E2B!696969"; var odc = new OneDriveCalls(); try { odc.deleteFileAsync(cd); } catch (Exception e) { Assert.Fail(); } }
public async Task<bool> deleteFileAsync(CommonDescriptor cd) { OneDriveCommunicationParser odcp = new OneDriveCommunicationParser(); var _oneDriveClient = InitializeAPI.oneDriveClient; var fileId = cd.FileID; try { await _oneDriveClient.Drive.Items[fileId].Request().DeleteAsync(); } catch (Exception e) { Console.WriteLine(e); return false; } return true; }
public async Task<bool> copyFileAsync(CommonDescriptor fileToMove, CommonDescriptor folderDestination) { var _oneDriveClient = InitializeAPI.oneDriveClient; var newItemName = fileToMove.FileName; var itemId = fileToMove.FileID; var copyLocationId = folderDestination.FileID; try { var request = await _oneDriveClient.Drive. Items[itemId] .Copy(newItemName, new ItemReference { Id = copyLocationId }).Request().PostAsync(); } catch (Exception e) { Console.WriteLine(e); return false; } return true; }
public Task <bool> shareFileAsync(CommonDescriptor fileToShare) { throw new NotImplementedException(); }
private bool removeParentToFile(CommonDescriptor fileToRemove, CommonDescriptor parentFolderToRemove) { return(true); }
//Following two methods are for option B in comments on line 277 private bool addParentToFile(CommonDescriptor fileToAdd, CommonDescriptor newParentFolder) { return(true); }
public List<string> uploadFiles(List<Models.SupportClasses.UploadInfo> toUpload, CommonDescriptor folderDestination) { uploadFilesAsync(toUpload, folderDestination); return null; }
public bool shareFile(CommonDescriptor fileToShare, string email, string role, string message) { shareFileAsync(fileToShare); return true; }
public async Task <bool> downloadFileAsync(CommonDescriptor cd) { var _googleDriveService = InitializeAPI.googleDriveService; //TODO: THE MIMETYPE THIS IS CAN'T BE THE SAME MIMETYPE AS WHAT IT WAS SAVED. It needs to be an export type. //https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents string extension, mimeType = ""; //figure out the mimetype by using the extension in the file name. GoogleDriveCommunicationParser gdcp = new GoogleDriveCommunicationParser(); if (cd.FileName.IndexOf('.') != -1) { //has an extension. extension = cd.FileName.Substring(cd.FileName.IndexOf('.')); //gets the extension. } else { //get a 'default' extension based on the format, convert to a real extension extension = cd.FileType; extension = gdcp.convertExtension(extension); if (extension == null) { //still can't find a good extension //not able to be downloaded, cancel download //TODO: ban the user from pressing download on these kinds of files? return(false); } } mimeType = gdcp.getMimeType(extension); if (mimeType == null) { //user cancelled giving us a new extension, cancel the download return(false); } var request = _googleDriveService.Files.Get(cd.FileID); var stream = new MemoryStream(); WindowsDownloadManager wdm = new WindowsDownloadManager(); request.MediaDownloader.ProgressChanged += (IDownloadProgress progress) => { switch (progress.Status) { case DownloadStatus.Downloading: { Console.WriteLine(progress.BytesDownloaded); break; } case DownloadStatus.Completed: { Console.WriteLine("Download complete."); break; } case DownloadStatus.Failed: { Console.WriteLine("Download failed."); break; } } }; try { IDownloadProgress x = await request.DownloadAsync(stream); wdm.downloadFile(stream, cd.FileName); } catch (Exception e) { Console.WriteLine(e); return(false); } return(true); }
public async Task<List<string>> uploadFilesAsync(List<Models.SupportClasses.UploadInfo> toUpload, CommonDescriptor folderDestination) { var _oneDriveClient = InitializeAPI.oneDriveClient; List<string> newFileIDs = new List<string>(); OneDriveCommunicationParser odcp = new OneDriveCommunicationParser(); string fileName, mimeType; foreach (Models.SupportClasses.UploadInfo ui in toUpload) { FileStream fileStream = (FileStream)ui.getFileStream(); fileName = ui.getFileName(); string fullPath = folderDestination.FilePath + "\\" + fileName; //TODO: need to remove the account name at the beginning of this string. //need file path var uploadedItem = await _oneDriveClient.Drive.Root.ItemWithPath(fullPath).Content.Request().PutAsync<Item>(fileStream); fileStream.Close(); newFileIDs.Add(uploadedItem.Id); } return newFileIDs; }
public async Task <List <string> > uploadFilesAsync(List <UploadInfo> toUpload, CommonDescriptor folderDestination) { throw new NotImplementedException(); }
public Task <bool> deleteFileAsync(CommonDescriptor cd) { throw new NotImplementedException(); }
public Task <bool> copyFileAsync(CommonDescriptor fileToMove, CommonDescriptor folderDestination) { throw new NotImplementedException(); }
public bool moveFile(CommonDescriptor fileToMove, CommonDescriptor folderDestination) { return(moveCopyFile(fileToMove, folderDestination, true)); }
private void uploadButton_Click(object sender, RoutedEventArgs e) { //get the destination location if (selectedHierarchyFolder == null) { //can't upload without selecting DialogResult res = System.Windows.Forms.MessageBox.Show("Please select a folder to upload to."); return; } CommonDescriptor destinationLocation = selectedHierarchyFolder.getCommonDescriptor(); //determine what controller to use (google vs one drive) Models.SupportClasses.TreeNode rootNode = selectedHierarchyFolder; while (rootNode.getParent() != null) { rootNode = rootNode.getParent(); } CommonDescriptor root = rootNode.getCommonDescriptor(); string acctType = root.AccountType; ICloudCalls cloudCaller = null; //should be done with a level of obfuscation if (acctType.Equals("Google Drive")) { cloudCaller = new GoogleDriveCalls(); } else if (acctType.Equals("One Drive")) { cloudCaller = new OneDriveCalls(); } else { DialogResult res = System.Windows.Forms.MessageBox.Show("Cannot upload to this account for some reason."); return; //somehow nothing was set for the root node, this should be impossible. } //get the elements the user wants to upload List <UploadInfo> filesToUpload = windowsUploadManager.getUploadFiles(); //make the calls to upload List <string> uploadedFileIDs; uploadedFileIDs = cloudCaller.uploadFiles(filesToUpload, destinationLocation); //now that files are uploaded //download the metaData from these files //really bad, should have a more precise solution cloudCaller.fetchAllMetaData(metaDataController, root.FileName); //update the view //again a dumb solution, should be more precise Models.SupportClasses.TreeNode remadeRootNode = metaDataController.getRoot(root.FileName, root.FileID, root.AccountType); //attempt to 'refresh' the fileHierarchy view MenuItem temp = new MenuItem() { Title = root.FileName, ID = root.FileID }; //label as the account name hierarchyDelete(rootNode); hierarchyAdd(remadeRootNode); }
public bool shareFile(CommonDescriptor fileToShare) { shareFileAsync(fileToShare); return true; }