示例#1
0
/// <summary>
/// Get client to connect to session service
/// </summary>
/// <returns></returns>

        private MobiusSessionService.MobiusSessionServiceClient GetSessionServiceClient()
        {
            if (_sessionServiceClient == null)
            {
                //EndpointType = EndpointTypeEnum.HTTPEndpoint; // debug

                string          endpointname   = GetServiceEndpointName(AvailableServicesEnum.Session);
                EndpointAddress serviceAddress = GetServiceAddress(AvailableServicesEnum.Session);

                _sessionServiceClient = // get service client object (e.g. http://[server]:7700/MobiusServices/MobiusSessionService)
                                        new MobiusSessionService.MobiusSessionServiceClient(endpointname, serviceAddress);
            }
            return(_sessionServiceClient);
        }
示例#2
0
        /// <summary>
        /// Retrieve session info for all current sessions
        /// </summary>

        public List <SessionInfo> GetSessionInfoForAllSessions()
        {
            if (!UseMobiusServices)
            {
                return(null);
            }

            MobiusSessionService.MobiusSessionServiceClient client = GetSessionServiceClient();
            Dictionary <Mobius.Services.Types.Session, Mobius.Services.Types.SessionInfo[]> sessionInfoDict = client.GetSessionInfoForAllSessions(Session);

            client.Close();

            if (sessionInfoDict == null)
            {
                return(null);
            }

            List <SessionInfo> sessionInfoList = new List <SessionInfo>();

            foreach (Session session in sessionInfoDict.Keys)
            {
                SessionInfo si = new SessionInfo();
                si.Id           = session.Id;
                si.UserId       = session.UserId;
                si.CreationDT   = session.CreationDT;
                si.ExpirationDT = session.ExpirationDT;
                si.Native       = IsNativeSession(session);

                if (!sessionInfoDict.ContainsKey(session))
                {
                    si = si;
                }

                if (sessionInfoDict.ContainsKey(session) &&
                    sessionInfoDict[session].Length >= 1 &&                     // should be just one entry
                    sessionInfoDict[session][0] != null)
                {
                    foreach (SessionInfoDataElement sde in sessionInfoDict[session][0].SessionData)
                    {
                        if (Lex.Eq(sde.Name, "PID"))
                        {
                            int.TryParse(sde.Value, out si.ProcessId);
                        }

                        else if (Lex.Eq(sde.Name, "CPU Time"))
                        {
                            double.TryParse(sde.Value, out si.CpuTimeSecs);
                        }

                        else if (Lex.Eq(sde.Name, "Mem (MB)"))
                        {
                            int.TryParse(sde.Value, out si.MemoryMb);
                        }

                        else if (Lex.Eq(sde.Name, "WSet (MB)"))
                        {
                            int.TryParse(sde.Value, out si.WorkingSetMb);
                        }

                        else if (Lex.Eq(sde.Name, "Threads"))
                        {
                            int.TryParse(sde.Value, out si.Threads);
                        }

                        else if (Lex.Eq(sde.Name, "Handles"))
                        {
                            int.TryParse(sde.Value, out si.Handles);
                        }
                    }
                }

                sessionInfoList.Add(si);
            }

            return(sessionInfoList);
        }
示例#3
0
        /// <summary>
        /// Create a session. Note that this should be done within a lock to avoid reentry.
        /// </summary>
        /// <returns></returns>

        internal Session CreateSession(bool native)
        {
            if (!UseMobiusServices)
            {
                return(null);                   // just return if not using Mobius Services
            }
            while (InCreateSession)             // extra reentrant check
            {
                System.Threading.Thread.Sleep(100);
            }

            InCreateSession = true;

            int t0 = TimeOfDay.Milliseconds();

            try
            {
                CreateSessionException = null;

                bool connectViaMobiusServiceHost = !DebugNativeSessionHost;
                if (connectViaMobiusServiceHost)                 // do normal creation of MobiusNativeServices process via MobiusServiceHost
                {
                    MobiusSessionService.MobiusSessionServiceClient client = GetSessionServiceClient();

                    if (native)
                    {
                        Session = client.CreateNativeSession();                             // create normal native session
                    }
                    else
                    {
                        Session = client.CreateSession();
                    }

                    client.Close();
                }

                else                                                       // for local debug just connect to existing NativeSessionHost process - Process.GetProcessesByName("MobiusNativeServices")
                {
                    string    serviceProcessName = "MobiusNativeServices"; // new name for Visual Studio 2017
                    Process[] processes          = Process.GetProcessesByName(serviceProcessName);

                    if (processes.Length == 0)
                    {
                        serviceProcessName = "MobiusNativeServices.vshost";                         // old name
                        processes          = Process.GetProcessesByName(serviceProcessName);
                    }
                    if (processes.Length == 0)
                    {
                        throw new Exception("Can't find service process: " + serviceProcessName);
                    }

                    int nativeSessionLineNumber = processes[0].Id;
                    Dictionary <SessionParameterName, string> sessionParams =
                        new Dictionary <SessionParameterName, string>();
                    sessionParams.Add(SessionParameterName.IsNativeSession, true.ToString());
                    sessionParams.Add(SessionParameterName.NativeSessionLine, nativeSessionLineNumber.ToString());

                    string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
                    Session =                     // build default session object
                              new Session()
                    {
                        Id                = 1,
                        UserId            = userName,
                        CreationDT        = DateTime.Now,
                        ExpirationDT      = DateTime.MaxValue,
                        SessionParameters = sessionParams
                    };
                }

                t0 = TimeOfDay.Milliseconds() - t0;
                if (LogStartupDetails && !String.IsNullOrEmpty(DebugLog.LogFileName))
                {
                    string msg = "CreateSession time";
                    if (InCreateSessionAsynch)
                    {
                        msg += " (asynch)";
                    }
                    msg += ": " + t0;
                    DebugLog.Message(msg);
                }
            }

            catch (Exception ex)
            {
                CreateSessionException = ex;
                DebugLog.Message(DebugLog.FormatExceptionMessage(ex));
                throw new Exception(ex.Message, ex);
            }

            InCreateSession = false;
            return(Session);
        }