예제 #1
0
        public WorkflowService(
            IUsersService users

          )
        {
            _users = users;
            T = NullLocalizer.Instance;
            Logger = NullLogger.Instance;
            SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(_users.ApplicationConnectionString);
            _wfApp = new WorkflowApplication(new XODB.Workflow.AssignResponsibility());
            _wfApp.InstanceStore = store;
            
            XName wfHostTypeName = XName.Get("XODB", _users.ApplicationID.ToString());
            Dictionary<XName, object> wfScope = new Dictionary<XName, object> { { workflowHostTypePropertyName, wfHostTypeName } };
            _wfApp.AddInitialInstanceValues(wfScope);
            
            _wfApp.Extensions.Add(new ResponsibilityExtension());
            List<XName> variantProperties = new List<XName>() 
            { 
                ResponsibilityExtension.xNS.GetName("CompanyID"), 
                ResponsibilityExtension.xNS.GetName("ContactID") 
            };
            store.Promote("Responsibility", variantProperties, null);

            InstanceHandle handle = store.CreateInstanceHandle(null);
            var cmd = new CreateWorkflowOwnerCommand
            {
                InstanceOwnerMetadata =
                    {
                        {workflowHostTypePropertyName, new InstanceValue(wfHostTypeName)}
                    }
            };
            InstanceOwner owner = store.Execute(handle, cmd, TimeSpan.MaxValue).InstanceOwner;
            store.DefaultInstanceOwner = owner;
            
            handle.Free();
   
            _wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
            {
                return PersistableIdleAction.Persist;
            };

            _wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    foreach (var item in e.Outputs)
                    {
                        System.Diagnostics.Debug.WriteLine("Variable:{0} has value: {1}", item.Key, item.Value);
                    }
                }
            };

            var trackingParticipant = new TrackingHelper.DebugTrackingParticipant
            {
                TrackingProfile = TrackingHelper.SimpleProfile
            };
            _wfApp.Extensions.Add(trackingParticipant);
        }
 /// <summary>
 /// The promote.
 /// </summary>
 /// <param name="instanceStore">
 /// The instance store.
 /// </param>
 public static void Promote(SqlWorkflowInstanceStore instanceStore)
 {
     instanceStore.Promote(RegistrationName, new List<XName> { EmailXName, UsernameXName }, null);
 }
        /// <summary>
        /// The promote.
        /// </summary>
        /// <param name="instanceStore">
        /// The instance store. 
        /// </param>
        public static void Promote(SqlWorkflowInstanceStore instanceStore)
        {
            Contract.Requires(instanceStore != null);
            if (instanceStore == null)
            {
                throw new ArgumentNullException("instanceStore");
            }

            instanceStore.Promote("StateTracker", new List<XName> { StateTrackerXName }, null);
        }