public async Task <object> Post(DriveFileOperation request) { string token = await getToken(); RegisterFileResponse response = new RegisterFileResponse(); Record record = new Record(this.Database, request.Uri); string driveId = record.ExternalReference; var registeredFile = new RegisterdFileResponse() { Id = driveId }; request.Action = request.Action ?? ""; if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1) { record.AddToFavorites(); } if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1) { record.RemoveFromFavorites(); } if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1) { var driveDetails = await ODataHelper.GetItem <string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token); record.SetDocument(new InputDocument(driveDetails), true, false, "checkin from Word Online"); } if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1) { await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token); record.ExternalReference = ""; } if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1) { record.SetAsFinal(false); } record.Save(); updateFromRecord(registeredFile, record); response.Results = new List <RegisterdFileResponse>() { registeredFile }; return(response); }
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> Post(DriveFileOperation request) { try { RegisterFileResponse response = new RegisterFileResponse(); Record record = new Record(this.Database, request.Uri); record.Refresh(); string driveId = record.SpURL; var registeredFile = new RegisterdFileResponse() { Id = driveId }; request.Action = request.Action ?? ""; if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1) { record.AddToFavorites(); } if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1) { record.RemoveFromFavorites(); } if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1) { string token = await getToken(); if (!string.IsNullOrWhiteSpace(request.FileName)) { // filePath = Path.Combine(TrimApplication.WebServerWorkPath, record.SuggestedFileName); //using (var stream = new FileStream(filePath, FileMode.Append)) //{ // stream.Write(request.Data, 0, request.Data.Length); //} //if (request.LastDataSlice == true) //{ // record.SetDocument(new InputDocument(filePath), true, false, "checkin from Word Online"); //} else //{ // response.Results = new List<RegisterdFileResponse>() { registeredFile }; // return response; //} // var driveDetails = await ODataHelper.GetItem<string>(GraphApiHelper.GetOneDriveItemContentIdUrl(driveId), token, filePath); var inputDocument = new InputDocument(request.FileName); inputDocument.CheckinAs = request.WebUrl; record.SetDocument(inputDocument, true, false, "checkin from Word Online"); } } if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1) { string token = await getToken(); await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token); record.SpURL = ""; } if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1) { record.SetAsFinal(false); } record.Save(); updateFromRecord(registeredFile, record); response.Results = new List <RegisterdFileResponse>() { registeredFile }; return(response); } finally { if (!string.IsNullOrWhiteSpace(request.FileName)) { File.Delete(request.FileName); } } }
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); }
public async Task <object> Post(DriveFileOperation request) { string fileName = request.FileName; try { RegisterFileResponse response = new RegisterFileResponse(); Record record = new Record(this.Database, request.Uri); record.Refresh(); string driveId = record.GetDriveId(); var registeredFile = new RegisterdFileResponse() { Id = driveId }; request.Action = request.Action ?? ""; if (request.Action.IndexOf("AddToFavorites", StringComparison.InvariantCultureIgnoreCase) > -1) { record.AddToFavorites(); } if (request.Action.IndexOf("RemoveFromFavorites", StringComparison.InvariantCultureIgnoreCase) > -1) { record.RemoveFromFavorites(); } if (request.Action.IndexOf("checkin", StringComparison.InvariantCultureIgnoreCase) > -1 && request.Action.IndexOf("checkin-requst-del", StringComparison.InvariantCultureIgnoreCase) < 1) { string token = await getToken(); if (!string.IsNullOrWhiteSpace(request.FileName)) { if (!Path.IsPathRooted(request.FileName)) { fileName = Path.Combine(this.ServiceDefaults.UploadBasePath, request.FileName); } var inputDocument = new InputDocument(fileName); inputDocument.CheckinAs = request.WebUrl; record.SetDocument(inputDocument, true, false, "checkin from Word Online"); } else { string downloadUrl = GraphApiHelper.GetOneDriveItemContentIdUrl(driveId); var fileResult = await ODataHelper.GetItem <OneDriveItem>(GraphApiHelper.GetOneDriveItemIdUrl(driveId), token, null); string filePath = Path.Combine(TrimApplication.WebServerWorkPath, fileResult.Name); await ODataHelper.GetItem <string>(downloadUrl, token, filePath); var inputDocument = new InputDocument(filePath); inputDocument.CheckinAs = record.SuggestedFileName; record.SetDocument(inputDocument, true, false, "checkin from Word Online"); } } if (request.Action.IndexOf("request-del", StringComparison.InvariantCultureIgnoreCase) > -1) { record.SetDeleteNow(!record.GetDeleteNow()); } if (request.Action.IndexOf("delete", StringComparison.InvariantCultureIgnoreCase) > -1) { string token = await getToken(); await ODataHelper.DeleteWithToken(GraphApiHelper.GetOneDriveItemIdUrlForDelete(driveId), token); record.SetDriveId(""); } if (request.Action.IndexOf("finalize", StringComparison.InvariantCultureIgnoreCase) > -1) { record.SetAsFinal(false); } record.Save(); updateFromRecord(registeredFile, record); response.Results = new List <RegisterdFileResponse>() { registeredFile }; return(response); } finally { if (!string.IsNullOrWhiteSpace(fileName)) { File.Delete(fileName); } } }
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); }