コード例 #1
0
ファイル: OutputWriterCSharpCode.cs プロジェクト: eyedia/idpe
        /// <summary>
        /// Executes CSharp code and returns string for output
        /// </summary>
        /// <returns></returns>
        public override StringBuilder GetOutput()
        {
            if (_Job.IsErrored)
            {
                return(new StringBuilder());
            }

            CSharpCodeInformation csharpCodeInformation = new CSharpCodeInformation(_Job.DataSource.Keys.GetKeyValue(IdpeKeyTypes.CSharpCodeOutputWriter));
            ExecuteCSharpCode     executeCSharpcode     = new ExecuteCSharpCode("Eyedia.IDPE.Common.CSharpCode",
                                                                                ExecuteCSharpCode.CompilerVersions.v40, csharpCodeInformation.GetReferencedAssemblies());

            return(new StringBuilder(executeCSharpcode.Execute(csharpCodeInformation.CompleteCode, "ExecuteAndReturnString", new object[] { _Job }).ToString()));
        }
コード例 #2
0
        protected override void Execute(CodeActivityContext context)
        {
            Job job = context.GetValue(this.Job);

            if (job == null)
            {
                WorkerData data = context.GetValue(this.Data);
                data.ThrowErrorIfNull(this.DisplayName);
            }

            Object obj        = context.GetValue(this.Object);
            string objectType = context.GetValue(this.ObjectType);
            string code       = context.GetValue(this.Code);
            string additionalUsingNamespace = context.GetValue(this.AdditionalUsingNamespace);
            string additionalReferences     = context.GetValue(this.AdditionalReferences);


            CSharpCodeInformation csharpCodeInformation = new CSharpCodeInformation();

            csharpCodeInformation.CodeType = CSharpCodeInformation.CodeTypes.Execute;
            csharpCodeInformation.Code     = string.Format("(({0})obj).{1}", objectType, code);
            if (string.IsNullOrEmpty(additionalUsingNamespace))
            {
                csharpCodeInformation.AdditionalUsingNamespace = additionalUsingNamespace;
            }

            if (string.IsNullOrEmpty(additionalReferences))
            {
                csharpCodeInformation.AdditionalReferences = "System.Linq.dll";
            }

            ExecuteCSharpCode cSharpCodeExecutor = new ExecuteCSharpCode("Eyedia.IDPE.Common.CSharpCode", null,
                                                                         ExecuteCSharpCode.CompilerVersions.v40, csharpCodeInformation.GetReferencedAssemblies());

            cSharpCodeExecutor.Execute(csharpCodeInformation.CompleteCode, "Execute", new object[] { obj });
        }