当前位置: 首页>>代码示例>>C#>>正文


C# ScriptContext类代码示例

本文整理汇总了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")));
         }
     }
 }
开发者ID:rexcardan,项目名称:AverageHU_ESAPI,代码行数:26,代码来源:PlaneStatisticsPlugin.cs

示例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;
        }
开发者ID:rofr,项目名称:playground,代码行数:26,代码来源:Set.cs

示例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;
        }
开发者ID:rofr,项目名称:playground,代码行数:26,代码来源:Get.cs

示例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);
        }
开发者ID:joemcbride,项目名称:outlander,代码行数:7,代码来源:CommandProcessor.cs

示例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;
            }
        }
开发者ID:joemcbride,项目名称:outlander,代码行数:29,代码来源:IfTokenHandler.cs

示例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;
 }
开发者ID:rofr,项目名称:playground,代码行数:7,代码来源:Arithmetic.cs

示例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);
        }
开发者ID:joemcbride,项目名称:outlander,代码行数:8,代码来源:WaitForReTokenHandler.cs

示例8: CreatePointObject

 public static ObjectValue CreatePointObject(ScriptContext ctx, float x, float y)
 {
     return ctx.Srm.CreateNewObject((obj) =>
     {
         obj["x"] = x;
         obj["y"] = y;
     });
 }
开发者ID:jing-lu,项目名称:ReoScript,代码行数:8,代码来源:Graphics.cs

示例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;
 }
开发者ID:rofr,项目名称:playground,代码行数:8,代码来源:BooleanOperators.cs

示例10: Replace

        public string Replace(string data, ScriptContext context)
        {
            data = SetArguments(data, context);
            data = SetLocalVars(data, context);
            data = SetGlobalVars(data, context);

            return data;
        }
开发者ID:joemcbride,项目名称:outlander,代码行数:8,代码来源:IVariableReplacer.cs

示例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);
     });
 }
开发者ID:joemcbride,项目名称:outlander,代码行数:9,代码来源:CommandProcessor.cs

示例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;
        }
开发者ID:mizzunet,项目名称:spike-box,代码行数:15,代码来源:SessionScope.cs

示例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;
        }
开发者ID:rofr,项目名称:playground,代码行数:10,代码来源:BooleanOperators.cs

示例14: Execute

        public virtual Task<CompletionEventArgs> Execute(ScriptContext context, Token token)
        {
            Token = token;
            Context = context;
            TaskSource = new TaskCompletionSource<CompletionEventArgs>();

            execute();

            return TaskSource.Task;
        }
开发者ID:joemcbride,项目名称:outlander,代码行数:10,代码来源:ITokenHandler.cs

示例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;
 }
开发者ID:rofr,项目名称:playground,代码行数:11,代码来源:Arithmetic.cs


注:本文中的ScriptContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。