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);
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
 private static void WriteCompilerOutput(string path, WorkflowCompilerResults results)
 {
     using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         XmlWriterSettings settings = new XmlWriterSettings {
             Indent = true
         };
         using (XmlWriter writer = XmlWriter.Create(stream, settings))
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             SurrogateSelector         selector   = new SurrogateSelector();
             selector.AddSurrogate(typeof(MemberAttributes), serializer.Context, new CompilerResultsSurrogate());
             serializer.SurrogateSelector = selector;
             serializer.WriteObject(writer, results);
         }
     }
 }
        private static WorkflowCompilerResults DeserializeWrapperOutput(string fileName)
        {
            WorkflowCompilerResults results;

            using (Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    NetDataContractSerializer serializer = new NetDataContractSerializer();
                    SurrogateSelector         selector   = new SurrogateSelector();
                    selector.AddSurrogate(typeof(MemberAttributes), serializer.Context, new CompilerResultsSurrogate());
                    serializer.SurrogateSelector = selector;
                    results = (WorkflowCompilerResults)serializer.ReadObject(reader);
                }
            }
            return(results);
        }
        /// <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);
 }