Esempio n. 1
0
        private static WorkflowServiceHost CreateServiceHostCustomPersistence(
            String xamlxName, IItemSupport extension)
        {
            WorkflowService     wfService = LoadService(xamlxName);
            WorkflowServiceHost host      = new WorkflowServiceHost(wfService);

            InstanceStore store = new FileSystemInstanceStore();

            host.DurableInstancingOptions.InstanceStore = store;

            WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior()
            {
                TimeToUnload = TimeSpan.FromSeconds(0)
            };

            host.Description.Behaviors.Add(idleBehavior);

            //host.Faulted += new EventHandler(host_Faulted);

            if (extension != null)
            {
                host.WorkflowExtensions.Add(extension);
            }

            _hosts.Add(host);

            return(host);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private static void StartNewInstance(
            ref Guid instanceId, InstanceStore store, IItemSupport extension)
        {
            WorkflowApplication wfApp = SetupInstance(
                ref instanceId, store, extension);

            wfApp.Run();
            _unloadedEvent.WaitOne(5000);
        }
Esempio n. 4
0
 private static void DisplayInventory(String desc, IItemSupport extension)
 {
     Console.WriteLine("\nItem inventory {0}:", desc);
     foreach (ItemDefinition item in extension.GetItemDefinitions())
     {
         Console.WriteLine("ItemId={0}, QtyAvailable={1}",
                           item.ItemId, item.QtyAvailable);
     }
     Console.WriteLine("");
 }
Esempio n. 5
0
        protected override Decimal Execute(CodeActivityContext context)
        {
            Decimal      price     = 0;
            IItemSupport extension = context.GetExtension <IItemSupport>();

            if (extension != null)
            {
                price = extension.GetItemPrice(ItemId.Get(context));
            }
            return(price);
        }
Esempio n. 6
0
        protected override Boolean Execute(CodeActivityContext context)
        {
            Boolean      result    = false;
            IItemSupport extension = context.GetExtension <IItemSupport>();

            if (extension != null)
            {
                result = extension.UpdatePendingInventory(OrderId.Get(context),
                                                          ItemId.Get(context), Quantity.Get(context));
            }
            return(result);
        }
Esempio n. 7
0
        private static WorkflowApplication SetupInstance(
            ref Guid instanceId, InstanceStore store, IItemSupport extension)
        {
            WorkflowApplication wfApp =
                new WorkflowApplication(new OrderEntry());

            wfApp.Idle = (e) =>
            {
                Console.WriteLine("{0} Is Idle", e.InstanceId);
            };
            wfApp.PersistableIdle = (e) =>
            {
                Console.WriteLine("{0} Is PersistableIdle", e.InstanceId);
                return(PersistableIdleAction.Unload);
            };
            wfApp.Unloaded = (e) =>
            {
                Console.WriteLine("{0} Is Unloaded", e.InstanceId);
                _unloadedEvent.Set();
            };
            wfApp.OnUnhandledException = (e) =>
            {
                Console.WriteLine("{0} OnUnhandledException: {1}",
                                  e.InstanceId, e.UnhandledException.Message);
                return(UnhandledExceptionAction.Cancel);
            };

            wfApp.InstanceStore = store;
            wfApp.Extensions.Add(extension);

            if (instanceId == Guid.Empty)
            {
                instanceId = wfApp.Id;
            }
            else
            {
                wfApp.Load(instanceId);
            }
            return(wfApp);
        }
Esempio n. 8
0
        private static void OrderComplete(
            Guid instanceId, InstanceStore store, IItemSupport extension)
        {
            WorkflowApplication wfApp = SetupInstance(
                ref instanceId, store, extension);

            wfApp.Completed = (e) =>
            {
                Console.WriteLine("{0} Is Completed", e.InstanceId);
                List <Item> items = e.Outputs["Items"] as List <Item>;
                Console.WriteLine("\nOrdered Items:");
                foreach (Item i in items)
                {
                    Console.WriteLine(
                        "ItemId={0}, Quantity={1}, UnitPrice={2}, Total={3}",
                        i.ItemId, i.Quantity, i.UnitPrice, i.TotalPrice);
                }
            };

            wfApp.ResumeBookmark("OrderComplete", null);
            _unloadedEvent.WaitOne(5000);
        }
Esempio n. 9
0
        private static WorkflowServiceHost CreateServiceHost(
            String xamlxName, IItemSupport extension)
        {
            WorkflowService     wfService = LoadService(xamlxName);
            WorkflowServiceHost host      = new WorkflowServiceHost(wfService);

            string connectionString = ConfigurationManager.ConnectionStrings
                                      ["InstanceStore"].ConnectionString;
            SqlWorkflowInstanceStoreBehavior storeBehavior =
                new SqlWorkflowInstanceStoreBehavior(connectionString);

            storeBehavior.InstanceCompletionAction =
                InstanceCompletionAction.DeleteAll;
            storeBehavior.InstanceLockedExceptionAction =
                InstanceLockedExceptionAction.BasicRetry;
            storeBehavior.InstanceEncodingOption =
                InstanceEncodingOption.GZip;
            storeBehavior.HostLockRenewalPeriod =
                TimeSpan.FromMinutes(1);

            //promption of persisted variables
            List <XName> variables = new List <XName>()
            {
                XName.Get("OrderId", "ActivityLibrary.ItemSupportExtension")
            };

            storeBehavior.Promote("OrderEntry", variables, null);

            host.Description.Behaviors.Add(storeBehavior);

            //WorkflowUnhandledExceptionBehavior exceptionBehavior =
            //    new WorkflowUnhandledExceptionBehavior
            //{
            //    Action = WorkflowUnhandledExceptionAction.Cancel
            //};
            //host.Description.Behaviors.Add(exceptionBehavior);

            WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior()
            {
                TimeToUnload = TimeSpan.FromSeconds(0)
            };

            host.Description.Behaviors.Add(idleBehavior);

            //add control endpoint in code
            //WorkflowControlEndpoint wce = new WorkflowControlEndpoint(
            //    new System.ServiceModel.WSHttpBinding(),
            //    new System.ServiceModel.EndpointAddress(
            //        "http://localhost:9000/OrderEntryControl"));
            //host.AddServiceEndpoint(wce);

            //add an extension instance for each workflow instance
            //host.WorkflowExtensions.Add<ItemSupportParticipant>(() =>
            //{
            //    ItemSupportParticipant ext = new ItemSupportParticipant();
            //    ext.AddItemDefinition(101, 1.23M, 10);
            //    ext.AddItemDefinition(202, 2.34M, 20);
            //    ext.AddItemDefinition(303, 3.45M, 30);
            //    return ext;
            //});

            if (extension != null)
            {
                host.WorkflowExtensions.Add(extension);
            }

            _hosts.Add(host);

            return(host);
        }