/// <summary> /// Get Client and Services versions and server name /// </summary> /// <param name="clientVersion"></param> /// <param name="servicesVersion"></param> /// <param name="server"></param> public static void GetClientAndServicesVersions( out string clientVersion, out string servicesVersion, out string server, bool includeSessionCount = false) { Version cv = Assembly.GetExecutingAssembly().GetName().Version; // version comes from this assembly (ServiceFacade) clientVersion = VersionMx.FormatVersion(cv); servicesVersion = server = ""; if (ServiceFacade.UseRemoteServices) { if (ServiceHostInfo == null) // get from services if don't have already { ServiceHostInfo = ServiceFacade.GetServiceHostInfo(); } if (ServiceHostInfo != null) { servicesVersion = VersionMx.FormatVersion(ServiceHostInfo.Version); server = ServiceHostInfo.ServerName; if (includeSessionCount) { int sessionCount = UsageDao.GetCurrentSessionCount(); server += " (" + sessionCount + " sessions)"; } } } else // not using services { servicesVersion = "Integrated"; } return; }
/// <summary> /// Main method for native session host /// </summary> /// <param name="args"></param> public static void StartUp(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); bool debug = (args.Length == 0); InitializeServicesLogFileName(); try { // Debug mode if (debug) { LogServiceCalls = true; NativeDebugMode = true; ServicesLog.LogToConsole = true; Initialize(); OpenServiceHost(); // Start the service host int processId = Process.GetCurrentProcess().Id; string endpointAddress = NativeSessionEndpointAddress.Build(processId); ServicesLog.Message("NativeSessionHost started in debug mode at endpoint address: " + endpointAddress); StartIdleMonitor(); // debug idle monitor } // Started by HostingApp else { ServiceHostProcessId = int.Parse(args[0]); string creatorClassTypeName = args[1]; int sessionId = int.Parse(args[2]); AppSettingsReader asr = new AppSettingsReader(); string enableLoggingStr = asr.GetValue("EnableNativeSessionLogging", typeof(string)) as string; bool.TryParse(enableLoggingStr, out LogServiceCalls); Initialize(); OpenServiceHost(); // Start the service host listening for requests RegisterSession(ServiceHostProcessId, sessionId); // register session with the service host that started us string msg = "MobiusNativeSession started for session " + sessionId + " in process " + Process.GetCurrentProcess().Id; Version version = Assembly.GetExecutingAssembly().GetName().Version; string tok = VersionMx.FormatVersion(version); msg += ", Services: " + tok; ServicesLog.Message(msg); // log initial message StartIdleMonitor(); // start thread that will exit if idle too long } return; } catch (Exception ex) { string msg = DebugLog.FormatExceptionMessage(ex); if (debug) { MessageBox.Show(msg); } ServicesLog.Message(msg); return; } }
/// <summary> /// Get new data & update grid /// </summary> void UpdateGrid() { InUpdateGrid = true; ServiceHostInfo svcInf = ServiceFacade.ServiceFacade.GetServiceHostInfo(); if (svcInf == null) { return; } List <Mobius.NativeSessionClient.SessionInfo> sil = new Mobius.NativeSessionClient.NativeSessionClient().GetSessionInfoForAllSessions(); if (sil == null) { sil = new List <SessionInfo>(); } Label.Text = "Server: " + svcInf.ServerName + ", Version: " + VersionMx.FormatVersion(svcInf.Version) + ", Count: " + sil.Count; DataTable.Rows.Clear(); DateTime now = DateTime.Now; foreach (SessionInfo si in sil) { DataRow dr = DataTable.NewRow(); dr["SessionIdCol"] = si.Id; dr["IsNonNativeCol"] = si.Native ? "" : "Y"; dr["UserIdCol"] = si.UserId; try { dr["UserNameCol"] = SecurityUtil.GetShortPersonNameReversed(si.UserId); } catch { } dr["CreationDtCol"] = CommandLine.FormatTimeSpan(now.Subtract(si.CreationDT)); if (!si.ExpirationDT.Equals(DateTime.MinValue)) // calc idle time { dr["IdleTimeCol"] = CommandLine.FormatTimeSpan(now.Subtract(si.ExpirationDT)); } if (si.ProcessId > 0) { dr["ProcessIdCol"] = si.ProcessId; } if (si.CpuTimeSecs > 0) { dr["CpuTimeCol"] = (int)si.CpuTimeSecs; } if (si.MemoryMb > 0) { dr["MemoryCol"] = si.MemoryMb; } if (si.Threads > 0) { dr["ThreadsCol"] = si.Threads; } if (si.Handles > 0) { dr["HandlesCol"] = si.Handles; } DataTable.Rows.Add(dr); } Grid.DataSource = DataTable; Grid.Refresh(); Application.DoEvents(); InUpdateGrid = false; return; }