コード例 #1
0
        public void EventHandler(object sender, ExternalDataEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                throw new ArgumentNullException("eventArgs");
            }

            try
            {
                object         workItem;
                IPendingWork   workHandler;
                object[]       args = this.enqueueWrapper.PrepareEventArgsArray(sender, eventArgs, out workItem, out workHandler);
                EventQueueName key  = GetKey(args);

                String securityIdentifier = null;
                if (eventArgs.Identity == null)
                {
                    IIdentity       identity        = System.Threading.Thread.CurrentPrincipal.Identity;
                    WindowsIdentity windowsIdentity = identity as WindowsIdentity;
                    if (windowsIdentity != null && windowsIdentity.User != null)
                    {
                        securityIdentifier = windowsIdentity.User.Translate(typeof(NTAccount)).ToString();
                    }
                    else if (identity != null)
                    {
                        securityIdentifier = identity.Name;
                    }

                    eventArgs.Identity = securityIdentifier;
                }
                else
                {
                    securityIdentifier = eventArgs.Identity;
                }

                MethodMessage message = new MethodMessage(this.proxiedType, this.eventName, args, securityIdentifier);

                WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "Firing event {0} for instance {1}", this.eventName, eventArgs.InstanceId);

                this.enqueueWrapper.DeliverMessage(eventArgs, key, message, workItem, workHandler);
            }
            catch (Exception e)
            {
                if (ExternalDataExchangeService.IsIrrecoverableException(e))
                {
                    throw;
                }
                else
                {
                    throw new EventDeliveryFailedException(SR.GetString(SR.Error_EventDeliveryFailedException, this.proxiedType, this.eventName, eventArgs.InstanceId), e);
                }
            }
        }
コード例 #2
0
 //Back - off logic for conflicting workflow load across workflow runtime boundaries.
 static void SafeEnqueueItem(WorkflowInstance instance, EventQueueName key, MethodMessage message)
 {
     while (true) //When Execution times out ASP.NET going to forcefully plung this request.
     {
         try
         {
             instance.EnqueueItem(key, message, null, null);
             return;
         }
         catch (WorkflowOwnershipException)
         {
             WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Warning, 0, String.Format(System.Globalization.CultureInfo.InvariantCulture, "Workflow Web Host Encountered Workflow Instance Ownership conflict for instanceid {0}.", instance.InstanceId));
             //Back-off for 1/2 sec. Should we make this configurable?
             System.Threading.Thread.Sleep(500);
             continue;
         }
     }
 }
 public void EventHandler(object sender, ExternalDataEventArgs eventArgs)
 {
     if (eventArgs == null)
     {
         throw new ArgumentNullException("eventArgs");
     }
     try
     {
         object obj2;
         IPendingWork work;
         object[] objArray = this.enqueueWrapper.PrepareEventArgsArray(sender, eventArgs, out obj2, out work);
         EventQueueName key = this.GetKey(objArray);
         string name = null;
         if (eventArgs.Identity == null)
         {
             IIdentity identity = Thread.CurrentPrincipal.Identity;
             WindowsIdentity identity2 = identity as WindowsIdentity;
             if ((identity2 != null) && (identity2.User != null))
             {
                 name = identity2.User.Translate(typeof(NTAccount)).ToString();
             }
             else if (identity != null)
             {
                 name = identity.Name;
             }
             eventArgs.Identity = name;
         }
         else
         {
             name = eventArgs.Identity;
         }
         MethodMessage message = new MethodMessage(this.proxiedType, this.eventName, objArray, name);
         WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "Firing event {0} for instance {1}", new object[] { this.eventName, eventArgs.InstanceId });
         this.enqueueWrapper.DeliverMessage(eventArgs, key, message, obj2, work);
     }
     catch (Exception exception)
     {
         if (ExternalDataExchangeService.IsIrrecoverableException(exception))
         {
             throw;
         }
         throw new EventDeliveryFailedException(SR.GetString("Error_EventDeliveryFailedException", new object[] { this.proxiedType, this.eventName, eventArgs.InstanceId }), exception);
     }
 }
 public void EventHandler(object sender, ExternalDataEventArgs eventArgs)
 {
     if (eventArgs == null)
     {
         throw new ArgumentNullException("eventArgs");
     }
     try
     {
         object         obj2;
         IPendingWork   work;
         object[]       objArray = this.enqueueWrapper.PrepareEventArgsArray(sender, eventArgs, out obj2, out work);
         EventQueueName key      = this.GetKey(objArray);
         string         name     = null;
         if (eventArgs.Identity == null)
         {
             IIdentity       identity  = Thread.CurrentPrincipal.Identity;
             WindowsIdentity identity2 = identity as WindowsIdentity;
             if ((identity2 != null) && (identity2.User != null))
             {
                 name = identity2.User.Translate(typeof(NTAccount)).ToString();
             }
             else if (identity != null)
             {
                 name = identity.Name;
             }
             eventArgs.Identity = name;
         }
         else
         {
             name = eventArgs.Identity;
         }
         MethodMessage message = new MethodMessage(this.proxiedType, this.eventName, objArray, name);
         WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "Firing event {0} for instance {1}", new object[] { this.eventName, eventArgs.InstanceId });
         this.enqueueWrapper.DeliverMessage(eventArgs, key, message, obj2, work);
     }
     catch (Exception exception)
     {
         if (ExternalDataExchangeService.IsIrrecoverableException(exception))
         {
             throw;
         }
         throw new EventDeliveryFailedException(SR.GetString("Error_EventDeliveryFailedException", new object[] { this.proxiedType, this.eventName, eventArgs.InstanceId }), exception);
     }
 }
コード例 #5
0
        private static MethodMessage PrepareMessage(Type interfaceType, String operation, object[] parameters, bool responseRequired)
        {
            // construct IMethodMessage object
            String          securityIdentifier = null;
            IIdentity       identity           = System.Threading.Thread.CurrentPrincipal.Identity;
            WindowsIdentity windowsIdentity    = identity as WindowsIdentity;

            if (windowsIdentity != null && windowsIdentity.User != null)
            {
                securityIdentifier = windowsIdentity.User.Translate(typeof(NTAccount)).ToString();
            }
            else if (identity != null)
            {
                securityIdentifier = identity.Name;
            }

            MethodMessage msg = new MethodMessage(interfaceType, operation, parameters, securityIdentifier, responseRequired);

            return(msg);
        }
コード例 #6
0
        public void EventHandler(object sender, ExternalDataEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                throw new ArgumentNullException("eventArgs");
            }

            try
            {
                object workItem;
                IPendingWork workHandler;
                object[] args = this.enqueueWrapper.PrepareEventArgsArray(sender, eventArgs, out workItem, out workHandler);
                EventQueueName key = GetKey(args);

                String securityIdentifier = null;
                if (eventArgs.Identity == null)
                {
                    IIdentity identity = System.Threading.Thread.CurrentPrincipal.Identity;
                    WindowsIdentity windowsIdentity = identity as WindowsIdentity;
                    if (windowsIdentity != null && windowsIdentity.User != null)
                        securityIdentifier = windowsIdentity.User.Translate(typeof(NTAccount)).ToString();
                    else if (identity != null)
                        securityIdentifier = identity.Name;

                    eventArgs.Identity = securityIdentifier;
                }
                else
                {
                    securityIdentifier = eventArgs.Identity;
                }

                MethodMessage message = new MethodMessage(this.proxiedType, this.eventName, args, securityIdentifier);

                WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "Firing event {0} for instance {1}", this.eventName, eventArgs.InstanceId);

                this.enqueueWrapper.DeliverMessage(eventArgs, key, message, workItem, workHandler);
            }
            catch (Exception e)
            {
                if (ExternalDataExchangeService.IsIrrecoverableException(e))
                {
                    throw;
                }
                else
                {
                    throw new EventDeliveryFailedException(SR.GetString(SR.Error_EventDeliveryFailedException, this.proxiedType, this.eventName, eventArgs.InstanceId), e);
                }
            }
        }
コード例 #7
0
        protected Object[] Invoke(Type interfaceType, String methodName, bool isActivation, Object[] parameters)
        {
            Guid             workflowInstanceId = GetWorkflowInstanceId(ref isActivation);
            WorkflowInstance wfInstance;

            EventQueueName key = new EventQueueName(interfaceType, methodName);

            MethodInfo mInfo = interfaceType.GetMethod(methodName);

            bool responseRequired = (mInfo.ReturnType != typeof(void));

            if (!responseRequired)
            {
                foreach (ParameterInfo parameter in mInfo.GetParameters())
                {
                    if (parameter.ParameterType.IsByRef || parameter.IsOut)
                    {
                        responseRequired = true;
                        break;
                    }
                }
            }

            MethodMessage methodMessage = PrepareMessage(interfaceType, methodName, parameters, responseRequired);

            EventHandler <WorkflowTerminatedEventArgs> workflowTerminationHandler = null;
            EventHandler <WorkflowCompletedEventArgs>  workflowCompletedHandler   = null;

            try
            {
                if (isActivation)
                {
                    wfInstance = WorkflowRuntime.CreateWorkflow(this.workflowType, null, workflowInstanceId);
                    SafeEnqueueItem(wfInstance, key, methodMessage);
                    wfInstance.Start();
                }
                else
                {
                    wfInstance = WorkflowRuntime.GetWorkflow(workflowInstanceId);
                    SafeEnqueueItem(wfInstance, key, methodMessage);
                }

                bool workflowTerminated = false;

                //Handler for workflow termination in b/w outstanding req-response.
                workflowTerminationHandler = delegate(Object sender, WorkflowTerminatedEventArgs e)
                {
                    if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId))
                    {
                        methodMessage.SendException(e.Exception);
                        workflowTerminated = true;
                    }
                };

                workflowCompletedHandler = delegate(Object sender, WorkflowCompletedEventArgs e)
                {
                    if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId))
                    {
                        methodMessage.SendException(new ApplicationException(SR.GetString(System.Globalization.CultureInfo.CurrentCulture, SR.Error_WorkflowCompleted)));
                    }
                };

                WorkflowRuntime.WorkflowTerminated += workflowTerminationHandler;
                WorkflowRuntime.WorkflowCompleted  += workflowCompletedHandler;

                ManualWorkflowSchedulerService scheduler = WorkflowRuntime.GetService <ManualWorkflowSchedulerService>();

                if (scheduler != null)
                {
                    scheduler.RunWorkflow(wfInstance.InstanceId);
                }

                if (!responseRequired)
                {
                    // no ret, out or ref
                    return(new Object[] { });
                }

                IMethodResponseMessage response = methodMessage.WaitForResponseMessage();

                if (response.Exception != null)
                {
                    if (!workflowTerminated)
                    {
                        throw response.Exception;
                    }
                    else
                    {
                        throw new ApplicationException(SR.GetString(System.Globalization.CultureInfo.CurrentCulture, SR.Error_WorkflowTerminated), response.Exception);
                    }
                }

                if (response.OutArgs != null)
                {
                    return(((ArrayList)response.OutArgs).ToArray());
                }
                else
                {
                    return new Object[] { }
                };
            }
            finally
            {
                if (workflowTerminationHandler != null)
                {
                    WorkflowRuntime.WorkflowTerminated -= workflowTerminationHandler;
                }

                if (workflowCompletedHandler != null)
                {
                    WorkflowRuntime.WorkflowCompleted -= workflowCompletedHandler;
                }
            }
        }
コード例 #8
0
 //Back - off logic for conflicting workflow load across workflow runtime boundaries.
 static void SafeEnqueueItem(WorkflowInstance instance, EventQueueName key, MethodMessage message)
 {
     while (true) //When Execution times out ASP.NET going to forcefully plung this request.
     {
         try
         {
             instance.EnqueueItem(key, message, null, null);
             return;
         }
         catch (WorkflowOwnershipException)
         {
             WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Warning, 0, String.Format(System.Globalization.CultureInfo.InvariantCulture, "Workflow Web Host Encountered Workflow Instance Ownership conflict for instanceid {0}.", instance.InstanceId));
             //Back-off for 1/2 sec. Should we make this configurable?
             System.Threading.Thread.Sleep(500);
             continue;
         }
     }
 }
コード例 #9
0
        private static MethodMessage PrepareMessage(Type interfaceType, String operation, object[] parameters, bool responseRequired)
        {
            // construct IMethodMessage object
            String securityIdentifier = null;
            IIdentity identity = System.Threading.Thread.CurrentPrincipal.Identity;
            WindowsIdentity windowsIdentity = identity as WindowsIdentity;
            if (windowsIdentity != null && windowsIdentity.User != null)
                securityIdentifier = windowsIdentity.User.Translate(typeof(NTAccount)).ToString();
            else if (identity != null)
                securityIdentifier = identity.Name;

            MethodMessage msg = new MethodMessage(interfaceType, operation, parameters, securityIdentifier, responseRequired);
            return msg;
        }
コード例 #10
0
        protected object[] Invoke(Type interfaceType, string methodName, bool isActivation, object[] parameters)
        {
            EventHandler <WorkflowCompletedEventArgs> handler3 = null;

            object[]       objArray;
            Guid           workflowInstanceId = GetWorkflowInstanceId(ref isActivation);
            EventQueueName key              = new EventQueueName(interfaceType, methodName);
            MethodInfo     method           = interfaceType.GetMethod(methodName);
            bool           responseRequired = method.ReturnType != typeof(void);

            if (!responseRequired)
            {
                foreach (ParameterInfo info2 in method.GetParameters())
                {
                    if (info2.ParameterType.IsByRef || info2.IsOut)
                    {
                        responseRequired = true;
                        break;
                    }
                }
            }
            MethodMessage methodMessage = PrepareMessage(interfaceType, methodName, parameters, responseRequired);
            EventHandler <WorkflowTerminatedEventArgs> handler  = null;
            EventHandler <WorkflowCompletedEventArgs>  handler2 = null;

            try
            {
                WorkflowInstance workflow;
                if (isActivation)
                {
                    workflow = this.WorkflowRuntime.CreateWorkflow(this.workflowType, null, workflowInstanceId);
                    SafeEnqueueItem(workflow, key, methodMessage);
                    workflow.Start();
                }
                else
                {
                    workflow = this.WorkflowRuntime.GetWorkflow(workflowInstanceId);
                    SafeEnqueueItem(workflow, key, methodMessage);
                }
                bool workflowTerminated = false;
                handler = delegate(object sender, WorkflowTerminatedEventArgs e) {
                    if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId))
                    {
                        methodMessage.SendException(e.Exception);
                        workflowTerminated = true;
                    }
                };
                if (handler3 == null)
                {
                    handler3 = delegate(object sender, WorkflowCompletedEventArgs e) {
                        if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId))
                        {
                            methodMessage.SendException(new ApplicationException(SR.GetString(CultureInfo.CurrentCulture, "Error_WorkflowCompleted")));
                        }
                    };
                }
                handler2 = handler3;
                this.WorkflowRuntime.WorkflowTerminated += handler;
                this.WorkflowRuntime.WorkflowCompleted  += handler2;
                ManualWorkflowSchedulerService service = this.WorkflowRuntime.GetService <ManualWorkflowSchedulerService>();
                if (service != null)
                {
                    service.RunWorkflow(workflow.InstanceId);
                }
                if (!responseRequired)
                {
                    return(new object[0]);
                }
                IMethodResponseMessage message = methodMessage.WaitForResponseMessage();
                if (message.Exception != null)
                {
                    if (!workflowTerminated)
                    {
                        throw message.Exception;
                    }
                    throw new ApplicationException(SR.GetString(CultureInfo.CurrentCulture, "Error_WorkflowTerminated"), message.Exception);
                }
                if (message.OutArgs != null)
                {
                    return(((ArrayList)message.OutArgs).ToArray());
                }
                objArray = new object[0];
            }
            finally
            {
                if (handler != null)
                {
                    this.WorkflowRuntime.WorkflowTerminated -= handler;
                }
                if (handler2 != null)
                {
                    this.WorkflowRuntime.WorkflowCompleted -= handler2;
                }
            }
            return(objArray);
        }
コード例 #11
0
        private static void SafeEnqueueItem(WorkflowInstance instance, EventQueueName key, MethodMessage message)
        {
Label_0000:
            try
            {
                instance.EnqueueItem(key, message, null, null);
            }
            catch (WorkflowOwnershipException)
            {
                WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Warning, 0, string.Format(CultureInfo.InvariantCulture, "Workflow Web Host Encountered Workflow Instance Ownership conflict for instanceid {0}.", new object[] { instance.InstanceId }));
                Thread.Sleep(500);
                goto Label_0000;
            }
        }
 private static void SafeEnqueueItem(WorkflowInstance instance, EventQueueName key, MethodMessage message)
 {
 Label_0000:
     try
     {
         instance.EnqueueItem(key, message, null, null);
     }
     catch (WorkflowOwnershipException)
     {
         WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Warning, 0, string.Format(CultureInfo.InvariantCulture, "Workflow Web Host Encountered Workflow Instance Ownership conflict for instanceid {0}.", new object[] { instance.InstanceId }));
         Thread.Sleep(500);
         goto Label_0000;
     }
 }