本文整理汇总了C#中ScriptContext类的典型用法代码示例。如果您正苦于以下问题:C# ScriptContext类的具体用法?C# ScriptContext怎么用?C# ScriptContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptContext类属于命名空间,在下文中一共展示了ScriptContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(ScriptContext context /*, System.Windows.Window window*/)
{
//Get correct structure set... In our case structure set is named "PSOAS"
var ss = context.Patient.StructureSets
.FirstOrDefault(s => s.Structures.Any(st => st.Id.Equals("PSOAS", StringComparison.InvariantCultureIgnoreCase)));
//Find the structure named "L5_MID"
var l5mid = ss.Structures.FirstOrDefault(s => s.Id.Equals("L5_MID", StringComparison.InvariantCultureIgnoreCase));
double avg = double.NaN;
if (l5mid != null)
{
//Create a map of slice area to image slice, so we know which slice to sample
var l5midContours = GetSliceAreas(ss.Image, l5mid);
//If all slices have a NaN value, then there is no contour
if (!l5midContours.Any(p => !double.IsNaN(p.Value) && p.Value > 0))
{
MessageBox.Show("L5 Mid not found");
}
else
{
//Assumption is L5 contour is only on one slice, find the first slice with a valid area
var z = l5midContours.First(p => !double.IsNaN(p.Value) && p.Value > 0).Key;
avg = GetSliceHUAvg(ss.Image, z, l5mid);
MessageBox.Show(string.Format("L5_MID Stats :\nArea: {0} cm^2\nHUavg = {1} HU", l5midContours[z].ToString("F2"), avg.ToString("F2")));
}
}
}
示例2: Eval
public static object Eval(XmlNode node, ScriptContext ctx)
{
string varName = XmlHelper.ReadAttribute(node, "var");
string className = XmlHelper.ReadAttribute(node, "class");
string propertyName = XmlHelper.ReadAttribute(node, "property");
object value = ctx.Eval(node.ChildNodes);
if (varName != null)
{
if (propertyName == null)//Assign a new value to the variable
{
ctx.State[varName] = value;
}
else //assign a property of the variable
{
ReflectionHelper.SetProperty(ctx.State[varName], propertyName, value);
}
}
else if (className != null) //static property
{
throw new NotImplementedException("Static property setter not implemented");
}
return value;
}
示例3: Eval
public static object Eval(XmlNode node, ScriptContext ctx)
{
string varName = XmlHelper.ReadAttribute(node, "var");
string className = XmlHelper.ReadAttribute(node, "class");
string propertyName = XmlHelper.ReadAttribute(node, "property");
object result = null;
if (varName != null)
{
if (propertyName == null)//Get the variable itself
{
result = ctx.State[varName];
}
else //assign a property of the variable
{
result = ReflectionHelper.GetProperty(ctx.State[varName], propertyName);
}
}
else if (className != null) //static property
{
throw new NotImplementedException("Static property getter not implemented");
}
return result;
}
示例4: Eval
public string Eval(string command, ScriptContext context = null)
{
if(context == null)
context = new ScriptContext(Guid.NewGuid().ToString(), null, CancellationToken.None, _services, null);
return _variableReplacer.Replace(command, context);
}
示例5: Evaluate
public bool Evaluate(string block, ScriptContext context)
{
var replacer = context.Get<IVariableReplacer>();
var scriptLog = context.Get<IScriptLog>();
var replaced = replacer.Replace(block, context);
// replace single equals with double equals
replaced = Regex.Replace(replaced, "([^=:<>])=(?!=)", "$1==");
if(context.DebugLevel > 0) {
scriptLog.Log(context.Name, "if {0}".ToFormat(replaced), context.LineNumber);
}
try
{
var interpreter = new Interpreter();
var result = (bool)interpreter.Eval(replaced);
if(context.DebugLevel > 0) {
scriptLog.Log(context.Name, "if result {0}".ToFormat(result.ToString().ToLower()), context.LineNumber);
}
return result;
}
catch(Exception exc)
{
scriptLog.Log(context.Name, "if result {0}".ToFormat(exc), context.LineNumber);
return false;
}
}
示例6: Modulus
public static object Modulus(XmlNode node, ScriptContext ctx)
{
if(node.ChildNodes.Count != 2) throw new Exception();
int a = (int) ctx.Eval(node.ChildNodes[0]);
int b = (int)ctx.Eval(node.ChildNodes[1]);
return a % b;
}
示例7: Execute
public override Task<CompletionEventArgs> Execute(ScriptContext context, Token token)
{
if(context.DebugLevel > 0) {
context.Get<IScriptLog>().Log(context.Name, "waitforre " + token.Value, context.LineNumber);
}
return base.Execute(context, token);
}
示例8: CreatePointObject
public static ObjectValue CreatePointObject(ScriptContext ctx, float x, float y)
{
return ctx.Srm.CreateNewObject((obj) =>
{
obj["x"] = x;
obj["y"] = y;
});
}
示例9: And
public static object And(XmlNode node, ScriptContext ctx)
{
foreach(XmlNode childNode in node.ChildNodes)
{
if (!(bool)ctx.Eval(childNode)) return false;
}
return true;
}
示例10: Replace
public string Replace(string data, ScriptContext context)
{
data = SetArguments(data, context);
data = SetLocalVars(data, context);
data = SetGlobalVars(data, context);
return data;
}
示例11: Echo
public Task Echo(string command, ScriptContext context = null)
{
return Publish(command, context, t => {
t.Color = "#00FFFF";
t.Mono = true;
if(context != null && context.DebugLevel > 0)
_scriptLog.Log(context.Name, "echo {0}".ToFormat(t.Text), context.LineNumber);
});
}
示例12: SessionScope
/// <summary>
/// Constructs a new instance of an <see cref="AppScope"/>.
/// </summary>
/// <param name="name">The unique name for the scope.</param>
/// <param name="parent">The parent scope to attach to the scope.</param>
/// <param name="context">The execution context that is used to execute scripts.</param>
internal SessionScope(string name, AppScope parent, ScriptContext context)
: base(name, parent, context, context.GetPrototype("Session"))
{
// Create a new channel linked to the session
this.SessionChannel = new Channel(context);
// When creating, set the current thread channel
Channel.Current = this.SessionChannel;
}
示例13: LessThanOrEqual
public static object LessThanOrEqual(XmlNode node, ScriptContext ctx)
{
if(node.ChildNodes.Count != 2) throw new Exception("Expected 2 child nodes");
object o1 = ctx.Eval(node.ChildNodes[0]);
object o2 = ctx.Eval(node.ChildNodes[1]);
var n1 = o1 is double ? (double) o1 : (int) o1;
var n2 = o2 is double ? (double)o2 : (int) o2;
return n1 <= n2;
}
示例14: Execute
public virtual Task<CompletionEventArgs> Execute(ScriptContext context, Token token)
{
Token = token;
Context = context;
TaskSource = new TaskCompletionSource<CompletionEventArgs>();
execute();
return TaskSource.Task;
}
示例15: Add
public static object Add(XmlNode node, ScriptContext ctx)
{
double sum = 0;
foreach(XmlNode childNode in node.ChildNodes)
{
object o = ctx.Eval(childNode);
double operand = o is int ? (int) o : (double) o;
sum += operand;
}
return sum;
}