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) { 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(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); }
static void Main(string[] args) { using (Database db = new Database()) { TrimMainObjectSearch objs = new TrimMainObjectSearch(db, BaseObjectTypes.Record); //792378 //First check to see if anything comes back //With more time this search should have been defined into manageable chunks objs.SetSearchString("type:16"); //Limit to the record type that I know is relevent //Initial attempts to manage the chunk runs //Console.WriteLine("Enter row limit"); //objs.LimitOnRowsReturned = Convert.ToInt64(Console.ReadLine()); // limit to 1000 out of 3.6 mill //Console.WriteLine("Enter row skip"); //objs.SkipCount = Convert.ToInt64(Console.ReadLine()); //objs.SetSearchString("number:792378"); //Changed to grab the entire set as an array of record uri's, so I can manage this in chunks by using a skip and take. Tried the RM Limitonrowsreturns and skipcount but I wasnt confident that it was working properly. Not enough time to invetigate and confirm. Each record type return is 3.6 mill records. long[] auri = objs.GetResultAsUriArray(); //db.FindTrimObjectByUri(BaseObjectTypes.fi) FieldDefinition fdNotes = new FieldDefinition(db, 42); var iCount = 0; var iTotal = objs.FastCount; //Im changing this for each compile and moving it to a prod WG server to run, doing 4 at a time which takes about 3 hours. 1 mill over 3 hours. foreach(var lUri in auri.Skip(1826354).Take(23646)) { //find the record from the looped uri try { Record rec = (Record)db.FindTrimObjectByUri(BaseObjectTypes.Record, lUri); if (rec != null) { iCount++; //Grab notes from the user defined field var sNotes = rec.GetFieldValue(fdNotes).ToString(); //grab the normal record system notes var sExistingNotes = rec.Notes; //Check for and exclude the custom notes field if empty, it would be nice if I could do this search as part of the original setsearchstring as about 50% of the 3.6 are empty but have a related db row. if (!string.IsNullOrWhiteSpace(sNotes)) { //Display something that maks me feel like its actually working Console.WriteLine("Processing {0} - {1} of 23646", rec.Number, iCount.ToString()); //Ive had a couple of runs at this using different methods and NO SORTING so there is the possibility that the notes have already been copied. if (!sExistingNotes.Contains(sNotes)) { if (rec.DateRegistered <= rec.DateReceived) { //If the date registered and date recieved are in the wrong order RM gets cranky. we check and save if needed, this is a data vallidation issue from the migration. DateTime tdtDateReceived = rec.DateReceived; rec.DateRegistered = (TrimDateTime)tdtDateReceived.AddHours(1); rec.Save(); } try { rec.Save(); Console.WriteLine("Notes transfered from udf to record notes"); } catch (Exception exp) { Console.WriteLine("Error saving notes. " + exp.Message.ToString()); } } else { Console.WriteLine("User defined notes already in Record notes"); } } else { Console.WriteLine("User defined notes empty"); } } else { Console.WriteLine("Uri {0} not found", lUri.ToString()); } } catch (Exception exp) { Console.WriteLine("Error: {0}", exp.Message.ToString()); } } } }