public void Dispose()
        {
            if (_disposed)
                return;

            _disposed = true;

            if (_thread != Thread.CurrentThread)
                throw new InvalidOperationException("Scope should be disposed in the original thread.");

            if (_currentScope != this)
                throw new InvalidOperationException("Scope is disposed in incorrect order.");

            _currentScope = _originalScope;
        }
Exemple #2
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>
 /// Initializes a new instance of the <see cref="IntegrationServiceCallScope"/> class.
 /// </summary>
 public IntegrationServiceCallScope()
 {
     _originalScope = _currentScope;
     _thread = Thread.CurrentThread;
     _currentScope = this;
 }
        /// <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);
                        }
                    }
                }
            }
        }