/// <summary>
        /// Logs the specified integration event.
        /// </summary>
        /// <param name="integrationEvent">The integration event.</param>
        /// <exception cref="System.ArgumentNullException">integrationEvent</exception>
        public void Log(IntegrationEvent integrationEvent)
        {
            if (integrationEvent == null)
                throw new ArgumentNullException("integrationEvent");

            try
            {
                var eventEdit = DynamicTypeManager.NewEditableRoot<IIntegrationEvent>(Constants.IntegrationEventProcessName);

                eventEdit.TimeCreated = integrationEvent.TimeCreated;
                eventEdit.IsSuccessful = integrationEvent.IsSuccessful;
                eventEdit.Process = integrationEvent.Process;
                eventEdit.Service = integrationEvent.Service;
                eventEdit.Username = integrationEvent.Username;
                eventEdit.Request = integrationEvent.Request;
                eventEdit.Response = integrationEvent.Response;
                eventEdit.Details = integrationEvent.Details;

                eventEdit.Save();
            }
            catch (Exception ex)
            {
                Logger.Log(LogSeverity.Error, "Integration Event Logger", ex);
            }
        }
        public void LogTest()
        {
            // Arrange.
            var timeCreated = new DateTime(2013, 7, 5, 14, 53, 30);
            const string ProcessName = "Test Process";
            const string ServiceName = "Test Service";
            const string Username = "******";
            const string Details = "Test Details";

            var @event = new IntegrationEvent
                             {
                                 TimeCreated = timeCreated,
                                 IsSuccessful = true,
                                 Process = ProcessName,
                                 Service = ServiceName,
                                 Username = Username,
                                 Details = Details
                             };

            var eventEdit = new Mock<IIntegrationEvent>();
            eventEdit.SetupAllProperties();

            var dtm = new Mock<IDynamicTypeManager>();
            dtm.Setup(x => x.NewEditableRoot<IIntegrationEvent>(Constants.IntegrationEventProcessName)).Returns(eventEdit.Object);

            var logger = new IntegrationEventLogger { DynamicTypeManager = dtm.Object };

            // Act.
            logger.Log(@event);

            // Assert.
            dtm.Verify(x => x.NewEditableRoot<IIntegrationEvent>(Constants.IntegrationEventProcessName), Times.Once());

            eventEdit.Verify(x => x.Save(), Times.Once());
            Assert.AreEqual(timeCreated, eventEdit.Object.TimeCreated);
            Assert.AreEqual(true, eventEdit.Object.IsSuccessful);
            Assert.AreEqual(ProcessName, eventEdit.Object.Process);
            Assert.AreEqual(ServiceName, eventEdit.Object.Service);
            Assert.AreEqual(Username, eventEdit.Object.Username);
            Assert.AreEqual(Details, eventEdit.Object.Details);
        }
Exemple #3
0
        /// <summary>
        /// Executes the specified item.
        /// </summary>
        /// <param name="item">
        /// The editable root item.
        /// </param>
        public void Execute(IEditableRoot item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (_callLocation != UrlServiceCallLocation.Server)
                throw new InvalidOperationException("Service call cannot be executed on server.");

            if (ServiceCallContext.IsExecutingService(Guid))
                throw new InvalidOperationException(
                    string.Format(CultureInfo.InvariantCulture, "The service \"{0}\" is already executing on this thread.", Name ?? string.Empty));

            using (new ThreadLocalBypassPropertyCheckContext())
            {
                using (new ServiceCallContext(Guid))
                {
                    using (var scope = new IntegrationServiceCallScope())
                    {
                        var integrationEvent = new IntegrationEvent
                                               {
                                                   TimeCreated = DateTime.Now,
                                                   Process = ProcessDisplayName,
                                                   Service = Name,
                                                   Username = Utils.CurrentUserName
                                               };

                        try
                        {
                            var request = GetRequestInternal(item);

                            try
                            {
                                switch (_httpMethod)
                                {
                                    case UrlServiceCallMethod.Get:
                                        RequestSender.SendGetRequest(request);
                                        break;

                                    case UrlServiceCallMethod.Post:
                                        RequestSender.SendPostRequest(request);
                                        break;
                                }
                            }
                            catch (Exception ex)
                            {
                                throw new ServiceCallException(ex.Message, ex);
                            }

                            integrationEvent.IsSuccessful = true;
                        }
                        catch (Exception ex)
                        {
                            integrationEvent.Details = ex.ToString();
                            throw;
                        }
                        finally
                        {
                            integrationEvent.Request = scope.Request;
                            integrationEvent.Response = scope.Response;

                            IntegrationEventLogger.Log(integrationEvent);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// When overridden in a derived class, allows a SOAP extension to initialize itself using the data cached in the <see cref="M:System.Web.Services.Protocols.SoapExtension.GetInitializer(System.Web.Services.Protocols.LogicalMethodInfo,System.Web.Services.Protocols.SoapExtensionAttribute)"/> method.
        /// </summary>
        /// <param name="initializer">The <see cref="T:System.Object"/> returned from <see cref="M:System.Web.Services.Protocols.SoapExtension.GetInitializer(System.Web.Services.Protocols.LogicalMethodInfo,System.Web.Services.Protocols.SoapExtensionAttribute)"/> cached by ASP.NET. </param>
        public override void Initialize(object initializer)
        {
            _integrationEvent = null;

            Ioc.SatisfyImportsOnce(this);

            var attribute = initializer as LogIntegrationEventExtensionAttribute;

            if (attribute != null)
            {
                _integrationEvent = new IntegrationEvent
                                    {
                                        TimeCreated = _timeService.Now,
                                        Process = attribute.ProcessName,
                                        Service = attribute.ServiceName,
                                        IsSuccessful = true
                                    };
            }
        }
        /// <summary>
        /// Executes a call to web service.
        /// </summary>
        /// <param name="item">The editable root item to be used as data source.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="item"/> parameter is null.
        /// </exception>
        public void Execute(IEditableRoot item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            if (ServiceCallContext.IsExecutingService(Guid))
                throw new InvalidOperationException(
                    string.Format(CultureInfo.InvariantCulture, "The service \"{0}\" is already executing on this thread.", Name ?? string.Empty));

            using (new ThreadLocalBypassPropertyCheckContext())
            {
                using (new ServiceCallContext(Guid))
                {
                    using (var scope = new IntegrationServiceCallScope())
                    {
                        var integrationEvent = new IntegrationEvent
                                               {
                                                   TimeCreated = DateTime.Now,
                                                   Process = ProcessDisplayName,
                                                   Service = Name,
                                                   Username = Utils.CurrentUserName
                                               };

                        try
                        {
                            var request = CreateRequest(item);
                            object response;

                            try
                            {
                                response = MethodProxy.Invoke(request);
                            }
                            catch (Exception ex)
                            {
                                throw new ServiceCallException(ex.Message, ex);
                            }

                            UpdateItem(item, response);
                            integrationEvent.IsSuccessful = true;
                        }
                        catch (Exception ex)
                        {
                            integrationEvent.Details = ex.ToString();
                            throw;
                        }
                        finally
                        {
                            integrationEvent.Request = scope.Request;
                            integrationEvent.Response = scope.Response;

                            IntegrationEventLogger.Log(integrationEvent);
                        }
                    }
                }
            }
        }