// 19Apr2013-05:58UTC chinajade public static void DeprecationWarning_Behavior(CustomForcedBehavior cfb, string newBehaviorName, List <Tuple <string, string> > replacementAttributes) { if (QuestBehaviorCoreSettings.Instance.LogNotifyOn_OnDeprecatedBehaviorUse) { var oldLoggingContext = QBCLog.BehaviorLoggingContext; QBCLog.BehaviorLoggingContext = cfb; string attributes = string.Join(" ", replacementAttributes.Select(t => string.Format("{0}=\"{1}\"", t.Item1, t.Item2))); QBCLog.Warning(QBCLog.BuildMessageWithContext(cfb.Element, "{0}/********************{0}DEPRECATED BEHAVIOR ({1}){0}" + "The {1} behavior has been deprecated, but will continue to function as originally designed." + " Please replace the use of the {1} behavior with the {2} behavior.{0}" + "The replacement command to accomplish this task is:{0} {3}", Environment.NewLine, cfb.GetType().Name, newBehaviorName, string.Format("<CustomBehavior File=\"{0}\" {1} />", newBehaviorName, attributes)) + Environment.NewLine + "********************/" + Environment.NewLine); AudibleNotifyOn(QuestBehaviorCoreSettings.Instance.AudibleNotify_OnDeprecatedBehaviorUse); QBCLog.BehaviorLoggingContext = oldLoggingContext; } }
/// <summary> /// Executes a hook. This also sets QBCLog.BehaviorLoggingContext and logs when hook starts/stops executing, if enabled /// </summary> /// <param name="cb">The CustomForcedBehavior.</param> /// <param name="taskProducer">The task producer.</param> /// <param name="name">The name. Used to identify hooks that can have multiple instances running at a time.</param> /// <param name="logExecution">if set to <c>true</c> [log execution].</param> /// <returns> /// Returns value produced by the coroutine returned from <paramref name="taskProducer" />. /// </returns> /// <exception cref="Exception">Coroutine status was invalid</exception> /// <exception cref="System.Exception">Coroutine status was invalid</exception> public static async Task <bool> ExecuteHook(CustomForcedBehavior cb, Func <Task <bool> > taskProducer, string name = "", bool logExecution = true) { using (var coroutine = new Coroutine(async() => await taskProducer())) { var hookType = cb.GetType(); string identifier = hookType + name; // Change the logging context to the Hook instance so QBCLog messages correctly display the originating QB. var originalLoggingContext = QBCLog.BehaviorLoggingContext; QBCLog.BehaviorLoggingContext = cb; try { while (true) { coroutine.Resume(); bool executed; switch (coroutine.Status) { case CoroutineStatus.Runnable: executed = true; break; case CoroutineStatus.RanToCompletion: executed = (bool)coroutine.Result; break; default: throw new Exception("Unexpected Coroutine status"); } if (logExecution) { bool executedPreviously; s_hookExecutionStates.TryGetValue(identifier, out executedPreviously); if (executed != executedPreviously) { s_hookExecutionStates[identifier] = executed; // log execution state changes. QBCLog.Debug(executed ? "Executing {0}hook" : "Stopped executing {0}hook", name != null ? name + " " : ""); } } if (coroutine.Status != CoroutineStatus.Runnable) { return(executed); } await Coroutine.Yield(); } } finally { QBCLog.BehaviorLoggingContext = originalLoggingContext; } } }
// 25Apr2013-11:42UTC chinajade private static string BuildVersionedBehaviorName(CustomForcedBehavior cfb) { var behaviorName = (cfb != null) ? cfb.GetType().Name : "UnknownBehavior"; var versionNumber = (cfb != null) ? cfb.VersionId : "0"; VersionedBehaviorName = string.Format("{0}-{1}", behaviorName, versionNumber); return(VersionedBehaviorName); }
public static void Warning(CustomForcedBehavior cfbContext, string format, params object[] args) { CustomForcedBehavior originalCfbContext = BehaviorLoggingContext; BehaviorLoggingContext = cfbContext; Warning(format, args); BehaviorLoggingContext = originalCfbContext; }
public static void MaintenanceError(CustomForcedBehavior cfbContext, string format, params object[] args) { CustomForcedBehavior originalCfbContext = BehaviorLoggingContext; BehaviorLoggingContext = cfbContext; MaintenanceError(format, args); BehaviorLoggingContext = originalCfbContext; }
public static void Exception(CustomForcedBehavior cfbContext, Exception except, string format, params object[] args) { CustomForcedBehavior originalCfbContext = BehaviorLoggingContext; BehaviorLoggingContext = cfbContext; Exception(except, format, args); BehaviorLoggingContext = originalCfbContext; }
public static void DeveloperInfo(CustomForcedBehavior cfbContext, string format, params object[] args) { CustomForcedBehavior originalCfbContext = BehaviorLoggingContext; BehaviorLoggingContext = cfbContext; DeveloperInfo(format, args); BehaviorLoggingContext = originalCfbContext; }
public static void UpdateGoalText(this CustomForcedBehavior cfb, int questId, string extraGoalTextDescription = null) { TreeRoot.GoalText = string.Format( "{0}: {1}{2} {3}", QBCLog.VersionedBehaviorName, (GetQuestReference(questId) + Environment.NewLine), ((extraGoalTextDescription != null) ? (extraGoalTextDescription + Environment.NewLine) : string.Empty), Utility.GetProfileReference(cfb.Element)); }
public void GetChangesFromAttributes(CustomForcedBehavior behavior) { var configDescriptors = (from attributeKvp in behavior.Args from desc in _recognizedAttributes.Values where (desc != null) && (attributeKvp.Key == desc.Name) select desc); foreach (ConfigDescriptor configDesc in configDescriptors) { object result = configDesc.Constraint.AcquireUserInput(behavior, configDesc.Name); if (result != null) { _changeRequests.Add(configDesc, result); } } }
// 19Apr2013-05:58UTC chinajade public static void UsageCheck_ScheduledForDeprecation(CustomForcedBehavior cfb, string replacementBehaviorName) { if (QuestBehaviorCoreSettings.Instance.LogNotifyOn_OnScheduledForDeprecation) { var oldLoggingContext = QBCLog.BehaviorLoggingContext; QBCLog.BehaviorLoggingContext = cfb; QBCLog.Warning(QBCLog.BuildMessageWithContext(cfb.Element, "SCHEDULED FOR DEPRECATION ({1}){0}" + "Please replace the behavior with \"{2}\"", Environment.NewLine, cfb.GetType().Name, replacementBehaviorName)); AudibleNotifyOn(true); QBCLog.BehaviorLoggingContext = oldLoggingContext; } }
public override object AcquireUserInput(CustomForcedBehavior behavior, string configName) { return(behavior.GetAttributeAs <string>(configName, false, null, null)); }
public override object AcquireUserInput(CustomForcedBehavior behavior, string configName) { return(behavior.GetAttributeAsNullable <int>(configName, false, new CustomForcedBehavior.ConstrainTo.Domain <int>(MinValue, MaxValue), null)); }
// The returned object may be null. public abstract object AcquireUserInput(CustomForcedBehavior behavior, string configName);
public override object AcquireUserInput(CustomForcedBehavior behavior, string configName) { return(behavior.GetAttributeAsInteger(configName, false, MinValue, MaxValue, null)); }