B2021-045: Search/Load, don’t crash if noncompatible Xml file
This commit is contained in:
parent
1e85522762
commit
814d26f713
@ -2321,144 +2321,152 @@ namespace Volian.Controls.Library
|
|||||||
lbSrchResults.DataSource = null;
|
lbSrchResults.DataSource = null;
|
||||||
lbSrchResults.Items.Clear();
|
lbSrchResults.Items.Clear();
|
||||||
toolTip1.SetToolTip(lbSrchResults, null);
|
toolTip1.SetToolTip(lbSrchResults, null);
|
||||||
Cursor = Cursors.WaitCursor;
|
|
||||||
string unitPrefix = "";
|
string unitPrefix = "";
|
||||||
if (Mydocversion != null)
|
if (Mydocversion != null)
|
||||||
unitPrefix = Mydocversion.DocVersionConfig.Unit_ProcedureNumber;
|
unitPrefix = Mydocversion.DocVersionConfig.Unit_ProcedureNumber;
|
||||||
if (unitPrefix.EndsWith("#"))
|
if (unitPrefix.EndsWith("#"))
|
||||||
unitPrefix = unitPrefix.Replace("#", "");
|
unitPrefix = unitPrefix.Replace("#", "");
|
||||||
SearchResults = ItemInfoList.GetByContentID(0);
|
Cursor = Cursors.WaitCursor;
|
||||||
// C2021-006: removed all file type options except xml
|
try // B2021-045: don't crash if xml file cannot be loaded.
|
||||||
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
|
|
||||||
xd.Load(ofdSearchResults.FileName);
|
|
||||||
// B2020-107: Add missing attributes/nodes for loading of search results, include procsets & steptypes:
|
|
||||||
System.Xml.XmlNodeList nlp = xd.SelectNodes("search/procsets/set");
|
|
||||||
if (nlp != null)
|
|
||||||
{
|
{
|
||||||
DocVersionInfo tmpdvi = Mydocversion;
|
SearchResults = ItemInfoList.GetByContentID(0);
|
||||||
DocVersionInfo fromLoadFiledvi = null;
|
// C2021-006: removed all file type options except xml
|
||||||
foreach (System.Xml.XmlNode nd in nlp)
|
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
|
||||||
|
xd.Load(ofdSearchResults.FileName);
|
||||||
|
// B2020-107: Add missing attributes/nodes for loading of search results, include procsets & steptypes:
|
||||||
|
System.Xml.XmlNodeList nlp = xd.SelectNodes("search/procsets/set");
|
||||||
|
if (nlp != null)
|
||||||
{
|
{
|
||||||
int folderID = int.Parse(nd.Attributes.GetNamedItem("fid").InnerText);
|
DocVersionInfo tmpdvi = Mydocversion;
|
||||||
FolderInfo fi = FolderInfo.Get(folderID);
|
DocVersionInfo fromLoadFiledvi = null;
|
||||||
_MyDocVersion = fi.FolderDocVersions[0];
|
foreach (System.Xml.XmlNode nd in nlp)
|
||||||
if (fromLoadFiledvi == null) fromLoadFiledvi = _MyDocVersion;
|
|
||||||
advTreeProcSetsPreSelect();
|
|
||||||
}
|
|
||||||
foreach (System.Xml.XmlNode nd in nlp)
|
|
||||||
{
|
|
||||||
int folderID = int.Parse(nd.Attributes.GetNamedItem("fid").InnerText);
|
|
||||||
FolderInfo fi = FolderInfo.Get(folderID);
|
|
||||||
Node tnode = advTreeProcSets.FindNodeByDataKey(folderID);
|
|
||||||
if (tnode != null) tnode.Checked = true;
|
|
||||||
}
|
|
||||||
Mydocversion = tmpdvi == null ? fromLoadFiledvi : tmpdvi;
|
|
||||||
}
|
|
||||||
AdvTreeStepTypesFillIn();
|
|
||||||
System.Xml.XmlNodeList nl1 = xd.SelectNodes("search/StepType/type");
|
|
||||||
if (nl1 != null)
|
|
||||||
{
|
|
||||||
foreach (System.Xml.XmlNode nd in nl1)
|
|
||||||
{
|
|
||||||
string stptype = nd.Attributes.GetNamedItem("str").InnerText;
|
|
||||||
Node tnode = advTreeStepTypes.FindNodeByText(stptype);
|
|
||||||
if (tnode != null)
|
|
||||||
{
|
{
|
||||||
tnode.Checked = true;
|
int folderID = int.Parse(nd.Attributes.GetNamedItem("fid").InnerText);
|
||||||
xpStepTypes.TitleStyle.BackColor1.Color = saveXpStepTypeTitleColor;
|
FolderInfo fi = FolderInfo.Get(folderID);
|
||||||
lstCheckedStepTypesStr.Add(stptype);
|
_MyDocVersion = fi.FolderDocVersions[0];
|
||||||
StepData sd = (StepData)tnode.Tag;
|
if (fromLoadFiledvi == null) fromLoadFiledvi = _MyDocVersion;
|
||||||
lstCheckedStepTypes.Add((int)sd.Index);
|
advTreeProcSetsPreSelect();
|
||||||
}
|
}
|
||||||
}
|
foreach (System.Xml.XmlNode nd in nlp)
|
||||||
string typstr = null;
|
|
||||||
foreach (string s in lstCheckedStepTypesStr) typstr = typstr == null ? s : typstr + ", " + s;
|
|
||||||
TypesSelected = "Filtered By: " + ((typstr != null) ? typstr : "All Step Types");
|
|
||||||
ReportTitle = "Step Element Report"; //"Proms - Search by Type: " + typstr;
|
|
||||||
TypesSelected = "Filtered By: " + typstr;
|
|
||||||
advTreeStepTypes.RefreshItems();
|
|
||||||
buildStepTypePannelTitle();
|
|
||||||
}
|
|
||||||
cmbResultsStyle.Text = xd.SelectSingleNode("search/results/@style").InnerText;
|
|
||||||
int sti = int.Parse(xd.SelectSingleNode("search/criteria/@index").InnerText);
|
|
||||||
switch (sti)
|
|
||||||
{
|
|
||||||
case 0: //text or steptypes
|
|
||||||
{
|
{
|
||||||
System.Xml.XmlNode xn = xd.SelectSingleNode("search/criteria/@text");
|
int folderID = int.Parse(nd.Attributes.GetNamedItem("fid").InnerText);
|
||||||
tabSearchTypes.SelectedTab = tabStepTypeSearch;
|
FolderInfo fi = FolderInfo.Get(folderID);
|
||||||
if (xn != null) // text search
|
Node tnode = advTreeProcSets.FindNodeByDataKey(folderID);
|
||||||
{
|
if (tnode != null) tnode.Checked = true;
|
||||||
cbxTextSearchText.Text = xn.InnerText;
|
|
||||||
cbxCaseSensitive.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@case").InnerText);
|
|
||||||
cbxIncROTextSrch.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@ro").InnerText);
|
|
||||||
cbxByWord.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@byword").InnerText);
|
|
||||||
}
|
|
||||||
else // B2020-107: Add in step type search
|
|
||||||
{
|
|
||||||
cbxSrchTypeUsage.Checked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.Xml.XmlNodeList nl = xd.SelectNodes("search/results/item");
|
|
||||||
foreach (System.Xml.XmlNode nd in nl)
|
|
||||||
{
|
|
||||||
int itemID = int.Parse(nd.Attributes.GetNamedItem("id").InnerText);
|
|
||||||
ItemInfo ii = ItemInfo.Get(itemID);
|
|
||||||
if (ii.SearchAnnotationText == null && ii.ItemAnnotations != null) ii.SearchAnnotationText = AnnotationInfo.Get(ii.ItemAnnotations[0].AnnotationID).SearchText;
|
|
||||||
SearchResults.AddItemInfo(ii);
|
|
||||||
}
|
|
||||||
lbSrchResults.DataSource = SearchResults;
|
|
||||||
DisplayResults();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 1: //annotation
|
Mydocversion = tmpdvi == null ? fromLoadFiledvi : tmpdvi;
|
||||||
|
}
|
||||||
|
AdvTreeStepTypesFillIn();
|
||||||
|
System.Xml.XmlNodeList nl1 = xd.SelectNodes("search/StepType/type");
|
||||||
|
if (nl1 != null)
|
||||||
|
{
|
||||||
|
foreach (System.Xml.XmlNode nd in nl1)
|
||||||
{
|
{
|
||||||
cbxAnnoTypes.Text = xd.SelectSingleNode("search/criteria/@type").InnerText;
|
string stptype = nd.Attributes.GetNamedItem("str").InnerText;
|
||||||
cbxTextSearchAnnotation.Text = xd.SelectSingleNode("search/criteria/@text").InnerText;
|
Node tnode = advTreeStepTypes.FindNodeByText(stptype);
|
||||||
cbxCaseSensitiveAnnoText.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@case").InnerText);
|
if (tnode != null)
|
||||||
tabSearchTypes.SelectedTab = tabAnnotationSearch;
|
|
||||||
cmbResultsStyle.Text = xd.SelectSingleNode("search/results/@style").InnerText;
|
|
||||||
System.Xml.XmlNodeList nl = xd.SelectNodes("search/results/item");
|
|
||||||
foreach (System.Xml.XmlNode nd in nl)
|
|
||||||
{
|
{
|
||||||
int itemID = int.Parse(nd.Attributes.GetNamedItem("id").InnerText);
|
tnode.Checked = true;
|
||||||
ItemInfo ii = ItemInfo.Get(itemID);
|
xpStepTypes.TitleStyle.BackColor1.Color = saveXpStepTypeTitleColor;
|
||||||
// B2020-107: The following was needed to set the Step Path result type for annotations
|
lstCheckedStepTypesStr.Add(stptype);
|
||||||
if (ii.SearchAnnotationText == null && ii.ItemAnnotations != null)
|
StepData sd = (StepData)tnode.Tag;
|
||||||
|
lstCheckedStepTypes.Add((int)sd.Index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string typstr = null;
|
||||||
|
foreach (string s in lstCheckedStepTypesStr) typstr = typstr == null ? s : typstr + ", " + s;
|
||||||
|
TypesSelected = "Filtered By: " + ((typstr != null) ? typstr : "All Step Types");
|
||||||
|
ReportTitle = "Step Element Report"; //"Proms - Search by Type: " + typstr;
|
||||||
|
TypesSelected = "Filtered By: " + typstr;
|
||||||
|
advTreeStepTypes.RefreshItems();
|
||||||
|
buildStepTypePannelTitle();
|
||||||
|
}
|
||||||
|
cmbResultsStyle.Text = xd.SelectSingleNode("search/results/@style").InnerText;
|
||||||
|
int sti = int.Parse(xd.SelectSingleNode("search/criteria/@index").InnerText);
|
||||||
|
switch (sti)
|
||||||
|
{
|
||||||
|
case 0: //text or steptypes
|
||||||
|
{
|
||||||
|
System.Xml.XmlNode xn = xd.SelectSingleNode("search/criteria/@text");
|
||||||
|
tabSearchTypes.SelectedTab = tabStepTypeSearch;
|
||||||
|
if (xn != null) // text search
|
||||||
{
|
{
|
||||||
ii.SearchAnnotationText = AnnotationInfo.Get(ii.ItemAnnotations[0].AnnotationID).SearchText;
|
cbxTextSearchText.Text = xn.InnerText;
|
||||||
ii.SearchAnnotationID = ii.ItemAnnotations[0].AnnotationID;
|
cbxCaseSensitive.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@case").InnerText);
|
||||||
|
cbxIncROTextSrch.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@ro").InnerText);
|
||||||
|
cbxByWord.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@byword").InnerText);
|
||||||
}
|
}
|
||||||
SearchResults.AddItemInfo(ii);
|
else // B2020-107: Add in step type search
|
||||||
|
{
|
||||||
|
cbxSrchTypeUsage.Checked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Xml.XmlNodeList nl = xd.SelectNodes("search/results/item");
|
||||||
|
foreach (System.Xml.XmlNode nd in nl)
|
||||||
|
{
|
||||||
|
int itemID = int.Parse(nd.Attributes.GetNamedItem("id").InnerText);
|
||||||
|
ItemInfo ii = ItemInfo.Get(itemID);
|
||||||
|
if (ii.SearchAnnotationText == null && ii.ItemAnnotations != null) ii.SearchAnnotationText = AnnotationInfo.Get(ii.ItemAnnotations[0].AnnotationID).SearchText;
|
||||||
|
SearchResults.AddItemInfo(ii);
|
||||||
|
}
|
||||||
|
lbSrchResults.DataSource = SearchResults;
|
||||||
|
DisplayResults();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
lbSrchResults.DataSource = SearchResults;
|
case 1: //annotation
|
||||||
DisplayResults();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2: //referenced object
|
|
||||||
case 3: // transitions
|
|
||||||
{
|
|
||||||
FlexibleMessageBox.Show(this, "Loading Referenced Objects and Transitions searches is under construction.", "Under Construction", MessageBoxButtons.OK);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 4: // Incoming transitions
|
|
||||||
{
|
|
||||||
tabSearchTypes.SelectedTab = tabIncTrans;
|
|
||||||
cmbResultsStyle.Text = xd.SelectSingleNode("search/results/@style").InnerText;
|
|
||||||
string tmpi = xd.SelectSingleNode("search/results/@toid").InnerText;
|
|
||||||
SearchIncTransII = ItemInfo.Get(Convert.ToInt32(tmpi));
|
|
||||||
System.Xml.XmlNodeList nl = xd.SelectNodes("search/results/item");
|
|
||||||
foreach (System.Xml.XmlNode nd in nl)
|
|
||||||
{
|
{
|
||||||
int itemID = int.Parse(nd.Attributes.GetNamedItem("id").InnerText);
|
cbxAnnoTypes.Text = xd.SelectSingleNode("search/criteria/@type").InnerText;
|
||||||
ItemInfo ii = ItemInfo.Get(itemID);
|
cbxTextSearchAnnotation.Text = xd.SelectSingleNode("search/criteria/@text").InnerText;
|
||||||
if (ii.SearchAnnotationText == null && ii.ItemAnnotations != null) ii.SearchAnnotationText = AnnotationInfo.Get(ii.ItemAnnotations[0].AnnotationID).SearchText;
|
cbxCaseSensitiveAnnoText.Checked = bool.Parse(xd.SelectSingleNode("search/criteria/@case").InnerText);
|
||||||
SearchResults.AddItemInfo(ii);
|
tabSearchTypes.SelectedTab = tabAnnotationSearch;
|
||||||
|
cmbResultsStyle.Text = xd.SelectSingleNode("search/results/@style").InnerText;
|
||||||
|
System.Xml.XmlNodeList nl = xd.SelectNodes("search/results/item");
|
||||||
|
foreach (System.Xml.XmlNode nd in nl)
|
||||||
|
{
|
||||||
|
int itemID = int.Parse(nd.Attributes.GetNamedItem("id").InnerText);
|
||||||
|
ItemInfo ii = ItemInfo.Get(itemID);
|
||||||
|
// B2020-107: The following was needed to set the Step Path result type for annotations
|
||||||
|
if (ii.SearchAnnotationText == null && ii.ItemAnnotations != null)
|
||||||
|
{
|
||||||
|
ii.SearchAnnotationText = AnnotationInfo.Get(ii.ItemAnnotations[0].AnnotationID).SearchText;
|
||||||
|
ii.SearchAnnotationID = ii.ItemAnnotations[0].AnnotationID;
|
||||||
|
}
|
||||||
|
SearchResults.AddItemInfo(ii);
|
||||||
|
}
|
||||||
|
lbSrchResults.DataSource = SearchResults;
|
||||||
|
DisplayResults();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
lbSrchResultsIncTrans.DataSource = SearchResults;
|
case 2: //referenced object
|
||||||
DisplayResults();
|
case 3: // transitions
|
||||||
break;
|
{
|
||||||
}
|
FlexibleMessageBox.Show(this, "Loading Referenced Objects and Transitions searches is under construction.", "Under Construction", MessageBoxButtons.OK);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: // Incoming transitions
|
||||||
|
{
|
||||||
|
tabSearchTypes.SelectedTab = tabIncTrans;
|
||||||
|
cmbResultsStyle.Text = xd.SelectSingleNode("search/results/@style").InnerText;
|
||||||
|
string tmpi = xd.SelectSingleNode("search/results/@toid").InnerText;
|
||||||
|
SearchIncTransII = ItemInfo.Get(Convert.ToInt32(tmpi));
|
||||||
|
System.Xml.XmlNodeList nl = xd.SelectNodes("search/results/item");
|
||||||
|
foreach (System.Xml.XmlNode nd in nl)
|
||||||
|
{
|
||||||
|
int itemID = int.Parse(nd.Attributes.GetNamedItem("id").InnerText);
|
||||||
|
ItemInfo ii = ItemInfo.Get(itemID);
|
||||||
|
if (ii.SearchAnnotationText == null && ii.ItemAnnotations != null) ii.SearchAnnotationText = AnnotationInfo.Get(ii.ItemAnnotations[0].AnnotationID).SearchText;
|
||||||
|
SearchResults.AddItemInfo(ii);
|
||||||
|
}
|
||||||
|
lbSrchResultsIncTrans.DataSource = SearchResults;
|
||||||
|
DisplayResults();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
FlexibleMessageBox.Show("An error occurred while reading the xml file.\r\n\r\nThis can happen when the file selected for the Load is not saved\r\n" +
|
||||||
|
"from a PROMS Search or if some of the steps no longer exist.", "Search Load Failed", MessageBoxButtons.OK);
|
||||||
}
|
}
|
||||||
Cursor = Cursors.Default;
|
Cursor = Cursors.Default;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user