if (entityCollection.Entities.Count > 0)
{
#region Validate Specified Tab,Section and Insert Control
systemForm = (SystemForm)entityCollection[0];
//Loads form xml to customization
XmlDocument customization = new XmlDocument();
customization.LoadXml(systemForm.FormXml);
//Creates XPathNavigator
XPathNavigator xNav = customization.CreateNavigator();
//Set path to insert new section on mainform.
string validateTab = "//tabs/tab[@name='" + tabName + "']";
string validateSection = validateTab + "/columns/column/sections" +
"/section[@name='" + sectionName + "']";
//Creates new row to place new web resource control with necessary parameters
string newDDList = "<section name='" + sectionName + "' showlabel='false' showbar='false' locklevel='0' id='{6851ca85-b2a6-9689-ead3-3813de16082e}' IsUserDefined='0' layout='varwidth' columns='11' labelwidth='115' celllabelalignment='Left' celllabelposition='Left'> "+
" <labels> "+
" <label description='Extra' languagecode='1033' />"+
" </labels> "+
" <rows> "+
" <row> "+
" </row> "+
" </rows> "+
"</section>";
XPathNodeIterator xIterTab = xNav.Select(xNav.Compile(validateTab));
//Validate specified Tab exists or not
if (xIterTab.Count == 0)
{
throw new InvalidPluginExecutionException("Invalid Tab Name, Please verify");
}
XPathNodeIterator xIterSection = xNav.Select(xNav.Compile(validateSection));
//Validate specified Section exist or not
if (xIterSection.Count > 0)
throw new InvalidPluginExecutionException("The Section is already configured on a form. You cannot specify the existing "
+ "Section Name");
if (xNav.CanEdit)
{
XPathExpression xExpression = xNav.Compile(validateTab + "/columns/column/sections/section");
//Select node using specified path in expression.
XPathNodeIterator xIter = xNav.Select(xExpression);
if (xIter.Count > 0)
{
//Moves navigator to next node from current set node
while (xIter.MoveNext())
{
//Checks position of current node is last node or not.
if (xIter.CurrentPosition == xIter.Count)
//if currnt node is last node then insert new element
xIter.Current.InsertAfter(newDDList);
} }
}
#endregion
#region Update Form xml
//Now we place the updated FormXml back into the systemform, and update it.
systemForm.FormXml = customization.InnerXml;
try
{
organizationService.Update(systemForm);
}
catch (Exception)
{
throw new InvalidPluginExecutionException("Failure: Updating the Formxml changes...");
}
#endregion
}
}