public InstanceCommandWithTemporaryHandleAsyncResult(InstanceStore instanceStore, InstancePersistenceCommand command,
                                                                 TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.instanceStore   = instanceStore;
                this.command         = command;
                this.temporaryHandle = instanceStore.CreateInstanceHandle();

                var currentTransaction = Transaction.Current;

                if (currentTransaction != null)
                {
                    this.dependentTransaction = currentTransaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
                }

                this.OnCompleting = completeCallback;

                IAsyncResult result;

                using (this.PrepareTransactionalCall(this.dependentTransaction))
                {
                    result = instanceStore.BeginExecute(this.temporaryHandle, command, timeout, this.PrepareAsyncCompletion(commandCompletedCallback), this);
                }

                if (this.SyncContinue(result))
                {
                    this.Complete(true);
                }
            }
예제 #2
0
        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
            SetupHost();

            LoadExistingLeads();
        }
예제 #3
0
        private static void CreateInstanceStoreOwner()
        {
            InstanceHandle = InstanceStore.CreateInstanceHandle();

            var ownerCommand = new CreateWorkflowOwnerCommand();

            ownerCommand.InstanceOwnerMetadata.Add(
                WorkflowHostTypePropertyName, new InstanceValue(WorkflowHostTypeName));

            InstanceStore.DefaultInstanceOwner =
                InstanceStore.Execute(InstanceHandle, ownerCommand, TimeSpan.FromSeconds(30)).InstanceOwner;
        }
예제 #4
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;
        }
예제 #5
0
        private static InstanceOwner CreateWorkflowInstanceOwner(InstanceStore store)
        {
            InstanceHandle handle = null;

            try
            {
                handle = store.CreateInstanceHandle();
                return(CreateWorkflowInstanceOwner(store, handle));
            }
            finally
            {
                handle?.Free();
            }
        }
예제 #6
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);
        }
예제 #7
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());
        }
예제 #8
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());
        }
예제 #9
0
        private static void DeleteWorkflowInstanceOwner(InstanceStore store, InstanceOwner owner, Guid instanceId)
        {
            InstanceHandle handle = null;

            var command = new DeleteWorkflowOwnerCommand();

            try
            {
                handle = store.CreateInstanceHandle(owner, instanceId);
                store.Execute(handle, command, TimeSpan.FromMinutes(1.0));
                store.DefaultInstanceOwner = null;
            }
            finally
            {
                handle?.Free();
            }
        }
예제 #10
0
            public PersistenceManager(InstanceStore store, IDictionary <XName, InstanceValue> instanceMetadata)
            {
                Fx.Assert(store != null, "We should never get here without a store.");

                this.isTryLoad        = true;
                this.instanceMetadata = instanceMetadata;

                this.InitializeInstanceMetadata();

                this.owner = store.DefaultInstanceOwner;
                if (this.owner != null)
                {
                    this.handle = store.CreateInstanceHandle(this.owner);
                }

                this.store = store;
            }
예제 #11
0
        private static InstanceHandle CreateOwnerHandle(InstanceStore store)
        {
            var ownerHandle = store.CreateInstanceHandle();

            var instanceView = store.Execute(ownerHandle,
                                             new CreateWorkflowOwnerCommand()
            {
                InstanceOwnerMetadata =
                {
                    { WorkflowHostTypePropertyName, new InstanceValue(HostTypeName) }
                }
            }
                                             , TimeSpan.FromSeconds(5)
                                             );

            store.DefaultInstanceOwner = instanceView.InstanceOwner;

            return(ownerHandle);
        }
예제 #12
0
        static void Main(string[] args)
        {
            InstanceStore store = CreateInstanceStore();
            //InstanceStore store = CreateCustomInstanceStore();

            ItemSupportExtension extension = new ItemSupportExtension();

            extension.AddItemDefinition(101, 1.23M, 10);
            extension.AddItemDefinition(202, 2.34M, 20);
            extension.AddItemDefinition(303, 3.45M, 30);
            DisplayInventory("Before Execution", extension);

            Guid instanceId = Guid.Empty;

            StartNewInstance(ref instanceId, store, extension);
            Boolean isRunning = true;

            while (isRunning)
            {
                Console.WriteLine(
                    "Enter ItemId and Quantity (Ex: 101 1) or [Enter] to quit");
                String input = Console.ReadLine();
                if (!String.IsNullOrEmpty(input))
                {
                    AddItem(instanceId, store, extension, input);
                }
                else
                {
                    OrderComplete(instanceId, store, extension);
                    isRunning = false;
                }
            }

            DisplayInventory("After Execution", extension);

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();

            store.Execute(store.CreateInstanceHandle(),
                          new DeleteWorkflowOwnerCommand(), TimeSpan.FromSeconds(10));
        }
        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();
        }
예제 #14
0
        private static bool WaitForRunnableInstance(InstanceStore store, InstanceOwner owner, Guid instanceId, TimeSpan timeout)
        {
            var handle = store.CreateInstanceHandle(owner, instanceId);

            return(WaitForRunnableInstance(store, handle, timeout));
        }