Esempio n. 1
0
        public void WorkflowStart(String assemblyUrl, String workflowClassName, WorkflowStartRequest startRequest, System.Threading.AutoResetEvent threadWaitHandle)
        {
            waitHandle = threadWaitHandle;

            WorkflowStart(assemblyUrl, workflowClassName, startRequest);

            return;
        }
Esempio n. 2
0
        public void WorkflowStart(String assemblyUrl, String workflowClassName, WorkflowStartRequest startRequest)
        {
            workflowId = startRequest.WorkflowId;


            assemblyReferencePath = assemblyUrl.Substring(0, assemblyUrl.LastIndexOf('\\') + 1);

            assemblyReferenceName = assemblyUrl.Replace(assemblyReferencePath, "");


            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            System.Reflection.Assembly workflowAssembly = System.Reflection.Assembly.LoadFrom(assemblyUrl);

            Type workflowClass = workflowAssembly.GetType(workflowClassName);

            if (workflowClass == null)
            {
                throw new ApplicationException("Unable to find Class [" + workflowClassName + "] in referenced Assembly [" + assemblyUrl + "].");
            }


            Dictionary <String, Object> workflowArguments = new Dictionary <String, Object> ();

            foreach (System.Reflection.PropertyInfo currentProperty in workflowClass.GetProperties())
            {
                String propertyName = currentProperty.Name;

                Type propertyType = currentProperty.PropertyType;

                // System.Diagnostics.Trace.WriteLineIf (application.TraceSwitchWorkflow.TraceVerbose, "Property [" + propertyName + "]: " + propertyType.Name);

                if (startRequest.Arguments.Keys.Contains(propertyName))
                {
                    try {
                        switch (propertyType.Name)
                        {
                        case "Int16": workflowArguments.Add(propertyName, Convert.ToInt16(startRequest.Arguments[propertyName])); break;

                        case "Int32": workflowArguments.Add(propertyName, Convert.ToInt32(startRequest.Arguments[propertyName])); break;

                        case "Int64": workflowArguments.Add(propertyName, Convert.ToInt64(startRequest.Arguments[propertyName])); break;

                        case "DateTime": workflowArguments.Add(propertyName, Convert.ToDateTime(startRequest.Arguments[propertyName])); break;

                        case "Decimal": workflowArguments.Add(propertyName, Convert.ToDecimal(startRequest.Arguments[propertyName])); break;

                        case "Single": workflowArguments.Add(propertyName, Convert.ToSingle(startRequest.Arguments[propertyName])); break;

                        case "Double": workflowArguments.Add(propertyName, Convert.ToDouble(startRequest.Arguments[propertyName])); break;

                        case "Boolean": workflowArguments.Add(propertyName, Convert.ToBoolean(startRequest.Arguments[propertyName])); break;

                        case "String": workflowArguments.Add(propertyName, Convert.ToString(startRequest.Arguments[propertyName])); break;

                        default: workflowArguments.Add(propertyName, startRequest.Arguments[propertyName]); break;
                        }
                    }

                    catch (Exception conversionException) {
                        System.Diagnostics.Trace.WriteLineIf(application.TraceSwitchWorkflow.TraceError, conversionException.Message);
                    }
                }

                else
                {
                    //System.Diagnostics.Trace.WriteLineIf (application.TraceSwitchWorkflow.TraceVerbose, "Ignored Property [" + propertyName + "]: " + propertyType.Name);

                    //System.Diagnostics.Trace.WriteLine ("Ignored Property [" + propertyName + "]: " + propertyType.Name);
                }
            }



            workflowInstance = workflowRuntime.CreateWorkflow(workflowAssembly.GetType(workflowClassName), workflowArguments);

            workflowResponse.WorkQueueItemId = startRequest.WorkQueueItemId;

            workflowResponse.WorkflowInstanceId = workflowInstance.InstanceId;

            workflowInstance.Start();

            return;
        }
Esempio n. 3
0
        public void WorkflowStart(String assemblyUrl, String workflowClassName, WorkflowStartRequest startRequest)
        {
            workflowResponse.WorkQueueItemId = startRequest.WorkQueueItemId;


            #region Load Workflow Assembly

            assemblyReferencePath = assemblyUrl.Substring(0, assemblyUrl.LastIndexOf('\\') + 1);

            assemblyReferenceName = assemblyUrl.Replace(assemblyReferencePath, "");


            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            System.Reflection.Assembly workflowAssembly = System.Reflection.Assembly.LoadFrom(assemblyUrl);

            Type workflowClass = workflowAssembly.GetType(workflowClassName);

            if (workflowClass == null)
            {
                throw new ApplicationException("Unable to find Class [" + workflowClassName + "] in referenced Assembly [" + assemblyUrl + "].");
            }

            #endregion


            #region Build Workflow Arguments (Inputs)

            Dictionary <String, Object> workflowArguments = new Dictionary <String, Object> ();

            workflowArguments.Add("WorkflowManager", this);

            foreach (System.Reflection.PropertyInfo currentProperty in workflowClass.GetProperties())
            {
                String propertyName = currentProperty.Name;

                Type propertyType = currentProperty.PropertyType;


                System.Diagnostics.Debug.WriteLine("Workflow Property: " + propertyName + " [" + propertyType + "]");

                System.Diagnostics.Debug.WriteLine(currentProperty.ToString());


                if (startRequest.Arguments.ContainsKey(propertyName))
                {
                    try {
                        switch (propertyType.Name)
                        {
                        case "Int16": workflowArguments.Add(propertyName, Convert.ToInt16(startRequest.Arguments[propertyName])); break;

                        case "Int32": workflowArguments.Add(propertyName, Convert.ToInt32(startRequest.Arguments[propertyName])); break;

                        case "Int64": workflowArguments.Add(propertyName, Convert.ToInt64(startRequest.Arguments[propertyName])); break;

                        case "DateTime": workflowArguments.Add(propertyName, Convert.ToDateTime(startRequest.Arguments[propertyName])); break;

                        case "Decimal": workflowArguments.Add(propertyName, Convert.ToDecimal(startRequest.Arguments[propertyName])); break;

                        case "Single": workflowArguments.Add(propertyName, Convert.ToSingle(startRequest.Arguments[propertyName])); break;

                        case "Double": workflowArguments.Add(propertyName, Convert.ToDouble(startRequest.Arguments[propertyName])); break;

                        case "Boolean": workflowArguments.Add(propertyName, Convert.ToBoolean(startRequest.Arguments[propertyName])); break;

                        case "String": workflowArguments.Add(propertyName, Convert.ToString(startRequest.Arguments[propertyName])); break;

                        default:

                            if (propertyName.EndsWith("Id"))
                            {
                                workflowArguments.Add(propertyName, Convert.ToInt64(startRequest.Arguments[propertyName]));
                            }

                            else
                            {
                                workflowArguments.Add(propertyName, startRequest.Arguments[propertyName]);
                            }

                            break;
                        }
                    }

                    catch (Exception conversionException) {
                        System.Diagnostics.Trace.WriteLineIf(Application.TraceSwitchWorkflow.TraceError, conversionException.Message);
                    }
                }
            }

            #endregion


            // START WORKFLOW

            workflowInstance = new System.Activities.WorkflowApplication((System.Activities.Activity)Activator.CreateInstance(workflowAssembly.GetType(workflowClassName)), workflowArguments);


            // LINK EVENT HANDLERS

            workflowInstance.Completed = WorkflowCompleted;

            workflowInstance.Aborted = WorkflowAborted;

            // workflowInstance.Idle = WorkflowIdle; // DO NOTHING, REMOVED, FALL THROUGH TO PERSISTABLE IDLE TO UNLOAD

            workflowInstance.PersistableIdle = WorkflowPersistableIdle;

            workflowInstance.Unloaded = WorkflowUnloaded;

            workflowInstance.OnUnhandledException = WorkflowOnUnhandledException;


            // LINK PERSISTANCE INSTANCE STORE

            workflowInstance.InstanceStore = instanceStore;


            // EXECUTE WORKFLOW

            WorkflowStatus = Workflows.WorkflowStatus.Started;

            workflowInstance.Run();

            return;
        }