public async Task <object> Get(RegisterFile request) { var log = LogManager.GetLogger(typeof(RegisterFileService)); log.Debug("GET start"); RegisterFileResponse response = new RegisterFileResponse(); log.Debug("getToken"); string token = await getToken(); log.Debug("gotToken"); string driveId = getDriveIdFromTrim(request); log.Debug("got Drive ID"); OneDriveItem fileResult = null; try { if (!string.IsNullOrWhiteSpace(request.WebUrl) && new string[] { "https://", "http://" } .Any(s => request.WebUrl.StartsWith(s, StringComparison.InvariantCultureIgnoreCase))) { log.Debug("GetItem"); var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveShareUrl(request.WebUrl); fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token, null); log.Debug("GotItem"); } else if (!string.IsNullOrWhiteSpace(driveId)) { fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null); } } catch { throw; } RegisterdFileResponse registeredFile = new RegisterdFileResponse(); if (fileResult != null) { registeredFile.Id = fileResult?.getDriveAndId(); registeredFile.DriveItem = fileResult; TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record); TrimSearchClause clause = new TrimSearchClause(this.Database, BaseObjectTypes.Record, SearchClauseIds.RecordSpURL); clause.SetCriteriaFromString(fileResult.getDriveAndId()); search.AddSearchClause(clause); var uris = search.GetResultAsUriArray(2); if (uris.Count == 1) { updateFromRecord(registeredFile, new Record(this.Database, uris[0])); } //if (request.Uri > 0) //{ // Record record = new Record(this.Database, request.Uri); // response.RecordTitle = record.Title; // response.Name = this.Database.CurrentUser.FormattedName; //} } response.Results = new List <RegisterdFileResponse>() { registeredFile }; log.Debug("Finished"); return(response); }
public async Task <object> Get(RegisterFile request) { var log = LogManager.GetLogger(typeof(RegisterFileService)); log.Debug("GET start"); RegisterFileResponse response = new RegisterFileResponse(); log.Debug("getToken"); string token = await getToken(); log.Debug("gotToken"); string driveId = getDriveIdFromTrim(request); log.Debug("got Drive ID"); OneDriveItem fileResult = null; long recordUri = 0; RegisterdFileResponse registeredFile = new RegisterdFileResponse(); try { if (request.IsEmail) { recordUri = await getEmailLinkUri(request.WebUrl, token); //var mailResult = await ODataHelper.GetItem<MailItem>(GraphApiHelper.GetMailItemURL(request.WebUrl), token, null); //if (mailResult != null && mailResult.SingleValueExtendedProperties != null) //{ // foreach (var prop in mailResult.SingleValueExtendedProperties) // { // if (prop.Id.Equals(GraphApiHelper.IDPropName(), StringComparison.InvariantCultureIgnoreCase)) // { // long.TryParse(prop.Value.Split('/').Last(), out recordUri); // } // } //} } if (request.IsEmail && recordUri == 0) { var emailUrl = GraphApiHelper.GetEMLUrl(request.WebUrl); string userFolder = Path.Combine("ForUser", this.Database.CurrentUser.Uri.ToString()); string fullUserFolder = Path.Combine(this.ServiceDefaults.UploadBasePath, userFolder); Directory.CreateDirectory(fullUserFolder); string fileName = Path.ChangeExtension(request.WebUrl, "eml"); string filePath = Path.Combine(fullUserFolder, fileName); await ODataHelper.GetItem <string>(emailUrl, token, filePath); registeredFile.EmailPath = Path.Combine(userFolder, fileName);; } else if (!string.IsNullOrWhiteSpace(request.WebUrl) && new string[] { "https://", "http://" } .Any(s => request.WebUrl.StartsWith(s, StringComparison.InvariantCultureIgnoreCase))) { log.Debug("GetItem"); var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveShareUrl(request.WebUrl); fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token, null); log.Debug("GotItem"); } else if (!string.IsNullOrWhiteSpace(driveId) && !request.IsEmail) { fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null); } } catch { throw; } DroppedFilesUserOptions fileOptions = new DroppedFilesUserOptions(this.Database); var options = new TrimOptions(); if (fileOptions.UseDefaultRecordTypeInOffice == true) { options.DefaultDocumentRecordType = fileOptions.RecordType.Uri; } registeredFile.Options = options; var enumItems = new List <MyEnumItem>(); HP.HPTRIM.SDK.Enum relationshipEnum = new HP.HPTRIM.SDK.Enum(AllEnumerations.RecordRelationshipType, this.Database); foreach (var relEnum in relationshipEnum.GetItemArray(new int[] { (int)RecordRelationshipType.InSharepointSite, (int)RecordRelationshipType.IsInSeries, (int)RecordRelationshipType.IsRootPart, (int)RecordRelationshipType.IsTempCopy, (int)RecordRelationshipType.IsVersion, (int)RecordRelationshipType.RedactionOf }, true).OrderBy(ei => ei.Caption)) { enumItems.Add(new MyEnumItem() { Name = relEnum.Name, Caption = relEnum.Caption }); } Dictionary <string, IList <MyEnumItem> > enumDetails = new Dictionary <string, IList <MyEnumItem> >(); enumDetails.Add("RecordRelationshipType", enumItems); registeredFile.Enums = enumDetails; if (fileResult != null) { registeredFile.Id = fileResult?.getDriveAndId(); registeredFile.DriveItem = fileResult; TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record); search.AddSearchClause(fileResult.getDriveAndId().GetDriveIdSearchClause(this.Database)); var uris = search.GetResultAsUriArray(2); if (uris.Count == 1) { updateFromRecord(registeredFile, new Record(this.Database, uris[0])); } } else if (request.IsEmail && recordUri > 0) { updateFromRecord(registeredFile, new Record(this.Database, recordUri)); } response.Results = new List <RegisterdFileResponse>() { registeredFile }; log.Debug("Finished"); return(response); }