/// <summary> /// Called When the package is initialized. /// </summary> public override void InitializeCustomExtension() { if (RuntimeSettings != null) { PackageLog.Log(string.Format("Runtime Settings populated. Count = {0}", RuntimeSettings.Count)); foreach (var setting in RuntimeSettings) { PackageLog.Log(string.Format("Key={0} | Value={1}", setting.Key, setting.Value.ToString())); } if (RuntimeSettings.ContainsKey("SkipSampleData")) { bool sample = false; if (bool.TryParse((string)RuntimeSettings["SkipSampleData"], out sample)) { DataImportBypass = sample; } } } else { // Skip sample data by default DataImportBypass = true; } }
private void SetUpPermissions() { if (GetExistingUser() == null) { var roleId = GetRoleId(); var privileges = GetPrivilegeRecords(); var addPrivilegesRoleRequest = new AddPrivilegesRoleRequest { RoleId = roleId, Privileges = ( from p in privileges select new RolePrivilege(RequiredPrivileges[(string)p.Value["name"]], (Guid)p.Value["privilegeid"], BusinessUnitId.Value) ).ToArray() }; CrmSvc.ExecuteCrmOrganizationRequest(addPrivilegesRoleRequest); var user = CreateProposalManagerUser(); PackageLog.Log("User created..."); PackageLog.Log(user.ToString()); CrmSvc.Associate( "systemuser", user, new Relationship("systemuserroles_association"), new EntityReferenceCollection { new EntityReference("role", roleId) }); } }
/// <summary> /// Called after Import completes. /// </summary> /// <returns></returns> public override bool AfterPrimaryImport() { LogStart("AfterPrimaryImport"); PackageLog.Log("Running AfterPrimaryImport"); // Verify Connection if (CrmSvc == null || !CrmSvc.IsReady) { PackageLog.Log("Error: Not connected to crm service.", TraceEventType.Critical); LogEnd("AfterPrimaryImport"); return(false); } // Log Version var version = CrmSvc.ConnectedOrgVersion; PackageLog.Log($"Connected CRM Version: {version}", TraceEventType.Information); // Queue Items QueueItems.AddToQueue(PackageLog, CrmSvc, GetImportPackageDataFolderPath("queueitems.json")); // Enable all the steps in the plugin assembly EnablePluginSteps(); LogEnd("AfterPrimaryImport"); return(true); }
/// <summary> /// Called after Import completes. /// </summary> /// <returns></returns> public override bool AfterPrimaryImport() { try { var success = true; foreach (var deployment in _solutionDeployments) { if (!success) { break; } success = deployment.AfterPrimaryImport(); } return(success); } catch (Exception ex) { PackageLog.Log($"Exception: {ex}"); RaiseFailEvent(ex.Message, ex); return(false); } }
/// <summary> /// Called When the package is initialized. /// </summary> public override void InitializeCustomExtension() { if (RuntimeSettings != null) { PackageLog.Log(string.Format("Runtime Settings populated. Count = {0}", RuntimeSettings.Count), TraceEventType.Verbose); foreach (var setting in RuntimeSettings) { PackageLog.Log(string.Format("Key={0} | Value={1}", setting.Key, setting.Value.ToString()), TraceEventType.Verbose); } } else { PackageLog.Log("Runtime Settings not populated", TraceEventType.Verbose); } }
/// <summary> /// Called after Import completes. /// </summary> /// <returns>After primary import value</returns> public override bool AfterPrimaryImport() { PackageLog.Log("AfterPrimaryImport: Start"); try { if (RuntimeSettings != null) { PackageLog.Log("AfterPrimaryImport: RuntimeSettings is not null"); Settings.AddRuntimeSettings(RuntimeSettings); } var appUser = Settings.GetApplicationUser(); // If the application user Id isn't passed in as parameter, it will be Guid.Empty. In that case we shouldn't proceed further. if (appUser.Id != Guid.Empty) { PackageLog.Log(string.Format("AfterPrimaryImport: Application user Id is: {0}", appUser.Id)); // TODO: Handle First-party application AAD provisioning (auth + single call to graphAPI?) //1.Create application user if it doesn't exist. Get its Id if one exists. var systemUserId = CreateOrGetApplicationUser(appUser); //2.Associate role with user. if (systemUserId != Guid.Empty) { PackageLog.Log(string.Format("AfterPrimaryImport: System user Id is: {0}", systemUserId)); AssignRoleToUser(systemUserId, appUser.RoleId); AssignRoleToUser(systemUserId, appUser.ExportRoleId); } } PackageLog.Log("AfterPrimaryImport: Creating Bulk Delete Job"); CreateBulkDeleteJob(DefaultMonths); PackageLog.Log("AfterPrimaryImport: Completed"); } catch (Exception ex) { PackageLog.Log(string.Format("AfterPrimaryImport: Exception: {0}", ex.ToString())); PackageLog.Log(string.Format("AfterPrimaryImport: StackTrace: {0}", ex.StackTrace)); return(false); } return(true); }
/// <summary> /// Returns the version of specified solution if present. /// </summary> private int[] GetSolutionVersion(string solutionName) { FilterExpression filter = new FilterExpression(LogicalOperator.And); filter.AddCondition(new ConditionExpression("uniquename", ConditionOperator.Equal, solutionName)); QueryExpression query = new QueryExpression { EntityName = "solution", ColumnSet = new ColumnSet("uniquename", "version"), Criteria = filter, PageInfo = new PagingInfo() { ReturnTotalRecordCount = true } }; EntityCollection stuff = CrmSvc.RetrieveMultiple(query); foreach (var i in stuff.Entities) { PackageLog.Log($"Name: {i.GetAttributeValue<string>("uniquename").ToString()} Version: {i.GetAttributeValue<string>("version")}"); } if (stuff.TotalRecordCount < 1) { return(null); } string version = stuff.Entities.First().GetAttributeValue <string>("version"); if (string.IsNullOrEmpty(version)) { return(null); } string[] versions = version.Split('.'); PackageLog.Log($"NonprofitCore - Major:{versions[0]} Minor:{versions[1]} Build:{versions[2]} Revision:{versions[3]}"); int[] versionNumbers = new int[4]; int.TryParse(versions[0], out versionNumbers[0]); int.TryParse(versions[1], out versionNumbers[1]); int.TryParse(versions[2], out versionNumbers[2]); int.TryParse(versions[3], out versionNumbers[3]); return(versionNumbers); }
/// <summary> /// Called When the package is initialized. /// </summary> public override void InitializeCustomExtension() { if (RuntimeSettings != null) { //RuntimeSettings.Add("CommonDataModelNonprofitSampleAppsBase", "true"); PackageLog.Log(string.Format("Runtime Settings populated. Count = {0}", RuntimeSettings.Count)); foreach (var setting in RuntimeSettings) { PackageLog.Log(string.Format("Key={0} | Value={1}", setting.Key, setting.Value.ToString())); } int[] version = GetSolutionVersion("NonprofitCore"); bool? installCore = GetRuntimeSetting("NonprofitCore"); if (installCore == true && version != null && version[0] < 3 && version[1] < 3) { PackageLog.Log("Older version of the Core found adding sample app base solution."); RuntimeSettings.Add("CommonDataModelNonprofitSampleAppsBase", "true"); } else { PackageLog.Log("New install detected no sample app base install required."); RuntimeSettings.Add("CommonDataModelNonprofitSampleAppsBase", "false"); } if (RuntimeSettings.ContainsKey("SkipSampleData")) { bool sample = false; if (bool.TryParse((string)RuntimeSettings["SkipSampleData"], out sample)) { DataImportBypass = sample; } } } else { // Skip sample data by default DataImportBypass = true; } }
/// <summary> /// Override default decision made by PD. /// </summary> public override UserRequestedImportAction OverrideSolutionImportDecision(string solutionUniqueName, Version organizationVersion, Version packageSolutionVersion, Version inboundSolutionVersion, Version deployedSolutionVersion, ImportAction systemSelectedImportAction) { // Solution appears in settings if the request came from the SPA. Follow that request if it exists. if (RuntimeSettings != null && RuntimeSettings.ContainsKey(solutionUniqueName)) { bool install = false; if (bool.TryParse((string)RuntimeSettings[solutionUniqueName], out install) && !install) { PackageLog.Log("Skipping package: " + solutionUniqueName); return(UserRequestedImportAction.Skip); } } // If this request didn't come from the SPA, then this is an upgrade, but default to allow the anchor solution. We don't want to install new solutions, // so only import the ones that already exist on the instance else if (solutionUniqueName?.Equals(ANCHOR_SOLUTION_UNIQUE_NAME) == false && deployedSolutionVersion.Equals(new Version(0, 0, 0, 0))) { return(UserRequestedImportAction.Skip); } PackageLog.Log("Not skipping package: " + solutionUniqueName); return(base.OverrideSolutionImportDecision(solutionUniqueName, organizationVersion, packageSolutionVersion, inboundSolutionVersion, deployedSolutionVersion, systemSelectedImportAction)); }
private Guid?GetExistingUser() { var users = CrmSvc.GetEntityDataBySearchParams("systemuser", new List <CrmServiceClient.CrmSearchFilter> { new CrmServiceClient.CrmSearchFilter { SearchConditions = new List <CrmServiceClient.CrmFilterConditionItem> { new CrmServiceClient.CrmFilterConditionItem { FieldName = "applicationid", FieldOperator = ConditionOperator.Equal, FieldValue = ProposalManagerApplicationId.Value } } } }, CrmServiceClient.LogicalSearchOperator.None, new List <string> { "systemuserid" }); if (users != null) { if (users.Any()) { PackageLog.Log("PM user already created. Id: " + users.First().Value["systemuserid"].ToString()); return((Guid?)users.First().Value["systemuserid"]); } else { return(null); } } else { return(null); } }
private void LogEnd(string name) { PackageLog.Log($"{name.ToUpper()} FINISHED"); PackageLog.Log(Seperator, TraceEventType.Information); }
private void LogStart(string name) { PackageLog.Log(Seperator, TraceEventType.Information); PackageLog.Log($"{name.ToUpper()} STARTING"); }