Skip to content

Commit

Permalink
add setpublishtheme command (WaelHamze#177)
Browse files Browse the repository at this point in the history
* add setpublishtheme command

* rename to publish rather than set

* rename for consistency

* added option to publish by theme name
  • Loading branch information
MattTrinder1 authored and WaelHamze committed Dec 17, 2018
1 parent a5b2122 commit 5e6e8a0
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Management.Automation;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Xrm.Framework.CI.PowerShell.Cmdlets.Common;
using System.Linq;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;

namespace Xrm.Framework.CI.PowerShell.Cmdlets
{
/// <summary>
/// <para type="synopsis">Publishes a Dynamics Theme</para>
/// <para type="description">The Publish-XrmTheme cmdlet publishes a Dynamics Theme.
/// </summary>
/// <example>
/// <code>C:\PS>Publish-XrmTheme -ThemeId $themeId</code>
/// <para>Publishes a theme.</para>
/// </example>
/// <para type="link" uri="https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.publishthemerequest?view=dynamics-general-ce-9">PublishTheme.</para>
[Cmdlet(VerbsData.Publish, "XrmTheme")]
public class PublishXrmThemeCommand : XrmCommandBase
{
#region Parameters

/// <summary>
/// <para type="description">The Id of the Theme to publish.</para>
/// </summary>
[Parameter(Mandatory = false)]
public Guid? ThemeId { get; set; }

[Parameter(Mandatory = false)]
public string ThemeName { get; set; }

#endregion

#region Process Record

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"));
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<Compile Include="RemoveXrmEntityCommand.cs" />
<Compile Include="RemoveXrmRecordCommand.cs" />
<Compile Include="SelectXrmWhoAmICommand.cs" />
<Compile Include="PublishXrmThemeCommand.cs" />
<Compile Include="SetXrmEntityCommand.cs" />
<Compile Include="SetXrmSolutionVersionCommand.cs" />
<Compile Include="SetXrmSolutionVersionInFolderCommand.cs" />
Expand Down

0 comments on commit 5e6e8a0

Please sign in to comment.