4 Replies Latest reply on Mar 15, 2016 11:48 AM by Kyle Baesler

    How to use c# .net code to programming create a ArcFm session

    Kathy Li

      How to use c# .net code to programming create a ArcFm session. Current Miner.Interop.Process.Session.dll has two interfaces ( IMMSession and IMMSessionManager), IMMSessionManager has method CreateSession(), there is no implementation code inside. Really appreciated if somebody here can share the code, I would think it is common requirement or point to right place to find the existing code for createSession programming.

        • Re: How to use c# .net code to programming create a ArcFm session
          Kathy Li

          Does anybody here create an ArcFm session by using c# programming? Really appreciated any help here. Thanks

            • Re: How to use c# .net code to programming create a ArcFm session
              FAYAZ BAIG

              public bool CreateArcFmSession()
                      {
                          bool isSessionOpen = false;
                          IMMSession pSession = null; IMMPxTask pTask;
                          string nodeName = string.Empty;
                          try
                          {
                              IMMPxIntegrationCache mmSessionMangerIntegrationExt = FindExtesionByName("Session Manager Integration Extension") as IMMPxIntegrationCache;
                              var pxlogin = new PxLoginClass();
                              pxlogin.Connection = GetConnection();
                              if (mmSessionMangerIntegrationExt != null)
                              {
                                  IMMPxApplication _pxApp = mmSessionMangerIntegrationExt.Application;
                                  _pxApp.Startup(pxlogin);
                                  if (_pxApp != null)
                                  {
                                      IMMSessionManager3 _mmSessionMangerExt = _pxApp.FindPxExtensionByName("MMSessionManager") as IMMSessionManager3;
                                      if (_mmSessionMangerExt != null)
                                      {
                                          pSession = _mmSessionMangerExt.CreateSession();
                                          int SessionID = pSession.get_ID();
                                          // bool isNew = false;
                                          //pSession.Initialize(_pxApp, ref SessionID, ref isNew);
                                          IMMEnumPxNodeType PxNodeTypes = _pxApp.NodeTypes;
                                          PxNodeTypes.Reset();
                                          int nodeID = PxNodeTypes.Next();
                                          while (nodeID != -1)
                                          {
                                              nodeName = (_pxApp.Helper as IMMPxHelper2).GetNodeTypeName(nodeID);
                                              IMMPxNode PxNode = Miner.Process.Messaging.ProcessorHelper.GetPxNode(_pxApp, SessionID, nodeID, nodeName);
                                              Miner.Interop.Process.IMMEnumPxTasks EnumPxTasks = (PxNode as IMMPxNode4).AllTasks;
                                              EnumPxTasks.Reset();
                                              while ((pTask = EnumPxTasks.Next()) != null)
                                              {
                                                  if (pTask.TaskID == 1044)//1044 is taskid of open edit session
                                                  {
                                                      isSessionOpen = pTask.Execute(PxNode);
                                                      break;
                                                  }
                                              }

                                              nodeID = PxNodeTypes.Next();
                                          }
                                      }
                                    
                                  }
                              }
                          }
                          catch (Exception)
                          {

                              throw;
                          }
                          finally
                          {

                          }
                          return isSessionOpen;
                      }

                      private ADODB.Connection GetConnection()
                      {
                          ADODB.Connection con = null;
                          try
                          {
                              con = new ADODB.Connection();
                              string sPxConnectionString = "Provider=OraOLEDB.Oracle.1;Password=xxxx;Persist Security Info=True;User ID=xxx;Data Source=xxxx.world";
                              con.Open(sPxConnectionString);

                          }
                          catch (Exception)
                          {

                              throw;
                          }
                          return con;

                      }


                      private IExtension FindExtesionByName(string name)
                      {
                          try
                          {
                              IExtensionManager extensionMgr = Activator.CreateInstance(Type.GetTypeFromProgID(
                                      "esriSystem.ExtensionManager")) as IExtensionManager;
                              IExtension extension = extensionMgr.FindExtension(name);
                              return extension;
                          }
                          catch (Exception)
                          {

                              throw;
                          }


                      }

            • Re: How to use c# .net code to programming create a ArcFm session
              Kathy Li

              Thank you very much Fayaz. 

              I am new for ArcFm developer and really appreciated for your help.

              I tried IMMPxIntegrationCache mmSessionMangerIntegrationExt = FindExtesionByName("Session Manager Integration Extension") as IMMPxIntegrationCache;

              But it return null. Should it return a Value? What did I do wrong.

              Again thank you for your help.

                • Re: How to use c# .net code to programming create a ArcFm session
                  Kyle Baesler

                  Kathy,

                   

                  At the most simplistic level you'll want to use the IMMSessionManager interface which corresponds to a Process Framework Extension to create a IMMSession object, which relates to a session. You should only be using these methods, if you need to customize the creation of a session, perhaps to store additional client data in a separate table. If you don't have these requirements I would recommend you leave the creation of a session to the "Create Session" task in session manager.

                   

                  The following snippet assumes that you have a reference to an IMMPxApplication (i.e. pxApp), and you should be obtaining the IMMSessionManager reference from the IMMPxApplication, as the IMMPxIntegrationCache is only available after a session has been open.

                   

                  string userName = pxApp.User.Name;

                  IMMSessionManager sm = pxApp.FindPxExtensionByName("MMSessionManager") as IMMSessionManager;

                  IMMSession session = sm.CreateSession(ref userName);

                   

                  You might find the following online resource helpful.