B2022-055 Fix to help prevent crashing when opening/closing/re-opening procedures.

This commit is contained in:
John Jenko 2022-05-16 13:54:46 +00:00
parent 4f987dc7fc
commit 4b6b9451df

View File

@ -49,17 +49,21 @@ namespace Volian.Controls.Library
_Text = text; _Text = text;
} }
} }
public partial class DisplayTabControl : UserControl public partial class DisplayTabControl : UserControl
{ {
#region Log4Net #region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion #endregion
private static bool _SyncronizeEnahnced = false; private static bool _SyncronizeEnahnced = false;
public static bool SyncronizeEnhanced public static bool SyncronizeEnhanced
{ {
get { return DisplayTabControl._SyncronizeEnahnced; } get { return DisplayTabControl._SyncronizeEnahnced; }
set { DisplayTabControl._SyncronizeEnahnced = value; } set { DisplayTabControl._SyncronizeEnahnced = value; }
} }
private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>(); private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
private int _VersionID = 0; private int _VersionID = 0;
// zero tells us to PROMS just opened and no procedure was selected yet so use the main proms window // zero tells us to PROMS just opened and no procedure was selected yet so use the main proms window
@ -181,12 +185,15 @@ namespace Volian.Controls.Library
} }
// C2015-022 added copystep event to commuicate with child windows // C2015-022 added copystep event to commuicate with child windows
public event ItemChangedEventHandler CopyStepSelected; public event ItemChangedEventHandler CopyStepSelected;
public void OnCopyStepSelected(ItemChangedEventArgs args) public void OnCopyStepSelected(ItemChangedEventArgs args)
{ {
if (CopyStepSelected != null) if (CopyStepSelected != null)
CopyStepSelected(this, args); CopyStepSelected(this, args);
} }
#region Private Fields #region Private Fields
/// <summary> /// <summary>
/// This is a lookup table for all of the DisplayTabItems that are currently open /// This is a lookup table for all of the DisplayTabItems that are currently open
/// The key is: /// The key is:
@ -194,11 +201,13 @@ namespace Volian.Controls.Library
/// "Doc - " + DocumentID for Word Documents /// "Doc - " + DocumentID for Word Documents
/// </summary> /// </summary>
public Dictionary<string, DisplayTabItem> _MyDisplayTabItems; public Dictionary<string, DisplayTabItem> _MyDisplayTabItems;
/// <summary> /// <summary>
/// When a Tab is closed it is added to this list. /// When a Tab is closed it is added to this list.
/// When another Tab is opened, any Tabs in this list are closed /// When another Tab is opened, any Tabs in this list are closed
/// </summary> /// </summary>
private List<DisplayTabItem> _RemovedDisplayTabItems = null; private List<DisplayTabItem> _RemovedDisplayTabItems = null;
/// <summary> /// <summary>
/// This stores a UniqueID for Bars as they are opened. /// This stores a UniqueID for Bars as they are opened.
/// A bar is the docking location for the DisplayTabItems. /// A bar is the docking location for the DisplayTabItems.
@ -381,47 +390,58 @@ namespace Volian.Controls.Library
} }
if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args); if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args);
} }
void _MyStepRTB_Disposed(object sender, EventArgs e) void _MyStepRTB_Disposed(object sender, EventArgs e)
{ {
_MyStepRTB = null; _MyStepRTB = null;
} }
public event StepPanelModeChangeEvent ModeChange; public event StepPanelModeChangeEvent ModeChange;
internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args) internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
{ {
if (ModeChange != null) ModeChange(sender, args); if (ModeChange != null) ModeChange(sender, args);
else FlexibleMessageBox.Show("Cannot change mode"); else FlexibleMessageBox.Show("Cannot change mode");
} }
public event StepPanelTabDisplayEvent PanelTabDisplay; public event StepPanelTabDisplayEvent PanelTabDisplay;
internal void OnPanelTabDisplay(object sender, StepPanelTabDisplayEventArgs args) internal void OnPanelTabDisplay(object sender, StepPanelTabDisplayEventArgs args)
{ {
if (PanelTabDisplay != null) PanelTabDisplay(sender, args); if (PanelTabDisplay != null) PanelTabDisplay(sender, args);
else FlexibleMessageBox.Show("Cannot display information"); else FlexibleMessageBox.Show("Cannot display information");
} }
public event StepPanelWordSectionCloseEvent WordSectionClose; public event StepPanelWordSectionCloseEvent WordSectionClose;
internal void OnWordSectionClose(object sender, WordSectionEventArgs args) internal void OnWordSectionClose(object sender, WordSectionEventArgs args)
{ {
if (WordSectionClose != null) WordSectionClose(sender, args); if (WordSectionClose != null) WordSectionClose(sender, args);
else FlexibleMessageBox.Show("Cannot close associated Word section"); else FlexibleMessageBox.Show("Cannot close associated Word section");
} }
public event StepPanelWordSectionDeletedEvent WordSectionDeleted; public event StepPanelWordSectionDeletedEvent WordSectionDeleted;
internal void OnWordSectionDeleted(object sender, WordSectionEventArgs args) internal void OnWordSectionDeleted(object sender, WordSectionEventArgs args)
{ {
if (WordSectionDeleted != null) WordSectionDeleted(sender, args); if (WordSectionDeleted != null) WordSectionDeleted(sender, args);
else FlexibleMessageBox.Show("Cannot delete associated Word section"); else FlexibleMessageBox.Show("Cannot delete associated Word section");
} }
public event StepPanelItemPastedEvent ItemPaste; public event StepPanelItemPastedEvent ItemPaste;
internal void OnItemPaste(object sender, vlnTreeItemInfoPasteEventArgs args) internal void OnItemPaste(object sender, vlnTreeItemInfoPasteEventArgs args)
{ {
if (ItemPaste != null) ItemPaste(sender, args); if (ItemPaste != null) ItemPaste(sender, args);
else FlexibleMessageBox.Show("Cannot adjust panels for pasted item"); else FlexibleMessageBox.Show("Cannot adjust panels for pasted item");
} }
#endregion #endregion
#region Contructor & Setup #region Contructor & Setup
public DisplayTabControl() public DisplayTabControl()
{ {
InitializeComponent(); InitializeComponent();
SetUp(); SetUp();
} }
private void SetUp() private void SetUp()
{ {
ItemsChangeIds = new Dictionary<int, string>(); ItemsChangeIds = new Dictionary<int, string>();
@ -534,6 +554,7 @@ namespace Volian.Controls.Library
OpenItem(myItemInfo, false); OpenItem(myItemInfo, false);
} }
} }
public DisplayTabItem OpenItem(ItemInfo myItemInfo2) public DisplayTabItem OpenItem(ItemInfo myItemInfo2)
{ {
//B2017-251 Added Error Log message for Open Step or MSWord section include time to do open //B2017-251 Added Error Log message for Open Step or MSWord section include time to do open
@ -542,6 +563,7 @@ namespace Volian.Controls.Library
_MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath); _MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath);
return dti; return dti;
} }
/// <summary> /// <summary>
/// Open a Step Item or a Word Item /// Open a Step Item or a Word Item
/// </summary> /// </summary>
@ -550,11 +572,13 @@ namespace Volian.Controls.Library
public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus) public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus)
{ {
ItemInfo myItemInfo = myItemInfo2; ItemInfo myItemInfo = myItemInfo2;
if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion
{ {
FlexibleMessageBox.Show(this, "Possible disconnected item", "Item Not Found"); FlexibleMessageBox.Show(this, "Possible disconnected item", "Item Not Found");
return null; return null;
} }
string message = string.Empty; string message = string.Empty;
//if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyDocVersion.VersionID, CheckOutType.DocVersion, ref message)) //if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyDocVersion.VersionID, CheckOutType.DocVersion, ref message))
//{ //{
@ -587,6 +611,7 @@ namespace Volian.Controls.Library
FlexibleMessageBox.Show("This is an automatically generated 'Table of Contents' section. It is not editable. It is generated during Print.", "Item not Editable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); FlexibleMessageBox.Show("This is an automatically generated 'Table of Contents' section. It is not editable. It is generated during Print.", "Item not Editable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return SelectedDisplayTabItem; return SelectedDisplayTabItem;
} }
bool libDocAlreadyOpen = false; bool libDocAlreadyOpen = false;
if (myItemInfo.MyContent.MyEntry != null) // Trying to open a Word document - see if it's a library document that is already opened. if (myItemInfo.MyContent.MyEntry != null) // Trying to open a Word document - see if it's a library document that is already opened.
libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo); libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo);
@ -611,6 +636,7 @@ namespace Volian.Controls.Library
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo); return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
} }
} }
if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID)) if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{ {
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo); return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
@ -621,11 +647,17 @@ namespace Volian.Controls.Library
VersionID = myItemInfo.MyDocVersion.VersionID; // add it to _AllDTCs VersionID = myItemInfo.MyDocVersion.VersionID; // add it to _AllDTCs
_MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item. _MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item.
if (myItemInfo.MyContent.MyEntry == null) // If it is not a Word document open in step editor if (myItemInfo.MyContent.MyEntry == null) // If it is not a Word document open in step editor
{
return OpenStepTabPage(myItemInfo, setFocus); return OpenStepTabPage(myItemInfo, setFocus);
}
else // Otherwise open it in the Word editor else // Otherwise open it in the Word editor
{
return OpenDSOTabPage(myItemInfo); return OpenDSOTabPage(myItemInfo);
} }
}
public bool PasteRTBItem(ItemInfo myItemInfo, int copyStartID, ItemInfo.EAddpingPart pasteType, int type) public bool PasteRTBItem(ItemInfo myItemInfo, int copyStartID, ItemInfo.EAddpingPart pasteType, int type)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
@ -660,13 +692,14 @@ namespace Volian.Controls.Library
} }
break; break;
default: default:
return false; ; return false;
} }
return true; return true;
} }
} }
return false; return false;
} }
public bool DeleteRTBItem(ItemInfo myItemInfo) public bool DeleteRTBItem(ItemInfo myItemInfo)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
@ -694,6 +727,7 @@ namespace Volian.Controls.Library
} }
return false; return false;
} }
public bool InsertRTBItem(ItemInfo myItemInfo, string text, E_InsertType insertType, E_FromType fromType, int type, bool updateSelection) public bool InsertRTBItem(ItemInfo myItemInfo, string text, E_InsertType insertType, E_FromType fromType, int type, bool updateSelection)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
@ -725,6 +759,7 @@ namespace Volian.Controls.Library
} }
return false; return false;
} }
private void CleanUpClosedItems() private void CleanUpClosedItems()
{ {
while (_RemovedDisplayTabItems.Count > 0) // Clean-up any items that have been closed. while (_RemovedDisplayTabItems.Count > 0) // Clean-up any items that have been closed.
@ -734,10 +769,12 @@ namespace Volian.Controls.Library
RemoveItem(myTabItem); RemoveItem(myTabItem);
} }
} }
public void CloseWordItem(ItemInfo myItemInfo) public void CloseWordItem(ItemInfo myItemInfo)
{ {
CloseWordItem(myItemInfo, false); CloseWordItem(myItemInfo, false);
} }
public void CloseWordItem(ItemInfo myItemInfo, bool isBeingDeleted) public void CloseWordItem(ItemInfo myItemInfo, bool isBeingDeleted)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
@ -1023,6 +1060,7 @@ namespace Volian.Controls.Library
} }
} }
} }
public DisplayTabItem GetProcDisplayTabItem(ItemInfo myItemInfo) public DisplayTabItem GetProcDisplayTabItem(ItemInfo myItemInfo)
{ {
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
@ -1059,6 +1097,7 @@ namespace Volian.Controls.Library
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
string key = "Item - " + proc.ItemID.ToString(); string key = "Item - " + proc.ItemID.ToString();
DisplayTabItem pg = null; DisplayTabItem pg = null;
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{ {
pg = _MyDisplayTabItems[key]; pg = _MyDisplayTabItems[key];
@ -1166,7 +1205,10 @@ namespace Volian.Controls.Library
private bool LibDocAlreadyOpen(ItemInfo myItemInfo, string key, ref DisplayTabItem pg, bool displayMsg) private bool LibDocAlreadyOpen(ItemInfo myItemInfo, string key, ref DisplayTabItem pg, bool displayMsg)
{ {
bool libDocAlreadyOpen = false; bool libDocAlreadyOpen = false;
// C2015-022 part of separate windows logic, check all tabs in all windows to see if lib docs // C2015-022 part of separate windows logic, check all tabs in all windows to see if lib docs
if (_AllDTCs != null && _AllDTCs.Count > 0)
{
foreach (int k in _AllDTCs.Keys) foreach (int k in _AllDTCs.Keys)
{ {
DisplayTabControl dtc = _AllDTCs[k]; DisplayTabControl dtc = _AllDTCs[k];
@ -1185,6 +1227,8 @@ namespace Volian.Controls.Library
} }
} }
} }
}
return libDocAlreadyOpen; return libDocAlreadyOpen;
} }
/// <summary> /// <summary>
@ -1252,16 +1296,27 @@ namespace Volian.Controls.Library
/// </summary> /// </summary>
/// <param name="myDisplayTabItem"></param> /// <param name="myDisplayTabItem"></param>
internal void RemoveItem(DisplayTabItem myDisplayTabItem) internal void RemoveItem(DisplayTabItem myDisplayTabItem)
{
if (_MyDisplayTabItems.ContainsKey(myDisplayTabItem.MyKey))
{
try
{ {
_MyDisplayTabItems.Remove(myDisplayTabItem.MyKey); _MyDisplayTabItems.Remove(myDisplayTabItem.MyKey);
// Dispose the Panel
// Dispose of the procedure tab panel
if (myDisplayTabItem.MyStepTabPanel != null) if (myDisplayTabItem.MyStepTabPanel != null)
myDisplayTabItem.MyStepTabPanel.Dispose(); myDisplayTabItem.MyStepTabPanel.Dispose();
// Dispose of the MS Word Panel
if (myDisplayTabItem.MyDSOTabPanel != null) if (myDisplayTabItem.MyDSOTabPanel != null)
myDisplayTabItem.MyDSOTabPanel.CloseDSO(); myDisplayTabItem.MyDSOTabPanel.CloseDSO();
components.Remove(myDisplayTabItem); components.Remove(myDisplayTabItem);
myDisplayTabItem.Dispose(); myDisplayTabItem.Dispose();
} }
catch { }
}
}
#endregion #endregion
} }
} }