/// <summary> /// Opens a connection to the process framework database. /// </summary> /// <param name="connectionString">The connection string.</param> /// <param name="userName">Name of the user.</param> /// <param name="extensionNames">The names of process framework extensions.</param> /// <returns> /// Returns the <see cref="IMMPxApplication" /> application reference; otherwise <c>null</c>. /// </returns> /// <exception cref="System.ArgumentNullException"> /// connectionString /// or /// userName /// or /// extensionNames /// </exception> public virtual IMMPxApplication Open(string connectionString, string userName, params string[] extensionNames) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } if (userName == null) { throw new ArgumentNullException("userName"); } if (extensionNames == null) { throw new ArgumentNullException("extensionNames"); } // Open the connection with the given properties. Connection connection = new ConnectionClass(); connection.Open(connectionString); // Create PxLogin object. IMMPxLogin pxLogin = new PxLoginClass(); pxLogin.Connection = connection; // Load the extensions. IMMEnumExtensionNames extensions = new PxExtensionNamesClass(); foreach (var extension in extensionNames) { extensions.Add(extension); } // Initialize the application using the user name and extensions. IMMPxApplication pxApp = new PxApplicationClass(); var pxAppEx3 = (IMMPxApplicationEx3)pxApp; pxAppEx3.Startup(pxLogin, extensions, ref userName); return(pxApp); }
public bool CREATE_ARCFM_SESSION(string sConnStr) { IMxDocument pMXDoc; IApplication pApp; IMMLoginUtils pMMLogin; IMMPxLogin pPxLogin; IMMSessionManager2 pmmSessionMangerExt; IMMPxIntegrationCache pmmSessionMangerIntegrationExt; IMMSessionVersion pMMSessVer; IMMSession pMMSession; IMMPxApplication pPXApp; IWorkspace pWKS; IExtension pExt; IVersion pVersion; IVersion pNewVersion; ADODB.Connection pPXConnection; try { SW1.Reset(); SW1.Start(); pMMLogin = new MMLoginUtils(); Logger.WriteLine("Get LoginWorkspace"); pWKS = pMMLogin.LoginWorkspace; Type t = Type.GetTypeFromProgID("esriFramework.AppRef"); System.Object obj = Activator.CreateInstance(t); pApp = obj as IApplication; pMXDoc = (IMxDocument)pApp.Document; Logger.WriteLine("Find PX Framework"); pExt = pApp.FindExtensionByName("Session Manager Integration Extension"); pmmSessionMangerIntegrationExt = (IMMPxIntegrationCache)pExt; pPXApp = pmmSessionMangerIntegrationExt.Application; pPxLogin = pPXApp.Login; Logger.WriteLine("open Connection"); if (pPxLogin == null) { if (sConnStr != "") { pPxLogin = new PxLoginClass(); pPXConnection = new Connection(); pPXConnection.ConnectionString = sConnStr; pPXConnection.Open(); pPxLogin.Connection = pPXConnection; pPXApp.Startup(pPxLogin); } else { Logger.WriteLine("No PX Connection String provided"); } } else { pPXConnection = pPxLogin.Connection; } Logger.WriteLine("Start PX"); //pPXApp.Startup(pPxLogin); pmmSessionMangerExt = (IMMSessionManager2)pPXApp.FindPxExtensionByName("MMSessionManager"); pMMSession = pmmSessionMangerExt.CreateSession(); pMMSessVer = (IMMSessionVersion)pMMSession; pVersion = (IVersion)pWKS; Logger.WriteLine("Create PX version"); pNewVersion = pVersion.CreateVersion(pMMSessVer.get_Name()); //pCV = new ChangeDatabaseVersion(); //pVSet = pCV.Execute(pVersion, pNewVersion, (IBasicMap)pMXDoc.FocusMap); SwizzleDatasets(pApp, (IFeatureWorkspace)pVersion, (IFeatureWorkspace)pNewVersion); this.Workspace = (IWorkspace)pNewVersion; //pMXDoc.ActiveView.Refresh(); SW1.Stop(); RecordActionTime("CREATE_ARCFM_SESSION:", SW1.ElapsedMilliseconds); //pMXDoc.ActiveView.Refresh(); ScriptEngine.BroadcastProperty("Workspace", Workspace, this); StartEditor(Workspace); pMXDoc.ActiveView.Refresh(); return true; } catch (Exception EX) { this.Logger.WriteLine("CREATE_ARCFM_SESSION Failed: " + EX.Message + " " + EX.StackTrace); return false; } }