public TChannel CreateLocalChannel <TChannel>()
        {
            ChannelFactory <TChannel> channelFactory = new ChannelFactory <TChannel>(localBinding, localWorkflowAddress);
            TChannel channel = channelFactory.CreateChannel();
            IDictionary <string, string> context = ContextManager.DepersistContext(contextFileName);

            if (context != null && context.Count > 0)
            {
                ContextManager.ApplyContextToChannel(context, (IClientChannel)channel);
                recoveredContext = true;
                // register handlers to cleanup context file when Workflow completes or terminates.
                this.Description.Behaviors.Find <WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { ContextManager.DeleteContext(contextFileName); };
                this.Description.Behaviors.Find <WorkflowRuntimeBehavior>().WorkflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { ContextManager.DeleteContext(contextFileName); };
            }
            return(channel);
        }
        public IDictionary <string, string> MaintainContext(IClientChannel channel)
        {
            IDictionary <string, string> context = null;

            if (!RecoveredContext)
            {
                context = ContextManager.ExtractContextFromChannel((IClientChannel)channel);
                ContextManager.PersistContext(context, contextFileName);
                // register handlers to cleanup context file when Workflow completes or terminates.
                wfRuntime.WorkflowCompleted  += delegate(object sender, WorkflowCompletedEventArgs e) { ContextManager.DeleteContext(contextFileName); };
                wfRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { ContextManager.DeleteContext(contextFileName); };
            }
            return(context);
        }
예제 #3
0
        void DoOperation(object sender, RoutedEventArgs e)
        {
            int    value     = 0;
            string operation = ((Button)sender).Content.ToString();

            if (!operation.StartsWith("=") && !int.TryParse(Display.Text, out value))
            {
                MessageBox.Show("Invalid input! Try again.");
                Display.Text = String.Empty;
            }

            try
            {
                if (!PowerOn)
                {
                    PowerSwitch(ButtonC, null);
                }

                using (new OperationContextScope((IContextChannel)Client.InnerChannel))
                {
                    if (!contextApplied)
                    {
                        ContextManager.ApplyContextToChannel(Context, Client.InnerChannel);
                        contextApplied = true;
                    }

                    switch (operation)
                    {
                    case "=": { value = Client.Add(0); break; }

                    case "+": { value = Client.Add(value); break; }

                    case "-": { value = Client.Subtract(value); break; }

                    case "x": { value = Client.Multiply(value); break; }

                    case "/": {
                        if (value == 0)
                        {
                            MessageBox.Show("Divide By Zero is not allowed");
                            value = client.Add(0);
                            break;
                        }
                        else
                        {
                            value = Client.Divide(value);
                            break;
                        }
                    }
                    }
                }
            }
            catch (CommunicationException ce)
            {
                MessageBox.Show(ce.Message);
                Client.Abort();
                client = null;
            }

            Display.Background = onBrush;
            Display.Text       = value.ToString();
            displayNew         = true;
        }