public void OnMakeNewSession( CswSessionsListEntry CswSessionsListEntry ) { if ( _RecordStatistics ) { _CswNbtStatisticsEvents.CswNbtStatisticsEntry.SessionId = CswSessionsListEntry.SessionId; _CswNbtStatisticsEvents.CswNbtStatisticsEntry.UserId = CswSessionsListEntry.UserId; _CswNbtStatisticsEvents.CswNbtStatisticsEntry.UserName = CswSessionsListEntry.UserName; _CswNbtStatisticsEvents.CswNbtStatisticsEntry.SessionId = CswSessionsListEntry.SessionId; _CswNbtStatisticsEvents.CswNbtStatisticsEntry.AccessId = CswSessionsListEntry.AccessId; } }
public void threadCallBack(ICswResources CswResources) { _LogicRunStatus = CswEnumScheduleLogicRunStatus.Running; CswNbtResources CurrentSchemaResources = (CswNbtResources)CswResources; CurrentSchemaResources.AuditContext = "Scheduler Task: " + RuleName; if (CswEnumScheduleLogicRunStatus.Stopping != _LogicRunStatus) { try { if (null == _MasterSchemaResources) { _MasterSchemaResources = _getMasterSchemaResources((CswNbtResources)CswResources); } if (null != _MasterSchemaResources) { if (_StaleDataExists) { //The higher level classes that CswSessions is used require http reponse and request objects, //so we have to use th bare CswSessions class directly. CswSessionsFactory CswSessionsFactory = new CswSessionsFactory(CswEnumAppType.Nbt, _MasterSchemaResources.SetupVbls, _MasterSchemaResources.CswDbCfgInfo, _MasterSchemaResources.CswLogger); CswSessions CswSessions = CswSessionsFactory.make(CswEnumSessionsStorageType.DbStorage, _MasterSchemaResources); //We must get and delete the session data from the master schema, //but delete expired temp nodes from the current schema CswTableSelect SessionListSelect = _MasterSchemaResources.makeCswTableSelect("delete_expired_sessionlist_records", "sessionlist"); DataTable SessionListTable = SessionListSelect.getTable(_SessionListWhere(CurrentSchemaResources.AccessId)); CswNbtSessionDataMgr CswNbtSessionDataMgr = new CswNbtSessionDataMgr(CurrentSchemaResources); foreach (DataRow CurrentRow in SessionListTable.Rows) { //Step # 1: Remove stranded temp nodes in the _current_ schema using session id we got from master schema session list string CurrentSessionId = CurrentRow["sessionid"].ToString(); CswNbtSessionDataMgr.removeAllSessionData(CurrentSessionId); //Step # 2: Remove Session Record from master schema //If our session management code were organized differently, we would be calling //CswSessionManager::clearSession() instead of rolloing our own here. In the future //CswSessionManager::clearSession() could acquire functionality that we would miss. //Moreover, it calls an OnDeathenticate() event that is passsed in from //CswSessionResourcesNbt. Using the aforementioned chain of classes here would be //problematic because of said classes deep-endencies on, for example, various http //classes. So, if we add something in one place that the other place should also be //doing, we'll have to add it manually. CswSessionsListEntry CswSessionsListEntry = new CswSessionsListEntry(CurrentSessionId); CswSessions.remove(CswSessionsListEntry); } //iterate session records //Case 30266 - remove all rows in the current schema's session_data with no corresponding session id in the master schema's SessionList CswTableUpdate DoomedSessionDataTU = CurrentSchemaResources.makeCswTableUpdate("purge_doomed_session_data", "session_data"); DataTable DoomedSessionDataDT = DoomedSessionDataTU.getTable(_getMasterSessionIdsWhere()); foreach (DataRow DoomedRow in DoomedSessionDataDT.Rows) { DoomedRow.Delete(); } DoomedSessionDataTU.update(DoomedSessionDataDT); //case 31415 - there are still temp nodes hanging around, this should kill anything with a sessionid that has previously expired CswArbitrarySelect SelectOrphanedNodes = CurrentSchemaResources.makeCswArbitrarySelect("orphaned_nodeids", "select nodeid from nodes n left outer join sessionlist s on n.sessionid=s.sessionid where istemp=1 and s.sessionid is null"); foreach (DataRow Row in SelectOrphanedNodes.getTable().Rows) { CswPrimaryKey NodeId = new CswPrimaryKey("nodes", CswConvert.ToInt32(Row["nodeid"])); if (CswTools.IsPrimaryKey(NodeId)) { CswNbtNode TempNode = CurrentSchemaResources.Nodes[NodeId]; if (null != TempNode) { TempNode.delete(true, true); } } } //for each node with an inactive sessionid } //_StaleDataExists _CswScheduleLogicDetail.StatusMessage = "Completed without error"; _LogicRunStatus = CswEnumScheduleLogicRunStatus.Succeeded; //last line } else { CswResources.CswLogger.reportError(new CswDniException("Unable to process sessionlist records: The master schmea resource object is null")); } }//try catch (Exception Exception) { _CswScheduleLogicDetail.StatusMessage = "CswScheduleLogicNbtPurgeSessionData exception: " + Exception.Message + "; " + Exception.StackTrace; CurrentSchemaResources.logError(new CswDniException(_CswScheduleLogicDetail.StatusMessage)); _LogicRunStatus = CswEnumScheduleLogicRunStatus.Failed; }//catch finally { _StaleDataExists = false; _MasterSchemaResources.release(); //These must be marked null so that they get garbage collected _MasterSchemaResources = null; } } //if we're not shutting down } //threadCallBack()
public JObject makeVersionJson(CswSessionResourcesNbt _CswSessionResources) { JObject ret = new JObject(); string AssemblyFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "/_Assembly.txt"; if (File.Exists(AssemblyFilePath)) { TextReader AssemblyFileReader = new StreamReader(AssemblyFilePath); ret.Add(new JProperty("assembly", AssemblyFileReader.ReadLine())); AssemblyFileReader.Close(); } JObject ComponentObj = new JObject(); JProperty ComponentsProp = new JProperty("components", ComponentObj); ret.Add(ComponentsProp); string ThisYear = DateTime.Now.Year.ToString(); ArrayList CswAssemblies = new ArrayList(); CswAssemblies.Add("NbtWebApp"); CswAssemblies.Add("CswCommon"); CswAssemblies.Add("CswWebControls"); CswAssemblies.Add("NbtLogic"); CswAssemblies.Add("NbtWebControls"); foreach (string AssemblyName in CswAssemblies) { string name = AssemblyName.Contains(",") ? AssemblyName.Substring(0, AssemblyName.IndexOf(',')) : AssemblyName; JObject AssemObj = new JObject(); ComponentObj.Add(new JProperty(name, AssemObj)); Assembly AssemblyInfo = Assembly.Load(AssemblyName); string Version = AssemblyInfo.GetName().Version.ToString(); AssemObj.Add(new JProperty("name", name)); AssemObj.Add(new JProperty("version", Version)); AssemObj.Add(new JProperty("copyright", "Copyright © ChemSW, Inc. 2005-" + ThisYear)); } ArrayList ThirdAssemblies = new ArrayList(); ThirdAssemblies.Add("CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"); ThirdAssemblies.Add("Telerik.Web.UI"); foreach (string AssemblyName in ThirdAssemblies) { string name = AssemblyName.Contains(",") ? AssemblyName.Substring(0, AssemblyName.IndexOf(',')) : AssemblyName; JObject AssemObj = new JObject(); ComponentObj.Add(new JProperty(name, AssemObj)); Assembly AssemblyInfo = Assembly.Load(AssemblyName); object[] AssemblyAttributes = (object[])AssemblyInfo.GetCustomAttributes(true); string Version = AssemblyInfo.GetName().Version.ToString(); string Copyright = string.Empty; foreach (AssemblyCopyrightAttribute AssemblyAttribute in AssemblyAttributes.OfType <AssemblyCopyrightAttribute>()) { Copyright = (AssemblyAttribute).Copyright; } AssemObj.Add(new JProperty("name", name)); AssemObj.Add(new JProperty("version", Version)); AssemObj.Add(new JProperty("copyright", Copyright)); } ComponentObj.Add(new JProperty("Schema", new JObject( new JProperty("name", "Schema"), new JProperty("version", _CswNbtResources.ConfigVbls.getConfigVariableValue("schemaversion")), new JProperty("copyright", "Copyright © ChemSW, Inc. 2005-" + ThisYear) ) )); #region ChemCatCentral Products Versions // Add ChemCatCentral version to the About dialog: Case 29380 if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3Products)) { CswC3Params CswC3Params = new CswC3Params(); CswNbtC3ClientManager C3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params); SearchClient C3SearchClient = C3ClientManager.initializeC3Client(); if (null != C3SearchClient) { string C3Version = C3ClientManager.getCurrentC3Version(); ComponentObj.Add(new JProperty("ChemCatCentral", new JObject( new JProperty("name", "ChemCatCentral"), new JProperty("version", Regex.Replace(C3Version, "_", " ")), new JProperty("copyright", "Copyright © ChemSW, Inc. 2005-" + ThisYear)))); // Add the datasource import dates (if they are available to the user and/or the module is enabled CswC3ServiceLogicGetDataSourcesDataSource[] DataSourceDates = C3ClientManager.getDataSourceDates(); if (null != DataSourceDates) { JObject DSDatesObj = new JObject(); foreach (CswC3ServiceLogicGetDataSourcesDataSource ds in DataSourceDates) { if (ds.DataType == "Extra Chemical") { switch (ds.DataSourceName) { case "FireDb": if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.FireDbSync)) { DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate)); } break; case "PCID": if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.PCIDSync)) { DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate)); } break; } //switch } else { DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate)); } } ret.Add(new JProperty("dsDates", DSDatesObj)); } }//if( C3ClientManager.checkC3ServiceReferenceStatus() ) } #endregion ChemCatCentral Products Versions #region ACD Version if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3ACD)) { CswC3Params CswC3Params = new CswC3Params(); CswNbtC3ClientManager C3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params); SearchClient C3SearchClient = C3ClientManager.initializeC3Client(); if (null != C3SearchClient) { CswRetObjSearchResults Results = C3SearchClient.getACDVersion(CswC3Params); if (null != Results) { ComponentObj.Add(new JProperty("ACD", new JObject( new JProperty("name", "Available Chemicals Directory (ACD)"), new JProperty("version", Regex.Replace(Results.ACDVersion, "_", " ")), new JProperty("copyright", "Copyright © Accelrys, Inc. 1983-" + ThisYear)))); } } } #endregion ACD Version SortedList <string, CswSessionsListEntry> sessions = _CswSessionResources.CswSessionManager.SessionsList.AllSessions; CswDateTime loginDate = new CswDateTime(_CswNbtResources); foreach (var entry in sessions) { CswSessionsListEntry sessionEntry = entry.Value; if (sessionEntry.UserName.Equals(_CswNbtResources.CurrentUser.Username)) { loginDate.FromClientDateString(sessionEntry.LoginDate.ToString()); } } JObject UserObj = new JObject(); UserObj["customerid"] = new JObject(new JProperty("componentName", "Customer ID:"), new JProperty("value", _CswNbtResources.AccessId)); UserObj["loggedinas"] = new JObject(new JProperty("componentName", "Logged in as:"), new JProperty("value", _CswNbtResources.CurrentUser.Username)); UserObj["sessionsince"] = new JObject(new JProperty("componentName", "Session since:"), new JProperty("value", loginDate.ToDateTime().ToString())); ret.Add(new JProperty("userProps", UserObj)); return(ret); } // makeVersionJson()