public TaskDataSelectionForm() { InitializeComponent(); Theming.ApplyTheme(this); file.Checked = true; foreach (VolumeInfo volume in VolumeInfo.Volumes) { DriveType driveType = volume.VolumeType; if (driveType != DriveType.Unknown && driveType != DriveType.NoRootDirectory && driveType != DriveType.CDRom && driveType != DriveType.Network) { if (!volume.IsMounted) continue; DriveItem item = new DriveItem(); string volumePath = volume.MountPoints[0]; DirectoryInfo root = new DirectoryInfo(volumePath); item.Drive = volumePath; item.Label = root.GetDescription(); item.Icon = root.GetIcon(); unusedDisk.Items.Add(item); } } if (unusedDisk.Items.Count != 0) unusedDisk.SelectedIndex = 0; Dictionary<Guid, ErasureMethod> methods = ErasureMethodManager.Items; this.method.Items.Add(ErasureMethodManager.Default); foreach (ErasureMethod method in methods.Values) this.method.Items.Add(method); if (this.method.Items.Count != 0) this.method.SelectedIndex = 0; }
private async Task UploadExcelToGroupOneDriveAsync(GraphServiceClient graphService, string graphAccessToken, Graph.Group group, string excelPath) { string excelPathName = "Property-Costs.xlsx"; string[] excelPathArry = excelPath.Split(new char[] { '\\' }); if (excelPathArry.Length > 0) { excelPathName = excelPathArry[excelPathArry.Length - 1]; } DriveItem driveItem = new DriveItem(); driveItem.Name = excelPathName; driveItem.File = new Microsoft.Graph.File(); driveItem = await graphService.Groups[group.Id].Drive.Root.Children.Request().AddAsync(driveItem); using (FileStream file = new FileStream(_baseFolderPath + excelPath, FileMode.Open, FileAccess.Read)) { await graphService.Groups[group.Id].Drive.Items[driveItem.Id].Content.Request().PutAsync<DriveItem>(file); } }
public static void MockUploadOneDriveItemAsync(this Mock <IGraphServiceClient> mock, DriveItem returnValue) { mock.Setup(client => client .Me .Drive .Root .ItemWithPath(It.IsAny <string>()) .Content .Request(null) .PutAsync <DriveItem>(It.IsAny <Stream>())) .Returns(Task.FromResult(returnValue)); }
private async Task <string> GetFileContentAsBase64(string fileUrl, string accessToken, DriveItem sourceItem) { string baseUrl = ActionHelpers.ParseBaseUrl(fileUrl); var itemContentUrl = $"https://graph.microsoft.com/v1.0/drives/{sourceItem.ParentReference.DriveId}/items/{sourceItem.Id}/content"; var contentStream = await HttpHelper.Default.GetStreamContentForUrlAsync(itemContentUrl, accessToken); byte[] bytes; using (var memoryStream = new MemoryStream()) { contentStream.CopyTo(memoryStream); bytes = memoryStream.ToArray(); } return(Convert.ToBase64String(bytes)); }
private static bool IsFolder(DriveItem driveItem) { return driveItem.Folder != null; }
public OneDriveFile(DriveItem item) : base(item) { }
internal OneDriveFile(DriveItem driveItem) : base(driveItem) { }
public async Task RenameOfferDocumentsAsync(string directory, int pageSize = 999) { var fileNameRegex = new Regex(@"^([0-9]{2})([0-9]{2})([0-9]{2})_*([0-9]{2})_*(.*)\.pdf$", RegexOptions.Multiline); Dictionary <string, string> driveItems = new Dictionary <string, string>(); try { var driveItemsPage = await _client.Drives[_fileStorageConfig.DriveId].Root .ItemWithPath(directory) .Children .Request() .Top(pageSize) .GetAsync(); var pageIterator = PageIterator <DriveItem> .CreatePageIterator( _client, driveItemsPage, (driveItem) => { driveItems.Add(driveItem.Id, driveItem.Name); return(true); } ); await pageIterator.IterateAsync(); _logger.LogInformation($"Found {driveItems.Count} drive items in {directory} that need to be renamed."); foreach (var entry in driveItems) { string driveItemId = entry.Key; string fileName = entry.Value; var match = fileNameRegex.Match(fileName); if (match.Success) { var offerNumber = $"{match.Groups[1].Value}/{match.Groups[2].Value}/{match.Groups[3].Value}/{match.Groups[4].Value}"; try { var offer = await _offerDataProvider.GetByOfferNumberAsync(offerNumber); var postfix = String.IsNullOrEmpty(match.Groups[5].Value) ? "" : $"_{match.Groups[5].Value}"; var adFileName = $"AD{offer.RequestNumber}{postfix}.pdf"; var renamedDriveItem = new DriveItem { Name = adFileName }; await _client.Drives[_fileStorageConfig.DriveId] .Items[driveItemId] .Request() .UpdateAsync(renamedDriveItem); } catch (EntityNotFoundException) { _logger.LogWarning($"Cannot find offer with number {offerNumber}. Unable to rename document."); } catch (ServiceException ex) { _logger.LogWarning($"Something went wrong renaming file {fileName}: {ex.ToString()}"); } } else { _logger.LogWarning($"Ignoring file {fileName} from drive {_fileStorageConfig.DriveId} in directory {directory} because it doesn't have a standardized offer document name"); } } } catch (ServiceException) { _logger.LogWarning($"Something went wrong listing files in {directory}"); } }
// Create the email message. public async Task <Message> BuildEmailMessage(GraphServiceClient graphClient, string recipients, string subject) { // Get current user photo Stream photoStream = await GetCurrentUserPhotoStreamAsync(graphClient); // If the user doesn't have a photo, or if the user account is MSA, we use a default photo if (photoStream == null) { photoStream = System.IO.File.OpenRead(System.Web.Hosting.HostingEnvironment.MapPath("/Content/test.jpg")); } MemoryStream photoStreamMS = new MemoryStream(); // Copy stream to MemoryStream object so that it can be converted to byte array. photoStream.CopyTo(photoStreamMS); DriveItem photoFile = await UploadFileToOneDrive(graphClient, photoStreamMS.ToArray()); MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage(); attachments.Add(new FileAttachment { ODataType = "#microsoft.graph.fileAttachment", ContentBytes = photoStreamMS.ToArray(), ContentType = "image/png", Name = "me.png" }); Permission sharingLink = await GetSharingLinkAsync(graphClient, photoFile.Id); // Add the sharing link to the email body. string bodyContent = string.Format(Resources.CaptionsAll.Graph_SendMail_Body_Content, sharingLink.Link.WebUrl); // Prepare the recipient list. string[] splitter = { ";" }; string[] splitRecipientsString = recipients.Split(splitter, StringSplitOptions.RemoveEmptyEntries); List <Recipient> recipientList = new List <Recipient>(); foreach (string recipient in splitRecipientsString) { recipientList.Add(new Recipient { EmailAddress = new EmailAddress { Address = recipient.Trim() } }); } // Build the email message. Message email = new Message { Body = new ItemBody { Content = bodyContent, ContentType = BodyType.Html, }, Subject = subject, ToRecipients = recipientList, Attachments = attachments }; return(email); }
private static bool NewFile(DriveItem drive, long lastSyncDate) { return drive.File != null && drive.CreatedDateTime == drive.LastModifiedDateTime && (lastSyncDate<=drive.LastModifiedDateTime.Value.Ticks) ; }
private static bool SkipFolder(DriveItem drive, long lastSyncDate) { return drive.Folder != null && drive.Deleted==null && (lastSyncDate > drive.LastModifiedDateTime.Value.Ticks); }
private static bool FolderDeleted(DriveItem drive) { return drive.Folder != null && drive.Deleted != null; }
private static bool FileDeleted(DriveItem drive) { return drive.File != null && drive.Deleted != null; }
/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageFile"/> class. /// <para>Permissions : Have full access to user files and files shared with user</para> /// </summary> /// <param name="graphProvider">Instance of Graph Client class</param> /// <param name="requestBuilder">Http request builder.</param> /// <param name="oneDriveItem">OneDrive's item</param> public OneDriveStorageFile(IBaseClient graphProvider, IBaseRequestBuilder requestBuilder, DriveItem oneDriveItem) : base(graphProvider, requestBuilder, oneDriveItem) { StorageFilePlatformService = OneDriveService.ServicePlatformInitializer.CreateOneDriveStorageFilePlatformInstance(OneDriveService.Instance, this); ParseFileType(oneDriveItem.Name); }
public static bool IsFolder(this DriveItem item) { return(item.Folder != null); }
public FileViewModel(DriveItem item, string driveId) : this(item) { DriveId = driveId; }
internal FileSelectedEventArgs(DriveItem fileSelected) { FileSelected = fileSelected; }
internal OneDriveResource(DriveItem driveItem) : this(driveItem.Id, driveItem.Name, driveItem.Description, driveItem.WebUrl) { }
public static async Task <Stream> DownloadFile(DriveItem driveItem) { throw new NotImplementedException(); }
internal OneDriveFolder(DriveItem driveItem) : base(driveItem) { }
public static async Task <Stream> ConvertContetPDF(DriveItem driveItem) { throw new NotImplementedException(); }
private FileDescription GetFileDescription(OneDrive2ItemLocation <OneDrive2PrefixContainerType> path, DriveItem i) { FileDescription e = new FileDescription(); if (i.Size != null) { e.SizeInBytes = (long)i.Size; } else if ((i.RemoteItem != null) && (i.RemoteItem.Size != null)) { e.SizeInBytes = (long)i.RemoteItem.Size; } e.DisplayName = i.Name; e.CanRead = e.CanWrite = true; e.Path = path.ToString(); if (i.LastModifiedDateTime != null) { e.LastModified = i.LastModifiedDateTime.Value.LocalDateTime; } else if ((i.RemoteItem != null) && (i.RemoteItem.LastModifiedDateTime != null)) { e.LastModified = i.RemoteItem.LastModifiedDateTime.Value.LocalDateTime; } e.IsDirectory = (i.Folder != null) || ((i.RemoteItem != null) && (i.RemoteItem.Folder != null)); return(e); }
/// <summary> /// Initializes a new instance of the <see cref="OneDriveStorageItem"/> class. /// </summary> /// <param name="oneDriveProvider">Instance of Graph Client class</param> /// <param name="requestBuilder">Http request builder.</param> /// <param name="oneDriveItem">OneDrive's item</param> public OneDriveStorageItem(IBaseClient oneDriveProvider, IBaseRequestBuilder requestBuilder, DriveItem oneDriveItem) { StorageItemPlatformService = OneDriveService.ServicePlatformInitializer.CreateOneDriveStorageItemPlatformInstance(OneDriveService.Instance, this); RequestBuilder = requestBuilder; Provider = oneDriveProvider; OneDriveItem = oneDriveItem; Name = oneDriveItem.Name; FileSize = oneDriveItem.Size; DateCreated = oneDriveItem.CreatedDateTime; DateModified = oneDriveItem.LastModifiedDateTime; DisplayName = Name; FolderRelativeId = oneDriveItem.Id; if (IsFile()) { DisplayType = "File"; } else if (IsFolder()) { DisplayType = "Folder"; } else { DisplayType = "OneNote"; } // ParentReference null means is root if (oneDriveItem.ParentReference?.Path != null) { string rootMarker = "/root:"; int index = oneDriveItem.ParentReference.Path.LastIndexOf(rootMarker) + rootMarker.Length; if (index >= 0) { Path = oneDriveItem.ParentReference.Path.Substring(index); } } }
// Private methods private async void RequestAndGenerateChildrenEntitiesRecursively(BusinessEntities.Folder parentFolder, DriveItem expandedFolderDriveItem) { // Generate entities for its children foreach (var childDriveItem in expandedFolderDriveItem.Children.CurrentPage) { // Folder if (childDriveItem.Folder != null) { var newChildFolder = new BusinessEntities.Folder(childDriveItem.Id, childDriveItem.Name, childDriveItem.Size, parentFolder); parentFolder.Folders.Add(newChildFolder); // Generate its children when it is a Folder if (expandedFolderDriveItem.Children != null && expandedFolderDriveItem.Children.CurrentPage != null) { var expandedChildDriveItem = await graphAPI.GetDriveItemAsync(childDriveItem.Id); RequestAndGenerateChildrenEntitiesRecursively(newChildFolder, expandedChildDriveItem); } } // File else if (childDriveItem.File != null) { var newFile = new BusinessEntities.File(childDriveItem.Id, childDriveItem.Name, childDriveItem.Size, parentFolder); parentFolder.Files.Add(newFile); } } }
/// <summary> /// Initialize a GraphOneDriveStorageFile /// </summary> /// <param name="oneDriveItem">A OneDrive item</param> /// <returns>New instance of GraphOneDriveStorageFile</returns> internal OneDriveStorageFile InitializeOneDriveStorageFile(DriveItem oneDriveItem) { IBaseRequestBuilder requestBuilder = GetDriveRequestBuilderFromDriveId(oneDriveItem.ParentReference.DriveId).Items[oneDriveItem.Id]; return(new OneDriveStorageFile(Provider, requestBuilder, oneDriveItem)); }
public static void MockGetOneDriveItemAsync(this Mock <IGraphServiceClient> mock, DriveItem returnValue) { mock.Setup(client => client .Me .Drive .Root .ItemWithPath(It.IsAny <string>()) .Request() .GetAsync()) .Returns(Task.FromResult(returnValue)); }
private void LoadProperties(DriveItem item) { this.SelectedItem = item; objectBrowser.SelectedItem = item; }
public async Task<bool> UploadFileAsync(GraphServiceClient graphService, UploadFileModel model) { try { var graphToken = AuthenticationHelper.GetGraphAccessTokenAsync(); var propertyGroup = await graphService.GetGroupByDisplayNameAsync(model.PropertyTitle); if (propertyGroup == null) return false; DriveItem driveItem = new DriveItem(); driveItem.Name = model.File.FileName; driveItem.File = new Microsoft.Graph.File(); driveItem = await graphService.Groups[propertyGroup.Id].Drive.Root.Children.Request().AddAsync(driveItem); await graphService.Groups[propertyGroup.Id].Drive.Items[driveItem.Id].Content.Request().PutAsync<DriveItem>(model.File.InputStream); } catch (Exception el) { throw el; } return false; }
private void AddItemToFolderContents(DriveItem obj) { flowLayoutContents.Controls.Add(CreateControlForChildObject(obj)); }
private void RemoveItemFromFolderContents(DriveItem itemToDelete) { flowLayoutContents.Controls.RemoveByKey(itemToDelete.Id); }
public static bool IsFile(this DriveItem item) { return(item.File != null); }