Пример #1
0
        public void AddGetRemoveTest()
        {
            SampleService2              sample      = new SampleService2();
            WorkflowRuntime             workflow    = new WorkflowRuntime();
            ExternalDataExchangeService data_change = new ExternalDataExchangeService();

            workflow.AddService(data_change);
            data_change.AddService(sample);

            Assert.AreEqual(sample, data_change.GetService(sample.GetType()), "C1#1");
            data_change.RemoveService(sample);
            Assert.AreEqual(null, data_change.GetService(sample.GetType()), "C1#2");
        }
Пример #2
0
        /// <summary>
        /// Ensures that the instance of AppointmentWorkFlowService has been initialized
        /// and added to the workflow's data exchange
        /// </summary>
        /// <remarks>
        /// There will only be a single instance of this object in activation
        /// at any point in time.
        /// </remarks>
        private void SetupWorkflowEnvironment()
        {
            if (_appointmentLocalService == null)
            {
                WfWcfExtension extension =
                    OperationContext.Current.Host.Extensions.Find <WfWcfExtension>();

                _workflowRuntime = extension.WorkflowRuntime;

                // We will try and fetch the instance from the active WorkflowRuntime's
                // ExtenalDataExchangeService and if it currently does not have an
                // activated instance, we will create a new instance and add it.

                ExternalDataExchangeService dataExchangeService =
                    _workflowRuntime.GetService <ExternalDataExchangeService>();

                _appointmentLocalService =
                    (AppointmentWorkflowService)dataExchangeService.GetService(typeof(AppointmentWorkflowService));

                if (_appointmentLocalService == null)
                {
                    _appointmentLocalService = new AppointmentWorkflowService();
                    dataExchangeService.AddService(_appointmentLocalService);
                }
            }
        }
        /// <exclude />
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            FormsWorkflow formsWorkflow = this.GetRoot <FormsWorkflow>();

            IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(this.FormDefinitionFileName);

            ExternalDataExchangeService   externalDataExchangeService = WorkflowFacade.WorkflowRuntime.GetService <ExternalDataExchangeService>();
            IFormsWorkflowActivityService service = externalDataExchangeService.GetService(typeof(IFormsWorkflowActivityService)) as IFormsWorkflowActivityService;

            service.DeliverFormData(
                WorkflowEnvironment.WorkflowInstanceId,
                this.ContainerLabel,
                StandardUiContainerTypes.Document,
                markupProvider,
                formsWorkflow.Bindings,
                formsWorkflow.BindingsValidationRules
                );

            if (string.IsNullOrEmpty(this.CustomToolbarDefinitionFileName) == false)
            {
                IFormMarkupProvider customToolbarMarkupProvider = new FormDefinitionFileMarkupProvider(this.CustomToolbarDefinitionFileName);
                service.DeliverCustomToolbarDefinition(WorkflowEnvironment.WorkflowInstanceId, customToolbarMarkupProvider);
            }

            return(ActivityExecutionStatus.Closed);
        }
Пример #4
0
        public static Invoker Create(Guid instanceId)
        {
            // workflow runtime core
            WorkflowRuntime workflowRuntime = WorkflowHosting.WorkflowRuntime;

            // Get a reference to the ExternalDataExchangeService from the WorkflowRuntime
            ExternalDataExchangeService dataExchangeService = workflowRuntime.GetService <ExternalDataExchangeService>();

            // Get a reference to the LocalService
            InvokerLocalService invokerLocalService = (InvokerLocalService)dataExchangeService.GetService(typeof(InvokerLocalService));

            // get instance of the workflow
            WorkflowInstance instance = workflowRuntime.GetWorkflow(instanceId);

            try
            {
                // workaround to detect WorkflowStatus, if the status == Created, the executor will start this instance
                instance.Start();
            }
            catch (Exception ex)
            {
                // WorkflowStatus != Created (therefore we can go ahead and use it)
                Trace.WriteLine(ex.Message);
            }

            // plug-in the local service
            Invoker invoker = new Invoker(invokerLocalService, instance, true);

            // now we can communicate with workflow instance
            return(invoker);
        }
Пример #5
0
        /// <summary>
        /// Adds the cms:layout elements Form Definition to the UI toolbar.
        /// </summary>
        /// <param name="customToolbarMarkupProvider">Markup provider that can deliver a valid Form Definition markup document</param>
        protected void SetCustomToolbarDefinition(IFormMarkupProvider customToolbarMarkupProvider)
        {
            ExternalDataExchangeService externalDataExchangeService = WorkflowFacade.WorkflowRuntime.GetService <ExternalDataExchangeService>();
            var formsWorkflowActivityService = externalDataExchangeService.GetService(typeof(IFormsWorkflowActivityService)) as IFormsWorkflowActivityService;

            formsWorkflowActivityService.DeliverCustomToolbarDefinition(WorkflowEnvironment.WorkflowInstanceId, customToolbarMarkupProvider);
        }
Пример #6
0
        /// <summary>
        /// Adds the cms:layout elements Form Definition to the UI toolbar.
        /// </summary>
        /// <param name="customToolbarDefinition">String containing a valid Form Definition markup document</param>
        public void SetCustomToolbarDefinition(string customToolbarDefinition)
        {
            ExternalDataExchangeService externalDataExchangeService = WorkflowFacade.WorkflowRuntime.GetService <ExternalDataExchangeService>();

            IFormsWorkflowActivityService formsWorkflowActivityService = externalDataExchangeService.GetService(typeof(IFormsWorkflowActivityService)) as IFormsWorkflowActivityService;

            formsWorkflowActivityService.DeliverCustomToolbarDefinition(WorkflowEnvironment.WorkflowInstanceId, customToolbarDefinition);
        }
Пример #7
0
        /// <exclude />
        protected void DeliverFormData(string containerLabel, IFlowUiContainerType containerType, IFormMarkupProvider formMarkupProvider, Dictionary <string, object> bindings, Dictionary <string, List <ClientValidationRule> > bindingsValidationRules)
        {
            ExternalDataExchangeService externalDataExchangeService = WorkflowFacade.WorkflowRuntime.GetService <ExternalDataExchangeService>();

            IFormsWorkflowActivityService formsWorkflowActivityService = externalDataExchangeService.GetService(typeof(IFormsWorkflowActivityService)) as IFormsWorkflowActivityService;

            formsWorkflowActivityService.DeliverFormData(WorkflowEnvironment.WorkflowInstanceId, containerLabel, containerType, formMarkupProvider, bindings, bindingsValidationRules);
        }
Пример #8
0
        public void ExternalDataExchangeInterfacesAreAdded()
        {
            _container.AddComponent("testingexternaldata.service", typeof(TestingExternalData));

            WorkflowRuntime             runtime = _container.Resolve <WorkflowRuntime>();
            ExternalDataExchangeService externalDataExchangeService = runtime.GetService <ExternalDataExchangeService>();

            Assert.IsNotNull(externalDataExchangeService, "A default external data exchange service must be added");

            object instance = externalDataExchangeService.GetService(typeof(ITestingExternalData));

            Assert.IsInstanceOfType(typeof(TestingExternalData), instance, "External data service must be of expected type");
        }
Пример #9
0
        /// <exclude />
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            FormsWorkflow formsWorkflow = this.GetRoot <FormsWorkflow>();

            IFormMarkupProvider markupProvider = new FormDefinitionFileMarkupProvider(this.FormDefinitionFileName);

            ExternalDataExchangeService   externalDataExchangeService = WorkflowFacade.WorkflowRuntime.GetService <ExternalDataExchangeService>();
            IFormsWorkflowActivityService service = externalDataExchangeService.GetService(typeof(IFormsWorkflowActivityService)) as IFormsWorkflowActivityService;

            service.DeliverFormData(
                WorkflowEnvironment.WorkflowInstanceId,
                this.ContainerLabel,
                StandardUiContainerTypes.WarningDialog,
                markupProvider,
                formsWorkflow.Bindings,
                formsWorkflow.BindingsValidationRules
                );

            return(ActivityExecutionStatus.Closed);
        }
Пример #10
0
        private void EnsureWorkflowStarted()
        {
            if (instance == null)
            {
                // we need to manage the service's subscription to the dataexchangeservice with the lifetime of the workflow

                // Aquire the callback from the current OperationContext
                callback = OperationContext.Current.GetCallbackChannel <ICalculatorCallback>();
                //grab the version of the incoming message in case we need to create a fault later
                version = OperationContext.Current.IncomingMessageVersion;

                // retrieve the WorkflowRuntime from our WFServiceHostExtension
                WorkflowRuntime workflowRuntime = OperationContext.Current.Host.Extensions.Find <WFServiceHostExtension>().WorkflowRuntime;

                // grab a reference to our mathService
                ExternalDataExchangeService dataExchangeService = workflowRuntime.GetService <ExternalDataExchangeService>();
                mathService = (MathDataExchangeService)dataExchangeService.GetService(typeof(MathDataExchangeService));

                // if it is null set it up
                if (mathService == null)
                {
                    mathService = new MathDataExchangeService();
                    dataExchangeService.AddService(mathService);
                }

                //register with the ResultReceived event
                mathService.ResultReceived += HandleResultReceived;

                //register to get signaled when the workflow completes
                workflowRuntime.WorkflowCompleted  += this.OnWorkflowCompleted;
                workflowRuntime.WorkflowTerminated += this.OnWorkflowTerminated;

                //create and start the Workflow
                instance = workflowRuntime.CreateWorkflow(typeof(Workflow1));

                instance.Start();
            }
        }
Пример #11
0
 public static T GetService <T>(this ExternalDataExchangeService serviceContainer) where T : class
 {
     return(serviceContainer.GetService(typeof(T)) as T);
 }
Пример #12
0
        public static Invoker Create(Type workflowType, Dictionary <string, object> namedArgumentValues, Guid instanceId, bool bStart)
        {
            if (workflowType == null)
            {
                throw new ArgumentNullException("Invoker requires a workflowType");
            }

            // state machine?
            bool isStateMachine = (workflowType.BaseType == typeof(StateMachineWorkflowActivity));

            // workflow runtime core
            WorkflowRuntime workflowRuntime = WorkflowHosting.WorkflowRuntime;

            // Get a reference to the ExternalDataExchangeService from the WorkflowRuntime
            ExternalDataExchangeService dataExchangeService = workflowRuntime.GetService <ExternalDataExchangeService>();

            // Get a reference to the LocalService
            InvokerLocalService invokerLocalService = (InvokerLocalService)dataExchangeService.GetService(typeof(InvokerLocalService));

            // check XOML attribute
            object[] attributes = workflowType.GetCustomAttributes(typeof(CreateWorkflowByXOMLAttribute), true);

            // create workflow instance based on the configuration options
            WorkflowInstance instance = null;

            if (attributes == null || attributes.Length == 0)
            {
                // default: create instance of the workflow
                instance = workflowRuntime.CreateWorkflow(workflowType, namedArgumentValues, instanceId);
            }
            else
            {
                // options: direct from the file system or via a custom XomlLoader (database, filesystem, remoting, ...)
                CreateWorkflowByXOMLAttribute attribute = attributes[0] as CreateWorkflowByXOMLAttribute;

                try
                {
                    // sources link
                    string workflowDefinitionSource = attribute.WorkflowDefinitionKey.StartsWith("@") ? ConfigurationManager.AppSettings[attribute.WorkflowDefinitionKey.Substring(1)] : attribute.WorkflowDefinitionKey;
                    string rulesSource = attribute.RulesKey.StartsWith("@") ? ConfigurationManager.AppSettings[attribute.RulesKey.Substring(1)] : attribute.RulesKey;

                    // text readers
                    bool bIsXomlLoader = workflowType.GetInterface(typeof(IXomlLoader).FullName) != null;
                    if (bIsXomlLoader)
                    {
                        IXomlLoader loader = Activator.CreateInstance(workflowType) as IXomlLoader;
                        using (Stream xomlStream = loader.GetWorkflowDefinition(workflowDefinitionSource, namedArgumentValues))
                            using (Stream rulesStream = loader.GetWorkflowRules(rulesSource, namedArgumentValues))
                                using (XmlTextReader xomlReader = xomlStream == null ? null : new XmlTextReader(xomlStream))
                                    using (XmlTextReader rulesReader = rulesStream == null ? null : new XmlTextReader(rulesStream))
                                    {
                                        instance = workflowRuntime.CreateWorkflow(xomlReader, rulesReader, null, instanceId);
                                    }
                    }
                    else
                    {
                        using (XmlTextReader xomlReader = string.IsNullOrEmpty(workflowDefinitionSource) ? null : new XmlTextReader(workflowDefinitionSource))
                            using (XmlTextReader rulesReader = string.IsNullOrEmpty(rulesSource) ? null : new XmlTextReader(rulesSource))
                            {
                                instance = workflowRuntime.CreateWorkflow(xomlReader, rulesReader, null, instanceId);
                            }
                    }
                }
                catch (WorkflowValidationFailedException ex)
                {
                    string errMsg = string.Format("{0} {1} TotalErrors={2}", ex.Message, ex.Errors[0].ErrorText, ex.Errors.Count);
                    ex.GetType().BaseType.InvokeMember("_message", BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.ExactBinding | BindingFlags.FlattenHierarchy | BindingFlags.Instance, null, ex, new object[1] {
                        errMsg
                    }, CultureInfo.InvariantCulture);
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            // start workflow
            if (bStart)
            {
                instance.Start();
            }

            // plug-in the local service
            Invoker invoker = new Invoker(invokerLocalService, instance, isStateMachine);

            // now we can communicate with workflow instance
            return(invoker);
        }