private void CompileInSeparateProcess(WorkflowCompilerParameters parameters, string[] files)
        {
            string str          = SerializeInputToWrapper(parameters, files);
            string tempFileName = Path.GetTempFileName();

            try
            {
                ProcessStartInfo info = new ProcessStartInfo(CompilerPath)
                {
                    CreateNoWindow  = true,
                    UseShellExecute = false,
                    ErrorDialog     = false,
                    Arguments       = string.Format("\"{0}\" \"{1}\"", str, tempFileName)
                };
                Process process = new Process {
                    StartInfo = info
                };
                process.Start();
                process.WaitForExit();
                this.results = DeserializeWrapperOutput(tempFileName);
            }
            finally
            {
                File.Delete(str);
                File.Delete(tempFileName);
            }
        }
 public WorkflowCompilerResults Compile(WorkflowCompilerParameters parameters, params string[] files)
 {
     if (parameters == null)
     {
         throw new ArgumentNullException("parameters");
     }
     if (files == null)
     {
         throw new ArgumentNullException("files");
     }
     if (EnvironmentExtension.Is64BitOS() && EnvironmentExtension.IsWowProcess())
     {
         if (Has64bitAssembliesInReferences(parameters))
         {
             this.CompileInSeparateProcess(parameters, files);
         }
         else
         {
             this.CompileInSameProcess(parameters, files);
         }
     }
     else
     {
         this.CompileInSameProcess(parameters, files);
     }
     return(this.results);
 }
Esempio n. 3
0
        private static void CompileWorkflow(
            String fileName, String assemblyName)
        {
            WorkflowCompiler           compiler = new WorkflowCompiler();
            WorkflowCompilerParameters parameters
                = new WorkflowCompilerParameters();

            parameters.OutputAssembly = assemblyName;
            parameters.ReferencedAssemblies.Add("SharedWorkflows.dll");
#if COMPILE_RULES_WORKFLOW
            //add the .rules file for this workflow as a resource
            parameters.EmbeddedResources.Add("ProWF.MyNewWorkflowClass.rules");
#endif
            WorkflowCompilerResults results
                = compiler.Compile(parameters, fileName);
            if (results.Errors.Count > 0)
            {
                foreach (System.CodeDom.Compiler.CompilerError error
                         in results.Errors)
                {
                    Console.WriteLine("Compiler error: Line{0}: {1}",
                                      error.Line, error.ErrorText);
                }
            }
        }
 private static bool Has64bitAssembliesInReferences(WorkflowCompilerParameters parameters)
 {
     for (int i = 0; i < parameters.ReferencedAssemblies.Count; i++)
     {
         if (PEHeader.Is64BitRequiredExecutable(parameters.ReferencedAssemblies[i]))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);

                WorkflowCompiler           compiler           = new WorkflowCompiler();
                WorkflowCompilerParameters compilerParameters = new WorkflowCompilerParameters();
                compilerParameters.GenerateInMemory = true;

                String[] workflowFilenames = GetWorkflowFilenames();

                WorkflowCompilerResults results = compiler.Compile(compilerParameters, workflowFilenames);
                if (results.Errors.Count > 0)
                {
                    Console.WriteLine("Errors occurred while building the workflow:");
                    foreach (WorkflowCompilerError compilerError in results.Errors)
                    {
                        Console.WriteLine(compilerError.Line.ToString() + "," + compilerError.Column.ToString() + " : " + compilerError.ErrorText);
                    }

                    return;
                }

                Type workflowType = results.CompiledAssembly.GetType("Microsoft.Samples.Workflow.SimpleInMemorySample.SequentialWorkflow");

                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                {
                    string orderStatus = e.OutputParameters["Status"].ToString();
                    Console.WriteLine("Order was " + orderStatus);
                    waitHandle.Set();
                };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("Amount", 300);

                WorkflowInstance instance = workflowRuntime.CreateWorkflow(workflowType, parameters);
                instance.Start();

                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }
Esempio n. 6
0
        private void CompileWorkflowButton(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.xamlFile))
            {
                return;
            }
            if (!File.Exists(this.xamlFile))
            {
                MessageBox.Show(this, "Cannot locate XAML file: " + Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), xamlFile), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            compileWorkflowButton.Enabled = false;
            Cursor cursor = this.Cursor;

            this.Cursor = Cursors.WaitCursor;
            try
            {
                // Compile the workflow
                String[]                   assemblyNames = { "ReadEmailActivity.dll" };
                WorkflowCompiler           compiler      = new WorkflowCompiler();
                WorkflowCompilerParameters parameters    = new WorkflowCompilerParameters(assemblyNames);
                parameters.LibraryPaths.Add(Path.GetDirectoryName(typeof(BaseMailbox).Assembly.Location));
                parameters.OutputAssembly = "CustomOutlookWorkflow" + Guid.NewGuid().ToString() + ".dll";
                results = compiler.Compile(parameters, this.xamlFile);

                StringBuilder errors = new StringBuilder();
                foreach (CompilerError compilerError in results.Errors)
                {
                    errors.Append(compilerError.ToString() + '\n');
                }

                if (errors.Length != 0)
                {
                    MessageBox.Show(this, errors.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    compileWorkflowButton.Enabled = true;
                }
                else
                {
                    MessageBox.Show(this, "Workflow compiled successfully. Compiled assembly:\n" + results.CompiledAssembly.GetName(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    startWorkflowButton.Enabled = true;
                }
            }
            finally
            {
                this.Cursor = cursor;
            }
        }
        private static string SerializeInputToWrapper(WorkflowCompilerParameters parameters, string[] files)
        {
            string tempFileName = Path.GetTempFileName();

            using (Stream stream = new FileStream(tempFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                XmlWriterSettings settings = new XmlWriterSettings {
                    Indent = true
                };
                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    CompilerInput graph = new CompilerInput(MultiTargetingInfo.MultiTargetingUtilities.NormalizeReferencedAssemblies(parameters), files);
                    new DataContractSerializer(typeof(CompilerInput)).WriteObject(writer, graph);
                }
            }
            return(tempFileName);
        }
Esempio n. 8
0
 public CompilerInput(WorkflowCompilerParameters parameters, string[] files)
 {
     this.parameters = parameters;
     this.files      = files;
 }
        /// <summary>
        /// Compile the workflow along with the code beside file and the rules file if they exist
        /// </summary>
        public void CompileWorkflow()
        {
            if (string.IsNullOrEmpty(this.loader.Xoml))
            {
                return;
            }

            if (!File.Exists(this.loader.Xoml))
            {
                MessageBox.Show(this, "Cannot locate XAML file: " + Path.Combine(Path.GetDirectoryName(this.GetType().Assembly.Location), this.loader.Xoml), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // If everything is Ok then save the files before compiling
            this.Save();

            Cursor cursor = this.Cursor;

            this.Cursor = Cursors.WaitCursor;
            try
            {
                // Check for code beside file and rules file

                WorkflowCompiler           compiler   = new WorkflowCompiler();
                WorkflowCompilerParameters parameters = new WorkflowCompilerParameters();

                string codeBesideFile = Path.Combine(Path.GetDirectoryName(this.loader.Xoml), Path.GetFileNameWithoutExtension(this.loader.Xoml) + ".cs");
                string rulesFile      = Path.Combine(Path.GetDirectoryName(this.loader.Xoml), Path.GetFileNameWithoutExtension(this.loader.Xoml) + ".rules");

                ArrayList files = new ArrayList();
                files.Add(this.loader.Xoml);

                if (File.Exists(codeBesideFile))
                {
                    files.Add(codeBesideFile);
                }

                if (File.Exists(rulesFile))
                {
                    // adding the rules file to the resources
                    string resources = @"/resource:" + rulesFile + "," + this.NameSpace + "." + this.TypeName + "." + "rules";
                    parameters.CompilerOptions += resources;
                }

                object[] objArray = new object[] { };
                objArray = files.ToArray();

                string[] strArr = new string[objArray.Length];
                Array.Copy(objArray, 0, strArr, 0, objArray.Length);

                // Compile the workflow
                parameters.ReferencedAssemblies.Add("Dude.dll");
                parameters.OutputAssembly = "CustomWorkflow" + Guid.NewGuid().ToString() + ".dll";
                WorkflowCompilerResults results = compiler.Compile(parameters, strArr);

                StringBuilder errors = new StringBuilder();
                foreach (CompilerError compilerError in results.Errors)
                {
                    errors.Append(compilerError.ToString() + '\n');
                }

                if (errors.Length != 0)
                {
                    MessageBox.Show(this, errors.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(this, "Workflow compiled successfully. Compiled assembly: \n" + results.CompiledAssembly.GetName(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            finally
            {
                this.Cursor = cursor;
            }
        }
 private void CompileInSameProcess(WorkflowCompilerParameters parameters, string[] files)
 {
     this.results = new WorkflowCompiler().Compile(parameters, files);
 }