Skip to content

Commit

Permalink
Merge pull request MscrmTools#236 from daryllabar/master
Browse files Browse the repository at this point in the history
Fix Bug where opening a connection after the plugin is open, results in a null ref error
  • Loading branch information
MscrmTools committed Sep 17, 2015
2 parents ad2e846 + e6018bc commit a0be884
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public FormHelper(Form innerAppForm)
/// Asks this manager to select a Crm connection to use
/// </summary>
/// <param name="connectionParameter">The connection parameter.</param>
/// <param name="preConnectionRequest">The action to be performed before the async call to create the connection. Userful to display a please wait message</param>
/// <param name="preConnectionRequestAction">The action to be performed before the async call to create the connection. Useful to display a please wait message</param>
/// <returns></returns>
public bool AskForConnection(object connectionParameter, Action preConnectionRequest)
public bool AskForConnection(object connectionParameter, Action preConnectionRequestAction)
{
var cs = new ConnectionSelector
{
Expand Down Expand Up @@ -51,11 +51,10 @@ public bool AskForConnection(object connectionParameter, Action preConnectionReq
}
}

if (preConnectionRequest != null)
if (preConnectionRequestAction != null)
{
preConnectionRequest();
preConnectionRequestAction();
}

ConnectionManager.Instance.ConnectToServer(connectionDetail, connectionParameter);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug Without GemBox|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug Without GemBox\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Crm.Sdk.Proxy">
<HintPath>..\..\Referenced Assemblies\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
Expand Down Expand Up @@ -105,7 +114,7 @@
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_ConfigurationName="Release" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.YearStamp.MonthStamp.DayStamp" />
<UserProperties BuildVersion_BuildVersioningStyle="None.YearStamp.MonthStamp.DayStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_ConfigurationName="Release" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,48 @@ public bool RemoveLibrary(Entity form, string libraryName, Form parentForm)
}

// Retrieve events that use the library
var eventNodes = formNode.SelectNodes(string.Format("events/event/Handlers/Handler[@libraryName='{0}']", libraryName));
if (eventNodes != null && eventNodes.Count > 0)
{
var result =
MessageBox.Show(parentForm,
string.Format(
"The library '{2}' is used by {0} event{1}. If you remove the library, {0} event{1} will be removed too\r\n\r\nDo you want to continue?",
eventNodes.Count, eventNodes.Count > 1 ? "s" : "", libraryName), "Question", MessageBoxButtons.YesNo,
var handlerEventNodes = formNode.SelectNodes(string.Format("events/event/Handlers/Handler[@libraryName='{0}']", libraryName));
if (handlerEventNodes != null && handlerEventNodes.Count > 0)
{
var result = DialogResult.None;
parentForm.Invoke((MethodInvoker)delegate {
result = MessageBox.Show(parentForm, string.Format(
"The library '{2}' is used by {0} event{1}. If you remove the library, {0} event{1} will be removed too\r\n\r\nDo you want to continue?",
handlerEventNodes.Count, handlerEventNodes.Count > 1 ? "s" : "", libraryName)
, "Question", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
});

if (result == DialogResult.No)
{
return false;
}

// Remove events that were using the library
foreach (XmlNode handlerNode in handlerEventNodes)
{
// Events> <Event> <Handlers><Handler>
if (handlerNode.ParentNode.ChildNodes.Count == 1)
{
var events = formNode.SelectSingleNode("events");
if (events.ChildNodes.Count == 1)
{
// Remove Events since it only has one Event and the Event only has on handler, and the Handler is getting removed
events.ParentNode.RemoveChild(events);
}
else
{
// Remove Event since it only has one handler and it is being removed, but there are other events
events.RemoveChild(handlerNode.ParentNode.ParentNode);
}

}
else
{
// Remove only handler since there are other handlers
handlerNode.ParentNode.RemoveChild(handlerNode);
}
}
}

var formLibrariesNode = formNode.SelectSingleNode("formLibraries");
Expand All @@ -148,7 +176,7 @@ public bool RemoveLibrary(Entity form, string libraryName, Form parentForm)
var libraryNode = formLibrariesNode.SelectSingleNode(string.Format("Library[@name='{0}']", libraryName));
if (libraryNode == null)
{
throw new Exception("This library is noy included in this form");
throw new Exception("This library is not included in this form");
}

// Remove library
Expand All @@ -159,19 +187,6 @@ public bool RemoveLibrary(Entity form, string libraryName, Form parentForm)
formLibrariesNode.ParentNode.RemoveChild(formLibrariesNode);
}

// Remove events that was using the library
foreach (XmlNode eventNode in eventNodes)
{
if (eventNode.ParentNode.ChildNodes.Count == 1)
{
formNode.SelectSingleNode("events").RemoveChild(eventNode.ParentNode.ParentNode);
}
else
{
eventNode.ParentNode.RemoveChild(eventNode);
}
}

// Update the form xml content
form["formxml"] = formDoc.OuterXml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ private void tsbRemoveCheckedScripts_Click(object sender, EventArgs e)
WorkAsync("Updating forms...",
(bw, evt) =>
{
var scripts = (List<Entity>)((object[])evt.Argument)[0];
var forms = (List<Entity>)((object[])evt.Argument)[1];
var argArray = (List<Entity>[]) evt.Argument;
var scripts = argArray[0];
var forms = argArray[1];
var fManager = new FormManager(Service);
Expand Down Expand Up @@ -307,7 +309,7 @@ private void tsbRemoveCheckedScripts_Click(object sender, EventArgs e)
}
},
evt => SetWorkingMessage(evt.UserState.ToString()),
new[] { scriptsParam, formsParam });
new [] { scriptsParam, formsParam });
}
}
}
9 changes: 9 additions & 0 deletions Plugins/MsCrmTools.FormRelated/MsCrmTools.FormRelated.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug Without GemBox|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug Without GemBox\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Crm.Sdk.Proxy">
<HintPath>..\..\Referenced Assemblies\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug Without GemBox|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug Without GemBox\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Crm.Sdk.Proxy">
<HintPath>..\..\Referenced Assemblies\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
Expand Down
9 changes: 9 additions & 0 deletions XrmToolBox.Extensibility/XrmToolBox.Extensibility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug Without GemBox|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug Without GemBox\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Crm.Sdk.Proxy">
<HintPath>..\Referenced Assemblies\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
Expand Down
20 changes: 10 additions & 10 deletions XrmToolBox.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XrmToolBox", "XrmToolBox\XrmToolBox.csproj", "{328D55BE-8B9A-4087-A5C2-9FBAF623F54B}"
EndProject
Expand Down Expand Up @@ -504,8 +504,8 @@ Global
{236F1329-C748-4C01-948B-98AE9EA89086}.Release|x86.ActiveCfg = Release|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug Without GemBox|Any CPU.ActiveCfg = Debug|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug Without GemBox|Any CPU.Build.0 = Debug|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug Without GemBox|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug Without GemBox|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug Without GemBox|x86.ActiveCfg = Debug|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -519,8 +519,8 @@ Global
{5244E9BE-820A-4613-8ACC-ADC858B83C26}.Release|x86.ActiveCfg = Release|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug Without GemBox|Any CPU.ActiveCfg = Debug|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug Without GemBox|Any CPU.Build.0 = Debug|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug Without GemBox|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug Without GemBox|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug Without GemBox|x86.ActiveCfg = Debug|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -534,8 +534,8 @@ Global
{DF77AEA3-43F7-403C-91AF-3023A3BB06EC}.Release|x86.ActiveCfg = Release|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug Without GemBox|Any CPU.ActiveCfg = Debug|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug Without GemBox|Any CPU.Build.0 = Debug|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug Without GemBox|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug Without GemBox|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug Without GemBox|x86.ActiveCfg = Debug|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -549,8 +549,8 @@ Global
{28F6D950-BC28-4067-98AF-5D6AE70E90A7}.Release|x86.ActiveCfg = Release|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug Without GemBox|Any CPU.ActiveCfg = Debug|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug Without GemBox|Any CPU.Build.0 = Debug|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug Without GemBox|Mixed Platforms.ActiveCfg = Debug Without GemBox|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug Without GemBox|Mixed Platforms.Build.0 = Debug Without GemBox|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug Without GemBox|x86.ActiveCfg = Debug|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACC1243E-912B-45E7-A8B0-E312EE9141DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down
39 changes: 29 additions & 10 deletions XrmToolBox/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
Expand Down Expand Up @@ -89,7 +90,16 @@ private void ManageConnectionControl()
var control = parameter.ConnectionParmater as UserControl;
if (control != null)
{
this.DisplayPluginControl((Lazy<IXrmToolBoxPlugin, IPluginMetadata>)control.Tag);
var pluginModel = control.Tag as Lazy<IXrmToolBoxPlugin, IPluginMetadata>;
if (pluginModel == null)
{
// Actual Plugin was passed, Just update the plugin's Tab.
UpdateTabConnection((TabPage) control.Parent);
}
else
{
this.DisplayPluginControl(pluginModel);
}
}
else if (parameter.ConnectionParmater.ToString() == "ApplyConnectionToTabs" && tabControl1.TabPages.Count > 1)
{
Expand Down Expand Up @@ -281,10 +291,14 @@ private async void MainForm_Load(object sender, EventArgs e)

var tasks = new List<Task>
{
this.LaunchWelcomeDialog(),
this.LaunchVersionCheck()
this.LaunchWelcomeDialog()
};

if (!Debugger.IsAttached)
{
tasks.Add(this.LaunchVersionCheck());
}

if (!string.IsNullOrEmpty(this.initialConnectionName))
{
var connectionDetail = ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(x => x.ConnectionName == this.initialConnectionName); ;
Expand Down Expand Up @@ -662,17 +676,22 @@ private void ApplyConnectionToTabs()
{
foreach (TabPage tab in tcu.SelectedTabs)
{
tab.GetPlugin().UpdateConnection(service, currentConnectionDetail);

tab.Text = string.Format("{0} ({1})",
((Lazy<IXrmToolBoxPlugin, IPluginMetadata>)tab.Tag).Metadata.Name,
currentConnectionDetail != null
? currentConnectionDetail.ConnectionName
: "Not connected");
UpdateTabConnection(tab);
}
}
}

private void UpdateTabConnection(TabPage tab)
{
tab.GetPlugin().UpdateConnection(service, currentConnectionDetail);

tab.Text = string.Format("{0} ({1})",
((Lazy<IXrmToolBoxPlugin, IPluginMetadata>) tab.Tag).Metadata.Name,
currentConnectionDetail != null
? currentConnectionDetail.ConnectionName
: "Not connected");
}

private string ExtractSwitchValue(string key, ref string[] args)
{
var name = string.Empty;
Expand Down

0 comments on commit a0be884

Please sign in to comment.