本文整理汇总了C#中Story.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Story.Stop方法的具体用法?C# Story.Stop怎么用?C# Story.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Story
的用法示例。
在下文中一共展示了Story.Stop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnFileChanged
private void OnFileChanged(string fileContent)
{
var story = new Story("FileBasedStoryRulesetProvider.OnFileChanged", this.ruleset, notInContext: true);
story.Start();
try
{
// Create a new instance of the C# compiler
var compiler = new CSharpCodeProvider();
// Create some parameters for the compiler
var parms = new CompilerParameters()
{
GenerateExecutable = false,
GenerateInMemory = true,
TreatWarningsAsErrors = false
};
// Load assemblies from current domain
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
try
{
parms.ReferencedAssemblies.Add(assembly.Location);
foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
{
parms.ReferencedAssemblies.Add(Assembly.Load(assemblyName).Location);
}
}
catch
{
}
}
// Try to compile the string into an assembly
var results = compiler.CompileAssemblyFromSource(parms, fileContent);
// Create ruleset
if (results.Errors.Count == 0)
{
try
{
var rulesetType = results.CompiledAssembly.DefinedTypes.FirstOrDefault(definedType => definedType.GetInterfaces().Any(i => i == typeof(IRuleset<IStory, IStoryHandler>)));
if (rulesetType != null)
{
var args = this.rulesetConstructorArgsProvider();
var newRuleset =
results.CompiledAssembly.CreateInstance(rulesetType.FullName, false, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public, null, args, null, null) as IRuleset<IStory, IStoryHandler>;
this.ruleset = newRuleset;
story.Log.Info("Ruleset updated to {0}", rulesetType.Name);
}
else
{
Storytelling.Warn("Missing IRuleset<IStory, IStoryHandler>");
}
}
catch (Exception ex)
{
story.Log.Error(ex.ToString());
}
}
else
{
foreach (var error in results.Errors)
{
story.Log.Warn(error.ToString());
}
}
}
finally
{
story.Stop();
}
}