public async Task <object> Get(OpenFile request) { if (request.Uri < 1) { throw new Exception("Invalid Uri"); } var response = new OpenFileResponse(); var record = new Record(this.Database, request.Uri); string token = await getToken(); string driveId = record.ExternalReference; OneDriveItem fileResult = null; if (!string.IsNullOrWhiteSpace(driveId)) { fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null); response.WebUrl = fileResult.WebUrl; } else if (record.IsElectronic) { string folderId = string.Empty; try { var documentFolder = await ODataHelper.PostFolder <OneDriveItem>(GraphApiHelper.GetOneDriveChildrenUrl(), token); folderId = documentFolder.Id; if (!record.IsDocumentInClientCache) { record.LoadDocumentIntoClientCache(); } var fileItem = await ODataHelper.PostFile <OneDriveItem>(GraphApiHelper.GetOneDriveFileUploadUrl(folderId, record.SuggestedFileName), token, record.DocumentPathInClientCache); record.ExternalReference = fileItem.Id; record.Save(); record.GetDocument(null, true, null, null); response.WebUrl = fileItem.WebUrl; } catch { throw; } } else { throw new Exception("Record is not a valid document."); } 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; 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); }
internal static string GetOneDriveChildrenUrl(OneDriveItem item) { return($"{BaseUrl}/drives/{item.getDriveAndId()}/children"); }
internal static string GetOneDriveSessionUrl(OneDriveItem item) { return($"{BaseUrl}/drives/{item.getDriveAndId()}/createUploadSession"); }
public async Task <object> Get(RegisterFile request) { RegisterFileResponse response = new RegisterFileResponse(); //string[] addinScopes = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/scope").Value.Split(' '); string token = await getToken(); string driveId = getDriveIdFromTrim(request); OneDriveItem fileResult = null; try { if (!string.IsNullOrWhiteSpace(request.WebUrl)) { var driveDetails = await ODataHelper.GetItem <OneDriveDrive>(GraphApiHelper.GetMyOneDriveUrl(), token); string filePath = request.WebUrl.Substring(driveDetails.WebUrl.Length); var fullOneDriveItemsUrl = GraphApiHelper.GetOneDriveItemPathsUrl(filePath); fileResult = await ODataHelper.GetItem <OneDriveItem>(fullOneDriveItemsUrl, token); } else if (!string.IsNullOrWhiteSpace(driveId)) { fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token); } } catch { throw; } var registeredFile = new RegisterdFileResponse() { Id = fileResult?.Id, DriveItem = fileResult }; TrimMainObjectSearch search = new TrimMainObjectSearch(this.Database, BaseObjectTypes.Record); TrimSearchClause clause = new TrimSearchClause(this.Database, BaseObjectTypes.Record, SearchClauseIds.RecordExternal); clause.SetCriteriaFromString(fileResult.Id); 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 }; return(response); }
public async Task <object> Get(OpenFile request) { if (request.Uri < 1) { throw new HttpError(HttpStatusCode.BadRequest, "400", "Invalid Uri"); } var response = new OpenFileResponse() { UserHasAccess = true }; var record = new Record(this.Database, request.Uri); string driveId = record.SpURL; if (!string.IsNullOrWhiteSpace(driveId)) { OneDriveItem fileResult = null; string token = await getToken(); try { fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null); } catch (Exception ex) { response.UserHasAccess = false; } if (response.UserHasAccess == false) { token = getApplicationToken(); fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null); } response.WebUrl = fileResult.WebUrl; response.WebDavUrl = fileResult.WebDavUrl; } else if (record.IsElectronic) { try { string token = await getToken(); string folderId = string.Empty; var documentFolder = await ODataHelper.PostFolder <OneDriveItem>(GraphApiHelper.GetOneDriveChildrenUrl(), token); folderId = documentFolder.Id; if (!record.IsDocumentInClientCache) { record.LoadDocumentIntoClientCache(); } Regex pattern = new Regex("[\\\\/<>|?]|[\n]{2}"); string fileName = $"{Path.GetFileNameWithoutExtension(record.SuggestedFileName)} ({pattern.Replace(record.Number, "_")}){Path.GetExtension(record.SuggestedFileName)}"; var uploadedFile = await doUpload(record.DocumentPathInClientCache, fileName, token); record.GetDocument(null, true, null, uploadedFile.ParentReference.DriveId + "/items/" + uploadedFile.Id); record.SpURL = uploadedFile.ParentReference.DriveId + "/items/" + uploadedFile.Id; // uploadedFile. fileItem.getDriveAndId(); record.Save(); response.WebUrl = uploadedFile.WebUrl; response.WebDavUrl = uploadedFile.WebDavUrl; } catch { try { record.UndoCheckout(null); } catch { } // return new Error throw; } } else { throw new Exception("Record is not a valid document."); } return(response); }