Exemplo n.º 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);
                }
            }
        }
 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);
     }
 }