[commit] r2025 - in trunk/GME: Gme Mga

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Thu Aug 16 11:30:51 CDT 2012


Author: ksmyth
Date: Thu Aug 16 11:30:50 2012
New Revision: 2025

Log:
If addon fails in CommitTransaction, SetErrorInfo to include Addon progid

Modified:
   trunk/GME/Gme/GMEView.cpp
   trunk/GME/Gme/GMEView.h
   trunk/GME/Gme/StdAfx.cpp
   trunk/GME/Mga/MgaFCO.cpp
   trunk/GME/Mga/MgaProject.cpp
   trunk/GME/Mga/MgaProject.h
   trunk/GME/Mga/MgaTerritory.h
   trunk/GME/Mga/MgaTrukk.h
   trunk/GME/Mga/StdAfx.cpp

Modified: trunk/GME/Gme/GMEView.cpp
==============================================================================
--- trunk/GME/Gme/GMEView.cpp	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Gme/GMEView.cpp	Thu Aug 16 11:30:50 2012	(r2025)
@@ -1495,6 +1495,17 @@
 	inRWTransaction = false;
 }
 
+void CGMEView::__CommitTransaction()
+{
+	if(inEventHandler)
+		return;
+	VERIFY(inTransaction > 0);
+	if(inTransaction == 1)
+		theApp.mgaProject->__CommitTransaction();
+	inTransaction--;
+	inRWTransaction = false;
+}
+
 void CGMEView::AbortTransaction(HRESULT hr)
 {
 	if(inEventHandler)
@@ -3189,13 +3200,24 @@
 				COMTHROW(guiConn->mgaFco->get_Status(&status));
 				if(status == OBJECT_EXISTS)
 					DeleteConnection(guiConn,false);
-				CommitTransaction();
+				__CommitTransaction();
 			}
 			catch(hresult_exception e) {
 				AbortTransaction(e.hr);
-				AfxMessageBox(_T("Unable to delete connection"),MB_ICONSTOP | MB_OK);
+				AfxMessageBox(_T("Unable to delete connection"), MB_ICONSTOP | MB_OK);
 				CGMEEventLogger::LogGMEEvent(_T("    Unable to delete connection.\r\n"));
 			}
+			catch(_com_error& e) {
+				AbortTransaction(e.Error());
+				CString error = _T("Unable to delete connection");
+				if (e.Description().length() != 0)
+				{
+					error += _T(": ");
+					error += static_cast<const TCHAR*>(e.Description());
+				}
+				CGMEEventLogger::LogGMEEvent(error + _T("\r\n"));
+				AfxMessageBox(error,MB_ICONSTOP | MB_OK);
+			}
 		}
 	}
 }
@@ -4226,7 +4248,7 @@
 		newObjectIDs.AddHead(newID);
 
 		SetObjectLocation(child, role, pt);
-		CommitTransaction();
+		__CommitTransaction();
 	}
 	catch(hresult_exception &e) {
 		AbortTransaction(e.hr);
@@ -4235,6 +4257,19 @@
 		CGMEEventLogger::LogGMEEvent(_T("    Unable to insert new part.\r\n"));
 		return;
 	}
+	catch(_com_error& e) {                
+		AbortTransaction(e.Error());
+		newObjectIDs.RemoveAll();
+		CString error = _T("Unable to insert new part");
+		if (e.Description().length() != 0)
+		{
+			error += _T(": ");
+			error += static_cast<const TCHAR*>(e.Description());
+		}
+		CGMEEventLogger::LogGMEEvent(error + _T("\r\n"));
+		AfxMessageBox(error,MB_ICONSTOP | MB_OK);
+		return;
+	}
 	ChangeAttrPrefObjs(selected);
 	try {
 		BeginTransaction(TRANSACTION_READ_ONLY);
@@ -6168,7 +6203,7 @@
 				CGuiObject::ShiftModels(selected, diff);
 				CGuiAnnotator::ShiftAnnotations(selectedAnnotations,diff);
 				ResetParent();
-				CommitTransaction();
+				__CommitTransaction();
 			}
 			catch(hresult_exception e) {                
 				AbortTransaction(e.hr);
@@ -6177,6 +6212,19 @@
 				Reset(true);
 				return FALSE;
 			}
+			catch(_com_error& e) {                
+				AbortTransaction(e.Error());
+				CString error = _T("Unable to complete drop operation");
+				if (e.Description().length() != 0)
+				{
+					error += _T(": ");
+					error += static_cast<const TCHAR*>(e.Description());
+				}
+				CGMEEventLogger::LogGMEEvent(error + _T("\r\n"));
+				AfxMessageBox(error,MB_ICONSTOP | MB_OK);
+				Reset(true);
+				return FALSE;
+			}
 			AutoRoute(); // HACK reroute the whole thing for now!
 			Invalidate(true);
 			inDrag = false;
@@ -6562,13 +6610,24 @@
 				}
 				contextSelection = 0;
 				contextPort = 0;
-				CommitTransaction();
+				__CommitTransaction();
 			}
 			catch(hresult_exception e) {
 				AbortTransaction(e.hr);
 				AfxMessageBox(_T("Could not complete disconnect operation"),MB_OK | MB_ICONSTOP);
 				CGMEEventLogger::LogGMEEvent(_T("    Could not complete disconnect operation.\r\n"));
 			}
+			catch(_com_error& e) {                
+				AbortTransaction(e.Error());
+				CString error = _T("Could not complete disconnect operation");
+				if (e.Description().length() != 0)
+				{
+					error += _T(": ");
+					error += static_cast<const TCHAR*>(e.Description());
+				}
+				CGMEEventLogger::LogGMEEvent(error + _T("\r\n"));
+				AfxMessageBox(error,MB_ICONSTOP | MB_OK);
+			}
 		}
 	}
 }
@@ -8757,7 +8816,7 @@
 
 		needsReset = true;
 		EndWaitCursor();
-		CommitTransaction();
+		__CommitTransaction();
 	}
 	catch(hresult_exception &e) {
 		AbortTransaction(e.hr);
@@ -8766,6 +8825,18 @@
 		EndWaitCursor();
 		return;
 	}
+	catch(_com_error& e) {                
+		AbortTransaction(e.Error());
+		CString error = _T("Unable to synchronize aspects");
+		if (e.Description().length() != 0)
+		{
+			error += _T(": ");
+			error += static_cast<const TCHAR*>(e.Description());
+		}
+		CGMEEventLogger::LogGMEEvent(error + _T("\r\n"));
+		AfxMessageBox(error, MB_ICONSTOP | MB_OK);
+		EndWaitCursor();
+	}
 
 }
 

Modified: trunk/GME/Gme/GMEView.h
==============================================================================
--- trunk/GME/Gme/GMEView.h	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Gme/GMEView.h	Thu Aug 16 11:30:50 2012	(r2025)
@@ -297,7 +297,8 @@
 	bool					IsConnectionConversionNeeded(void);
 	void					ConvertNeededConnections(void);
 	void					BeginTransaction(transactiontype_enum mode = TRANSACTION_GENERAL);
-	void					CommitTransaction();
+	void					CommitTransaction(); // throws hresult_exception
+	void					__CommitTransaction(); // throws _com_error
 	void					AbortTransaction(HRESULT hr);
 	void					PasteAnnotations(CComPtr<IMgaModel>& targetModel, CComPtr<IMgaRegNodes>& regNodes,
 											 CComPtr<IMgaRegNodes>& newRegNodes, bool isMove);

Modified: trunk/GME/Gme/StdAfx.cpp
==============================================================================
--- trunk/GME/Gme/StdAfx.cpp	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Gme/StdAfx.cpp	Thu Aug 16 11:30:50 2012	(r2025)
@@ -6,4 +6,5 @@
 
 #import "MgaUtilLib.tlb" implementation_only no_namespace raw_method_prefix("") high_method_prefix("__") no_registry
 #import "MetaLib.tlb" implementation_only no_namespace raw_method_prefix("") high_method_prefix("__") no_registry
+#import "MgaLib.tlb" implementation_only no_namespace raw_method_prefix("") high_method_prefix("__") no_registry
 #import "ParserLib.tlb" implementation_only no_namespace raw_method_prefix("") high_method_prefix("__") no_registry

Modified: trunk/GME/Mga/MgaFCO.cpp
==============================================================================
--- trunk/GME/Mga/MgaFCO.cpp	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Mga/MgaFCO.cpp	Thu Aug 16 11:30:50 2012	(r2025)
@@ -919,8 +919,6 @@
 }
 //-------------------------------------------------------------------------------------
 
-#define REQUIRE_NOTIFICATION_SUCCESS 1   // return with error if addons/rwhandlers fail
-
 HRESULT FCO::objrwnotify() {
 	COMTRY {
 			unsigned long chmask = changemask;
@@ -941,14 +939,27 @@
 						CComPtr<IMgaObject> tt;
 						getinterface(&tt);
 
-#if(REQUIRE_NOTIFICATION_SUCCESS)
-						// FIXME: if this throws, user has no idea the addon failed
-						COMTHROW(t->handler->ObjectEvent(tt, mmask, mods));
-#else
-						if((s = t->handler->ObjectEvent(tt, mmask, mods)) != S_OK) {
-							ASSERT(("Notification failed", false));
+						try
+						{
+							t->handler->__ObjectEvent(tt, mmask, mods);
+						}
+						catch (_com_error& e)
+						{
+							if (t->progid.length() == 0)
+								throw;
+							_bstr_t error = e.Description();
+							if (!error.length())
+							{
+								GetErrorInfo(e.Error(), error.GetAddress());
+								if (error.length() == 0)
+								{
+									error = L"Unknown error";
+								}
+							}
+							error = _bstr_t(L"Error in Addon '") + t->progid + _bstr_t("'. Addon returned error: ") + error;
+							SetErrorInfo(error);
+							_com_issue_errorex(e.Error(), t->handler, __uuidof(t->handler));
 						}
-#endif
 					    t->notified = true;
 					}
 				}
@@ -976,13 +987,7 @@
 							{
 								CComPtr<IMgaObject> newoo;
 								getinterface(&newoo, t);
-#if(REQUIRE_NOTIFICATION_SUCCESS)
 								COMTHROW(t->rwhandler->ObjectEvent(newoo, (unsigned long)OBJEVENT_CREATED, dummy));
-#else
-								if(t->rwhandler->ObjectEvent(newoo, (unsigned long)OBJEVENT_CREATED, dummy) != S_OK) {
-									ASSERT(("Notification failed", false));
-								}
-#endif
 							}
 							COMTHROW(mgaproject->popterr());
 							t->notified = true;
@@ -1001,13 +1006,7 @@
 				long mmask;
 				if(t->rwhandler && (mmask = (t->rweventmask & chmask)) != 0) {
 					COMTHROW(mgaproject->pushterr(*t));
-#if(REQUIRE_NOTIFICATION_SUCCESS)
 					COMTHROW(t->rwhandler->ObjectEvent(obj, mmask,ud));
-#else
-					if(t->rwhandler->ObjectEvent(obj, mmask,ud) != S_OK) {
-						ASSERT(("Notification failed", false));
-					}
-#endif
 					t->notified = true;
 					COMTHROW(mgaproject->popterr());  // this may release the territory!!!
 				}

Modified: trunk/GME/Mga/MgaProject.cpp
==============================================================================
--- trunk/GME/Mga/MgaProject.cpp	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Mga/MgaProject.cpp	Thu Aug 16 11:30:50 2012	(r2025)
@@ -1084,6 +1084,7 @@
 		CComPtr< CMgaAddOn > saddon;
 		CreateComObject(saddon);
 		saddon->mgaproject = this;
+		saddon->progid = autoaddoncreate_progid;
 		alladdons.push_front(saddon);
 		saddon->handler=sink;
 		if(inautoaddoncreate) {
@@ -1222,6 +1223,7 @@
 		for(std::vector<CComBstrObj>::iterator i = vec.begin(); i < vec.end(); ++i) {
 			try {
 				CComPtr<IMgaComponent> addon;
+				autoaddoncreate_progid = *i;
 				COMTHROW(CreateMgaComponent(addon, *i)); // Was: COMTHROW( addon.CoCreateInstance(*i) );
 				ASSERT( addon != NULL );
 				CComQIPtr<IGMEVersionInfo> vv=addon;
@@ -1242,6 +1244,7 @@
 			}
 		}
 		inautoaddoncreate = false;
+		autoaddoncreate_progid = L"";
 		if(errs) {
 				SetErrorInfo(errs);
 				COMTHROW(E_MGA_COMPONENT_ERROR); // change error type
@@ -1362,7 +1365,9 @@
 			COMTHROW(dataproject->get_RootObject(&self.ComPtr()));
 //			self[ATTRID_MDATE] = Now();
 		}
-		COMTHROW(CommitNotify());		
+		HRESULT hr = CommitNotify();
+		if (FAILED(hr))
+			return hr;
 		COMTHROW(dataproject->PopTerritory());
 		short nestedCount;
 		COMTHROW(dataproject->get_NestedTransactionCount(&nestedCount));
@@ -1502,13 +1507,12 @@
                                 FCOPtr f = changedobjs.front();
                                 changedobjs.pop();
 
-#if(1)
-                                COMTHROW(f->objrwnotify());
-#else
-                                if(f->objrwnotify() != S_OK) {
-                                        ASSERT(("Notification failed", false));
-                                }
-#endif
+								HRESULT hr = f->objrwnotify();
+								if (FAILED(hr))
+								{
+									read_only = false;
+									return hr;
+								}
                 }
 
                 read_only = true;

Modified: trunk/GME/Mga/MgaProject.h
==============================================================================
--- trunk/GME/Mga/MgaProject.h	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Mga/MgaProject.h	Thu Aug 16 11:30:50 2012	(r2025)
@@ -195,6 +195,7 @@
 	HRESULT  commitnested();
 	bool autoaddons;         // automatic addon instantiation enabled
 	bool inautoaddoncreate;	 // addons are just being instantiated
+	_bstr_t autoaddoncreate_progid;
 #ifdef DEBUG
 public:
 #endif

Modified: trunk/GME/Mga/MgaTerritory.h
==============================================================================
--- trunk/GME/Mga/MgaTerritory.h	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Mga/MgaTerritory.h	Thu Aug 16 11:30:50 2012	(r2025)
@@ -148,6 +148,7 @@
 	unsigned long eventmask;
 	bool notified;
 	CMgaProject *mgaproject;
+	_bstr_t progid;
 	CComPtr<IMgaEventSink> handler;    // non-null if object active 
 };
 

Modified: trunk/GME/Mga/MgaTrukk.h
==============================================================================
--- trunk/GME/Mga/MgaTrukk.h	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Mga/MgaTrukk.h	Thu Aug 16 11:30:50 2012	(r2025)
@@ -384,6 +384,16 @@
 		MgaSetErrorInfo(e.hr); \
 		return e.hr; \
 	} \
+	catch(_com_error &err) \
+	{ \
+		struct { HRESULT hr; } e = { err.Error() }; \
+		{ CLEANUP; } \
+		if (err.Description() != _bstr_t()) \
+			SetErrorInfo(err.Description()); \
+		else \
+			SetStandardOrGMEErrorInfo(err.Error()); \
+		return e.hr; \
+	} \
 	catch(std::bad_alloc&) \
 	{ \
 		struct { HRESULT hr; } e = { E_OUTOFMEMORY }; \

Modified: trunk/GME/Mga/StdAfx.cpp
==============================================================================
--- trunk/GME/Mga/StdAfx.cpp	Thu Aug 16 11:30:34 2012	(r2024)
+++ trunk/GME/Mga/StdAfx.cpp	Thu Aug 16 11:30:50 2012	(r2025)
@@ -7,3 +7,5 @@
 #ifdef _ATL_STATIC_REGISTRY
 #include <statreg.h>
 #endif
+
+#import "MgaLib.tlb" implementation_only no_namespace raw_method_prefix("") high_method_prefix("__") no_registry


More information about the gme-commit mailing list