private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Open the config file and get the connection string
            Configuration config =
                ConfigurationManager.OpenExeConfiguration
                    (ConfigurationUserLevel.None);
            ConnectionStringsSection css =
                (ConnectionStringsSection)config.GetSection("connectionStrings");
            _connectionString =
                css.ConnectionStrings["LeadResponse"].ConnectionString;

            _instanceStore = new SqlWorkflowInstanceStore(_connectionString);
            InstanceView view = _instanceStore.Execute
                (_instanceStore.CreateInstanceHandle(),
                new CreateWorkflowOwnerCommand(),
                TimeSpan.FromSeconds(30));
            _instanceStore.DefaultInstanceOwner = view.InstanceOwner;

            // Create the DBExtension
            _dbExtension = new DBExtension(_connectionString);

            // Create a service to handle incoming requests
            LoadExistingLeads();
            SetupHost();

            
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Open the config file and get the connection string


            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConnectionStringsSection css = (ConnectionStringsSection)config.GetSection("connectionStrings");
            _connectionString = css.ConnectionStrings["LeadGenerator"].ConnectionString;

            _dbExtension = new DBExtension(_connectionString);
            _instanceStore = new SqlWorkflowInstanceStore(_connectionString);
            InstanceView view = _instanceStore.Execute(_instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
            _instanceStore.DefaultInstanceOwner = view.InstanceOwner;

            
            // Set up the tracking participants
            CreateTrackingParticipant();
            CreateETWTrackingParticipant();
            CreateSqlTrackingParticipant();

            LoadExistingLeads();



        }
Esempio n. 3
0
 /// <summary>
 /// Creates a test host
 /// </summary>
 /// <param name="instanceStore">
 /// The instance store. 
 /// </param>
 /// <returns>
 /// The test host 
 /// </returns>
 private static WorkflowApplicationTest<ActivityWithDelay> CreateTestHost(InstanceStore instanceStore)
 {
     var host = WorkflowApplicationTest.Create(new ActivityWithDelay());
     Debug.Assert(host != null, "host != null");
     host.InstanceStore = instanceStore;
     host.PersistableIdle += args => PersistableIdleAction.Unload;
     return host;
 }
 internal InstanceHandle(InstanceStore store, InstanceOwner owner)
 {
     this.thisLock = new object();
     this.Version = -1L;
     this.Store = store;
     this.Owner = owner;
     this.View = new InstanceView(owner);
     this.IsValid = true;
 }
Esempio n. 5
0
 internal InstanceHandle(InstanceStore store, InstanceOwner owner)
 {
     this.thisLock = new object();
     this.Version  = -1L;
     this.Store    = store;
     this.Owner    = owner;
     this.View     = new InstanceView(owner);
     this.IsValid  = true;
 }
Esempio n. 6
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner)
        {
            Fx.Assert(store != null, "Shouldn't be possible.");

            Version = -1;
            Store = store;
            Owner = owner;
            View = new InstanceView(owner);
            IsValid = true;
        }
Esempio n. 7
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner)
        {
            Fx.Assert(store != null, "Shouldn't be possible.");

            Version = -1;
            Store   = store;
            Owner   = owner;
            View    = new InstanceView(owner);
            IsValid = true;
        }
        internal PersistenceProviderDirectory(InstanceStore store, InstanceOwner owner, IDictionary<XName, InstanceValue> instanceMetadataChanges, WorkflowDefinitionProvider workflowDefinitionProvider, WorkflowServiceHost serviceHost,
            DurableConsistencyScope consistencyScope, int maxInstances)
            : this(workflowDefinitionProvider, serviceHost, consistencyScope, maxInstances)
        {
            Fx.Assert(store != null, "InstanceStore must be specified on PPD.");
            Fx.Assert(owner != null, "InstanceOwner must be specified on PPD.");

            this.store = store;
            this.owner = owner;
            this.InstanceMetadataChanges = instanceMetadataChanges;
        }
Esempio n. 9
0
        // Creates and configures a new instance of WorkflowApplication
        private static WorkflowApplication CreateWorkflowApplication(Activity rootActivity, InstanceStore store, XName wfHostTypeName)
        {
            WorkflowApplication wfApp = new WorkflowApplication(rootActivity);

            wfApp.InstanceStore = store;

            Dictionary<XName, object> wfScope = new Dictionary<XName, object>
            {
                 { WorkflowHostTypePropertyName, wfHostTypeName }
            };

            // Add the WorkflowHostType value to workflow application so that it stores this data in the instance store when persisted
            wfApp.AddInitialInstanceValues(wfScope);

            // This statement is optional (see the comments in AbsoluteDelay.CacheMetadata details for more info).
            // wfApp.Extensions.Add<DurableTimerExtension>(() => new DurableTimerExtension());

            // For demonstration purposes the workflow is unloaded as soon as it is idle (and able to persist)
            wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs idleArgs)
            {
                Console.WriteLine("Workflow unloading...");
                return PersistableIdleAction.Unload;
            };

            // Configure some tracing and synchronization for the other WorkflowApplication events

            wfApp.Unloaded = delegate(WorkflowApplicationEventArgs eargs)
            {
                if (!workflowCompleted)
                {
                    Console.WriteLine("Workflow unloaded");
                }
                else
                {
                    Console.WriteLine("Workflow unloaded after completing");
                }

                workflowUnloadedEvent.Set();
            };

            wfApp.Completed = delegate
            {
                Console.WriteLine("Workflow completed");
                workflowCompleted = true;
            };

            wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs abortArgs)
            {
                Console.WriteLine("Workflow aborted (expected in this sample)");
            };

            return wfApp;
        }
Esempio n. 10
0
 static WorkflowApplication CreateWorkflowApplication(AccumulatorActivity activity, InstanceStore instanceStore)
 {
     var application = new WorkflowApplication(activity);
     application.InstanceStore = instanceStore;
     application.Completed = new Action<WorkflowApplicationCompletedEventArgs>((e) =>
     {
         _result = (int)e.Outputs["Sum"];
         _more = false;
         _event.Set();
     });
     application.PersistableIdle = new Func<WorkflowApplicationIdleEventArgs, PersistableIdleAction>((e) => PersistableIdleAction.Unload);
     application.Extensions.Add(new Notification(NotifySum));
     return application;
 }
Esempio n. 11
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner, Guid instanceId)
        {
            Fx.Assert(store != null, "Shouldn't be possible here either.");
            Fx.Assert(instanceId != Guid.Empty, "Should be validating this.");

            Version = -1;
            Store = store;
            Owner = owner;
            Id = instanceId;
            View = new InstanceView(owner, instanceId);
            IsValid = true;
            if (Fx.Trace.IsEtwProviderEnabled)
            {
                eventTraceActivity = new EventTraceActivity(instanceId);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 创建工作流
        /// </summary>
        /// <param name="parameters">传入的参数</param>
        /// <returns>获取工作流实例的Id值</returns>
        public string Create(IDictionary<string, object> parameters)
        {
            _instanceStore = new SqlWorkflowInstanceStore(connectionString);
            InstanceView view = _instanceStore.Execute
                (_instanceStore.CreateInstanceHandle(),
                new CreateWorkflowOwnerCommand(),
                TimeSpan.FromSeconds(30));
            _instanceStore.DefaultInstanceOwner = view.InstanceOwner;

            WorkflowApplication i = new WorkflowApplication(ActivityXamlServices.Load(path), parameters);
            i.InstanceStore = _instanceStore;
            i.PersistableIdle = (waiea) => PersistableIdleAction.Unload;
            i.Run();
            return i.Id.ToString();

        }
Esempio n. 13
0
        // Configure a Default Owner for the instance store so instances can be re-loaded from WorkflowApplication
        private static InstanceHandle CreateInstanceStoreOwner(InstanceStore store, XName wfHostTypeName)
        {
            InstanceHandle ownerHandle = store.CreateInstanceHandle();

            CreateWorkflowOwnerCommand ownerCommand = new CreateWorkflowOwnerCommand()
            {
                InstanceOwnerMetadata =
                {
                    { WorkflowHostTypePropertyName, new InstanceValue(wfHostTypeName) }
                }
            };

            store.DefaultInstanceOwner = store.Execute(ownerHandle, ownerCommand, TimeSpan.FromSeconds(30)).InstanceOwner;

            return ownerHandle;
        }
Esempio n. 14
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner, Guid instanceId)
        {
            Fx.Assert(store != null, "Shouldn't be possible here either.");
            Fx.Assert(instanceId != Guid.Empty, "Should be validating this.");

            Version = -1;
            Store   = store;
            Owner   = owner;
            Id      = instanceId;
            View    = new InstanceView(owner, instanceId);
            IsValid = true;
            if (Fx.Trace.IsEtwProviderEnabled)
            {
                eventTraceActivity = new EventTraceActivity(instanceId);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 加载工作流
        /// </summary>
        /// <param name="id">工作流的唯一标示</param>
        /// <param name="bookMark">标签名称</param>
        /// <param name="ids">恢复指定名称的书签的时候,传入的参数</param>
        /// <returns>工作流的加载的状态</returns>
        public string Load(string id, object inputs = null)
        {
            _instanceStore = new SqlWorkflowInstanceStore(connectionString);
            InstanceView view = _instanceStore.Execute
                (_instanceStore.CreateInstanceHandle(),
                new CreateWorkflowOwnerCommand(),
                TimeSpan.FromSeconds(30));
            _instanceStore.DefaultInstanceOwner = view.InstanceOwner;

            WorkflowApplication i = new WorkflowApplication(ActivityXamlServices.Load(path));
            i.InstanceStore = _instanceStore;
            i.PersistableIdle = (waiea) => PersistableIdleAction.Unload;
            i.Load(new Guid(id));
            return i.ResumeBookmark(bookMark, inputs).GetString();

        }
Esempio n. 16
0
        private static void WaitForRunnableInstance(InstanceStore store, InstanceHandle ownerHandle)
        {
            IEnumerable<InstancePersistenceEvent> events = store.WaitForEvents(ownerHandle, TimeSpan.MaxValue);

            bool foundRunnable = false;

            // Loop through the persistence events looking for the HasRunnableWorkflow event (in this sample, it corresponds with
            // the workflow instance whose timer has expired and is ready to be resumed by the host).
            foreach (InstancePersistenceEvent persistenceEvent in events)
            {
                if (persistenceEvent.Equals(HasRunnableWorkflowEvent.Value))
                {
                    foundRunnable = true;
                    break;
                }
            }

            if (!foundRunnable)
            {
                throw new ApplicationException("Unexpected: No runnable instances found in the instance store");
            }
        }
        /// <summary>
        /// Opens the host
        /// </summary>
        /// <param name="workflowServiceFile">
        /// The workflow service file. 
        /// </param>
        /// <param name="serviceUri">
        /// The service URI. 
        /// </param>
        /// <param name="instanceStore">
        /// The instance Store. 
        /// </param>
        /// <param name="behaviors">
        /// The behaviors. 
        /// </param>
        /// <returns>
        /// The workflow service host 
        /// </returns>
        public static WorkflowServiceTestHost Open(
            string workflowServiceFile, Uri serviceUri, InstanceStore instanceStore, params IServiceBehavior[] behaviors)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(workflowServiceFile));
            if (string.IsNullOrWhiteSpace(workflowServiceFile))
            {
                throw new ArgumentNullException("workflowServiceFile");
            }

            Contract.Requires(serviceUri != null);
            if (serviceUri == null)
            {
                throw new ArgumentNullException("serviceUri");
            }

            return Open((WorkflowService)XamlServices.Load(workflowServiceFile), serviceUri, instanceStore, behaviors);
        }
 internal WorkflowApplication CreateWorkflowApplication(AccumulatorActivity activity, InstanceStore instanceStore)
 {
     var application = new WorkflowApplication(activity);
     application.InstanceStore = instanceStore;
     application.Unloaded = new Action<WorkflowApplicationEventArgs>((e) =>
         {
             this.Suspended = true;
             this.SyncEvent.Set();
         });
     application.Completed = new Action<WorkflowApplicationCompletedEventArgs>((e) =>
         {
             this.Sum = (int)e.Outputs["Sum"];
             this.Completed = true;
             this.SyncEvent.Set();
         });
     application.PersistableIdle = new Func<WorkflowApplicationIdleEventArgs, PersistableIdleAction>((e) => PersistableIdleAction.Unload);
     application.Extensions.Add(new Notification(NotifySum));
     this.Suspended = false;
     return application;
 }
        /// <summary>
        /// The open.
        /// </summary>
        /// <param name="xamlReader">
        /// The XAML reader. 
        /// </param>
        /// <param name="serviceUri">
        /// The service URI. 
        /// </param>
        /// <param name="instanceStore">
        /// The instance Store. 
        /// </param>
        /// <param name="behaviors">
        /// The behaviors. 
        /// </param>
        /// <returns>
        /// An opened WorkflowServiceTestHost 
        /// </returns>
        public static WorkflowServiceTestHost Open(
            XamlReader xamlReader, Uri serviceUri, InstanceStore instanceStore, params IServiceBehavior[] behaviors)
        {
            Contract.Requires(xamlReader != null);
            if (xamlReader == null)
            {
                throw new ArgumentNullException("xamlReader");
            }

            Contract.Requires(serviceUri != null);
            if (serviceUri == null)
            {
                throw new ArgumentNullException("serviceUri");
            }

            return Open((WorkflowService)XamlServices.Load(xamlReader), serviceUri, instanceStore, behaviors);
        }
        /// <summary>
        /// Opens the host
        /// </summary>
        /// <param name="workflowService">
        /// The workflow service. 
        /// </param>
        /// <param name="serviceEndpoint">
        /// The service endpoint. 
        /// </param>
        /// <param name="instanceStore">
        /// The instance Store. 
        /// </param>
        /// <param name="behaviors">
        /// The behaviors. 
        /// </param>
        /// <returns>
        /// The workflow service host 
        /// </returns>
        public static WorkflowServiceTestHost Open(
            WorkflowService workflowService, 
            EndpointAddress serviceEndpoint, 
            InstanceStore instanceStore, 
            params IServiceBehavior[] behaviors)
        {
            Contract.Requires(workflowService != null);
            if (workflowService == null)
            {
                throw new ArgumentNullException("workflowService");
            }

            Contract.Requires(serviceEndpoint != null);
            if (serviceEndpoint == null)
            {
                throw new ArgumentNullException("serviceEndpoint");
            }

            return Open(workflowService, serviceEndpoint.Uri, instanceStore, behaviors);
        }
Esempio n. 21
0
        private static void SetupInstanceStore()
        {
            instanceStore =
                new SqlWorkflowInstanceStore(@"Data Source=.\SQLEXPRESS;Initial Catalog=SampleInstanceStore;Integrated Security=True;Asynchronous Processing=True");

            InstanceHandle handle = instanceStore.CreateInstanceHandle();
            InstanceView view = instanceStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
            handle.Free();

            instanceStore.DefaultInstanceOwner = view.InstanceOwner;
        }
        public DefaultWorkflowApplicationHostInstanceStore(InstanceStore instanceStore)
        {
            if(instanceStore == null) throw new ArgumentNullException("instanceStore");

            _instanceStore = instanceStore;            
        }
 internal PersistenceProviderDirectory(InstanceStore store, InstanceOwner owner, IDictionary<XName, InstanceValue> instanceMetadataChanges, Activity workflowDefinition, WorkflowServiceHost serviceHost, DurableConsistencyScope consistencyScope, int maxInstances) : this(workflowDefinition, serviceHost, consistencyScope, maxInstances)
 {
     this.store = store;
     this.owner = owner;
     this.InstanceMetadataChanges = instanceMetadataChanges;
 }
        /// <summary>
        /// The open.
        /// </summary>
        /// <param name="xmlReader">
        /// The xml reader. 
        /// </param>
        /// <param name="serviceEndpoint">
        /// The service endpoint. 
        /// </param>
        /// <param name="instanceStore">
        /// The instance Store. 
        /// </param>
        /// <param name="behaviors">
        /// The behaviors. 
        /// </param>
        /// <returns>
        /// An opened WorkflowServiceTestHost 
        /// </returns>
        public static WorkflowServiceTestHost Open(
            XmlReader xmlReader, 
            EndpointAddress serviceEndpoint, 
            InstanceStore instanceStore, 
            params IServiceBehavior[] behaviors)
        {
            Contract.Requires(xmlReader != null);
            if (xmlReader == null)
            {
                throw new ArgumentNullException("xmlReader");
            }

            Contract.Requires(serviceEndpoint != null);
            if (serviceEndpoint == null)
            {
                throw new ArgumentNullException("serviceEndpoint");
            }

            return Open((WorkflowService)XamlServices.Load(xmlReader), serviceEndpoint, instanceStore, behaviors);
        }
        public void Open()
        {
            this.instanceStore = new SqlWorkflowInstanceStore(connectionString);

            CreateWorkflowOwnerCommand createWorkflowOwnerCommand = new CreateWorkflowOwnerCommand();
            InstanceHandle handle = this.instanceStore.CreateInstanceHandle();

            try
            {
                this.instanceStore.BeginExecute(handle, createWorkflowOwnerCommand, TimeSpan.FromSeconds(30), OnInstanceStoreEndExecute, null);
            }
            catch (InstancePersistenceException persistenceException)
            {
                WriteException(persistenceException, "An error has occured setting up the InstanceStore");
            }
        }
        /// <summary>
        /// Opens the host
        /// </summary>
        /// <param name="workflowService">
        /// The workflow service. 
        /// </param>
        /// <param name="serviceUri">
        /// The service URI. 
        /// </param>
        /// <param name="instanceStore">
        /// The instance Store. 
        /// </param>
        /// <param name="behaviors">
        /// The behaviors. 
        /// </param>
        /// <returns>
        /// The workflow service host 
        /// </returns>
        public static WorkflowServiceTestHost Open(
            WorkflowService workflowService, 
            Uri serviceUri, 
            InstanceStore instanceStore, 
            params IServiceBehavior[] behaviors)
        {
            Contract.Requires(workflowService != null);
            Contract.Requires(serviceUri != null);

            if (workflowService == null)
            {
                throw new ArgumentNullException("workflowService");
            }

            if (serviceUri == null)
            {
                throw new ArgumentNullException("serviceUri");
            }

            var workflowServiceTestHost = new WorkflowServiceTestHost(workflowService, serviceUri);

            if (instanceStore != null)
            {
                workflowServiceTestHost.InstanceStore = instanceStore;
            }

            if (behaviors != null)
            {
                Debug.Assert(workflowServiceTestHost.Host != null, "workflowServiceTestHost.Host != null");
                Debug.Assert(
                    workflowServiceTestHost.Host.Description != null, "workflowServiceTestHost.Host.Description != null");
                Debug.Assert(
                    workflowServiceTestHost.Host.Description.Behaviors != null,
                    "workflowServiceTestHost.Host.Description.Behaviors != null");
                foreach (var serviceBehavior in behaviors)
                {
                    workflowServiceTestHost.Host.Description.Behaviors.Add(serviceBehavior);
                }
            }

            workflowServiceTestHost.Open();
            return workflowServiceTestHost;
        }