protected override void ProcessRecord() { try { base.ProcessRecord(); Guid theme = Guid.Empty; if (string.IsNullOrWhiteSpace(ThemeId)) { // Hämta aktivt tema från CRM? throw new Exception("Theme ID not provided."); } if (!Guid.TryParse(ThemeId, out theme)) { WriteInformation(new InformationRecord($"Could not parse ThemeId {ThemeId} as a GUID.", "PublishThemeCmdlet")); throw new Exception($"Could not parse ThemeId {ThemeId} as a GUID."); } WriteVerbose($"Publishing theme '{theme}'."); var request = new PublishThemeRequest(); request.Target = new EntityReference("theme", theme); Service.Execute(request); } catch (Exception e) { WriteError(new ErrorRecord(e, "Error in PublishThemeCmdlet", ErrorCategory.NotSpecified, "")); } }
protected override void ProcessRecord() { base.ProcessRecord(); if (ThemeId == null && ThemeName == null) { throw new Exception("ThemeId or ThemeName not provided"); } if (ThemeId != null && ThemeName != null) { throw new Exception("Only 1 of ThemeId or ThemeName can be specified"); } if (ThemeName != null) { //query for the theme to get the Id var q = new QueryExpression("theme"); q.Criteria.AddCondition("name", ConditionOperator.Equal, ThemeName); var entities = OrganizationService.RetrieveMultiple(q); if (!entities.Entities.Any()) { throw new Exception("Could not locate theme by name"); } ThemeId = entities.Entities.First().Id; } base.WriteVerbose(string.Format("Publishing Theme")); var req = new PublishThemeRequest(); req.Target = new EntityReference("theme", ThemeId.Value); OrganizationService.Execute(req); base.WriteVerbose(string.Format("Theme Published")); }
private void PublishTheme() { string themeName = "xRMCISample"; string logoName = "ud_/Images/logo.png"; bool publish = false; bool update = false; QueryByAttribute qba = new QueryByAttribute("theme"); qba.Attributes.Add("name"); qba.Values.Add(themeName); qba.ColumnSet = new ColumnSet("themeid", "isdefaulttheme", "logoid"); EntityCollection themes = base.CrmSvc.RetrieveMultiple(qba); if (themes.Entities.Count == 0) { throw new Exception("Theme not found"); } Entity theme = themes.Entities[0]; if (!(bool)theme.Attributes["isdefaulttheme"]) { base.PackageLog.Log($"{themeName} is not published", TraceEventType.Information); publish = true; } Entity logo = GetLogo(logoName); if (!theme.Attributes.Contains("logoid")) { base.PackageLog.Log($"{logoName} is not set", TraceEventType.Information); publish = true; update = true; } else { if (logo.Id != ((EntityReference)theme["logoid"]).Id) { base.PackageLog.Log($"{logoName} has changed", TraceEventType.Information); publish = true; update = true; } else { base.PackageLog.Log($"{logoName} is same", TraceEventType.Verbose); } } if (update) { Entity logoUpdate = new Entity("theme", theme.Id); logoUpdate["logoid"] = logo.ToEntityReference(); base.CrmSvc.Update(logoUpdate); base.PackageLog.Log($"{logoName} Updated", TraceEventType.Information); } if (publish) { base.PackageLog.Log("Publishing Theme", TraceEventType.Verbose); PublishThemeRequest req = new PublishThemeRequest(); req.Target = theme.ToEntityReference(); base.CrmSvc.Execute(req); base.PackageLog.Log("Published Theme", TraceEventType.Information); } }