public void TestCLSIDRegistryPull() { var comMapping = RegistryServices.GetComClsidMapping(); //All windows systems should have more than 100 COMs registered... right??? Assert.IsTrue(comMapping.Keys.Count() > 100); }
private static ThisEntityDetail MapToAPI(ThisEntity input) { var output = new ThisEntityDetail() { Meta_Id = input.Id, CTID = input.CTID, Name = input.Name, FriendlyName = HttpUtility.UrlPathEncode(input.Name), Description = input.Description, SubjectWebpage = input.SubjectWebpage, EntityTypeId = 23, CredentialRegistryURL = RegistryServices.GetResourceUrl(input.CTID), RegistryData = ServiceHelper.FillRegistryData(input.CTID) }; //TODO - add pathway if (input.Pathways != null && input.Pathways.Any()) { output.HasPathways = new List <WMA.Outline>(); foreach (var target in input.Pathways) { if (target != null && !string.IsNullOrWhiteSpace(target.Name)) { output.HasPathways.Add(ServiceHelper.MapToOutline(target, searchType)); } } output.HasPathway = ServiceHelper.MapOutlineToAJAX(output.HasPathways, "Has {0} Pathways(s)"); output.HasPathways = null; } return(output); }
public bool GetEnvelopePayload(ReadEnvelope item, SaveStatus status, ref string payload) { if (item == null || string.IsNullOrWhiteSpace(item.EnvelopeIdentifier)) { status.AddError("A valid ReadEnvelope must be provided."); return(false); } // DateTime createDate = new DateTime(); DateTime envelopeUpdateDate = new DateTime(); if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate)) { status.EnvelopeCreatedDate = createDate; } if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate)) { status.EnvelopeUpdatedDate = envelopeUpdateDate; } // payload = item.DecodedResource.ToString(); string envelopeIdentifier = item.EnvelopeIdentifier; string ctdlType = RegistryServices.GetResourceType(payload); //string envelopeUrl = RegistryServices.GetEnvelopeUrl( envelopeIdentifier ); return(true); }
/// <summary> /// Get an invoker for an activator's pipeline. /// </summary> /// <param name="activator">The activator.</param> /// <param name="registry">The applicable component registry.</param> /// <returns>A func to call that invokes the pipeline.</returns> public static Func <ILifetimeScope, IEnumerable <Parameter>, T> GetPipelineInvoker <T>(this IInstanceActivator activator, IComponentRegistry registry) { var services = new RegistryServices(registry); var pipelineBuilder = new ResolvePipelineBuilder(PipelineType.Registration); activator.ConfigurePipeline(services, pipelineBuilder); var built = pipelineBuilder.Build(); return((scope, parameters) => { // To get the sharing scope from what might be a container, we're going to resolve the lifetime scope. var lifetimeScope = scope.Resolve <ILifetimeScope>() as LifetimeScope; var request = new DefaultResolveRequestContext( new ResolveOperation(lifetimeScope, lifetimeScope.DiagnosticSource), new ResolveRequest(new TypedService(typeof(T)), Mocks.GetResolvableImplementation(), parameters), lifetimeScope, lifetimeScope.DiagnosticSource); built.Invoke(request); return (T)request.Instance; }); }
/// <summary> /// Get list of deleted records for the requested time period. /// </summary> /// <param name="community"></param> /// <param name="type"></param> /// <param name="startingDate">Date must be in UTC</param> /// <param name="endingDate">Date must be in UTC</param> /// <param name="pageNbr"></param> /// <param name="pageSize"></param> /// <param name="pTotalRows"></param> /// <param name="statusMessage"></param> /// <returns></returns> public static List <ReadEnvelope> GetDeleted(string community, string type, string startingDate, string endingDate, int pageNbr, int pageSize, ref int pTotalRows, ref string statusMessage) { string document = ""; string filter = "include_deleted=only"; string serviceUri = RegistryServices.GetRegistrySearchUrl(community); //from=2016-08-22T00:00:00&until=2016-08-31T23:59:59 //resource_type=credential if (!string.IsNullOrWhiteSpace(type)) { filter += string.Format("&resource_type={0}", type.ToLower()); } SetPaging(pageNbr, pageSize, ref filter); SetDateFilters(startingDate, endingDate, ref filter); serviceUri += filter.Length > 0 ? filter : ""; List <ReadEnvelope> list = new List <ReadEnvelope>(); ReadEnvelope envelope = new ReadEnvelope(); try { // Create a request for the URL. WebRequest request = WebRequest.Create(serviceUri); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = ( HttpWebResponse )request.GetResponse(); Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. document = reader.ReadToEnd(); // Cleanup the streams and the response. reader.Close(); dataStream.Close(); response.Close(); //Link contains links for paging var hdr = response.GetResponseHeader("Link"); Int32.TryParse(response.GetResponseHeader("Total"), out pTotalRows); //20-07-02 mp - seems the header name is now X-Total if (pTotalRows == 0) { Int32.TryParse(response.GetResponseHeader("X-Total"), out pTotalRows); } //map to the default envelope list = JsonConvert.DeserializeObject <List <ReadEnvelope> >(document); } catch (Exception exc) { LoggingHelper.LogError(exc, "RegistryServices.GetDeleted"); } return(list); }
public void TestCLSIDRegistryPathfind() { var comMapping = RegistryServices.GetComClsidMapping(); var paths = RegistryServices.GetRegisteredPathsForComFile("dao360.dll", comMapping); Assert.IsTrue(paths.Count == 1); Assert.IsTrue(paths.First() == "C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\DAO\\dao360.dll"); }
public static void ConfigureContainers(IServiceCollection services, IConfiguration configuration) { LoadValidators.Load(services); DbSQL.Load(services, configuration); RedisCacheRegister.Load(services, configuration); AuthenticationRegister.Load(services, configuration); SwaggerRegister.Load(services, configuration); AutoMapperLoadProfiles.Load(services); RegistryServices.Load(services); RegistryRepositories.Load(services); }
private void Export() { var saveFileDialog = new SaveFileDialog() { Filter = "Registry files|*.reg", }; if (saveFileDialog.ShowDialog(Application.Current.MainWindow).Value) { RegistryServices.ExportReg(saveFileDialog.FileName, this.IsHKLM); } }
private static ThisEntityDetail MapToAPI(ThisEntity input) { var output = new ThisEntityDetail() { Meta_Id = input.Id, CTID = input.CTID, Name = input.Name, FriendlyName = HttpUtility.UrlPathEncode(input.Name), Description = input.Description, SubjectWebpage = input.SubjectWebpage, EntityTypeId = 8, CredentialRegistryURL = RegistryServices.GetResourceUrl(input.CTID), RegistryData = ServiceHelper.FillRegistryData(input.CTID) }; return(output); }
public ApplicationListViewModel(bool isHKLM = false) { this.IsHKLM = isHKLM; this.Applications = new ObservableRangeCollection <ApplicationViewModel>(RegistryServices.GetApplications(this.RegistryKey)); this.AddFolderCommand = new DelegateCommand(this.AddFolder); this.AddFilesCommand = new DelegateCommand(this.AddFiles); this.SelectAllCommand = new DelegateCommand(this.SelectAll); this.UnselectAllCommand = new DelegateCommand(this.UnselectAll); this.RegeditCommand = new DelegateCommand(this.Regedit); this.ImportCommand = new DelegateCommand(this.Import, this.CanImport); this.ExportCommand = new DelegateCommand(this.Export); this.SubscribeEvents(); }
private void Import() { var openFileDialog = new OpenFileDialog() { Filter = "Registry files|*.reg", }; if (openFileDialog.ShowDialog(Application.Current.MainWindow).Value) { RegistryServices.ImportReg(openFileDialog.FileName); this.UnsubscribeEvents(); IsWaitingDisplayed.Instance.Publish(true); this.Applications.ClearItems(); this.Applications.AddRange(RegistryServices.GetApplications(this.RegistryKey)); IsWaitingDisplayed.Instance.Publish(false); this.SubscribeEvents(); } }
// public bool ImportByCtid(string ctid, SaveStatus status) { //this is currently specific, assumes envelop contains a credential //can use the hack fo GetResourceType to determine the type, and then call the appropriate import method if (string.IsNullOrWhiteSpace(ctid)) { status.AddError("ImportByCtid - a valid ctid must be provided"); return(false); } string statusMessage = ""; string ctdlType = ""; //string payload = ""; try { ReadEnvelope envelope = RegistryServices.GetEnvelopeByCtid(ctid, ref statusMessage, ref ctdlType); if (envelope == null || string.IsNullOrWhiteSpace(envelope.EnvelopeType)) { string defCommunity = UtilityManager.GetAppKeyValue("defaultCommunity"); string community = UtilityManager.GetAppKeyValue("additionalCommunity"); if (defCommunity != community) { envelope = RegistryServices.GetEnvelopeByCtid(ctid, ref statusMessage, ref ctdlType, community); } } if (envelope != null && !string.IsNullOrWhiteSpace(envelope.EnvelopeIdentifier)) { return(ImportEnvelope(envelope, ctdlType, status)); } else { status.AddError(string.Format("ImportHelperServices.ImportByCTID. Registry Envelope was not found for: {0}", ctid)); return(false); } /*======OLD =================== * payload = GetResourceGraphByCtid( ctid, ref ctdlType, ref statusMessage ); * if (string.IsNullOrWhiteSpace(payload)) * { * string defCommunity = UtilityManager.GetAppKeyValue( "defaultCommunity" ); * string community = UtilityManager.GetAppKeyValue( "additionalCommunity" ); * if ( defCommunity != community ) * payload = GetResourceGraphByCtid( ctid, ref ctdlType, ref statusMessage, community ); * } * if ( !string.IsNullOrWhiteSpace( payload ) ) * { * LoggingHelper.WriteLogFile( 5, ctid + "_ImportByCtid.json", payload, "", false ); * LoggingHelper.DoTrace( 4, string.Format( "RegistryServices.ImportByCtid ctdlType: {0}, ctid: {1} ", ctdlType, ctid ) ); * ctdlType = ctdlType.Replace( "ceterms:", "" ); * switch ( ctdlType.ToLower() ) * { * case "credentialorganization": * case "qacredentialorganization": * case "organization": * return new ImportOrganization().ImportByPayload( payload, status ); * //break;CredentialOrganization * case "assessmentprofile": * return new ImportAssessment().ImportByPayload( payload, status ); * //break; * case "learningopportunityprofile": * return new ImportLearningOpportunties().ImportByPayload( payload, status ); * //break; * case "conditionmanifest": * return new ImportConditionManifests().ImportByPayload( payload, status ); * //break; * case "costmanifest": * return new ImportCostManifests().ImportByPayload( payload, status ); * case "competencyframework": * return new ImportCompetencyFramesworks().Import( payload, "", status ); * case "conceptscheme": * case "skos:conceptscheme": * return new ImportConceptSchemes().Import( payload, "", status ); * case "pathway": * return new ImportPathways().Import( payload, "", status ); * case "pathwayset": * return new ImportPathwaySets().Import( payload, "", status ); * case "transfervalue": * case "transfervalueprofile": * return new ImportTransferValue().Import( payload, "", status ); * //break; * default: * //default to credential * return new ImportCredential().ImportByPayload( payload, status ); * //break; * } * } * else * return false; */ } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format("ImportCredential.ImportByCtid(). ctdlType: {0}", ctdlType)); status.AddError(ex.Message); if (ex.Message.IndexOf("Path '@context', line 1") > 0) { status.AddWarning("The referenced registry document is using an old schema. Please republish it with the latest schema!"); } return(false); } }
private static WMA.CredentialDetail MapToAPI(ThisEntity input) { var output = new WMA.CredentialDetail() { Meta_Id = input.Id, CTID = input.CTID, Name = input.Name, Description = input.Description, SubjectWebpage = input.SubjectWebpage, EntityTypeId = 1, CTDLTypeLabel = input.CredentialType, CTDLType = input.CredentialTypeSchema, CredentialRegistryURL = RegistryServices.GetResourceUrl(input.CTID), RegistryData = ServiceHelper.FillRegistryData(input.CTID) }; // //output.CTDLType = record.CredentialType; ; //output.AgentSectorType = ServiceHelper.MapPropertyLabelLinks( org.AgentSectorType, "organization" ); output.FriendlyName = HttpUtility.UrlPathEncode(input.Name); output.AlternateName = input.AlternateName; //owned by and offered by //need a label link for header if (input.OwningOrganizationId > 0) { output.OwnedByLabel = ServiceHelper.MapDetailLink("Organization", input.OrganizationName, input.OwningOrganizationId); } var work = ServiceHelper.MapOrganizationRoleProfileToOutline(input.OrganizationRole, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER); output.OwnedBy = ServiceHelper.MapOutlineToAJAX(work, ""); // work = ServiceHelper.MapOrganizationRoleProfileToOutline(input.OrganizationRole, Entity_AgentRelationshipManager.ROLE_TYPE_OFFERED_BY); output.OfferedBy = ServiceHelper.MapOutlineToAJAX(work, "Offered by {0} Organization(s)"); // //QA for owner,not offerer if (input.OwningOrganization != null && input.OwningOrganization.Id > 0) { if (input.OwningOrganization.OrganizationRole_Recipient != null && input.OwningOrganization.OrganizationRole_Recipient.Any()) { output.OwnerQAReceived = ServiceHelper.MapQAReceived(input.OwningOrganization.OrganizationRole_Recipient, searchType); } //var inheritedRoles = SetupRoles( roleSet.ActingAgent.OrganizationRole_Recipient, loadedAgentIDs ); //wrapper.QAFromOwner = inheritedRoles.QADirect; } // output.Meta_LastUpdated = input.EntityLastUpdated; output.Meta_StateId = input.EntityStateId; output.EntityTypeId = input.EntityTypeId; if (input.InLanguageCodeList != null && input.InLanguageCodeList.Any()) { //output.Meta_Language = input.InLanguageCodeList[ 0 ].TextTitle; output.InLanguage = new List <string>(); foreach (var item in input.InLanguageCodeList) { output.InLanguage.Add(item.TextTitle); } } try { if (input.HasVerificationType_Badge) { output.CTDLTypeLabel += " + Badge Issued"; } output.Image = input.Image; // if (!string.IsNullOrWhiteSpace(input.AvailabilityListing)) { output.AvailabilityListing = new List <string>() { input.AvailabilityListing } } ; if (!string.IsNullOrWhiteSpace(input.AvailableOnlineAt)) { output.AvailableOnlineAt = new List <string>() { input.AvailableOnlineAt } } ; if (input.CopyrightHolderOrganization != null && input.CopyrightHolderOrganization.Any()) { output.CopyrightHolder = new List <WMA.Outline>(); //output.CopyrightHolder2 = new List<WMA.LabelLink>(); foreach (var target in input.CopyrightHolderOrganization) { if (target != null && target.Id > 0) { //TODO - add overload to only get minimum data - like Link output.CopyrightHolder.Add(ServiceHelper.MapToOutline(target, "organization")); //var link = ServiceHelper.MapDetailLink( "organization", target.Name, target.Id ); //output.CopyrightHolder2.Add( link ); } } //or Link objects } output.CredentialStatusType = ServiceHelper.MapPropertyLabelLink(input.CredentialStatusType, searchType); output.CredentialType = ServiceHelper.MapPropertyLabelLink(input.CredentialTypeEnum, searchType); output.DateEffective = input.DateEffective; output.ExpirationDate = input.ExpirationDate; output.EstimatedDuration = ServiceHelper.MapDurationProfiles(input.EstimatedDuration); output.RenewalFrequency = ServiceHelper.MapDurationItem(input.RenewalFrequency); // if (input.DegreeConcentration != null && input.DegreeConcentration.Any()) { output.DegreeConcentration = ServiceHelper.MapPropertyLabelLinks(input.DegreeConcentration, searchType); } if (input.DegreeMajor != null && input.DegreeMajor.Any()) { output.DegreeMajor = ServiceHelper.MapPropertyLabelLinks(input.DegreeMajor, searchType); } if (input.DegreeMinor != null && input.DegreeMinor.Any()) { output.DegreeMinor = ServiceHelper.MapPropertyLabelLinks(input.DegreeMinor, searchType); } // if (input.EmbeddedCredentials != null && input.EmbeddedCredentials.Any()) { output.HasPart2 = new List <WMA.Outline>(); foreach (var target in input.EmbeddedCredentials) { if (target != null && !string.IsNullOrWhiteSpace(target.Name)) { output.HasPart2.Add(ServiceHelper.MapToOutline(target, searchType)); } } output.HasPart = ServiceHelper.MapOutlineToAJAX(output.HasPart2, "Includes {0} Credential(s)"); output.HasPart2 = null; } // if (input.IsPartOf != null && input.IsPartOf.Any()) { output.IsPartOf2 = new List <WMA.Outline>(); foreach (var target in input.IsPartOf) { if (target != null && !string.IsNullOrWhiteSpace(target.Name)) { output.IsPartOf2.Add(ServiceHelper.MapToOutline(target, searchType)); } } output.IsPartOf = ServiceHelper.MapOutlineToAJAX(output.IsPartOf2, "Is Part of {0} Credential(s)"); output.IsPartOf2 = null; } } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format(thisClassName + ".MapToAPI. Section 1, Name: {0}, Id: [1}", input.Name, input.Id)); } //addresses //MapAddress( input, ref output ); output.AvailableAt = ServiceHelper.MapAddress(input.Addresses); // output.Image = input.Image; if (!string.IsNullOrWhiteSpace(input.CredentialTypeSchema)) { output.Meta_Icon = WorkITSearchServices.GetCredentialIcon(input.CredentialTypeSchema.ToLower()); } // output.IndustryType = ServiceHelper.MapReferenceFrameworkLabelLink(input.IndustryType, searchType, CodesManager.PROPERTY_CATEGORY_NAICS); output.OccupationType = ServiceHelper.MapReferenceFrameworkLabelLink(input.OccupationType, searchType, CodesManager.PROPERTY_CATEGORY_SOC); output.InstructionalProgramType = ServiceHelper.MapReferenceFrameworkLabelLink(input.InstructionalProgramType, searchType, CodesManager.PROPERTY_CATEGORY_CIP); // output.IsReferenceVersion = input.IsReferenceVersion; // if (input.Keyword != null && input.Keyword.Any()) { output.Keyword = ServiceHelper.MapPropertyLabelLinks(input.Keyword, searchType); } if (input.Subject != null && input.Subject.Any()) { output.Subject = ServiceHelper.MapPropertyLabelLinks(input.Subject, searchType); } // output.AssessmentDeliveryType = ServiceHelper.MapPropertyLabelLinks(input.AssessmentDeliveryType, searchType); output.AudienceLevelType = ServiceHelper.MapPropertyLabelLinks(input.AudienceLevelType, searchType); output.AudienceType = ServiceHelper.MapPropertyLabelLinks(input.AudienceType, searchType); output.LearningDeliveryType = ServiceHelper.MapPropertyLabelLinks(input.LearningDeliveryType, searchType); // //condition profiles try { output.Corequisite = ServiceHelper.MapToConditionProfiles(input.Corequisite, searchType); output.Recommends = ServiceHelper.MapToConditionProfiles(input.Recommends, searchType); output.Renewal = ServiceHelper.MapToConditionProfiles(input.Renewal, searchType); output.Requires = ServiceHelper.MapToConditionProfiles(input.Requires, searchType); if (input.CommonConditions != null && input.CommonConditions.Any()) { //these will likely just be mapped to specific conditions output.CommonConditions = ServiceHelper.MapConditionManifests(input.CommonConditions, searchType); if (output.CommonConditions != null && output.CommonConditions.Any()) { foreach (var item in output.CommonConditions) { if (item.Requires != null && item.Requires.Any()) { output.Requires = AppendConditions(item.Requires, output.Requires); } if (item.Recommends != null && item.Recommends.Any()) { output.Recommends = AppendConditions(item.Recommends, output.Recommends); } if (item.Corequisite != null && item.Corequisite.Any()) { output.Corequisite = AppendConditions(item.Requires, output.Corequisite); } if (item.Renewal != null && item.Renewal.Any()) { output.Renewal = AppendConditions(item.Renewal, output.Renewal); } } } } //connection profiles if (input.CredentialConnections != null && input.CredentialConnections.Any()) { //var list = input.CredentialConnections.Where( s => s.ConditionSubTypeId == 2 && s.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_AdvancedStandingFor ).ToList(); //foreach ( var item in input.CredentialConnections ) //{ // //some default for 1?? // if ( item.ConditionSubTypeId == 2 && item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_AdvancedStandingFor ) // input.IsAdvancedStandingFor.Add( item ); // else if ( item.ConditionSubTypeId == 2 && item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_AdvancedStandingFrom ) // input.AdvancedStandingFrom.Add( item ); // else if ( item.ConditionSubTypeId == 2 && item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_PreparationFor ) // input.IsPreparationFor.Add( item ); // else if ( item.ConditionSubTypeId == 2 && item.ConnectionProfileTypeId == Entity_ConditionProfileManager.ConnectionProfileType_PreparationFrom ) // input.PreparationFrom.Add( item ); // { // //????; // } //} } output.AdvancedStandingFrom = ServiceHelper.MapToConditionProfiles(input.AdvancedStandingFrom, searchType); output.IsAdvancedStandingFor = ServiceHelper.MapToConditionProfiles(input.IsAdvancedStandingFor, searchType); // output.PreparationFrom = ServiceHelper.MapToConditionProfiles(input.PreparationFrom, searchType); output.IsPreparationFor = ServiceHelper.MapToConditionProfiles(input.IsPreparationFor, searchType); // output.IsRequiredFor = ServiceHelper.MapToConditionProfiles(input.IsRequiredFor, searchType); output.IsRecommendedFor = ServiceHelper.MapToConditionProfiles(input.IsRecommendedFor, searchType); } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format(thisClassName + ".MapToAPI. Section 2, Name: {0}, Id: [1}", input.Name, input.Id)); } //==================================== //the following can be made a common method var dataMergedRequirements = new MergedConditions(); var dataMergedRecommendations = new MergedConditions(); var dataConnections = new ConnectionData(); ServiceHelper.GetAllChildren(dataMergedRequirements, dataMergedRecommendations, dataConnections, input, null, null); //now pull out estimated durations if (dataMergedRequirements.TargetCredential != null && dataMergedRequirements.TargetCredential.Any()) { output.CredentialEstimatedDuration = ServiceHelper.GetAllDurations(dataMergedRequirements.CredentialsSansSelf(input.Id), "Estimated Time to Complete Required Embedded Credentials"); } if (dataMergedRequirements.TargetAssessment != null && dataMergedRequirements.TargetAssessment.Any()) { //output.AssessmentEstimatedDuration = ServiceHelper.GetAllDurationsOLD( dataMergedRequirements.TargetAssessment, "Estimated Time to Complete Required Assessments" ); output.AssessmentEstimatedDuration = ServiceHelper.GetAllDurations(dataMergedRequirements.TargetAssessment, "Estimated Time to Complete Required Assessments"); } if (dataMergedRequirements.TargetLearningOpportunity != null && dataMergedRequirements.TargetLearningOpportunity.Any()) { output.LearningOpportunityEstimatedDuration = ServiceHelper.GetAllDurations(dataMergedRequirements.TargetLearningOpportunity, "Estimated Time to Complete Required Learning Opportunities"); } //competencies var dataAllCompetencies = ServiceHelper.GetAllCompetencies(dataMergedRequirements); var allCompetencies = dataAllCompetencies.RequiresByFramework .Concat(dataAllCompetencies.AssessesByFramework) .Concat(dataAllCompetencies.TeachesByFramework) .ToList(); var allFrameWorks = new Dictionary <string, List <string> >(); foreach (var frameWork in allCompetencies) { if (!string.IsNullOrWhiteSpace(frameWork.CaSSViewerUrl) && !allFrameWorks.ContainsKey(frameWork.CaSSViewerUrl ?? "")) { allFrameWorks.Add(frameWork.CaSSViewerUrl, frameWork.Items.Select(m => m.TargetNode).ToList()); } } var frameworkGraphs = new List <string>(); foreach (var framework in allCompetencies) { var uri = (framework.FrameworkUri ?? "").Replace("/resources/", "/graph/"); if (framework.IsARegistryFrameworkUrl && framework.ExistsInRegistry) { var frameworkData = RegistryServices.GetRegistryData("", uri); if (!string.IsNullOrWhiteSpace(frameworkData) && frameworkData.IndexOf("<") != 0) //Avoid empty results and results like "<h2>Incomplete response received from application</h2>" { frameworkGraphs.Add(frameworkData); } } } if (dataAllCompetencies.RequiresByFramework.Count() > 0) { } if (dataAllCompetencies.AssessesByFramework.Count() > 0) { } if (dataAllCompetencies.TeachesByFramework.Count() > 0) { } //======================================= try { // if (input.CommonCosts != null && input.CommonCosts.Any()) { output.CommonCosts = ServiceHelper.MapCostManifests(input.CommonCosts, searchType); output.EstimatedCost = new List <Models.Elastic.CostProfile>(); foreach (var item in output.CommonCosts) { output.EstimatedCost.AddRange(item.EstimatedCost); } output.CommonCosts = null; } if (input.EstimatedCost != null && input.EstimatedCost.Any()) { if (output.EstimatedCost == null) { output.EstimatedCost = new List <Models.Elastic.CostProfile>(); } var estimatedCost = ServiceHelper.MapCostProfiles(input.EstimatedCost, searchType); if (estimatedCost != null && estimatedCost.Any()) { output.EstimatedCost.AddRange(estimatedCost); } } //loop costs if (input.Requires.SelectMany(x => x.TargetLearningOpportunity.Where(y => y.EstimatedCost.Count() + y.CommonCosts.Count() > 0)).Count() > 0) { var list = input.Requires.SelectMany(x => x.TargetLearningOpportunity).ToList(); foreach (var item in list) { if (item.CommonCosts.Any() || item.EstimatedCost.Any()) { var commonCosts = ServiceHelper.MapCostManifests(item.CommonCosts, searchType); output.LearningOpportunityCost = new List <Models.Elastic.CostProfile>(); if (commonCosts != null && commonCosts.Any()) { foreach (var cc in commonCosts) { output.LearningOpportunityCost.AddRange(cc.EstimatedCost); } } } // if (item.EstimatedCost != null && item.EstimatedCost.Any()) { if (output.LearningOpportunityCost == null) { output.LearningOpportunityCost = new List <Models.Elastic.CostProfile>(); } var estimatedCost = ServiceHelper.MapCostProfiles(item.EstimatedCost, searchType); if (estimatedCost != null && estimatedCost.Any()) { output.LearningOpportunityCost.AddRange(estimatedCost); } } } } //asmt costs if (input.Requires.SelectMany(x => x.TargetAssessment.Where(y => y.EstimatedCost.Count() + y.CommonCosts.Count() > 0)).Count() > 0) { var list = input.Requires.SelectMany(x => x.TargetAssessment).ToList(); foreach (var item in list) { if (item.CommonCosts.Any() || item.EstimatedCost.Any()) { var commonCosts = ServiceHelper.MapCostManifests(item.CommonCosts, searchType); output.AssessmentCost = new List <Models.Elastic.CostProfile>(); if (commonCosts != null && commonCosts.Any()) { foreach (var cc in commonCosts) { output.AssessmentCost.AddRange(cc.EstimatedCost); } } } // if (item.EstimatedCost.Any() || item.EstimatedCost.Any()) { if (output.AssessmentCost == null) { output.AssessmentCost = new List <Models.Elastic.CostProfile>(); } var estimatedCost = ServiceHelper.MapCostProfiles(item.EstimatedCost, searchType); if (estimatedCost != null && estimatedCost.Any()) { output.AssessmentCost.AddRange(estimatedCost); } } } } } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format(thisClassName + ".MapToAPI. Section 3, Name: {0}, Id: [1}", input.Name, input.Id)); } // if (input.FinancialAssistance != null && input.FinancialAssistance.Any()) { output.FinancialAssistance = ServiceHelper.MapFinancialAssistanceProfiles(input.FinancialAssistance, searchType); } // output.CredentialId = input.CredentialId; output.ISICV4 = input.ISICV4; //InLanguage // output.Identifier = ServiceHelper.MapIdentifierValue(input.Identifier); // MapProcessProfiles(input, ref output); output.SameAs = ServiceHelper.MapTextValueProfileTextValue(input.SameAs); // //output.ProcessStandards = input.ProcessStandards; //output.ProcessStandardsDescription = input.ProcessStandardsDescription; output.ProcessStandards = ServiceHelper.MapPropertyLabelLink(input.ProcessStandards, "Process Standards", input.ProcessStandardsDescription); // output.Revocation = ServiceHelper.MapRevocationProfile(searchType, input.Revocation); //these are can be links to existing credentials, likely to be in finder output.LatestVersion = ServiceHelper.MapPropertyLabelLink(input.LatestVersion, "Latest Version"); output.NextVersion = ServiceHelper.MapPropertyLabelLink(input.NextVersion, "Next Version"); output.PreviousVersion = ServiceHelper.MapPropertyLabelLink(input.PreviousVersion, "Previous Version"); output.Supersedes = ServiceHelper.MapPropertyLabelLink(input.Supersedes, "Supersedes"); output.SupersededBy = ServiceHelper.MapPropertyLabelLink(input.SupersededBy, "Superseded By"); // output.TargetPathway = ServiceHelper.MapPathwayToAJAXSettings(input.TargetPathway, "Has {0} Target Pathway(s)"); // output.VersionIdentifier = ServiceHelper.MapIdentifierValue(input.VersionIdentifierList, "Version Identifier"); try { MapJurisdictions(input, ref output); // //QA received //==> need to exclude 30-published by if (input.OrganizationRole.Any()) { output.QAReceived = ServiceHelper.MapQAReceived(input.OrganizationRole, searchType); //old var renewedBy2 = ServiceHelper.MapRoleReceived(input.OrganizationRole, searchType, Entity_AgentRelationshipManager.ROLE_TYPE_RenewedBy); var revokedBy2 = ServiceHelper.MapRoleReceived(input.OrganizationRole, searchType, Entity_AgentRelationshipManager.ROLE_TYPE_RevokedBy); //new output.RenewedBy = ServiceHelper.MapOutlineToAJAX(renewedBy2, "Renewed by {0} Organization(s)"); output.RevokedBy = ServiceHelper.MapOutlineToAJAX(revokedBy2, "Revoked by {0} Organization(s)"); } } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format(thisClassName + ".MapToAPI. Section 4, Name: {0}, Id: [1}", input.Name, input.Id)); } // // return(output); }
private static MCD.LearningOpportunityDetail MapToAPI(ThisEntity input) { var searchType = "learningopportunity"; var output = new MCD.LearningOpportunityDetail() { Meta_Id = input.Id, CTID = input.CTID, Name = input.Name, FriendlyName = HttpUtility.UrlPathEncode(input.Name), Description = input.Description, SubjectWebpage = input.SubjectWebpage, EntityTypeId = 7, CredentialRegistryURL = RegistryServices.GetResourceUrl(input.CTID), RegistryData = ServiceHelper.FillRegistryData(input.CTID) }; output.Meta_LastUpdated = input.EntityLastUpdated; output.Meta_StateId = input.EntityStateId; if (input.InLanguageCodeList != null && input.InLanguageCodeList.Any()) { //output.Meta_Language = input.InLanguageCodeList[ 0 ].TextTitle; output.InLanguage = new List <string>(); foreach (var item in input.InLanguageCodeList) { output.InLanguage.Add(item.TextTitle); } } if (input.OwningOrganizationId > 0) { output.OwnedByLabel = ServiceHelper.MapDetailLink("Organization", input.OrganizationName, input.OwningOrganizationId); } var work = ServiceHelper.MapOrganizationRoleProfileToOutline(input.OrganizationRole, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER); output.OwnedBy = ServiceHelper.MapOutlineToAJAX(work, ""); // work = ServiceHelper.MapOrganizationRoleProfileToOutline(input.OrganizationRole, Entity_AgentRelationshipManager.ROLE_TYPE_OFFERED_BY); output.OfferedBy = ServiceHelper.MapOutlineToAJAX(work, "Offered by {0} Organization(s)"); // // //QA for owner,not offerer if (input.OwningOrganization != null && input.OwningOrganization.Id > 0) { if (input.OwningOrganization.OrganizationRole_Recipient != null && input.OwningOrganization.OrganizationRole_Recipient.Any()) { output.OwnerQAReceived = ServiceHelper.MapQAReceived(input.OwningOrganization.OrganizationRole_Recipient, searchType); } } // output.AssessmentMethodType = ServiceHelper.MapPropertyLabelLinks(input.AssessmentMethodType, searchType); output.AssessmentMethodDescription = input.AssessmentMethodDescription; if (!string.IsNullOrWhiteSpace(input.AvailabilityListing)) { output.AvailabilityListing = new List <string>() { input.AvailabilityListing } } ; if (!string.IsNullOrWhiteSpace(input.AvailableOnlineAt)) { output.AvailableOnlineAt = new List <string>() { input.AvailableOnlineAt } } ; //MapAddress( input, ref output ); output.AvailableAt = ServiceHelper.MapAddress(input.Addresses); // output.AudienceLevelType = ServiceHelper.MapPropertyLabelLinks(input.AudienceLevelType, searchType); output.AudienceType = ServiceHelper.MapPropertyLabelLinks(input.AudienceType, searchType); output.CreditUnitTypeDescription = input.CreditUnitTypeDescription; output.CreditValue = ServiceHelper.MapValueProfile(input.CreditValue, searchType); // output.DateEffective = input.DateEffective; output.ExpirationDate = input.ExpirationDate; output.DeliveryType = ServiceHelper.MapPropertyLabelLinks(input.DeliveryType, searchType); output.DeliveryTypeDescription = input.DeliveryTypeDescription; output.EstimatedDuration = ServiceHelper.MapDurationProfiles(input.EstimatedDuration); // //CostProfiles if (input.CommonCosts != null && input.CommonCosts.Any()) { output.CommonCosts = ServiceHelper.MapCostManifests(input.CommonCosts, searchType); output.EstimatedCost = new List <Models.Elastic.CostProfile>(); foreach (var item in output.CommonCosts) { output.EstimatedCost.AddRange(item.EstimatedCost); } output.CommonCosts = null; } if (input.EstimatedCost != null && input.EstimatedCost.Any()) { if (output.EstimatedCost == null) { output.EstimatedCost = new List <Models.Elastic.CostProfile>(); } var estimatedCost = ServiceHelper.MapCostProfiles(input.EstimatedCost, searchType); if (estimatedCost != null && estimatedCost.Any()) { output.EstimatedCost.AddRange(estimatedCost); } } // if (input.FinancialAssistance != null && input.FinancialAssistance.Any()) { output.FinancialAssistance = ServiceHelper.MapFinancialAssistanceProfiles(input.FinancialAssistance, searchType); } //condition profiles output.Corequisite = ServiceHelper.MapToConditionProfiles(input.Corequisite, searchType); output.EntryCondition = ServiceHelper.MapToConditionProfiles(input.EntryCondition, searchType); output.Recommends = ServiceHelper.MapToConditionProfiles(input.Recommends, searchType); output.EntryCondition = ServiceHelper.MapToConditionProfiles(input.EntryCondition, searchType); output.Requires = ServiceHelper.MapToConditionProfiles(input.Requires, searchType); // if (input.CommonConditions != null && input.CommonConditions.Any()) { output.CommonConditions = ServiceHelper.MapConditionManifests(input.CommonConditions, searchType); if (output.CommonConditions != null && output.CommonConditions.Any()) { foreach (var item in output.CommonConditions) { if (item.Requires != null && item.Requires.Any()) { output.Requires = ServiceHelper.AppendConditions(item.Requires, output.Requires); } if (item.Recommends != null && item.Recommends.Any()) { output.Recommends = ServiceHelper.AppendConditions(item.Recommends, output.Recommends); } if (item.Corequisite != null && item.Corequisite.Any()) { output.Corequisite = ServiceHelper.AppendConditions(item.Requires, output.Corequisite); } if (item.EntryCondition != null && item.EntryCondition.Any()) { output.EntryCondition = ServiceHelper.AppendConditions(item.EntryCondition, output.EntryCondition); } } } } // //connection profiles output.AdvancedStandingFrom = ServiceHelper.MapToConditionProfiles(input.AdvancedStandingFrom, searchType); output.IsAdvancedStandingFor = ServiceHelper.MapToConditionProfiles(input.IsAdvancedStandingFor, searchType); // output.PreparationFrom = ServiceHelper.MapToConditionProfiles(input.PreparationFrom, searchType); output.IsPreparationFor = ServiceHelper.MapToConditionProfiles(input.IsPreparationFor, searchType); // output.IsRequiredFor = ServiceHelper.MapToConditionProfiles(input.IsRequiredFor, searchType); output.IsRecommendedFor = ServiceHelper.MapToConditionProfiles(input.IsRecommendedFor, searchType); // // if (input.HasPart != null && input.HasPart.Any()) { output.HasPart = new List <MCD.Outline>(); foreach (var target in input.HasPart) { if (target != null && !string.IsNullOrWhiteSpace(target.Name)) { output.HasPart.Add(ServiceHelper.MapToOutline(target, searchType)); } } } // if (input.IsPartOf != null && input.IsPartOf.Any()) { output.IsPartOf = new List <MCD.Outline>(); foreach (var target in input.IsPartOf) { if (target != null && !string.IsNullOrWhiteSpace(target.Name)) { output.IsPartOf.Add(ServiceHelper.MapToOutline(target, searchType)); } } } // output.Identifier = ServiceHelper.MapIdentifierValue(input.Identifier); // output.IndustryType = ServiceHelper.MapReferenceFrameworkLabelLink(input.IndustryType, searchType, CodesManager.PROPERTY_CATEGORY_NAICS); output.OccupationType = ServiceHelper.MapReferenceFrameworkLabelLink(input.OccupationType, searchType, CodesManager.PROPERTY_CATEGORY_SOC); output.InstructionalProgramType = ServiceHelper.MapReferenceFrameworkLabelLink(input.InstructionalProgramType, searchType, CodesManager.PROPERTY_CATEGORY_CIP); output.IsReferenceVersion = input.IsReferenceVersion; // MapJurisdictions(input, ref output); // if (input.Keyword != null && input.Keyword.Any()) { output.Keyword = ServiceHelper.MapPropertyLabelLinks(input.Keyword, searchType); } if (input.Subject != null && input.Subject.Any()) { output.Subject = ServiceHelper.MapPropertyLabelLinks(input.Subject, searchType); } // output.LearningMethodType = ServiceHelper.MapPropertyLabelLinks(input.LearningMethodType, searchType); output.LearningMethodDescription = input.LearningMethodDescription; // //none yet, leave here for likely additions //MapProcessProfiles( input, ref output ); // output.SameAs = ServiceHelper.MapTextValueProfileTextValue(input.SameAs); // output.VersionIdentifier = ServiceHelper.MapIdentifierValue(input.VersionIdentifierList, "Version Identifier"); //QA received //==> need to exclude 30-published by if (input.OrganizationRole.Any()) { output.QAReceived = ServiceHelper.MapQAReceived(input.OrganizationRole, searchType); } return(output); }
public string Import(string registryEntityType, int entityTypeId, string startingDate, string endingDate, int maxRecords, bool downloadOnly, ref int recordsImported, string sortOrder = "asc") { bool importingThisType = UtilityManager.GetAppKeyValue("importing_" + registryEntityType, true); if (!importingThisType) { LoggingHelper.DoTrace(1, string.Format("=== ***************** Skipping import of {0} ***************** ", registryEntityType)); return("Skipped import of " + registryEntityType); } LoggingHelper.DoTrace(1, string.Format("=== ***************** Importing {0} ***************** ", registryEntityType)); //JsonEntity input = new JsonEntity(); ReadEnvelope envelope = new ReadEnvelope(); List <ReadEnvelope> list = new List <ReadEnvelope>(); string entityType = registryEntityType; CodeItem ci = CodesManager.Codes_EntityType_Get(entityTypeId); if (ci != null && ci.Id > 0) { entityType = ci.Title; } int pageNbr = 1; int pageSize = UtilityManager.GetAppKeyValue("importPageSize", 100); string importResults = ""; string importNote = ""; //ThisEntity output = new ThisEntity(); List <string> messages = new List <string>(); int cntr = 0; int actualTotalRows = 0; int pTotalRows = 0; int exceptionCtr = 0; string statusMessage = ""; bool isComplete = false; bool importSuccessfull = true; //will need to handle multiple calls - watch for time outs while (pageNbr > 0 && !isComplete) { //19-09-22 chg to use RegistryServices to remove duplicate services list = RegistryServices.Search(registryEntityType, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, Community, sortOrder); //list = RegistryImport.GetLatest( registryEntityType, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, Community ); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { //importNote = registryEntityType + ": No records where found for date range "; //Console.WriteLine( thisClassName + importNote ); LoggingHelper.DoTrace(4, registryEntityType + ": No records where found for date range. "); } else if (cntr < actualTotalRows) { //if no data found and have not processed actual rows, could have been an issue with the search. //perhaps should be an error to ensure followup LoggingHelper.DoTrace(2, string.Format("**************** WARNING -Import for '{0}' didn't find data on this pass, but has only processed {1} of an expected {2} records.", registryEntityType, cntr, actualTotalRows)); LoggingHelper.LogError(string.Format("**************** WARNING -Import for '{0}' didn't find data on this pass, but has only processed {1} of an expected {2} records.", registryEntityType, cntr, actualTotalRows), true, "Finder Import Ended Early"); } break; } if (pageNbr == 1) { actualTotalRows = pTotalRows; LoggingHelper.DoTrace(2, string.Format("Import {0} Found {1} records to process.", registryEntityType, pTotalRows)); } foreach (ReadEnvelope item in list) { cntr++; importSuccessfull = ProcessEnvelope(item, registryEntityType, entityTypeId, cntr, downloadOnly); if (maxRecords > 0 && cntr >= maxRecords) { break; } } //end foreach pageNbr++; if ((maxRecords > 0 && cntr >= maxRecords)) { isComplete = true; LoggingHelper.DoTrace(2, string.Format("Import {2} EARLY EXIT. Completed {0} records out of a total of {1} for {2} ", cntr, pTotalRows, registryEntityType)); } else if (cntr >= actualTotalRows) { isComplete = true; //LoggingHelper.DoTrace( 2, string.Format( "Completed {0} records out of a total of {1} for {2}", cntr, pTotalRows, registryEntityType ) ); } //if ( pageNbr * pageSize < pTotalRows ) // pageNbr++; //else // isComplete = true; } importResults = string.Format("Import {0} - Processed {1} records, with {2} exceptions. \r\n", registryEntityType, cntr, exceptionCtr); LoggingHelper.DoTrace(2, importResults); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } recordsImported += cntr; return(importResults); }
public bool ProcessEnvelope(ReadEnvelope item, string registryEntityType, int entityTypeId, int cntr, bool doingDownloadOnly = false) { bool importSuccessfull = false; if (item == null || item.DecodedResource == null) { return(false); } int newImportId = 0; var status = new SaveStatus { DoingDownloadOnly = doingDownloadOnly, ValidationGroup = string.Format("{0} Import", registryEntityType) }; DateTime started = DateTime.Now; DateTime envelopeUpdateDate = new DateTime(); DateTime createDate = new DateTime(); if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate)) { status.SetEnvelopeCreated(createDate); } if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate)) { status.SetEnvelopeUpdated(envelopeUpdateDate); } LoggingHelper.DoTrace(2, string.Format("{0}. {1} CTID {2}, Updated: {3} ", cntr, registryEntityType, item.EnvelopeCetermsCtid, envelopeUpdateDate.ToString())); var messages = new List <string>(); string importError = ""; importSuccessfull = false; //var documentPublishedBy = item.documentPublishedBy ?? "" //====================================================== //21-01-28 mp - moving common code back here to improve maintenance if (item.documentPublishedBy != null) { //only providing DocumentPublishedBy where apparantly a 3PP if (item.documentOwnedBy == null || (item.documentPublishedBy != item.documentOwnedBy)) { status.DocumentPublishedBy = item.documentPublishedBy; } } else { //will need to check elsewhere //OR as part of import check if existing one had 3rd party publisher } string payload = item.DecodedResource.ToString(); status.EnvelopeId = item.EnvelopeIdentifier; var ctid = item.EnvelopeCetermsCtid; var envelopeCtdlType = item.EnvelopeCtdlType; string ctdlType = RegistryServices.GetResourceType(payload); //string envelopeUrl = RegistryServices.GetEnvelopeUrl( envelopeIdentifier ); LoggingHelper.WriteLogFile(UtilityManager.GetAppKeyValue("logFileTraceLevel", 5), item.EnvelopeCetermsCtid + "_" + ctdlType, payload, "", false); // try { switch (entityTypeId) { case 1: //importSuccessfull = credImportMgr.ProcessEnvelope( item, status ); if (ctdlType.IndexOf("Organization") > -1 || ctdlType.IndexOf("LearningOpportunity") > -1 || ctdlType.IndexOf("Assessment") > -1) { //how can this happen???? //- expected as the FTS search will also search blank nodes importError = string.Format("*****WHILE DOING A CREDENTIAL IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid); //status.AddError( importError ); //LoggingHelper.DoTrace( 1, importError ); } //else if ( ctdlType != envelopeCtdlType ) //{ // LoggingHelper.DoTrace( 1, "___skipping blank node" ); //} else { importSuccessfull = credImportMgr.ImportV3(payload, status); } break; case 2: //importSuccessfull = orgImportMgr.ProcessEnvelope( item, status ); if (ctdlType.IndexOf("Organization") > -1) { importSuccessfull = orgImportMgr.ImportV3(payload, status); } else { //how can this happen???? importError = string.Format("*****WHILE DOING AN ORGANIZATION IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid); status.AddError(importError); LoggingHelper.DoTrace(1, importError); } break; case 3: if (ctdlType.IndexOf("Assessment") > -1) { importSuccessfull = asmtImportMgr.ProcessEnvelope(item, status); } else { //how can this happen???? importError = string.Format("*****WHILE DOING AN Assessment IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid); status.AddError(importError); LoggingHelper.DoTrace(1, importError); } break; case 7: if (ctdlType.IndexOf("LearningOpportunity") > -1) { importSuccessfull = loppImportMgr.ProcessEnvelope(item, status); } else { //how can this happen???? //importError = string.Format( "*****WHILE DOING A LearningOpportunity IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid ); //status.AddError( importError ); //LoggingHelper.DoTrace( 1, importError ); } break; case 8: // if (ctdlType.IndexOf("Pathway") > -1) { importSuccessfull = pathwayImportMgr.ProcessEnvelope(item, status); } else { //how can this happen???? //importError = string.Format( "*****WHILE DOING A Pathway IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid ); //status.AddError( importError ); //LoggingHelper.DoTrace( 1, importError ); } break; case 9: // DisplayMessages(string.Format("{0}. Rubrics ({1}) are not handled at this time. ", cntr, entityTypeId)); return(true); case 10: case 17: if (ctdlType.IndexOf("CompetencyFramework") > -1) { importSuccessfull = cfImportMgr.ProcessEnvelope(item, status); } else { //how can this happen???? //importError = string.Format( "*****WHILE DOING A CompetencyFramework IMPORT (#{0}), A RECORD OF TYPE: '{1}', CTID: '{2}' WAS ENCOUNTERED! *********************", cntr, ctdlType, ctid ); //status.AddError( importError ); //LoggingHelper.DoTrace( 1, importError ); } break; case 11: //concept scheme //DisplayMessages( string.Format( "{0}. Concept Schemes ({1}) are not handled at this time. ", cntr, entityTypeId ) ); importSuccessfull = new ImportConceptSchemes().ProcessEnvelope(item, status); return(true); case 19: importSuccessfull = cndManImportMgr.ProcessEnvelope(item, status); break; case 20: importSuccessfull = cstManImportMgr.ProcessEnvelope(item, status); break; case 23: importSuccessfull = new ImportPathwaySets().ProcessEnvelope(item, status); //DisplayMessages( string.Format( "{0}. PathwaySets ({1}) are not handled at this time. ", cntr, entityTypeId ) ); break; case 26: importSuccessfull = tvpImportMgr.ProcessEnvelope(item, status); //DisplayMessages( string.Format( "{0}. TransferValueProfiles ({1}) are not handled at this time. ", cntr, entityTypeId ) ); break; default: DisplayMessages(string.Format("{0}. RegistryImport. Unhandled Entity type encountered: {1} ", cntr, entityTypeId)); break; } } catch (Exception ex) { if (ex.Message.IndexOf("Path '@context', line 1") > 0) { importError = "The referenced registry document is using an old schema. Please republish it with the latest schema!"; status.AddError(importError); } else { LoggingHelper.LogError(ex, string.Format(registryEntityType + " Exception encountered in envelopeId: {0}", item.EnvelopeIdentifier), true, "CredentialFinder Import exception"); status.AddError(ex.Message); importError = ex.Message; } //make continue on exceptions an option //exceptionCtr++; //if ( maxExceptions > 0 && exceptionCtr > maxExceptions ) //{ // //arbitrarily stop if large number of exceptions // importNote = string.Format( thisClassName + " - {0} Many exceptions ({1}) were encountered during import - abandoning.", entityType, exceptionCtr ); // //Console.WriteLine( importNote ); // LoggingHelper.DoTrace( 1, importNote ); // LoggingHelper.LogError( importNote, true, thisClassName + "- many exceptions" ); // isComplete = true; // break; //} } finally { if (!importSuccessfull) { if (string.IsNullOrWhiteSpace(importError)) { importError = string.Join("\r\n", status.GetAllMessages().ToArray()); } } //store document //add indicator of success newImportId = importMgr.Add(item, entityTypeId, status.Ctid, importSuccessfull, importError, ref messages); if (newImportId > 0 && status.Messages != null && status.Messages.Count > 0) { //add indicator of current recored string msg = string.Format("========= Messages for {4}, EnvelopeIdentifier: {0}, ctid: {1}, Id: {2}, rowId: {3} =========", item.EnvelopeIdentifier, status.Ctid, status.DocumentId, status.DocumentRowId, registryEntityType); //ensure status has info on the current context, so can be include in messages. Or N/A. The message has the Import.Staging record as the parent importMgr.AddMessages(newImportId, status, ref messages); } TimeSpan duration = DateTime.Now.Subtract(started); LoggingHelper.DoTrace(2, string.Format(" Total Duration: {0:N2} seconds ", duration.TotalSeconds)); } //finally return(importSuccessfull); }
/// <summary> /// Handle deleted records for the requested time period /// Save to file systems with prefix of Deleted /// </summary> /// <param name="community"></param> /// <param name="maxRecords"></param> /// <param name="recordsDeleted"></param> /// <returns></returns> public string HandleDeletes(string community, int maxRecords, ref int recordsDeleted) { int pageNbr = 1; int pageSize = 50; //string importError = ""; //may want to just do all types! string type = ""; List <string> messages = new List <string>(); List <ReadEnvelope> list = new List <ReadEnvelope>(); SaveStatus status = new SaveStatus(); int pTotalRows = 0; int cntr = 0; bool isComplete = false; int exceptionCtr = 0; string statusMessage = ""; string importResults = ""; string importNote = ""; LoggingHelper.DoTrace(1, string.Format("=== DELETE Check for: '{0}' to '{1}' ===", StartingDate, EndingDate)); //registryImport.StartingDate = "2017-10-29T00:00:00"; try { while (pageNbr > 0 && !isComplete) { list = GetDeleted(community, type, StartingDate, EndingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { importNote = "Deletes: No records where found for date range "; //Console.WriteLine( thisClassName + ".HandleDeletes() - " + importNote ); LoggingHelper.DoTrace(1, string.Format("Download.Main.HandleDeletes() Community: {0} - ", community) + importNote); } break; } foreach (ReadEnvelope item in list) { cntr++; string payload = item.DecodedResource.ToString(); string ctdlType = RegistryServices.GetResourceType(payload); string ctid = item.EnvelopeCtid; LoggingHelper.DoTrace(6, string.Format("{0}. ctdlType: {1} ctid: {2} ", cntr, ctdlType, ctid)); try { //only need the envelopeId and type //so want a full delete, or set EntityStateId to 0 - just as a precaution messages = new List <string>(); //action - place in a deleted folder? LoggingHelper.WriteLogFile(1, "Deleted_" + ctdlType + "_" + ctid, payload, "", false); } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format("Exception encountered in envelopeId: {0}", item.EnvelopeIdentifier), false, "CredentialFinder Import exception"); //importError = ex.Message; } if (maxRecords > 0 && cntr > maxRecords) { break; } } //foreach ( ReadEnvelope item in list ) pageNbr++; if ((maxRecords > 0 && cntr > maxRecords) || cntr > pTotalRows) { isComplete = true; DisplayMessages(string.Format("Delete EARLY EXIT. Completed {0} records out of a total of {1} ", cntr, pTotalRows)); } } //while //delete from elastic if (cntr > 0) { messages = new List <string>(); } importResults = string.Format("HandleDeletes - Processed {0} records, with {1} exceptions. \r\n", cntr, exceptionCtr); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } } catch (Exception ex) { LoggingHelper.LogError(ex, "Import.HandleDeletes"); } //actually only attepted at this time, need to account for errors! recordsDeleted = cntr; return(importResults); }
private void Regedit() { RegistryServices.OpenRegedit(this.IsHKLM); }
private static WMA.OrganizationDetail MapToAPI(Organization input, OrganizationManager.OrganizationRequest request) { var output = new WMA.OrganizationDetail() { Meta_Id = input.Id, Name = input.Name, FriendlyName = HttpUtility.UrlPathEncode(input.Name), Description = input.Description, SubjectWebpage = input.SubjectWebpage, EntityTypeId = 2, CredentialRegistryURL = RegistryServices.GetResourceUrl(input.CTID), RegistryData = ServiceHelper.FillRegistryData(input.CTID) }; if (input.ISQAOrganization) { output.CTDLType = "ceterms:QACredentialOrganization"; output.CTDLTypeLabel = "Quality Assurance Organization"; } else { output.CTDLType = "ceterms:CredentialOrganization"; output.CTDLTypeLabel = "Credentialing Organization"; } //output.CTDLType = record.AgentDomainType; output.AgentSectorType = ServiceHelper.MapPropertyLabelLinks(input.AgentSectorType, "organization"); output.AgentType = ServiceHelper.MapPropertyLabelLinks(input.AgentType, "organization"); //TODO consider using LabelLink to provide both the URL and description output.AgentPurpose = ServiceHelper.MapPropertyLabelLink(input.AgentPurpose, "Purpose", input.AgentPurposeDescription); //output.AgentPurpose = ServiceHelper.MapPropertyLabelLink( input.AgentPurpose, "Purpose" ); //output.AgentPurposeDescription = input.AgentPurposeDescription; // output.AlternateName = input.AlternateName; if (!string.IsNullOrWhiteSpace(input.AvailabilityListing)) { output.AvailabilityListing = new List <string>() { input.AvailabilityListing } } ; else { output.AvailabilityListing = input.AvailabilityListings; } // output.CTID = input.CTID; if (input.Emails != null && input.Emails.Any()) { output.Email = input.Emails.Select(s => s.TextValue).ToList(); } output.Meta_LastUpdated = input.EntityLastUpdated; output.Meta_StateId = input.EntityStateId; output.EntityTypeId = input.EntityTypeId; output.FoundingDate = input.FoundingDate; output.FriendlyName = input.FriendlyName; //identifiers output.Identifier = ServiceHelper.MapIdentifierValue(input.Identifier); output.DUNS = input.ID_DUNS; output.FEIN = input.ID_FEIN; output.IPEDSID = input.ID_IPEDSID; output.ISICV4 = input.ID_ISICV4; output.LEICode = input.ID_LEICode; output.NECS = input.ID_NECS; output.OPEID = input.ID_OPEID; // output.Image = input.Image; output.IndustryType = ServiceHelper.MapReferenceFrameworkLabelLink(input.IndustryType, searchType, CodesManager.PROPERTY_CATEGORY_NAICS); //output.IsReferenceVersion = record.IsReferenceVersion; // if (input.Keyword != null && input.Keyword.Any()) { output.Keyword = ServiceHelper.MapPropertyLabelLinks(input.Keyword, "organization"); } //output.MissionAndGoalsStatement = ServiceHelper.MapPropertyLabelLink( input.MissionAndGoalsStatement, "Mission Statement" ); //output.MissionAndGoalsStatementDescription = input.MissionAndGoalsStatementDescription; output.MissionAndGoalsStatement = ServiceHelper.MapPropertyLabelLink(input.MissionAndGoalsStatement, "Mission Statement", input.MissionAndGoalsStatementDescription); //this is NOT pertinent to organization //output.OrganizationId = org.OrganizationId; //output.OrganizationName = org.OrganizationName; //output.OrganizationSubjectWebpage = ""; output.ServiceType = ServiceHelper.MapPropertyLabelLinks(input.ServiceType, "organization"); output.SameAs = ServiceHelper.MapTextValueProfileTextValue(input.SameAs); output.SocialMedia = ServiceHelper.MapTextValueProfileTextValue(input.SocialMediaPages); //output.TransferValueStatement = ServiceHelper.MapPropertyLabelLink( input.TransferValueStatement, "Transfer Value Statement" ); //output.TransferValueStatementDescription = input.TransferValueStatementDescription; output.TransferValueStatement = ServiceHelper.MapPropertyLabelLink(input.TransferValueStatement, "Transfer Value Statement", input.TransferValueStatementDescription); //input.FriendlyName = HttpUtility.UrlPathEncode ( input.Name ); //searches var links = new List <WMA.LabelLink>(); output.Connections = null; if (input.TotalCredentials > 0) { //output.CredentialsSearch = ServiceHelper.MapEntitySearchLink( org.Id, org.Name, org.TotalCredentials, "Owns/Offers {0} Credential(s)", "credential" ); //output.Connections.Add( output.CredentialsSearch ); ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalCredentials, "Owns/Offers {0} Credential(s)", "credential", ref links); } if (input.TotalLopps > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalLopps, "Owns/Offers {0} Learning Opportunity(ies)", "learningopportunity", ref links); } if (input.TotalAssessments > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalAssessments, "Owns/Offers {0} Assesment(s)", "assessment", ref links); } if (input.TotalPathwaySets > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalPathwaySets, "Owns {0} Pathway Set(s)", "pathwayset", ref links); } if (input.TotalPathways > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalPathways, "Owns {0} Pathway(s)", "pathway", ref links); } if (input.TotalTransferValueProfiles > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalTransferValueProfiles, "Owns {0} Transfer Value Profiles(s)", "transfervalue", ref links); } if (input.TotalFrameworks > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalFrameworks, "Owns {0} Competency Framework(s)", "competencyframework", ref links); } if (input.TotalConceptSchemes > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.TotalConceptSchemes, "Owns {0} Concept Scheme(s)", "conceptscheme", ref links); } //21-03-10 combining revokes and renews if (input.RevokesCredentials > 0 || input.RenewsCredentials > 0) { ServiceHelper.MapEntitySearchLink(input.Id, input.Name, input.RevokesCredentials + input.RenewsCredentials, "Renews/Revokes {0} Credential(s)", "credential", ref links, "11, 13"); } //if ( org.RegulatesCredentials > 0 ) // ServiceHelper.MapEntitySearchLink( org.Id, org.Name, org.RegulatesCredentials, "Regulates {0} Credential(s)", "credential", ref links, "12" ); //if ( input.RenewsCredentials > 0 ) // ServiceHelper.MapEntitySearchLink( input.Id, input.Name, input.RenewsCredentials, "Renews {0} Credential(s)", "credential", ref links, "13" ); // if (links.Any()) { output.Connections = links; } //need to handle other roles: renews, revokes, regulates //QA performed output.QAPerformed = new List <WMA.LabelLink>(); links = new List <WMA.LabelLink>(); if (input.QAPerformedOnCredentialsCount > 0) { ServiceHelper.MapQAPerformedLink(input.Id, input.Name, input.QAPerformedOnCredentialsCount, "QA Identified as Performed on {0} Credential(s)", "credential", ref links); } if (input.QAPerformedOnOrganizationsCount > 0) { ServiceHelper.MapQAPerformedLink(input.Id, input.Name, input.QAPerformedOnOrganizationsCount, "QA Identified as Performed on {0} Organization(s)", "organization", ref links); } if (input.QAPerformedOnAssessmentsCount > 0) { ServiceHelper.MapQAPerformedLink(input.Id, input.Name, input.QAPerformedOnAssessmentsCount, "QA Identified as Performed on {0} Assessment(s)", "assessment", ref links); } if (input.QAPerformedOnLoppsCount > 0) { ServiceHelper.MapQAPerformedLink(input.Id, input.Name, input.QAPerformedOnLoppsCount, "QA Identified as Performed on {0} Learning Opportunity(ies)", "learningopportunity", ref links); } if (links.Any()) { output.QAPerformed = links; } //21-03-12 these should be populated now. Be sure to remove them from QaReceived. //need to be consistent. Seems this property will use acting agent, but dept/sub will use participating agent output.ParentOrganization = ServiceHelper.MapOrganizationRoleProfileToAJAX(input.ParentOrganizations, "Has Parent Organization"); if (input.ParentOrganization != null && input.ParentOrganization.Any()) { var parents = ServiceHelper.MapOrganizationRoleProfileToOutline(input.ParentOrganizations, Entity_AgentRelationshipManager.ROLE_TYPE_PARENT_ORG); if (parents != null && parents.Any()) { //just return one for now //output.ParentOrganizationOutline = parents[ 0 ]; } } // output.Department = ServiceHelper.MapOrganizationRoleProfileToAJAX(input.OrganizationRole_Dept, "Has {0} Departments(s)"); output.SubOrganization = ServiceHelper.MapOrganizationRoleProfileToAJAX(input.OrganizationRole_Subsidiary, "Has {0} Suborganization(s)"); // //QAReceived //==> need to exclude 30-published by //also check for 20, 21 and move to dept, subsidiary, parent var qaroles = "1,2,10,12"; if (input.OrganizationRole_Recipient.Any()) { output.QAReceived = ServiceHelper.MapQAReceived(input.OrganizationRole_Recipient, searchType); /* * output.QAReceived = new List<WMA.OrganizationRoleProfile>(); * foreach ( var item in input.OrganizationRole_Recipient ) * { * var orp = new WMA.OrganizationRoleProfile() * { * Label = string.IsNullOrWhiteSpace( item.ProfileName ) ? item.ParentSummary : item.ProfileName, * Description = item.Description ?? "" * }; * if ( string.IsNullOrWhiteSpace( orp.Label ) ) * { * if ( item.ActingAgent != null && item.ActingAgent.Id > 0 ) * { * orp.Label = item.ActingAgent.Name; * orp.Description = item.ActingAgent.Description; * } * } * if ( string.IsNullOrEmpty( item.ActingAgent.CTID ) ) * orp.URL = item.ActingAgent.SubjectWebpage; * else * orp.URL = externalFinderSiteURL + string.Format( "organization/{0}", input.Id ); * bool isPublishedByRole = false; * if ( item.AgentRole != null && item.AgentRole.Items.Any() ) * { * foreach ( var ar in item.AgentRole.Items ) * { * //no link * if ( ar.Id == 30 ) * { * //if published by, probably will not have other roles! * //continue; * isPublishedByRole = true; * break; * } else if ( ar.Id == 20 || ar.Id == 21 || ar.Id == 22) * { * //skip dept, subsidiary and parent * continue; * } * //should this be the reverseTitle? * if ( item.ActingAgent != null && item.ActingAgent.Id > 0 ) * { * //if role is QA, include all 4 in link * ServiceHelper.MapEntitySearchLink( item.ActingAgent.Id, item.ActingAgent.Name, 0, ar.Name, searchType, ref orp.Roles, qaroles );//ar.Id.ToString() * } else * orp.Roles.Add( new WMA.LabelLink() { Label = ar.Name } ); * } * } * if ( !isPublishedByRole && orp.Roles.Any() ) * output.QAReceived.Add( orp ); * } */ } // MapAddress(input, ref output); if (request.IncludingManifests) { } else { } //manifests MapManifests(input, ref output, request); //process profiles MapProcessProfiles(input, ref output, request); // MapJurisdictions(input, ref output); // MapVerificationServiceProfile(input, ref output, request); return(output); }
/// <summary> /// Retrieve an envelop from the registry and do import /// Custom version for Import from Finder.Import /// TODO - THIS IS SOMEWHAT HIDDEN HERE - easy to forget when adding new classes /// </summary> /// <param name="envelopeId"></param> /// <param name="status"></param> /// <returns></returns> public bool ImportByEnvelopeId(string envelopeId, SaveStatus status) { //this is currently specific, assumes envelop contains a credential //can use the hack for GetResourceType to determine the type, and then call the appropriate import method if (string.IsNullOrWhiteSpace(envelopeId)) { status.AddError("ImportByEnvelope - a valid envelope id must be provided"); return(false); } string statusMessage = ""; string ctdlType = ""; try { ReadEnvelope envelope = RegistryServices.GetEnvelope(envelopeId, ref statusMessage, ref ctdlType); if (envelope == null || string.IsNullOrWhiteSpace(envelope.EnvelopeType)) { string defCommunity = UtilityManager.GetAppKeyValue("defaultCommunity"); string community = UtilityManager.GetAppKeyValue("additionalCommunity"); if (defCommunity != community) { envelope = RegistryServices.GetEnvelope(envelopeId, ref statusMessage, ref ctdlType, community); } } if (envelope != null && !string.IsNullOrWhiteSpace(envelope.EnvelopeIdentifier)) { return(ImportEnvelope(envelope, ctdlType, status)); //LoggingHelper.DoTrace( 4, string.Format( "RegistryServices.ImportByEnvelopeId ctdlType: {0}, EnvelopeId: {1} ", ctdlType, envelopeId ) ); //ctdlType = ctdlType.Replace( "ceterms:", "" ); //switch ( ctdlType.ToLower() ) //{ // case "credentialorganization": // case "qacredentialorganization": //what distinctions do we need for QA orgs? // case "organization": // return new ImportOrganization().CustomProcessEnvelope( envelope, status ); // //break;CredentialOrganization // case "assessmentprofile": // return new ImportAssessment().CustomProcessEnvelope( envelope, status ); // //break; // case "learningopportunityprofile": // return new ImportLearningOpportunties().CustomProcessEnvelope( envelope, status ); // //break; // case "conditionmanifest": // return new ImportAssessment().CustomProcessEnvelope( envelope, status ); // //break; // case "costmanifest": // return new ImportLearningOpportunties().CustomProcessEnvelope( envelope, status ); // case "competencyframework": // return new ImportCompetencyFramesworks().CustomProcessEnvelope( envelope, status ); // case "conceptscheme": // return new ImportConceptSchemes().CustomProcessEnvelope( envelope, status ); // case "pathway": // return new ImportPathways().CustomProcessEnvelope( envelope, status ); // case "pathwaysset": // return new ImportPathwaySets().CustomProcessEnvelope( envelope, status ); // case "transfervalueprofile": // return new ImportTransferValue().CustomProcessEnvelope( envelope, status ); // case "job": // case "occupation": // case "rating": // case "rubric": // case "task": // case "workrole": // { // LoggingHelper.DoTrace( 1, string.Format( "ImportByEnvelopeId. {0} ({1}-{2}) is not handled at this time. ", ctdlType, envelope.EnvelopeCtdlType, envelope.EnvelopeCetermsCtid ) ); // return false; // } // //break; // default: // //default to credential // //actually should have an edit for this. // return new ImportCredential().CustomProcessRequest( envelope, status ); // //break; //} } else { status.AddError(string.Format("ImportHelperServices.ImportByEnvelopeId. Registry Envelope was not found for: {0}", envelopeId)); return(false); } } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format("RegistryServices`.ImportByEnvelopeId(). ctdlType: {0}", ctdlType)); status.AddError(ex.Message); if (ex.Message.IndexOf("Path '@context', line 1") > 0) { status.AddWarning("The referenced registry document is using an old schema. Please republish it with the latest schema!"); } return(false); } }
static void Main(string[] args) { //NOTE: consider the IOER approach that all candidate records are first downloaded, and then a separate process does the import LoggingHelper.DoTrace(1, "======================= STARTING IMPORT ======================="); TimeZone zone = TimeZone.CurrentTimeZone; // Demonstrate ToLocalTime and ToUniversalTime. DateTime local = zone.ToLocalTime(DateTime.Now); DateTime universal = zone.ToUniversalTime(DateTime.Now); LoggingHelper.DoTrace(1, "Local time: " + local); LoggingHelper.DoTrace(1, "Universal time: " + universal); //need to determine how to get last start date //may be run multiple times during day, so use a schedule type string scheduleType = UtilityManager.GetAppKeyValue("scheduleType", "daily"); int deleteAction = UtilityManager.GetAppKeyValue("deleteAction", 0); bool doingDownloadOnly = UtilityManager.GetAppKeyValue("DoingDownloadOnly", false); string defaultCommunity = UtilityManager.GetAppKeyValue("defaultCommunity"); string additionalCommunity = UtilityManager.GetAppKeyValue("additionalCommunity"); #region Import Type/Arguments if (args != null) { if (args.Length >= 1) { scheduleType = args[0]; } if (args.Length == 2) { // var altCommunity = args[1]; if (!string.IsNullOrWhiteSpace(altCommunity) && altCommunity.ToLower() == additionalCommunity.ToLower()) { //has to match additional to be valid defaultCommunity = additionalCommunity; } } } RegistryImport registryImport = new RegistryImport(defaultCommunity); string startingDate = DateTime.Now.AddDays(-1).ToString(); //typically will want this as registry server is UTC (+6 hours from central) bool usingUTC_ForTime = UtilityManager.GetAppKeyValue("usingUTC_ForTime", true); string endingDate = ""; string importResults = ""; //could ignore end date until a special scedule type of adhoc is used, then read the dates from config importResults = DisplayMessages(string.Format(" - Schedule type: {0} ", scheduleType)); int minutes = 0; if (Int32.TryParse(scheduleType, out minutes)) { //minutes //may want more flexibility and use input parms if (minutes < 1 || minutes > 1440) //doesn't really matter { DisplayMessages(string.Format("invalid value encountered for Minutes option: {0} - defaulting to 60.", scheduleType)); minutes = 60; } if (usingUTC_ForTime) { //UTC is +6 hours (360 minutes), so subtract entered minutes and add to current time // ex: If -60, want 5 hours (360 - 60) minutes = minutes * -1; //startingDate = DateTime.Now.AddMinutes( minutes ).ToString( "yyyy-MM-ddTHH:mm:ss" ); startingDate = zone.ToUniversalTime(DateTime.Now.AddMinutes(minutes)).ToString("yyyy-MM-ddTHH:mm:ss"); //no end date? endingDate = ""; } else { startingDate = DateTime.Now.AddMinutes(-minutes).ToString("yyyy-MM-ddTHH:mm:ss"); //the server date is UTC, so if we leave enddate open, we will get the same stuff all day, so setting an endate to the current hour endingDate = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"); } importResults = importResults + "<br/>" + DisplayMessages(string.Format(" - Community: {0}, Updates since: {1} {2}", defaultCommunity, startingDate, usingUTC_ForTime ? " (UTC)" : "")); } else if (scheduleType == "sinceLastRun") { SiteActivity lastRun = ActivityServices.GetLastImport(); if (usingUTC_ForTime) { startingDate = zone.ToUniversalTime(lastRun.Created).ToString("yyyy-MM-ddTHH:mm:ss"); } else { startingDate = lastRun.Created.ToString("yyyy-MM-ddTHH:mm:ss"); } endingDate = ""; importResults = importResults + "<br/>" + DisplayMessages(string.Format(" - Updates since: {0} {1}", startingDate, usingUTC_ForTime ? " (UTC)" : "")); } else if (scheduleType == "adhoc") { startingDate = UtilityManager.GetAppKeyValue("startingDate", ""); endingDate = UtilityManager.GetAppKeyValue("endingDate", ""); DateTime dtcheck = System.DateTime.Now; //LoggingHelper.DoTrace( 1, string.Format( " - Updates from: {0} to {1} ", startingDate, endingDate ) ); if (usingUTC_ForTime) { if (DateTime.TryParse(startingDate, out dtcheck)) { startingDate = zone.ToUniversalTime(dtcheck).ToString("yyyy-MM-ddTHH:mm:ss"); } if (DateTime.TryParse(endingDate, out dtcheck)) { endingDate = zone.ToUniversalTime(dtcheck).ToString("yyyy-MM-ddTHH:mm:ss"); } //no end date? //endingDate = ""; } importResults = importResults + "<br/>" + DisplayMessages(string.Format(" - Updates from: {0} to {1} for community: {2}", startingDate, endingDate, defaultCommunity)); } else if (scheduleType == "hourly") { if (usingUTC_ForTime) { //6 hour diff, so add 5 hours, equiv to +6 hours - 1 hour startingDate = zone.ToUniversalTime(DateTime.Now.AddHours(-1)).ToString("yyyy-MM-ddTHH:mm:ss"); } else { startingDate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-ddTHH:mm:ss"); //format into: 2016-08-01T23:59:59 //the server date is UTC, so if we leave enddate open, we will get the same stuff all day, so setting an endate to the current hour //HOWEVER - THIS COULD RESULT IN BEING 6 HOURS BEHIND endingDate = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"); } //LoggingHelper.DoTrace( 1, string.Format( " - Updates since: {0} ", startingDate ) ); importResults = importResults + "<br/>" + DisplayMessages(string.Format(" - Updates since: {0} {1}, community: {2}", startingDate, usingUTC_ForTime ? " (UTC)" : "", defaultCommunity)); } else { //assume daily startingDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-ddTHH:mm:ss"); //format into: 2016-08-01T23:59:59 endingDate = ""; //LoggingHelper.DoTrace( 1, string.Format( " - Updates since: {0} ", startingDate ) ); importResults = importResults + "<br/>" + DisplayMessages(string.Format(" - Updates since: {0} ", startingDate)); } #endregion //=================================================================================================== if (!doingDownloadOnly) { LogStart(); } //set to zero to handle all, or a number to limit records to process //partly for testing //although once can sort by date, we can use this, and update the start date int maxImportRecords = UtilityManager.GetAppKeyValue("maxImportRecords", 50); //NOTE - NEED TO REBUILD CACHE TABLES BEFORE BUILDING ELASTIC INDICES //Actions: 0-normal; 1-DeleteOnly; 2-SkipDelete int recordsDeleted = 0; if (deleteAction < 2) { //handle deleted records importResults = importResults + "<br/>" + HandleDeletes(defaultCommunity, startingDate, endingDate, maxImportRecords, ref recordsDeleted); } int recordsImported = 0; if (deleteAction != 1) { //do manifests if (UtilityManager.GetAppKeyValue("importing_condition_manifest_schema", true)) { importResults = importResults + "<br/>" + registryImport.Import("condition_manifest_schema", CodesManager.ENTITY_TYPE_CONDITION_MANIFEST, startingDate, endingDate, maxImportRecords, doingDownloadOnly, ref recordsImported); } // if (UtilityManager.GetAppKeyValue("importing_cost_manifest_schema", true)) { importResults = importResults + "<br/>" + registryImport.Import("cost_manifest_schema", CodesManager.ENTITY_TYPE_COST_MANIFEST, startingDate, endingDate, maxImportRecords, doingDownloadOnly, ref recordsImported); } //handle credentials // if (UtilityManager.GetAppKeyValue("importing_credential", true)) { importResults = importResults + "<br/>" + registryImport.Import("credential", CodesManager.ENTITY_TYPE_CREDENTIAL, startingDate, endingDate, maxImportRecords, doingDownloadOnly, ref recordsImported); } //handle assessments // if (UtilityManager.GetAppKeyValue("importing_assessment_profile", true)) { importResults = importResults + "<br/>" + registryImport.Import("assessment_profile", CodesManager.ENTITY_TYPE_ASSESSMENT_PROFILE, startingDate, endingDate, maxImportRecords, doingDownloadOnly, ref recordsImported); } //handle learning opps // if (UtilityManager.GetAppKeyValue("importing_learning_opportunity_profile", true)) { importResults = importResults + "<br/>" + registryImport.Import("learning_opportunity_profile", CodesManager.ENTITY_TYPE_LEARNING_OPP_PROFILE, startingDate, endingDate, maxImportRecords, doingDownloadOnly, ref recordsImported); } // if (UtilityManager.GetAppKeyValue("importing_competency_frameworks", true)) { importResults = importResults + "<br/>" + new CompetencyFramesworksImport().Import(startingDate, endingDate, maxImportRecords, defaultCommunity, doingDownloadOnly); } //new pathways //if ( UtilityManager.GetAppKeyValue( "importing_pathways", true ) ) // importResults = importResults + "<br/>" + new CompetencyFramesworksImport().Import( startingDate, endingDate, maxImportRecords, doingDownloadOnly ); //handle organizations //might be better to do last, then can populate placeholders, try first // if (UtilityManager.GetAppKeyValue("importing_organization", true)) { importResults = importResults + "<br/>" + registryImport.Import("organization", 2, startingDate, endingDate, maxImportRecords, doingDownloadOnly, ref recordsImported); } if (!doingDownloadOnly && recordsImported > 0) { if (UtilityManager.GetAppKeyValue("processingPendingRecords", true)) { //============================================================== //import pending string pendingStatus = new RegistryServices().ImportPending(); importResults = importResults + "<br/>TODO: add stats from ImportPending."; } } } //=================================================================================================== if (!doingDownloadOnly) { if (recordsImported > 0 || recordsDeleted > 0) { //update elastic if not included - probably will always delay elastic, due to multiple possible updates //may want to move this to services for use by other process, including adhoc imports if (UtilityManager.GetAppKeyValue("delayingAllCacheUpdates", true)) { //update elastic if a elasticSearchUrl exists if (UtilityManager.GetAppKeyValue("elasticSearchUrl") != "") { LoggingHelper.DoTrace(1, string.Format("=== ***************** UpdateElastic ***************** ")); ElasticServices.UpdateElastic(true); } } if (recordsImported > 0) { //set all resolved records in Import_EntityResolution to be resolved. LoggingHelper.DoTrace(1, string.Format("=== ***************** SetAllResolvedEntities ***************** ")); new ImportManager().SetAllResolvedEntities(); } //update code table counts LoggingHelper.DoTrace(1, string.Format("=== ***************** UpdateCodeTableCounts ***************** ")); new CacheManager().UpdateCodeTableCounts(); //send summary email string message = string.Format("<h2>Import Results</h2><p>{0}</p>", importResults); EmailManager.NotifyAdmin(string.Format("Credential Finder Import Results ({0})", envType), message); new ActivityServices().AddActivity(new SiteActivity() { ActivityType = "System", Activity = "Import", Event = "End", Comment = string.Format("Summary: {0} records were imported, {1} records were deleted.", recordsImported, recordsDeleted), SessionId = "batch job", IPAddress = "local" }); } else { new ActivityServices().AddActivity(new SiteActivity() { ActivityType = "System", Activity = "Import", Event = "End", Comment = "No data was found to import", SessionId = "batch job", IPAddress = "local" }); } } //summary, and logging LoggingHelper.DoTrace(1, "======================= all done =============================="); }
public string Import(string registryEntityType, int entityTypeId, string startingDate, string endingDate, int maxRecords, bool downloadOnly, ref int recordsImported) { bool importingThisType = UtilityManager.GetAppKeyValue("importing_" + registryEntityType, true); if (!importingThisType) { LoggingHelper.DoTrace(1, string.Format("=== ***************** Skipping import of {0} ***************** ", registryEntityType)); return("Skipped import of " + registryEntityType); } LoggingHelper.DoTrace(1, string.Format("=== ***************** Importing {0} ***************** ", registryEntityType)); //JsonEntity input = new JsonEntity(); ReadEnvelope envelope = new ReadEnvelope(); List <ReadEnvelope> list = new List <ReadEnvelope>(); //EntityServices mgr = new EntityServices(); ImportServiceHelpers importMgr = new ImportServiceHelpers(); string entityType = registryEntityType; CodeItem ci = CodesManager.Codes_EntityType_Get(entityTypeId); if (ci != null && ci.Id > 0) { entityType = ci.Title; } int pageNbr = 1; int pageSize = 25; string importError = ""; string importResults = ""; string importNote = ""; //ThisEntity output = new ThisEntity(); List <string> messages = new List <string>(); int cntr = 0; int pTotalRows = 0; int exceptionCtr = 0; string statusMessage = ""; bool isComplete = false; bool importSuccessfull = true; int newImportId = 0; SaveStatus status = new SaveStatus(); //will need to handle multiple calls - watch for time outs while (pageNbr > 0 && !isComplete) { //19-09-22 chg to use RegistryServices to remove duplicate services list = RegistryServices.Search(registryEntityType, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, Community); //list = RegistryImport.GetLatest( registryEntityType, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, Community ); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { //importNote = registryEntityType + ": No records where found for date range "; //Console.WriteLine( thisClassName + importNote ); LoggingHelper.DoTrace(4, registryEntityType + ": No records where found for date range. "); } break; } foreach (ReadEnvelope item in list) { cntr++; string payload = item.DecodedResource.ToString(); newImportId = 0; LoggingHelper.DoTrace(2, string.Format("{0}. {1} EnvelopeIdentifier {2} ", cntr, registryEntityType, item.EnvelopeIdentifier)); messages = new List <string>(); status = new SaveStatus(); status.DoingDownloadOnly = downloadOnly; status.ValidationGroup = string.Format("{0} Import", registryEntityType); importError = ""; importSuccessfull = false; try { //Console.WriteLine( string.Format( "{0}. {1} EnvelopeIdentifier {2} ", cntr, registryEntityType, item.EnvelopeIdentifier ) ); if (payload.IndexOf("@graphXXX") > 0) { DisplayMessages(string.Format("{0}. {1} Import Encountered an envelope using @graph which is not handled yet: {2} ", cntr, entityTypeId, item.EnvelopeIdentifier)); } else { switch (entityTypeId) { case 1: importSuccessfull = credImportMgr.ProcessEnvelope(item, status); break; case 2: importSuccessfull = orgImportMgr.ProcessEnvelope(item, status); break; case 3: importSuccessfull = asmtImportMgr.ProcessEnvelope(item, status); break; case 7: importSuccessfull = loppImportMgr.ProcessEnvelope(item, status); break; case 19: importSuccessfull = cndManImportMgr.ProcessEnvelope(item, status); break; case 20: importSuccessfull = cstManImportMgr.ProcessEnvelope(item, status); break; default: DisplayMessages(string.Format("{0}. Invalid Entity type encountered: {1} ", cntr, entityTypeId)); break; } } } catch (Exception ex) { if (ex.Message.IndexOf("Path '@context', line 1") > 0) { importError = "The referenced registry document is using an old schema. Please republish it with the latest schema!"; status.AddError(importError); } else { LoggingHelper.LogError(ex, string.Format(entityType + " Exception encountered in envelopeId: {0}", item.EnvelopeIdentifier), false, "CredentialFinder Import exception"); status.AddError(ex.Message); importError = ex.Message; } //make continue on exceptions an option exceptionCtr++; if (maxExceptions > 0 && exceptionCtr > maxExceptions) { //arbitrarily stop if large number of exceptions importNote = string.Format(thisClassName + " - {0} Many exceptions ({1}) were encountered during import - abandoning.", entityType, exceptionCtr); //Console.WriteLine( importNote ); LoggingHelper.DoTrace(1, importNote); LoggingHelper.LogError(importNote, true, thisClassName + "- many exceptions"); isComplete = true; break; } } finally { if (!importSuccessfull) { if (string.IsNullOrWhiteSpace(importError)) { importError = string.Join("\r\n", status.GetAllMessages().ToArray()); } } //store document //add indicator of success newImportId = importMgr.Add(item, entityTypeId, status.Ctid, importSuccessfull, importError, ref messages); if (newImportId > 0 && status.Messages != null && status.Messages.Count > 0) { //add indicator of current recored string msg = string.Format("========= Messages for {4}, EnvelopeIdentifier: {0}, ctid: {1}, Id: {2}, rowId: {3} =========", item.EnvelopeIdentifier, status.Ctid, status.DocumentId, status.DocumentRowId, registryEntityType); importMgr.AddMessages(newImportId, status, ref messages); } } //finally if (maxRecords > 0 && cntr > maxRecords) { break; } } //end foreach pageNbr++; if ((maxRecords > 0 && cntr > maxRecords) || cntr > pTotalRows) { isComplete = true; LoggingHelper.DoTrace(2, string.Format("Import {2} EARLY EXIT. Completed {0} records out of a total of {1} ", cntr, pTotalRows, registryEntityType)); } //if ( pageNbr * pageSize < pTotalRows ) // pageNbr++; //else // isComplete = true; } importResults = string.Format("Import {0} - Processed {1} records, with {2} exceptions. \r\n", registryEntityType, cntr, exceptionCtr); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } recordsImported += cntr; return(importResults); }
public string Retrieve(string registryEntityType, int entityTypeId, string startingDate, string endingDate, int maxRecords, bool downloadOnly, ref int recordsImported, string sortOrder = "asc") { bool importingThisType = UtilityManager.GetAppKeyValue("importing_" + registryEntityType, true); if (!importingThisType) { LoggingHelper.DoTrace(1, string.Format("=== ***************** Skipping import of {0} ***************** ", registryEntityType)); return("Skipped import of " + registryEntityType); } LoggingHelper.DoTrace(1, string.Format("=== ***************** Importing {0} ***************** ", registryEntityType)); //JsonEntity input = new JsonEntity(); ReadEnvelope envelope = new ReadEnvelope(); List <ReadEnvelope> list = new List <ReadEnvelope>(); int pageNbr = 1; int pageSize = UtilityManager.GetAppKeyValue("importPageSize", 100); string importError = ""; string importResults = ""; string importNote = ""; //ThisEntity output = new ThisEntity(); List <string> messages = new List <string>(); int cntr = 0; int pTotalRows = 0; int exceptionCtr = 0; string statusMessage = ""; bool isComplete = false; bool importSuccessfull = true; int newImportId = 0; //will need to handle multiple calls - watch for time outs while (pageNbr > 0 && !isComplete) { //19-09-22 chg to use RegistryServices to remove duplicate services list = Search(registryEntityType, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, Community, sortOrder); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { LoggingHelper.DoTrace(4, registryEntityType + ": No records where found for date range. "); } break; } if (pageNbr == 1) { LoggingHelper.DoTrace(2, string.Format("Import {0} Found {1} records to process.", registryEntityType, pTotalRows)); } foreach (ReadEnvelope item in list) { cntr++; string envelopeIdentifier = item.EnvelopeIdentifier; string ctid = item.EnvelopeCetermsCtid; string payload = item.DecodedResource.ToString(); LoggingHelper.DoTrace(2, string.Format("{0}. {1} ctid {2} ", cntr, registryEntityType, ctid)); string ctdlType = RegistryServices.GetResourceType(payload); string envelopeUrl = RegistryHelper.GetEnvelopeUrl(envelopeIdentifier); //LoggingHelper.DoTrace( 5, " envelopeUrl: " + envelopeUrl ); //to overwrite an existing file, suppress the date prefix (" "), or use an alternate prefix LoggingHelper.WriteLogFile(1, registryEntityType + "_" + ctid, payload, "", false); if (maxRecords > 0 && cntr >= maxRecords) { break; } } //end foreach pageNbr++; if ((maxRecords > 0 && cntr >= maxRecords)) { isComplete = true; LoggingHelper.DoTrace(2, string.Format("Import {2} EARLY EXIT. Completed {0} records out of a total of {1} for {2} ", cntr, pTotalRows, registryEntityType)); } else if (cntr >= pTotalRows) { isComplete = true; } } importResults = string.Format("Import {0} - Processed {1} records, with {2} exceptions. \r\n", registryEntityType, cntr, exceptionCtr); LoggingHelper.DoTrace(2, importResults); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } recordsImported += cntr; return(importResults); }
public void Retrieve(string registryEntityType, int entityTypeId, int maxRecords, ref int recordsImported, ref List <string> importSummary, string sortOrder = "asc") { bool importingThisType = UtilityManager.GetAppKeyValue("importing_" + registryEntityType, true); if (!importingThisType) { LoggingHelper.DoTrace(1, string.Format("=== ***************** Skipping import of {0} ***************** ", registryEntityType)); importSummary.Add("Skipped import of " + registryEntityType); return; } LoggingHelper.DoTrace(1, string.Format("=== ***************** Importing {0} ***************** ", registryEntityType)); //bool downloadOnly // ReadEnvelope envelope = new ReadEnvelope(); List <ReadEnvelope> list = new List <ReadEnvelope>(); int pageNbr = 1; int pageSize = UtilityManager.GetAppKeyValue("importPageSize", 100); string importResults = ""; string importNote = ""; //ThisEntity output = new ThisEntity(); List <string> messages = new List <string>(); // var savingDocumentToFileSystem = UtilityManager.GetAppKeyValue("savingDocumentToFileSystem", true); var savingDocumentToDatabase = UtilityManager.GetAppKeyValue("savingDocumentToDatabase", false); int cntr = 0; int pTotalRows = 0; int exceptionCtr = 0; string statusMessage = ""; bool isComplete = false; //var request = new SearchRequest() //{ // StartingDate = startingDate, // EndingDate = endingDate, // OwningOrganizationCTID = owningOrganizationCTID, // PublishingOrganizationCTID = publishingOrganizationCTID, // DownloadOnly = downloadOnly //}; //will need to handle multiple calls - watch for time outs while (pageNbr > 0 && !isComplete) { //19-09-22 chg to use RegistryServices to remove duplicate services list = Search(registryEntityType, StartingDate, EndingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, Community, OwningOrganizationCTID, PublishingOrganizationCTID, sortOrder); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { LoggingHelper.DoTrace(4, registryEntityType + ": No records where found for date range. "); } break; } if (pageNbr == 1) { LoggingHelper.DoTrace(2, string.Format("Import {0} Found {1} records to process.", registryEntityType, pTotalRows)); } foreach (ReadEnvelope item in list) { cntr++; string envelopeIdentifier = item.EnvelopeIdentifier; string ctid = item.EnvelopeCtid; string payload = item.DecodedResource.ToString(); DateTime createDate = new DateTime(); DateTime envelopeUpdateDate = new DateTime(); if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate)) { //status.SetEnvelopeCreated( createDate ); } if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate)) { //status.SetEnvelopeUpdated( envelopeUpdateDate ); } //payload contains the graph from DecodedResource //var ctdlType = RegistryServices.GetResourceType( payload ); LoggingHelper.DoTrace(2, string.Format("{0}. {1} ctid {2}, lastUpdated: {3} ", cntr, registryEntityType, ctid, envelopeUpdateDate)); //Save file to file system //existing files will be overridden. , suppress the date prefix (" "), or use an alternate prefix if (savingDocumentToFileSystem) { LoggingHelper.WriteLogFile(1, registryEntityType + "_" + ctid, payload, "", false); } #region future: define process to generic record to a database. //TODO - add optional save to a database // - will need entity type, ctid, name, description (maybe), created and lastupdated from envelope,payload // - only doing adds, allows for history, user can choose to do updates if (savingDocumentToDatabase) { var graphMainResource = RegistryServices.GetGraphMainResource(payload); var resource = new CredentialRegistryResource() { EntityType = graphMainResource.Type, CTID = ctid, DownloadDate = DateTime.Now, Created = createDate, LastUpdated = envelopeUpdateDate, CredentialRegistryGraph = payload }; if (entityTypeId == 10) { resource.Name = graphMainResource.CeasnName.ToString(); } else { resource.Name = graphMainResource.Name.ToString(); resource.Description = graphMainResource.Description.ToString(); resource.SubjectWebpage = graphMainResource.SubjectWebpage; } statusMessage = ""; //optionally save record to a database if (new DatabaseServices().Add(resource, ref statusMessage) == 0) { //error handling } } #endregion if (maxRecords > 0 && cntr >= maxRecords) { break; } } //end foreach pageNbr++; if ((maxRecords > 0 && cntr >= maxRecords)) { isComplete = true; LoggingHelper.DoTrace(2, string.Format("Import {2} EARLY EXIT. Completed {0} records out of a total of {1} for {2} ", cntr, pTotalRows, registryEntityType)); } else if (cntr >= pTotalRows) { isComplete = true; } } importResults = string.Format("Import {0} - Processed {1} records, with {2} exceptions. \r\n", registryEntityType, cntr, exceptionCtr); LoggingHelper.DoTrace(2, importResults); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } importSummary.Add(importResults); recordsImported += cntr; //return importResults; }
public RegistryObject(string payload) { if (!string.IsNullOrWhiteSpace(payload)) { dictionary = RegistryServices.JsonToDictionary(payload); if (payload.IndexOf("@graph") > 0 && payload.IndexOf("@graph\": null") == -1) { IsGraphObject = true; //get the graph object object graph = dictionary["@graph"]; //serialize the graph object var glist = JsonConvert.SerializeObject(graph); //parse graph in to list of objects JArray graphList = JArray.Parse(glist); var main = graphList[0].ToString(); BaseObject = JsonConvert.DeserializeObject <RegistryBaseObject>(main); CtdlType = BaseObject.CdtlType; Ctid = BaseObject.Ctid; //not important to fully resolve yet if (BaseObject.Name != null) { Name = BaseObject.Name.ToString(); if (Name.IndexOf("{") > -1 && Name.IndexOf(":") > 1) { int pos = Name.IndexOf("\"", Name.IndexOf(":")); int endpos = Name.IndexOf("\"", pos + 1); if (pos > 1 && endpos > pos) { Name = Name.Substring(pos + 1, endpos - (pos + 1)); } } //if ( BaseObject.Name is LanguageMap ) //{ //} } else if (CtdlType == "ceasn:CompetencyFramework") { Name = (BaseObject.CompetencyFrameworkName ?? "").ToString(); } else { Name = "?????"; } //if ( BaseObject.Name.GetType()) //{ //} } else { //check if old resource or standalone resource BaseObject = JsonConvert.DeserializeObject <RegistryBaseObject>(payload); CtdlType = BaseObject.CdtlType; Ctid = BaseObject.Ctid; Name = BaseObject.Name.ToString(); if (Name.IndexOf("{") > -1 && Name.IndexOf(":") > 1) { int pos = Name.IndexOf("\"", Name.IndexOf(":")); int endpos = Name.IndexOf("\"", pos + 1); if (pos > 1 && endpos > pos) { Name = Name.Substring(pos + 1, endpos - (pos + 1)); } } } CtdlType = CtdlType.Replace("ceterms:", ""); CtdlType = CtdlType.Replace("ceasn:", ""); } }
public static string HandleDeletes(string community, string startingDate, string endingDate, int maxRecords, ref int recordsDeleted) { int pageNbr = 1; int pageSize = 50; //string importError = ""; //may want to just do all types! string type = ""; List <string> messages = new List <string>(); List <ReadEnvelope> list = new List <ReadEnvelope>(); SaveStatus status = new SaveStatus(); int pTotalRows = 0; int cntr = 0; bool isComplete = false; int exceptionCtr = 0; string statusMessage = ""; string importResults = ""; string importNote = ""; LoggingHelper.DoTrace(1, string.Format("=== DELETES ===", thisClassName)); //startingDate = "2017-10-29T00:00:00"; try { while (pageNbr > 0 && !isComplete) { list = RegistryImport.GetDeleted(community, type, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { importNote = "Deletes: No records where found for date range "; //Console.WriteLine( thisClassName + ".HandleDeletes() - " + importNote ); LoggingHelper.DoTrace(1, thisClassName + ".HandleDeletes() - " + importNote); } break; } foreach (ReadEnvelope item in list) { cntr++; string payload = item.DecodedResource.ToString(); string ctdlType = RegistryServices.GetResourceType(payload); string ctid = RegistryServices.GetCtidFromUnknownEnvelope(item); //may not be available in database, may want to use ctid string envelopeIdentifier = item.EnvelopeIdentifier; string envelopeUrl = RegistryServices.GetEnvelopeUrl(item.EnvelopeIdentifier); LoggingHelper.DoTrace(5, " envelopeUrl: "+ envelopeUrl); LoggingHelper.DoTrace(6, string.Format("{0}. EnvelopeIdentifier: {1} ", cntr, item.EnvelopeIdentifier)); try { //only need the envelopeId and type //so want a full delete, or set EntityStateId to 4 or greater - just as a precaution messages = new List <string>(); status = new SaveStatus(); status.ValidationGroup = "Deletes"; //importError = ""; //each delete method will add an entry to SearchPendingReindex. //at the end of the process, call method to handle all the deletes switch (ctdlType.ToLower()) { case "credentialorganization": case "qacredentialorganization": case "organization": DisplayMessages(string.Format("{0}. Deleting {3} by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid, ctdlType)); if (!new OrganizationManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; case "assessmentprofile": DisplayMessages(string.Format("{0}. Deleting Assessment by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid)); if (!new AssessmentManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; case "learningopportunityprofile": DisplayMessages(string.Format("{0}. Deleting LearningOpportunity by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid)); if (!new LearningOpportunityManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; case "conditionmanifest": DisplayMessages(string.Format("{0}. Deleting ConditionManifest by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid)); if (!new ConditionManifestManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; case "costmanifest": DisplayMessages(string.Format("{0}. Deleting CostManifest by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid)); if (!new CostManifestManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; case "competencyframework": //CompetencyFramework DisplayMessages(string.Format("{0}. Deleting CompetencyFramework by EnvelopeIdentifier/ctid: {1}/{2} ", cntr, item.EnvelopeIdentifier, ctid)); if (!new EducationFrameworkManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; default: //default to credential DisplayMessages(string.Format("{0}. Deleting Credential ({2}) by EnvelopeIdentifier/ctid: {1}/{3} ", cntr, item.EnvelopeIdentifier, ctdlType, ctid)); if (!new CredentialManager().Delete(envelopeIdentifier, ctid, ref statusMessage)) { DisplayMessages(string.Format(" Delete failed: {0} ", statusMessage)); } break; } } catch (Exception ex) { LoggingHelper.LogError(ex, string.Format("Exception encountered in envelopeId: {0}", item.EnvelopeIdentifier), false, "CredentialFinder Import exception"); //importError = ex.Message; } if (maxRecords > 0 && cntr > maxRecords) { break; } } //foreach ( ReadEnvelope item in list ) pageNbr++; if ((maxRecords > 0 && cntr > maxRecords) || cntr > pTotalRows) { isComplete = true; DisplayMessages(string.Format("Delete EARLY EXIT. Completed {0} records out of a total of {1} ", cntr, pTotalRows)); } } //while //delete from elastic if (cntr > 0) { messages = new List <string>(); ElasticServices.HandlePendingDeletes(ref messages); } importResults = string.Format("HandleDeletes - Processed {0} records, with {1} exceptions. \r\n", cntr, exceptionCtr); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } } catch (Exception ex) { LoggingHelper.LogError(ex, "Import.HandleDeletes"); } //actually only attepted at this time, need to account for errors! recordsDeleted = cntr; return(importResults); }
public string Import(string startingDate, string endingDate, int maxRecords, string community, bool downloadOnly = false) { bool importingThisType = UtilityManager.GetAppKeyValue("importing_competency_frameworks", true); if (!importingThisType) { LoggingHelper.DoTrace(1, "=== ***************** Skipping import of Competency Frameworks ***************** "); return("Skipped import of competency_frameworks"); } LoggingHelper.DoTrace(1, string.Format("=== ***************** {0} ***************** ", thisClassName)); JsonEntity input = new JsonEntity(); ReadEnvelope envelope = new ReadEnvelope(); List <ReadEnvelope> list = new List <ReadEnvelope>(); EntityServices mgr = new EntityServices(); string type = "competency_framework"; int pageNbr = 1; int pageSize = 75; string importError = ""; string importResults = ""; string importNote = ""; ThisEntity output = new ThisEntity(); List <string> messages = new List <string>(); //the nbr of records needs to be monitored, to determine the optimum //NOTE: consider the IOER approach that all candidate records are first downloaded, and then a separate process does the import int cntr = 0; int pTotalRows = 0; int exceptionCtr = 0; string statusMessage = ""; bool isComplete = false; bool importSuccessfull = true; int newImportId = 0; SaveStatus status = new SaveStatus(); //will need to handle multiple calls - watch for time outs while (pageNbr > 0 && !isComplete) { list = RegistryServices.Search(type, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, community); //list = GetLatest( type, startingDate, endingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, community ); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { importNote = "Competency Frameworks: No records where found for date range "; //Console.WriteLine( thisClassName + importNote ); LoggingHelper.DoTrace(4, thisClassName + importNote); } break; } foreach (ReadEnvelope item in list) { cntr++; string payload = item.DecodedResource.ToString(); LoggingHelper.DoTrace(2, string.Format("{0}. EnvelopeIdentifier: {1} ", cntr, item.EnvelopeIdentifier)); status = new SaveStatus(); status.DoingDownloadOnly = downloadOnly; importError = ""; importSuccessfull = false; try { //Console.WriteLine( string.Format( "{0}. Competency Frameswork Envelope Identifier {1} ", cntr, item.EnvelopeIdentifier ) ); importSuccessfull = entityImportMgr.ProcessEnvelope(mgr, item, status); } catch (Exception ex) { if (ex.Message.IndexOf("Path '@context', line 1") > 0) { importError = "The referenced registry document is using an old schema. Please republish it with the latest schema!"; status.AddError(importError); } else { LoggingHelper.LogError(ex, string.Format("Exception encountered in envelopeId: {0}", item.EnvelopeIdentifier), false, "CredentialFinder Import exception"); status.AddError(ex.Message); importError = ex.Message; LoggingHelper.DoTrace(1, " show exception to use getting related envelopeId " + ex.Message); } //make continue on exceptions an option exceptionCtr++; if (maxExceptions > 0 && exceptionCtr > maxExceptions) { //arbitrarily stop if large number of exceptions importNote = string.Format(thisClassName + " - Many exceptions ({0}) were encountered during import - abandoning.", exceptionCtr); Console.WriteLine(importNote); LoggingHelper.DoTrace(1, importNote); LoggingHelper.LogError(importNote, true, thisClassName + "- many exceptions"); isComplete = true; break; } } finally { if (!importSuccessfull) { if (string.IsNullOrWhiteSpace(importError)) { importError = string.Join("\r\n", status.GetAllMessages().ToArray()); } } //store document //add indicator of success newImportId = importMgr.Add(item, entityTypeId, status.Ctid, importSuccessfull, importError, ref messages); if (newImportId > 0 && status.Messages != null && status.Messages.Count > 0) { importMgr.AddMessages(newImportId, status, ref messages); } } //finally if (maxRecords > 0 && cntr > maxRecords) { break; } } //end foreach pageNbr++; if ((maxRecords > 0 && cntr > maxRecords) || cntr == pTotalRows) { isComplete = true; if (cntr < pTotalRows) { LoggingHelper.DoTrace(2, string.Format("CompetencyFramesworkImport EARLY EXIT. Completed {0} records out of a total of {1} ", cntr, pTotalRows)); } } } // importResults = string.Format("{0} - Processed {1} records, with {2} exceptions. \r\n", thisClassName, cntr, exceptionCtr); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } //always call, as deletes are not tracked if (UtilityManager.GetAppKeyValue("updateCompetencyFrameworkReportTotals", false) == true) { mgr.UpdateCompetencyFrameworkReportTotals(); } return(importResults); }
private static WMA.TransferValueProfile MapToAPI(ThisEntity input) { var output = new WMA.TransferValueProfile() { Meta_Id = input.Id, CTID = input.CTID, Name = input.Name, FriendlyName = HttpUtility.UrlPathEncode(input.Name), Description = input.Description, SubjectWebpage = input.SubjectWebpage, EntityTypeId = 26, StartDate = input.StartDate, EndDate = input.EndDate, CredentialRegistryURL = RegistryServices.GetResourceUrl(input.CTID), RegistryData = ServiceHelper.FillRegistryData(input.CTID) }; if (input.OwningOrganizationId > 0) { output.OwnedByLabel = ServiceHelper.MapDetailLink("Organization", input.OrganizationName, input.OwningOrganizationId); } var orgOutline = ServiceHelper.MapToOutline(input.OwningOrganization, "organization"); //var work = ServiceHelper.MapOrganizationRoleProfileToOutline( input.OrganizationRole, Entity_AgentRelationshipManager.ROLE_TYPE_OWNER ); output.OwnedBy = ServiceHelper.MapOutlineToAJAX(orgOutline, "Owning Organization"); // // output.Identifier = ServiceHelper.MapIdentifierValue(input.Identifier); //transferValue output.TransferValue = ServiceHelper.MapValueProfile(input.TransferValue, ""); //for var work = new List <WMA.Outline>(); foreach (var target in input.TransferValueFor) { if (target != null && !string.IsNullOrWhiteSpace(target.Name)) { work.Add(ServiceHelper.MapToOutline(target, "")); } } output.TransferValueFor = ServiceHelper.MapOutlineToAJAX(work, "Includes {0} Transfer Value For"); //from work = new List <WMA.Outline>(); foreach (var target in input.TransferValueFrom) { if (target != null && !string.IsNullOrWhiteSpace(target.Name)) { work.Add(ServiceHelper.MapToOutline(target, "")); } } output.TransferValueFrom = ServiceHelper.MapOutlineToAJAX(work, "Includes {0} Transfer Value From"); // if (input.DevelopmentProcess.Any()) { output.DevelopmentProcess = ServiceHelper.MapAJAXProcessProfile("Development Process", "", input.DevelopmentProcess); } // output.InLanguage = null; return(output); }
public void TestRegFileKeyRetrieval() { var data = RegistryServices.ParseRegFile(TestRegFile); Assert.IsTrue(data.KeyValuePairs.Keys.ToList().IsEquivalentTo(ExpectedRegKeys)); }