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


C# IShellContext.Evaluate方法代码示例

本文整理汇总了C#中IShellContext.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# IShellContext.Evaluate方法的具体用法?C# IShellContext.Evaluate怎么用?C# IShellContext.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IShellContext的用法示例。


在下文中一共展示了IShellContext.Evaluate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoRun

        protected override void DoRun(IShellContext context)
        {
            object collection = context.Evaluate(Collection);

            var value = Value;
            if (value == null) value = context.Evaluate(ValueExpression);

            var dct = collection as IDictionary;
            if (dct != null && Key != null) dct[Key] = value;
            var lst = collection as IList;
            if (lst != null) lst.Add(value);
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:12,代码来源:Put.cs

示例2: DoRun

 protected override void DoRun(IShellContext context)
 {
     string file = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
     if (Expression != null && Value != null) throw new Exception("DBSH-00078 SaveToFile: both Expression and Value is set");
     if (Expression == null && Value == null) throw new Exception("DBSH-00079 SaveToFile: none of Expression and Value is set");
     if (Expression != null)
     {
         object obj = context.Evaluate(Expression);
         if (obj is byte[])
         {
             var bytes = (byte[]) obj;
             using (var fw = System.IO.File.OpenWrite(file))
             {
                 fw.Write(bytes, 0, bytes.Length);
             }
         }
         else
         {
             using (var fw = new StreamWriter(file, false, Encoding))
             {
                 fw.Write(obj.ToString());
             }
         }
     }
     if (Value!=null)
     {
         string val = context.Replace(Value);
         using (var fw = new StreamWriter(file, false, Encoding))
         {
             fw.Write(val);
         }
     }
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:33,代码来源:SaveToFile.cs

示例3: DoRun

        protected override void DoRun(IShellContext context)
        {
            object model = null;
            IModelProvider provider = null;
            if (Model is string)
            {
                model = context.Evaluate((string) Model);
                if (model is IModelProvider)
                {
                    provider = (IModelProvider) model;
                    model = provider.GetModel(context);
                }
            }
            else if (Model is IModelProvider)
            {
                provider = (IModelProvider)Model;
                model = provider.GetModel(context);
            }
            else
            {
                model = Model;
            }

            _log.InfoFormat("DBSH-00074 Apply template {0}=>{1}", TemplateFile ?? "(inline template)", File);

            string templateData = LoadTemplate(context);

            try
            {
                string fn = context.ResolveFile(context.Replace(File), ResolveFileMode.Output);
                context.OutputMessage("Generating file " + fn);
                using (var sw = new StreamWriter(fn))
                {
                    RazorScripting.ParseRazor(templateData, sw.Write, model, 
                        provider != null ? provider.InitializeTemplate : (Action<IRazorTemplate, IShellContext>) null, context);
                }
            }
            catch (RazorEngine.Templating.TemplateCompilationException err)
            {
                _log.ErrorFormat("DBSH-00075 Error compiling template {0}", TemplateFile);
                foreach (var error in err.Errors)
                {
                    _log.Error(error.ToString());
                }
                throw;
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:47,代码来源:Razor.cs

示例4: DoRun

        protected override void DoRun(IShellContext context)
        {
            ITabularDataSource source;

            if (Source != null && SourceExpression != null) throw new Exception("DBSH-00153 LoadTable: Both Source and SourceExpression are set");
            if (Source == null && SourceExpression == null) throw new Exception("DBSH-00154 LoadTable: None Source and SourceExpression are set");

            if (SourceExpression != null)
            {
                source = (ITabularDataSource)context.Evaluate(SourceExpression);
            }
            else
            {
                source = Source;
            }

            GetModel(context).LoadTable(source, new NameWithSchema(context.Replace(Schema), context.Replace(Table)), context);
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:18,代码来源:LoadTable.cs

示例5: DoRun

 protected override void DoRun(IShellContext context)
 {
     if (Value != null && Expression != null) throw new Exception("DBSH-00006 Both Value and Expression is set");
     if (Value != null)
     {
         if (Value is string)
         {
             context.SetVariable(context.Replace(Name), context.Replace(Value.ToString()));
         }
         else
         {
             context.SetVariable(context.Replace(Name), Value);
         }
     }
     if (Expression != null)
     {
         context.SetVariable(context.Replace(Name), context.Evaluate(Expression));
     }
     if (Expression == null && Value == null)
     {
         context.SetVariable(context.Replace(Name), null);
     }
 }
开发者ID:dbshell,项目名称:dbshell,代码行数:23,代码来源:SetVariable.cs

示例6: DoRun

        protected override void DoRun(IShellContext context)
        {
            ITabularDataSource source;
            ITabularDataTarget target;

            if (Source != null && SourceExpression != null) throw new Exception("DBSH-00087 CopyTable: Both Source and SourceExpression are set");
            if (Source == null && SourceExpression == null) throw new Exception("DBSH-00088 CopyTable: None Source and SourceExpression are set");
            if (Target != null && TargetExpression != null) throw new Exception("DBSH-00089 CopyTable: Both Target and TargetExpression are set");
            if (Target == null && TargetExpression == null) throw new Exception("DBSH-00090 CopyTable: None Target and TargetExpression are set");

            if (SourceExpression != null)
            {
                source = (ITabularDataSource) context.Evaluate(SourceExpression);
            }
            else
            {
                source = Source;
            }

            if (TargetExpression != null)
            {
                target = (ITabularDataTarget) context.Evaluate(TargetExpression);
            }
            else
            {
                target = Target;
            }

            var options = new CopyTableTargetOptions
                {
                    TruncateBeforeCopy = CleanTarget,
                    TargetMapMode = TargetMapMode,
                    AllowBulkCopy = AllowBulkCopy,
                };

            var table = source.GetRowFormat(context);

            _log.InfoFormat("Copy table data {0}=>{1}", Source.ToStringCtx(context), Target.ToStringCtx(context));
            context.OutputMessage(String.Format("Copy table data {0}=>{1}", Source.ToStringCtx(context), Target.ToStringCtx(context)));

            var transformedInputTable = table;
            var counts = new List<int>();
            if (ColumnMap.Count > 0)
            {
                transformedInputTable = new TableInfo(null);
                foreach (var mapItem in ColumnMap)
                {
                    var newCols = mapItem.GetOutputColumns(table, context);
                    counts.Add(newCols.Length);
                    transformedInputTable.Columns.AddRange(newCols);
                }
            }

            using (var reader = source.CreateReader(context))
            {
                using (var writer = target.CreateWriter(transformedInputTable, options, context, source.GetSourceFormat(context)))
                {
                    int rowNumber = 0;
                    while (reader.Read())
                    {
                        if (ColumnMap.Count > 0)
                        {
                            var outputRecord = new ArrayDataRecord(transformedInputTable);
                            int columnIndex = 0;
                            for (int i = 0; i < ColumnMap.Count; i++)
                            {
                                var map = ColumnMap[i];
                                int count = counts[i];
                                for (int j = 0; j < count; j++, columnIndex++)
                                {
                                    outputRecord.SeekValue(columnIndex);
                                    map.ProcessMapping(j, rowNumber, reader, outputRecord, context);
                                }
                            }
                            writer.Write(outputRecord);
                        }
                        else
                        {
                            writer.Write(reader);
                        }
                        rowNumber++;
                    }
                }
            }
        }
开发者ID:dbshell,项目名称:dbshell,代码行数:85,代码来源:CopyTable.cs


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