ArcFM Desktop Overview > Process Framework Overview > Process Framework Basics > Retrieve Current Open Session |
The following code sample depicts how you can retrieve the currently open session (CurrentOpenSession object).
Retrieve CurrentOpenSession |
Copy Code
|
---|---|
public class GetSessionManager { private IMMSessionManager2 _mmSessionMangerExt; private IMMPxApplication _pxApp; /// <summary> /// Gets IMMSessionManager2 from the IMMPxIntegrationCache /// </summary> private void GetSessionMgrExt() { if (_mmSessionMangerExt == null) { IMMPxIntegrationCache mmSessionMangerIntegrationExt = FindExtesionByName("Session Manager Integration Extension") as IMMPxIntegrationCache; if (mmSessionMangerIntegrationExt != null) { _pxApp = mmSessionMangerIntegrationExt.Application; if (_pxApp != null) { __PxApplication_Event pxAppEvents = _pxApp as __PxApplication_Event; pxAppEvents.Shutdown += new __PxApplication_ShutdownEventHandler(pxAppEvents_Shutdown); _mmSessionMangerExt = _pxApp.FindPxExtensionByName("MMSessionManager") as IMMSessionManager2; } } } } /// <summary> /// Finds the extension using IExtensionManager /// </summary> /// <param name="name">Name of Extension to find</param> /// <returns></returns> private IExtension FindExtesionByName(string name) { IExtensionManager extensionMgr = Activator.CreateInstance(Type.GetTypeFromProgID( "esriSystem.ExtensionManager")) as IExtensionManager; IExtension extension = extensionMgr.FindExtension(name); return extension; } /// <summary> /// Shuts down px /// </summary> /// <param name="bCancel"></param> void pxAppEvents_Shutdown(ref bool bCancel) { __PxApplication_Event pxAppEvents = _pxApp as __PxApplication_Event; pxAppEvents.Shutdown -= new __PxApplication_ShutdownEventHandler(pxAppEvents_Shutdown); _mmSessionMangerExt = null; _pxApp = null; } /// <summary> /// Checks to see if the MM Editor state is StateEditing. /// Also gets the current open session and checks /// if there is a current open session and if the /// current open session is an edit session (not redlining) /// </summary> /// <returns></returns> private bool IsEditSessionOpen() { bool enabled = false; if (Editor.EditState == EditState.StateEditing) { GetSessionMgrExt(); if (_mmSessionMangerExt != null) { IMMSession currentSession = _mmSessionMangerExt.CurrentOpenSession; IMMSession4 currentSession4 = currentSession as IMMSession4; //Check if we have a session open and //if it is not a redlining session (and is therefore an edit session) if (currentSession4 != null && !currentSession4.get_Redlining()) { enabled = true; } } } return enabled; } } |