Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronous implementation of the Invoke (Begin)
        /// </summary>
        public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
        {
            IAsyncResult result = null;
            // Create the Wcf audit event
            var auditWcfEvent = CreateWcfAuditEvent(instance, inputs);
            // Create the audit scope
            var eventType = _eventType.Replace("{contract}", auditWcfEvent.ContractName)
                            .Replace("{operation}", auditWcfEvent.OperationName);
            var auditEventWcf = new AuditEventWcfAction()
            {
                WcfEvent = auditWcfEvent
            };
            // Create the audit scope
            var auditScope = AuditScope.Create(new AuditScopeOptions()
            {
                EventType      = eventType,
                CreationPolicy = _creationPolicy,
                AuditEvent     = auditEventWcf,
                DataProvider   = GetAuditDataProvider(instance),
                CallingMethod  = _operationDescription.SyncMethod ?? _operationDescription.TaskMethod
            });
            // Store a reference to this audit scope
            var callbackState = new AuditScopeState()
            {
                AuditScope           = auditScope,
                OriginalUserCallback = callback,
                OriginalUserState    = state
            };

            AuditBehavior.CurrentAuditScope = auditScope;
            try
            {
                result = _baseInvoker.InvokeBegin(instance, inputs, this.InvokerCallback, callbackState);
            }
            catch (Exception ex)
            {
                AuditBehavior.CurrentAuditScope = null;
                auditWcfEvent.Fault             = GetWcfFaultData(ex);
                auditWcfEvent.Success           = false;
                (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
                auditScope.Dispose();
                throw;
            }
            AuditBehavior.CurrentAuditScope = null;
            return(new AuditScopeAsyncResult(result, callbackState));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns an object and a set of output objects from an instance and set of input objects.
        /// </summary>
        /// <param name="instance">The object to be invoked.</param>
        /// <param name="inputs">The inputs to the method.</param>
        /// <param name="outputs">The outputs from the method.</param>
        public object Invoke(object instance, object[] inputs, out object[] outputs)
        {
            object result = null;
            // Create the Wcf audit event
            var auditWcfEvent = CreateWcfAuditEvent(instance, inputs);
            // Create the audit scope
            var eventType = _eventType.Replace("{contract}", auditWcfEvent.ContractName)
                            .Replace("{operation}", auditWcfEvent.OperationName);
            var auditEventWcf = new AuditEventWcfAction()
            {
                WcfEvent = auditWcfEvent
            };

            // Create the audit scope
            using (var auditScope = AuditScope.Create(new AuditScopeOptions()
            {
                EventType = eventType,
                CreationPolicy = _creationPolicy,
                AuditEvent = auditEventWcf,
                DataProvider = GetAuditDataProvider(instance),
                CallingMethod = _operationDescription.SyncMethod ?? _operationDescription.TaskMethod
            }))
            {
                // Store a reference to this audit scope on a thread static field
                AuditBehavior.CurrentAuditScope = auditScope;
                try
                {
                    result = _baseInvoker.Invoke(instance, inputs, out outputs);
                }
                catch (Exception ex)
                {
                    AuditBehavior.CurrentAuditScope = null;
                    auditWcfEvent.Fault             = GetWcfFaultData(ex);
                    auditWcfEvent.Success           = false;
                    (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
                    throw;
                }
                AuditBehavior.CurrentAuditScope = null;
                auditWcfEvent.OutputParameters  = GetEventElements(outputs);
                auditWcfEvent.Result            = new AuditWcfEventElement(result);
                (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
            }
            return(result);
        }