public static void AddConditionProfileToCache(ConditionProfile entity) { int cacheMinutes = UtilityManager.GetAppKeyValue("learningOppCacheMinutes", 0); string key = "ConditionProfile_" + entity.Id.ToString(); if (cacheMinutes > 0) { var newCache = new CachedConditionProfile() { Item = entity, lastUpdated = DateTime.Now }; if (HttpContext.Current != null) { if (HttpContext.Current.Cache[key] != null) { HttpRuntime.Cache.Remove(key); HttpRuntime.Cache.Insert(key, newCache); LoggingHelper.DoTrace(7, string.Format("===CacheManager.AddConditionProfileToCache $$$ Updating cached version of ConditionProfile, Id: {0}, {1}", entity.Id, entity.ProfileName)); } else { LoggingHelper.DoTrace(7, string.Format("===CacheManager.AddConditionProfileToCache ****** Inserting new cached version of ConditionProfile, Id: {0}, {1}", entity.Id, entity.ProfileName)); System.Web.HttpRuntime.Cache.Insert(key, newCache, null, DateTime.Now.AddHours(cacheMinutes), TimeSpan.Zero); } } } //return entity; }
public static bool IsConditionProfileAvailableFromCache(int id, ref ConditionProfile entity) { //use same as lopp for now int cacheMinutes = UtilityManager.GetAppKeyValue("learningOppCacheMinutes", 0); DateTime maxTime = DateTime.Now.AddMinutes(cacheMinutes * -1); string key = "ConditionProfile_" + id.ToString(); if (HttpRuntime.Cache[key] != null && cacheMinutes > 0) { var cache = ( CachedConditionProfile )HttpRuntime.Cache[key]; try { if (cache.lastUpdated > maxTime) { LoggingHelper.DoTrace(7, string.Format("===CacheManager.IsConditionProfileAvailableFromCache === Using cached version of ConditionProfile, Id: {0}, {1}", cache.Item.Id, cache.Item.ProfileName)); //check if user can update the object //string status = ""; //if ( !CanUserUpdateCredential( id, user, ref status ) ) // cache.Item.CanEditRecord = false; entity = cache.Item; return(true); } } catch (Exception ex) { LoggingHelper.DoTrace(6, "===CacheManager.IsConditionProfileAvailableFromCache === exception " + ex.Message); } } return(false); }
public static ConditionManifestExpanded DisambiguateConditionProfiles(List <ConditionProfile> input) { var processed = ConditionProfile.DisambiguateConditionProfiles(input); var result = new ConditionManifestExpanded() { Requires = processed[ConditionProfile.ConditionProfileTypes.REQUIRES], Recommends = processed[ConditionProfile.ConditionProfileTypes.RECOMMENDS], PreparationFrom = processed[ConditionProfile.ConditionProfileTypes.PREPARATION_FROM], AdvancedStandingFrom = processed[ConditionProfile.ConditionProfileTypes.ADVANCED_STANDING_FROM], IsRequiredFor = processed[ConditionProfile.ConditionProfileTypes.IS_REQUIRED_FOR], IsRecommendedFor = processed[ConditionProfile.ConditionProfileTypes.IS_RECOMMENDED_FOR], IsPreparationFor = processed[ConditionProfile.ConditionProfileTypes.IS_PREPARATION_FOR], IsAdvancedStandingFor = processed[ConditionProfile.ConditionProfileTypes.IS_ADVANCED_STANDING_FOR], EntryCondition = processed[ConditionProfile.ConditionProfileTypes.ENTRY_CONDITION], Corequisite = processed[ConditionProfile.ConditionProfileTypes.COREQUISITE] }; return(result); }
public static void Setup() { var definitionList = MyDefinitionManager.Static.GetEntityComponentDefinitions(); //Get All Chat, Spawner foreach (var def in definitionList) { try { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Chat]") == true && ChatObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var chatObject = new ChatProfile(); chatObject.InitTags(def.DescriptionText); chatObject.ProfileSubtypeId = def.Id.SubtypeName; var chatBytes = MyAPIGateway.Utilities.SerializeToBinary <ChatProfile>(chatObject); //Logger.WriteLog("Chat Profile Added: " + def.Id.SubtypeName); ChatObjectTemplates.Add(def.Id.SubtypeName, chatBytes); continue; } if (def.DescriptionText.Contains("[RivalAI Spawn]") == true && SpawnerObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var spawnerObject = new SpawnProfile(); spawnerObject.InitTags(def.DescriptionText); spawnerObject.ProfileSubtypeId = def.Id.SubtypeName; var spawnerBytes = MyAPIGateway.Utilities.SerializeToBinary <SpawnProfile>(spawnerObject); //Logger.WriteLog("Spawner Profile Added: " + def.Id.SubtypeName); SpawnerObjectTemplates.Add(def.Id.SubtypeName, spawnerBytes); continue; } } catch (Exception) { Logger.MsgDebug(string.Format("Caught Error While Processing Definition {0}", def.Id)); } } foreach (var def in definitionList) { try { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Action]") == true && ActionObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var actionObject = new ActionProfile(); actionObject.InitTags(def.DescriptionText); actionObject.ProfileSubtypeId = def.Id.SubtypeName; var targetBytes = MyAPIGateway.Utilities.SerializeToBinary <ActionProfile>(actionObject); //Logger.WriteLog("Action Profile Added: " + def.Id.SubtypeName); ActionObjectTemplates.Add(def.Id.SubtypeName, targetBytes); continue; } if (def.DescriptionText.Contains("[RivalAI Condition]") == true && ChatObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var conditionObject = new ConditionProfile(); conditionObject.InitTags(def.DescriptionText); conditionObject.ProfileSubtypeId = def.Id.SubtypeName; var conditionBytes = MyAPIGateway.Utilities.SerializeToBinary <ConditionProfile>(conditionObject); //Logger.WriteLog("Condition Profile Added: " + def.Id.SubtypeName); ConditionObjectTemplates.Add(def.Id.SubtypeName, conditionBytes); continue; } if (def.DescriptionText.Contains("[RivalAI Target]") == true && TargetObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var targetObject = new TargetProfile(); targetObject.InitTags(def.DescriptionText); targetObject.ProfileSubtypeId = def.Id.SubtypeName; var targetBytes = MyAPIGateway.Utilities.SerializeToBinary <TargetProfile>(targetObject); //Logger.WriteLog("Target Profile Added: " + def.Id.SubtypeName); TargetObjectTemplates.Add(def.Id.SubtypeName, targetBytes); continue; } } catch (Exception e) { Logger.WriteLog(string.Format("Caught Error While Processing Definition {0}", def.Id)); Logger.WriteLog(e.ToString()); } } //Get All Triggers - Build With Action, Chat and Spawner foreach (var def in definitionList) { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Trigger]") == true && TriggerObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var triggerObject = new TriggerProfile(); triggerObject.InitTags(def.DescriptionText); triggerObject.ProfileSubtypeId = def.Id.SubtypeName; var triggerBytes = MyAPIGateway.Utilities.SerializeToBinary <TriggerProfile>(triggerObject); //Logger.WriteLog("Trigger Profile Added: " + def.Id.SubtypeName); TriggerObjectTemplates.Add(def.Id.SubtypeName, triggerBytes); continue; } } //Get All TriggerGroups, Autopilot foreach (var def in definitionList) { if (string.IsNullOrWhiteSpace(def.DescriptionText) == true) { continue; } if (def.DescriptionText.Contains("[RivalAI Autopilot]") == true && AutopilotObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var autopilotObject = new AutoPilotProfile(); autopilotObject.InitTags(def.DescriptionText); autopilotObject.ProfileSubtypeId = def.Id.SubtypeName; var autopilotBytes = MyAPIGateway.Utilities.SerializeToBinary <AutoPilotProfile>(autopilotObject); //Logger.WriteLog("Trigger Profile Added: " + def.Id.SubtypeName); AutopilotObjectTemplates.Add(def.Id.SubtypeName, autopilotBytes); continue; } if (def.DescriptionText.Contains("[RivalAI TriggerGroup]") == true && TriggerObjectTemplates.ContainsKey(def.Id.SubtypeName) == false) { var triggerObject = new TriggerGroupProfile(); triggerObject.InitTags(def.DescriptionText); triggerObject.ProfileSubtypeId = def.Id.SubtypeName; var triggerBytes = MyAPIGateway.Utilities.SerializeToBinary <TriggerGroupProfile>(triggerObject); //Logger.WriteLog("Trigger Profile Added: " + def.Id.SubtypeName); TriggerGroupObjectTemplates.Add(def.Id.SubtypeName, triggerBytes); continue; } } //Get All Behavior foreach (var def in definitionList) { if (string.IsNullOrWhiteSpace(def.DescriptionText)) { continue; } if ((def.DescriptionText.Contains("[RivalAI Behavior]") || def.DescriptionText.Contains("[Rival AI Behavior]")) && BehaviorTemplates.ContainsKey(def.Id.SubtypeName) == false) { BehaviorTemplates.Add(def.Id.SubtypeName, def.DescriptionText); continue; } } //Print Profile Names To Log: BuildKeyListAndWriteToLog("Behavior", BehaviorTemplates.Keys); BuildKeyListAndWriteToLog("Autopilot", AutopilotObjectTemplates.Keys); BuildKeyListAndWriteToLog("Trigger", TriggerObjectTemplates.Keys); BuildKeyListAndWriteToLog("TriggerGroup", TriggerGroupObjectTemplates.Keys); BuildKeyListAndWriteToLog("Condition", ConditionObjectTemplates.Keys); BuildKeyListAndWriteToLog("Action", ActionObjectTemplates.Keys); BuildKeyListAndWriteToLog("Chat", ChatObjectTemplates.Keys); BuildKeyListAndWriteToLog("Spawn", SpawnerObjectTemplates.Keys); BuildKeyListAndWriteToLog("Target", TargetObjectTemplates.Keys); }