Added Error Log code to record errors when import fails

Added Error handling to Import so that Change Manager is turned-on after Import whether it is successful or not.
Don't allow import if the Referenced Objects have not been selected.
Turn On Change Manager if there are no active sessions
Don't crash if the Referenced Objects are not set when you right-click on a Working Draft.
This commit is contained in:
Rich 2017-02-10 16:23:31 +00:00
parent 0deea55d7e
commit 69b7de9fc5
3 changed files with 213 additions and 165 deletions

View File

@ -16,6 +16,9 @@ namespace VEPROMS
{ {
public partial class dlgExportImport : Form public partial class dlgExportImport : Form
{ {
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
private bool _ConvertROsToTextDuringImport = false; private bool _ConvertROsToTextDuringImport = false;
private bool _ConvertROsAndTransitionsToText = false; // set to true when Approval creates an Export file private bool _ConvertROsAndTransitionsToText = false; // set to true when Approval creates an Export file
@ -211,7 +214,7 @@ namespace VEPROMS
if (MyFolder != null) // import a folder - a .expx file if (MyFolder != null) // import a folder - a .expx file
{ {
TurnChangeManagerOff.Execute(); TurnChangeManagerOff.Execute();
LoadImportDataDocument(); TryToLoadImportDataDocument();// Added Try Catch Error Handling to assure that the Change Manager is tuned-on
MyDocVersion = null; MyDocVersion = null;
isImported = true; isImported = true;
TurnChangeManagerOn.Execute(); TurnChangeManagerOn.Execute();
@ -226,6 +229,57 @@ namespace VEPROMS
// * set newRODbid to MyDocVersion rodbid // * set newRODbid to MyDocVersion rodbid
// - or convert ROs to text // - or convert ROs to text
TurnChangeManagerOff.Execute(); TurnChangeManagerOff.Execute();
// Added Try Catch Error Handling to assure that the Change Manager is tuned-on
bool result = TryToImportProcedure(ref isImported, ref canceledPressed);
TurnChangeManagerOn.Execute();
if (!result) return;
if (isImported)
{
TimeSpan elapsed = DateTime.Now.Subtract(MyStart);
lblImportStatus.Text = "Import Completed in " + elapsed.ToString();
}
else
{
btnImport.Enabled = true;
btnDoImport.Enabled = true;
}
}
this.Cursor = Cursors.Default;
btnCloseImport.Enabled = true;
if (isImported)
{
string msg = string.Format("Finished Importing:\n\n{0}", txtImport.Text.Substring(txtImport.Text.LastIndexOf("\\") + 1));
if (_DidConvertTransitionsToText || _DidConvertROsToText)
{
string msg1 = (_DidConvertTransitionsToText && _DidConvertROsToText)?"Transitions and Referenced Objects":(_DidConvertTransitionsToText)?"Transitions":"Referenced Objects";
msg += string.Format("\n\n{0} converted to text.\n\nThe locations can be found by doing a Global Search for the \"Link Converted To Text\" annotation type",msg1);
}
// B2016-225 added more information to the finish import message to tell the user when ROs or Transitions are converted to text.
MessageBox.Show(msg, "Import", MessageBoxButtons.OK, MessageBoxIcon.Information);
//MessageBox.Show(string.Format("Finished Importing:\n\n{0}", txtImport.Text.Substring(txtImport.Text.LastIndexOf("\\") + 1)), "Import", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (canceledPressed)
{
MessageBox.Show(string.Format("Canceling the import of:\n\n{0}",txtImport.Text.Substring(txtImport.Text.LastIndexOf("\\")+1)),"Import",MessageBoxButtons.OK,MessageBoxIcon.Information);
btnCloseImport.PerformClick();
}
}
private bool TryToImportProcedure(ref bool isImported, ref bool canceledPressed)
{
try
{
return ImportProcedure(ref isImported, ref canceledPressed);
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
_MyLog.Warn("Failed during Procedure Import", ex);
this.Close();
return false;
}
}
private bool ImportProcedure(ref bool isImported, ref bool canceledPressed)
{
XmlDocument xd = new XmlDocument(); XmlDocument xd = new XmlDocument();
xd.Load(txtImport.Text); xd.Load(txtImport.Text);
pbImportProcedure.Maximum = 1; pbImportProcedure.Maximum = 1;
@ -249,7 +303,7 @@ namespace VEPROMS
this.Cursor = Cursors.Default; this.Cursor = Cursors.Default;
this.btnImport.Enabled = true; // allow user to select a different export file to import this.btnImport.Enabled = true; // allow user to select a different export file to import
this.btnDoImport.Enabled = true; // allow user to change mind and perform the import this.btnDoImport.Enabled = true; // allow user to change mind and perform the import
return; return false; // Return False to Indicate that the Import did not succeed
} }
_ConvertROsToTextDuringImport = dlg.ConvertROsToText; _ConvertROsToTextDuringImport = dlg.ConvertROsToText;
} }
@ -293,7 +347,7 @@ namespace VEPROMS
{ {
MessageBox.Show("There has been no RO folder defined for this database.\r\n\r\nIn order to import a procedure, you need to assign a RO folder path.\r\n\r\nImport process will terminate."); MessageBox.Show("There has been no RO folder defined for this database.\r\n\r\nIn order to import a procedure, you need to assign a RO folder path.\r\n\r\nImport process will terminate.");
this.Cursor = Cursors.Default; this.Cursor = Cursors.Default;
return; return false;// Return False to Indicate that the Import did not succeed
} }
else else
{ {
@ -326,7 +380,7 @@ namespace VEPROMS
{ {
MessageBox.Show("Since you did not pick an existing RO folder defined for this database, the import process will terminate."); MessageBox.Show("Since you did not pick an existing RO folder defined for this database, the import process will terminate.");
this.Close();// Close the Import Window this.Close();// Close the Import Window
return; return false;// Return False to Indicate that the Import did not succeed
} }
} }
} }
@ -387,36 +441,18 @@ namespace VEPROMS
ImportProcedureNew(xd); ImportProcedureNew(xd);
isImported = true; isImported = true;
} }
TurnChangeManagerOn.Execute(); return true;// Import Suceeded
if (isImported)
{
TimeSpan elapsed = DateTime.Now.Subtract(MyStart);
lblImportStatus.Text = "Import Completed in " + elapsed.ToString();
} }
else // Added Error Handling to assure that Change Manager is turned-on regardless of success or failure of the import
private void TryToLoadImportDataDocument()
{ {
btnImport.Enabled = true; try
btnDoImport.Enabled = true;
}
}
this.Cursor = Cursors.Default;
btnCloseImport.Enabled = true;
if (isImported)
{ {
string msg = string.Format("Finished Importing:\n\n{0}", txtImport.Text.Substring(txtImport.Text.LastIndexOf("\\") + 1)); LoadImportDataDocument();
if (_DidConvertTransitionsToText || _DidConvertROsToText)
{
string msg1 = (_DidConvertTransitionsToText && _DidConvertROsToText)?"Transitions and Referenced Objects":(_DidConvertTransitionsToText)?"Transitions":"Referenced Objects";
msg += string.Format("\n\n{0} converted to text.\n\nThe locations can be found by doing a Global Search for the \"Link Converted To Text\" annotation type",msg1);
} }
// B2016-225 added more information to the finish import message to tell the user when ROs or Transitions are converted to text. catch (Exception ex)
MessageBox.Show(msg, "Import", MessageBoxButtons.OK, MessageBoxIcon.Information);
//MessageBox.Show(string.Format("Finished Importing:\n\n{0}", txtImport.Text.Substring(txtImport.Text.LastIndexOf("\\") + 1)), "Import", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (canceledPressed)
{ {
MessageBox.Show(string.Format("Canceling the import of:\n\n{0}",txtImport.Text.Substring(txtImport.Text.LastIndexOf("\\")+1)),"Import",MessageBoxButtons.OK,MessageBoxIcon.Information); _MyLog.Warn("Failure During Import", ex);
btnCloseImport.PerformClick();
} }
} }
private void ImportProcedureNew(XmlDocument xd) private void ImportProcedureNew(XmlDocument xd)

View File

@ -538,6 +538,13 @@ namespace VEPROMS
} }
else else
{ {
dvi.RefreshDocVersionAssociations(); // Refresh Associations Count
//Only allow Import if the Referenced Object Database is set
if ( dvi.DocVersionAssociationCount == 0)
{
MessageBox.Show("Prior to Importing Procedures you must set the Referenced Object Database", "No RO Database set", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
int ownerid = MySessionInfo.CheckOutItem(dvi.VersionID, CheckOutType.DocVersion); int ownerid = MySessionInfo.CheckOutItem(dvi.VersionID, CheckOutType.DocVersion);
dlgExportImport dlg = new dlgExportImport("Import", dvi); dlgExportImport dlg = new dlgExportImport("Import", dvi);
dlg.MyNewProcedure = null; dlg.MyNewProcedure = null;
@ -1494,6 +1501,7 @@ namespace VEPROMS
private void CloseSessionsNoLongerActive() private void CloseSessionsNoLongerActive()
{ {
SessionInfoList sil = SessionInfoList.Get(); SessionInfoList sil = SessionInfoList.Get();
int i = 0;
foreach(SessionInfo si in sil) foreach(SessionInfo si in sil)
{ {
if (si.DTSEnd == null && si.MachineName == Environment.MachineName && si.UserID == Volian.Base.Library.VlnSettings.UserID) if (si.DTSEnd == null && si.MachineName == Environment.MachineName && si.UserID == Volian.Base.Library.VlnSettings.UserID)
@ -1507,7 +1515,11 @@ namespace VEPROMS
Session.Delete(si.SessionID);// Remove Session record associated with a closed process Session.Delete(si.SessionID);// Remove Session record associated with a closed process
} }
} }
else if (si.DTSEnd == null)
i = i + 1;
} }
if (i == 0)// Turn-on Change Manger if there are no active Sessions
TurnChangeManagerOn.Execute();
} }
//public bool IsEnhancedDocumentOpen(ItemInfo ii) //public bool IsEnhancedDocumentOpen(ItemInfo ii)
//{ //{

View File

@ -209,7 +209,7 @@ namespace VEPROMS.CSLA.Library
{ {
get get
{ {
if (DocVersionAssociations == null) return false; if (DocVersionAssociations == null || DocVersionAssociationCount==0) return false;
ROFstInfo roFstInfo = ROFstInfo.GetJustROFst(DocVersionAssociations[0].ROFstID); ROFstInfo roFstInfo = ROFstInfo.GetJustROFst(DocVersionAssociations[0].ROFstID);
RODbInfo rdi = RODbInfo.GetJustRODB(roFstInfo.RODbID); RODbInfo rdi = RODbInfo.GetJustRODB(roFstInfo.RODbID);
string rofstPath = rdi.FolderPath + @"\ro.fst"; string rofstPath = rdi.FolderPath + @"\ro.fst";