Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Repeat Registration" functionality for plug-in assemblies #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Xrm.Sdk.PluginRegistration/Forms/PluginRegistrationForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public partial class PluginRegistrationForm : Form
private List<CrmPlugin> m_registeredPluginList;

#endregion Private Fields

#region Public Properties
public string AssemblyFileName { get; set; }
#endregion Public Properties

#region Public Constructors

Expand Down Expand Up @@ -161,13 +165,30 @@ private void AssemblyPathControl_PathChanged(object sender, EventArgs e)
}
}

public void RepeatRegistration(string assemblyFileName)
{
CheckAndLoadAssembly(assemblyFileName);
RegisterPlugin();
}

private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}


private void btnLoadAssembly_Click(object sender, EventArgs e)
{
CheckAndLoadAssembly();
}

private void CheckAndLoadAssembly(string assemblyFileName = null)
{
if (!string.IsNullOrEmpty(assemblyFileName))
{
AssemblyPathControl.FileName = assemblyFileName;
}

if (!AssemblyPathControl.FileExists)
{
MessageBox.Show("Error: Unable to locate the specified file. Please ensure that it exists",
Expand All @@ -179,6 +200,7 @@ private void btnLoadAssembly_Click(object sender, EventArgs e)
CrmPluginAssembly assembly;
try
{
AssemblyFileName = AssemblyPathControl.FileName;
assembly = RegistrationHelper.RetrievePluginsFromAssembly(AssemblyPathControl.FileName);
}
catch (Exception ex)
Expand All @@ -202,6 +224,11 @@ private void btnLoadAssembly_Click(object sender, EventArgs e)
}

private void btnRegister_Click(object sender, EventArgs e)
{
RegisterPlugin();
}

private void RegisterPlugin()
{
const string ERROR_CAPTION = "Registration Error";
string ERROR_MESSAGE;
Expand Down
12 changes: 12 additions & 0 deletions Xrm.Sdk.PluginRegistration/MainControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 74 additions & 4 deletions Xrm.Sdk.PluginRegistration/MainControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public partial class MainControl : PluginControlBase, IStatusBarMessenger, IGitH
private Dictionary<Guid, Guid> m_stepEntityMap = new Dictionary<Guid, Guid>();
private Dictionary<Guid, Guid> m_stepParentList = null;
private Dictionary<Guid, Guid> m_viewNodeList = null;
private string m_lastAssemblyFileName = null;
private string m_lastRepeatedAssemblyName = null;


#endregion Private Fields

Expand Down Expand Up @@ -138,7 +141,8 @@ public MainControl()
"UninstallProfiler",
"Debug",
"Close",
"Save");
"Save",
"Repeat");

toolRegister.Image = imageList["Register"];
toolView.Image = imageList["View"];
Expand All @@ -149,6 +153,8 @@ public MainControl()
toolUnregister.Image = imageList["Delete"];
mnuContextNodeUnregister.Image = toolUnregister.Image;

toolRepeat.Image = imageList["Repeat"];

toolSearch.Image = imageList["Search"];
mnuContextNodeSearch.Image = toolSearch.Image;
mnuContextGeneralSearch.Image = toolSearch.Image;
Expand Down Expand Up @@ -607,16 +613,23 @@ public void ShowAboutDialog()
}
}

public void ShowSystemItemError(string text)
public void ShowSystemItemError(string text, bool showSystemMessage = true)
{
if (text == null)
{
MessageBox.Show(SYSTEM_ERROR_MESSAGE, SYSTEM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show(string.Format("{0}\n{1}", SYSTEM_ERROR_MESSAGE, text),
SYSTEM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
if (showSystemMessage)
{
MessageBox.Show(string.Format("{0}\n{1}", SYSTEM_ERROR_MESSAGE, text),
SYSTEM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show( text, SYSTEM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

Expand Down Expand Up @@ -1282,6 +1295,7 @@ private void SelectItem(ICrmTreeNode node)
{
//Reset the visibility and enabled properties because we don't what is enabled
toolUpdate.Visible = false;
toolRepeat.Visible = false;
mnuContextNodeUpdate.Visible = false;

toolEnable.Visible = false;
Expand Down Expand Up @@ -1327,6 +1341,9 @@ private void SelectItem(ICrmTreeNode node)
btnSave.Enabled = true;
//Load the data table and display information
gridTable = OrganizationHelper.CreateDataTable<CrmPlugin>(CrmPlugin.Columns, assembly.Plugins);

toolRepeat.Visible = true;

}
break;

Expand Down Expand Up @@ -1697,6 +1714,55 @@ private void toolUnregister_Click(object sender, EventArgs e)
}
}


private void toolRepeat_Click(object sender, EventArgs e)
{
if (IsNodeSystemItem(trvPlugins.SelectedNode))
{
ShowSystemItemError("The assembly cannot be updated.");
return;
}

if (String.IsNullOrEmpty(m_lastAssemblyFileName))
{
ShowSystemItemError("Please register the assembly manually first", false);
return;
}

switch (trvPlugins.SelectedNode.NodeType)
{
case CrmTreeNodeType.Assembly:
{

if (m_lastRepeatedAssemblyName != ((CrmPluginAssembly)trvPlugins.SelectedNode).Name)
{
ShowSystemItemError("Repeat can only be used on the last registered assembly", false);
return;
}

var regForm = new PluginRegistrationForm(Organization, this, (CrmPluginAssembly)trvPlugins.SelectedNode);
m_lastRepeatedAssemblyName = ((CrmPluginAssembly)trvPlugins.SelectedNode).Name;


regForm.RepeatRegistration(m_lastAssemblyFileName);
}
break;


default:
ShowSystemItemError("Repeat can only be used on assemblies", false);
break;
}

ICrmTreeNode node = trvPlugins.SelectedNode;
if (node != null)
{
trvPlugins_SelectionChanged(sender, new CrmTreeNodeTreeEventArgs(node, TreeViewAction.Unknown));
}

}


private void toolUpdate_Click(object sender, EventArgs e)
{
if (IsNodeSystemItem(trvPlugins.SelectedNode))
Expand All @@ -1711,6 +1777,8 @@ private void toolUpdate_Click(object sender, EventArgs e)
{
var regForm = new PluginRegistrationForm(Organization, this, (CrmPluginAssembly)trvPlugins.SelectedNode);
regForm.ShowDialog(ParentForm);
m_lastAssemblyFileName = regForm.AssemblyFileName;
m_lastRepeatedAssemblyName = ((CrmPluginAssembly)trvPlugins.SelectedNode).Name;
}
break;

Expand Down Expand Up @@ -2350,5 +2418,7 @@ private void UpdateNodeText()
}

#endregion Private Classes


}
}
21 changes: 8 additions & 13 deletions Xrm.Sdk.PluginRegistration/MainControl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="mnuContextNode.TrayLocation" type="System.Drawing.Point, System.Drawing">
<metadata name="mnuContextNode.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>153, 17</value>
</data>
<data name="mnuContextGeneral.TrayLocation" type="System.Drawing.Point, System.Drawing">
</metadata>
<metadata name="mnuContextGeneral.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>291, 17</value>
</data>
<data name="toolBar.TrayLocation" type="System.Drawing.Point, System.Drawing">
</metadata>
<metadata name="toolBar.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>441, 17</value>
</data>
<data name="imlEnableImages.TrayLocation" type="System.Drawing.Point, System.Drawing">
</metadata>
<metadata name="imlEnableImages.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="TabIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\dynamics365_icon_32.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</metadata>
</root>
10 changes: 10 additions & 0 deletions Xrm.Sdk.PluginRegistration/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Xrm.Sdk.PluginRegistration/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,7 @@
<data name="TabIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\dynamics365-icon-16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Repeat" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Repeat-All-24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Xrm.Sdk.PluginRegistration/Resources/Repeat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Xrm.Sdk.PluginRegistration/Xrm.Sdk.PluginRegistration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Repeat-All-24.png" />
<None Include="Resources\Repeat.png" />
<None Include="bin\coretools\CrmSvcUtil.exe.config" />
<None Include="bin\coretools\LicenseTerms.docx" />
<None Include="bin\coretools\SolutionPackager.exe.config" />
Expand Down