public async Task VerifyWorkItemStatePersistedTest() { var entities = new List <InstanceEntityBase>(); entities.Add(Utils.InfiniteWorkItemTestData(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N")).First()); await InstanceStore.WriteEntitiesAsync(entities); //second call should simply update each entity, not write new ones await InstanceStore.WriteEntitiesAsync(entities); await InstanceStore.DeleteEntitiesAsync(entities); using (var connection = GetConnection()) using (var command = connection.CreateCommand()) { command.CommandText = $"SELECT COUNT(1) FROM {Settings.WorkItemTableName}"; await connection.OpenAsync(); var count = (int)await command.ExecuteScalarAsync(); Assert.AreEqual(0, count, "Incorrect Work Item row count."); } }
static void Main(string[] args) { InstanceStore store = CreateInstanceStore(); WorkflowApplication wfApp = SetupInstance(store); Guid instanceId = wfApp.Id; wfApp.Run(); //wait for the wf to unload itself unloadedHandle.WaitOne(5000); Thread.Sleep(1000); wfApp = SetupInstance(store); wfApp.Load(instanceId); wfApp.Run(); //wait for the wf to unload itself unloadedHandle.WaitOne(5000); Thread.Sleep(1000); wfApp = SetupInstance(store); wfApp.Load(instanceId); wfApp.Run(); //wait for the wf to unload itself unloadedHandle.WaitOne(5000); Thread.Sleep(5000); wfApp = SetupInstance(store); wfApp.Load(instanceId); wfApp.Run(); waitHandle.WaitOne(10000); }
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); } }
public async Task PurgeByCompletedTimeTest() { var orchestrations = Utils.InfiniteOrchestrationTestData().Take(3).ToArray(); var histories = orchestrations .SelectMany(r => Utils.InfiniteWorkItemTestData(r.State.OrchestrationInstance.InstanceId, r.State.OrchestrationInstance.ExecutionId).Take(5)) .ToArray(); int secondsToAdd = 0; foreach (var item in orchestrations) { item.State.CompletedTime = DateTime.UtcNow.AddSeconds(secondsToAdd++); item.State.CreatedTime = item.State.LastUpdatedTime = DateTime.MaxValue; } await InstanceStore.WriteEntitiesAsync(orchestrations.Cast <InstanceEntityBase>().Concat(histories)); var historyEntriesDeleted = await InstanceStore.PurgeOrchestrationHistoryEventsAsync(orchestrations.ElementAt(1).State.CompletedTime, OrchestrationStateTimeRangeFilterType.OrchestrationCompletedTimeFilter); Assert.AreEqual(10, historyEntriesDeleted); var instance = orchestrations.Last().State.OrchestrationInstance; var count = (await InstanceStore.GetOrchestrationHistoryEventsAsync(instance.InstanceId, instance.ExecutionId)).Count(); Assert.AreEqual(5, count); foreach (var item in orchestrations.Take(2)) { instance = item.State.OrchestrationInstance; count = (await InstanceStore.GetOrchestrationHistoryEventsAsync(instance.InstanceId, instance.ExecutionId)).Count(); Assert.AreEqual(0, count); } }
public ConsoleController() { store = new InstanceStore <object>(GetProvider); var output = Shell.RootInjector.GetService <IOutputWriter>(); writer = new ConsoleService(output); }
/// <summary> /// Constructs an instance of the workflow instance invoker. /// </summary> /// <param name="instance">The current workflow instance object.</param> /// <param name="instance">The Report that references the Workflow.</param> /// <param name="instanceStore">The durable instance store.</param> /// <param name="timeout">The default timeout.</param> /// <param name="reportId">A unique report identifier.</param> public WorkflowInstanceInvoker(WorkflowInstance instance, InstanceStore instanceStore, TimeSpan timeout) { if (instance == null) { throw new ArgumentNullException("instance"); } DefaultTimeout = timeout; _application = // create application and set handlers new WorkflowApplication(instance.Deserialize()) { Completed = OnCompleted, InstanceStore = instanceStore, PersistableIdle = OnPersistableIdle }; // attach the workflow instance as an extension _application.Extensions.Add(instance); // Attach Claims Principal _application.Extensions.Add(ClaimsPrincipal.Current); // sync up durable instance id with store _instanceId = instance.DurableInstanceId; _isComplete = false; _isIdle = false; }
PackageDB(PackageDB origin, InstanceStore store, Dictionary <string, PackageFeed> newFeeds, DateTime lastUpdate) { _version = origin._version + 1; _feeds = newFeeds ?? origin._feeds; _instances = store ?? origin._instances; _lastUpdate = lastUpdate; }
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(); }
private static WorkflowApplication CreateWorkflow(InstanceStore store, WorkflowApps appType = WorkflowApps.App1) { var identity = new WorkflowIdentity { Name = appType.ToString(), Version = new Version(1, 0), }; Activity activity = new WorkflowApp1(); if (appType == WorkflowApps.App2) { activity = new WorkflowApp2(); } var whoAmI = new PP(appType); var app = new WorkflowApplication(activity, identity) { InstanceStore = store }; app.Extensions.Add(whoAmI); SetEvents(app); return(app); }
private static void AddItem(Guid instanceId, InstanceStore store, IItemSupport extension, String input) { Int32 itemId = 0; Int32 quantity = 0; String[] parts = input.Split(' '); if (parts.Length != 2) { Console.WriteLine("Incorrect number of arguments entered!"); return; } Int32.TryParse(parts[0], out itemId); Int32.TryParse(parts[1], out quantity); if (itemId == 0 || quantity == 0) { Console.WriteLine("Arguments in incorrect format!"); return; } WorkflowApplication wfApp = SetupInstance( ref instanceId, store, extension); Item item = new Item { ItemId = itemId, Quantity = quantity }; wfApp.ResumeBookmark("AddItem", item); _unloadedEvent.WaitOne(5000); }
public async Task VerifyOrchestrationStateQueryByInstanceIdTest() { var instanceId = Guid.NewGuid().ToString("N"); var values = Enum.GetValues(typeof(OrchestrationStatus)).Cast <OrchestrationStatus>().ToArray(); var entities = new List <OrchestrationStateInstanceEntity>(); entities.AddRange(Utils.InfiniteOrchestrationTestData().Take(values.Length)); //ensure each status exists in the collection and they all have the same InstanceId entities.Select((e, i) => { e.State.OrchestrationStatus = values[i]; e.State.OrchestrationInstance.InstanceId = instanceId; return(e); }).ToList(); await InstanceStore.WriteEntitiesAsync(entities); var actual = (await InstanceStore.GetOrchestrationStateAsync(instanceId, false)).ToList(); Assert.AreEqual(1, actual.Count); var expectedState = entities .Where(e => e.State.OrchestrationStatus != OrchestrationStatus.ContinuedAsNew) .OrderBy(e => e.State.LastUpdatedTime) .First(); var actualState = actual.First(); Assert.AreEqual(expectedState.State.OrchestrationInstance.ExecutionId, actualState.State.OrchestrationInstance.ExecutionId); }
public async Task VerifyOrchestrationStatePersistedTest() { var entities = new List <InstanceEntityBase>(); entities.AddRange(Utils.InfiniteOrchestrationTestData().Take(5)); await InstanceStore.WriteEntitiesAsync(entities); //second call should simply update each entity, not write new ones await InstanceStore.WriteEntitiesAsync(entities); await InstanceStore.DeleteEntitiesAsync(entities); using (var connection = GetConnection()) using (var command = connection.CreateCommand()) { command.CommandText = $"SELECT COUNT(1) FROM {Settings.OrchestrationStateTableName}"; await connection.OpenAsync(); var count = (int)await command.ExecuteScalarAsync(); Assert.AreEqual(0, count, "Incorrect Orchestration Instance row count."); } }
public static void End(IAsyncResult result, out InstanceStore instanceStore, out InstanceView commandResult) { var thisPtr = AsyncResult.End <InstanceCommandWithTemporaryHandleAsyncResult>(result); instanceStore = thisPtr.instanceStore; commandResult = thisPtr.commandResult; }
public WorkflowHost(string storeConnectionString) { // Initialize the store and configure it so that it can be used for // multiple WorkflowApplication instances. _store = new SqlWorkflowInstanceStore(storeConnectionString); WorkflowApplication.CreateDefaultInstanceOwner(_store, null, WorkflowIdentityFilter.Any); //_store = new RemoteInstanceStore(); //using WorkflowContainer.Infrastructure; }
public TemplateProcessingService( IServiceProvider prov, IOptions <MoldsterModuleOptions> opt, IOutputWriter wtt) : base(wtt) { opts = opt.Value; Store = new InstanceStore <object>(prov); }
private static void StartNewInstance( ref Guid instanceId, InstanceStore store, IItemSupport extension) { WorkflowApplication wfApp = SetupInstance( ref instanceId, store, extension); wfApp.Run(); _unloadedEvent.WaitOne(5000); }
public ScriptGenerationService( IServiceProvider prov, IOptions <MoldsterModuleOptions> opt, IOutputWriter output) : base(output) { _store = new InstanceStore <object>(prov); _opts = opt.Value; _writer = new WriterService(); }
private static Guid RunWorkflow(InstanceStore store, WorkflowApps appType) { var app = CreateWorkflow(store, appType); app.Run(); Console.WriteLine($"{appType} instance {app.Id:d} is running."); return(app.Id); }
private static void WaitForRunnableInstance(InstanceStore store, InstanceHandle ownerHandle) { try { store.WaitForEvents(ownerHandle, TimeSpan.MaxValue); } catch (Exception) { } }
private static void ResumeWorkflow(InstanceStore store, Guid instanceId, string bookmarkName) { var appType = (WorkflowApps)Enum.Parse(typeof(WorkflowApps), bookmarkName); var app = CreateWorkflow(store, appType); app.Load(instanceId); System.Diagnostics.Debug.Assert(app.Id == instanceId); app.ResumeBookmark(bookmarkName, new object(), TimeSpan.FromSeconds(10.0)); }
public WorkflowsManager(InstanceStore instanceStore) { //string config_WorkflowInstanceStore = wfIntesa.Startup.config["WorkflowInstanceStore:StoreType"]; //string config_WorkflowInstanceParams = wfIntesa.Startup.config["WorkflowInstanceStore:InstanceParamsString"]; //if (!string.IsNullOrEmpty(config_WorkflowInstanceStore)) //{ // InstanceStore instanceStore = new JsonFileInstanceStore.FileInstanceStore(config_WorkflowInstanceParams); //} this.InstanceStore = instanceStore; }
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; }
public LoadRetryAsyncResult(SqlWorkflowInstanceStore store, InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.InstanceStore = store; this.InstancePersistenceContext = context; this.InstancePersistenceCommand = command; this.commandTimeout = new TimeoutHelper(timeout); InstanceStore.BeginTryCommandInternal(this.InstancePersistenceContext, this.InstancePersistenceCommand, this.commandTimeout.RemainingTime(), LoadRetryAsyncResult.onTryCommandCallback, this); }
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; }
private static void WaitForRunnableInstance() { bool foundWorkflow; do { foundWorkflow = InstanceStore.WaitForEvents(InstanceHandle, TimeSpan.MaxValue).Any( persistenceEvent => persistenceEvent == HasRunnableWorkflowEvent.Value); }while (!foundWorkflow); #if DEBUG Trace.WriteLine("Found registration workflow with expired timer"); #endif }
private static InstanceOwner CreateWorkflowInstanceOwner(InstanceStore store) { InstanceHandle handle = null; try { handle = store.CreateInstanceHandle(); return(CreateWorkflowInstanceOwner(store, handle)); } finally { handle?.Free(); } }
public async Task VerifyOrchestrationStateQueryTest() { var expectedOrchestrationState = Utils.InfiniteOrchestrationTestData().First(); //additional data to ensure query doesn't return back more data than it should var extraOrchestrationState = Utils.InfiniteOrchestrationTestData().First(); await InstanceStore.WriteEntitiesAsync(new InstanceEntityBase[] { expectedOrchestrationState, extraOrchestrationState }); var actual = await InstanceStore.GetOrchestrationStateAsync(expectedOrchestrationState.State.OrchestrationInstance.InstanceId, expectedOrchestrationState.State.OrchestrationInstance.ExecutionId); Assert.AreEqual(expectedOrchestrationState.State.OrchestrationInstance.InstanceId, actual.State.OrchestrationInstance.InstanceId); Assert.AreEqual(expectedOrchestrationState.State.OrchestrationInstance.ExecutionId, actual.State.OrchestrationInstance.ExecutionId); }
/// <summary> /// Initializes a database from its serialized binary data. /// </summary> /// <param name="r">The reader to use.</param> public PackageDB(ICKBinaryReader r) { var ctx = new DeserializerContext(r); _instances = new InstanceStore(ctx); int nbFeeds = ctx.Reader.ReadNonNegativeSmallInt32(); _feeds = new Dictionary <string, PackageFeed>(nbFeeds); while (--nbFeeds >= 0) { var f = new PackageFeed(_instances, ctx); _feeds.Add(f.TypedName, f); } _lastUpdate = DateTime.UtcNow; }
// 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); }
private static InstanceOwner CreateWorkflowInstanceOwner(InstanceStore store, InstanceHandle handle) { var command = new CreateWorkflowOwnerWithIdentityCommand { InstanceOwnerMetadata = { { WorkflowHostTypePropertyName, new InstanceValue(WorkflowHostType) }, { DefinitionIdentityFilterPropertyName, new InstanceValue(WorkflowIdentityFilter.Any) }, { DefinitionIdentitiesPropertyName, new InstanceValue(new Collection <WorkflowIdentity>()) }, }, }; var owner = store.Execute(handle, command, TimeSpan.FromMinutes(1.0)).InstanceOwner; return(owner); }