本文整理汇总了C#中ExecutionContext类的典型用法代码示例。如果您正苦于以下问题:C# ExecutionContext类的具体用法?C# ExecutionContext怎么用?C# ExecutionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExecutionContext类属于命名空间,在下文中一共展示了ExecutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUsingValue
private static object GetUsingValue(MutableTuple tuple, int index, ExecutionContext context)
{
UsingResult usingValueFromTuple = GetUsingValueFromTuple(tuple, index);
if (usingValueFromTuple != null)
{
return usingValueFromTuple.Value;
}
for (SessionStateScope scope = context.EngineSessionState.CurrentScope; scope != null; scope = scope.Parent)
{
usingValueFromTuple = GetUsingValueFromTuple(scope.LocalsTuple, index);
if (usingValueFromTuple != null)
{
return usingValueFromTuple.Value;
}
foreach (MutableTuple tuple2 in scope.DottedScopes)
{
usingValueFromTuple = GetUsingValueFromTuple(tuple2, index);
if (usingValueFromTuple != null)
{
return usingValueFromTuple.Value;
}
}
}
throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "UsingWithoutInvokeCommand", ParserStrings.UsingWithoutInvokeCommand, new object[0]);
}
示例2: Execute
public override object Execute(object[] args, ExecutionContext ctx)
{
ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);
checker.CheckForNumberOfArguments(ref args, 1, null);
decimal d = Convert.ToDecimal(args[0]);
return Math.Sign(d) * Math.Floor(Math.Abs(d));
}
示例3: ExecuteAsync
public IObservable<Unit> ExecuteAsync(ExecutionContext context)
{
context.AssertNotNull(nameof(context));
var childExecutions = this
.children
.Select(
child => Observable
.Return(Unit.Default)
.Select(
_ =>
{
context.CancellationToken.ThrowIfCancellationRequested();
var execute = true;
if (context.SkipAhead > TimeSpan.Zero && context.SkipAhead >= child.Duration)
{
context.AddProgress(child.Duration);
execute = false;
}
return new
{
Child = child,
Execute = execute
};
})
.Where(x => x.Execute)
.SelectMany(x => x.Child.ExecuteAsync(context)))
.DefaultIfEmpty(Observable.Return(Unit.Default));
return Observable
.Concat(childExecutions)
.RunAsync(context.CancellationToken);
}
示例4: execute_executes_each_child_action
public void execute_executes_each_child_action()
{
var action1 = new ActionMock(MockBehavior.Loose);
var action2 = new ActionMock(MockBehavior.Loose);
var action3 = new ActionMock(MockBehavior.Loose);
var sut = new SequenceActionBuilder()
.WithChild(action1)
.WithChild(action2)
.WithChild(action3)
.Build();
using (var context = new ExecutionContext())
{
sut.Execute(context).Subscribe();
action1
.Verify(x => x.Execute(context))
.WasCalledExactlyOnce();
action2
.Verify(x => x.Execute(context))
.WasCalledExactlyOnce();
action3
.Verify(x => x.Execute(context))
.WasCalledExactlyOnce();
}
}
示例5: Execute
public override void Execute(ExecutionContext context)
{
if (context.CurrentBlockWeb != null && ownerBlockId == null)
{
throw new Exception("You cannot nest standalone blockWebs");
}
IBlockWeb newWeb = null;
IBlockWeb oldWeb = context.CurrentBlockWeb;
if (ownerBlockId != null)
{
newWeb = (IBlockWeb)context.CurrentBlockWeb[ownerBlockId].ProcessRequest("ProcessMetaService", BlockMetaServiceType.GetInnerWeb,
null, null);
}
else
{
newWeb = new BlockWeb(webId, context.Broker);
}
context.CurrentBlockWeb = newWeb;
if (webId != null)
{
context.blockWebs[webId] = newWeb;
}
base.Execute(context);
context.CurrentBlockWeb = oldWeb;
}
示例6: DefaultCtorSplitsAtDashes
public void DefaultCtorSplitsAtDashes()
{
// Given
Engine engine = new Engine();
Metadata metadata = new Metadata(engine);
Pipeline pipeline = new Pipeline("Pipeline", engine, null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs = { new Document(metadata).Clone(@"FM1
FM2
---
Content1
Content2") };
string frontMatterContent = null;
FrontMatter frontMatter = new FrontMatter(new Execute(x =>
{
frontMatterContent = x.Content;
return new [] {x};
}));
// When
IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);
// Then
Assert.AreEqual(1, documents.Count());
Assert.AreEqual(@"FM1
FM2
", frontMatterContent);
Assert.AreEqual(@"Content1
Content2", documents.First().Content);
}
示例7: Execute
public override object Execute(object[] args, ExecutionContext ctx)
{
ArgumentChecker checker = new ArgumentChecker(this.GetType().Name);
checker.CheckForNumberOfArguments(ref args, 1, null);
CharMapAlphabet map = new CharMapAlphabet();
return map.GetCharacterCode(args[0].ToString()[0]);
}
示例8: ExecuteStatement
protected override void ExecuteStatement(ExecutionContext context)
{
var evaluated = Password.EvaluateToConstant(context.Request, null);
var passwordText = evaluated.AsVarChar().Value.ToString();
context.Request.Query.CreateUser(UserName, passwordText);
}
示例9: RegisterCommandDefault
private void RegisterCommandDefault(ExecutionContext context, string commandName, Type commandType)
{
CommandEntry entry = new CommandEntry();
entry.command.Initialize(context, commandName, commandType);
entry.command.AddNamedParameter("LineOutput", this.lo);
this.defaultCommandEntry = entry;
}
示例10: GetValidRules
public virtual IEnumerable<ILogicRuleObject> GetValidRules(View view, ExecutionContext executionContext) {
if (view!=null) {
var tuple = new Tuple<ITypeInfo, ExecutionContext>(view.ObjectTypeInfo, executionContext);
return LogicRuleManager.Instance[tuple].Where(rule => IsValidRule(rule, view)).OrderBy(rule => rule.Index);
}
return Enumerable.Empty<ILogicRuleObject>();
}
示例11: ConfigureSecurity
protected override void ConfigureSecurity(ExecutionContext context)
{
context.Assertions.Add(c => {
if (!c.User.CanManageUsers())
throw new SecurityException(String.Format("User '{0}' cannot create users.", c.User.Name));
});
}
示例12: DefaultCtorIgnoresDelimiterOnFirstLine
public void DefaultCtorIgnoresDelimiterOnFirstLine()
{
// Given
Engine engine = new Engine();
Pipeline pipeline = new Pipeline("Pipeline", null);
IExecutionContext context = new ExecutionContext(engine, pipeline);
IDocument[] inputs =
{
context.GetDocument(@"---
FM1
FM2
---
Content1
Content2")
};
string frontMatterContent = null;
FrontMatter frontMatter = new FrontMatter(new Execute((x, ctx) =>
{
frontMatterContent = x.Content;
return new[] {x};
}));
// When
IEnumerable<IDocument> documents = frontMatter.Execute(inputs, context);
// Then
Assert.AreEqual(1, documents.Count());
Assert.AreEqual(@"FM1
FM2
", frontMatterContent);
Assert.AreEqual(@"Content1
Content2", documents.First().Content);
}
示例13: TestConstruction
public static void TestConstruction()
{
AssertEquals(new Literal(false).AsValue(), false);
AssertEquals(new Literal(true).AsValue(), true);
AssertEquals(new Literal(0).AsValue(), 0);
AssertEquals(new Literal(1).AsValue(), 1);
AssertEquals(new Literal(5).AsValue(), 5);
AssertEquals(new Literal(0.1f).AsValue(), 0.1f);
AssertEquals(new Literal(2.4f).AsValue(), 2.4f);
AssertEquals(new Literal(5.0f).AsValue(), 5.0f);
AssertEquals(new Literal("Hello ").AsValue(), "Hello ");
AssertEquals(new Literal("World!").AsValue(), "World!");
AssertEquals(new Literal(new Literal(true)).AsValue(), true);
AssertEquals(new Literal(new Literal(1)).AsValue(), 1);
AssertEquals(new Literal(new Literal(2.4f)).AsValue(), 2.4f);
AssertEquals(new Literal(new Literal("Hello ")).AsValue(), "Hello ");
var context = new ExecutionContext(new Python3Calculator());
AssertEquals(new Variable("foo", context).Type, ValueType.ANY);
AssertEquals(new Variable(ValueType.BOOL, "bar", context).Type, ValueType.BOOL);
AssertException<InvalidOperationException>(() => new Variable("foo", context));
}
示例14: GetVariableAsRef
private static PSReference GetVariableAsRef(VariablePath variablePath, ExecutionContext executionContext, Type staticType)
{
SessionStateScope scope;
SessionStateInternal engineSessionState = executionContext.EngineSessionState;
CommandOrigin scopeOrigin = engineSessionState.CurrentScope.ScopeOrigin;
PSVariable variable = engineSessionState.GetVariableItem(variablePath, out scope, scopeOrigin);
if (variable == null)
{
throw InterpreterError.NewInterpreterException(variablePath, typeof(RuntimeException), null, "NonExistingVariableReference", ParserStrings.NonExistingVariableReference, new object[0]);
}
object obj2 = variable.Value;
if ((staticType == null) && (obj2 != null))
{
obj2 = PSObject.Base(obj2);
if (obj2 != null)
{
staticType = obj2.GetType();
}
}
if (staticType == null)
{
ArgumentTypeConverterAttribute attribute = variable.Attributes.OfType<ArgumentTypeConverterAttribute>().FirstOrDefault<ArgumentTypeConverterAttribute>();
staticType = (attribute != null) ? attribute.TargetType : typeof(LanguagePrimitives.Null);
}
return PSReference.CreateInstance(variable, staticType);
}
示例15: Divide
internal override ElaValue Divide(ElaValue left, ElaValue right, ExecutionContext ctx)
{
if (right.TypeId != ElaMachine.REA)
{
if (right.TypeId == ElaMachine.DBL)
return new ElaValue(left.DirectGetSingle() / right.Ref.AsDouble());
else if (right.TypeId == ElaMachine.INT)
return new ElaValue(left.DirectGetSingle() / right.I4);
else if (right.TypeId == ElaMachine.LNG)
return new ElaValue(left.DirectGetSingle() / right.Ref.AsLong());
else
{
NoOverloadBinary(TCF.SINGLE, right, "divide", ctx);
return Default();
}
}
if (right.DirectGetSingle() == 0)
{
ctx.DivideByZero(left);
return Default();
}
return new ElaValue(left.DirectGetSingle() / right.DirectGetSingle());
}