Exemplo n.º 1
0
        public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            base.GetUpdateRequests(updateRequest);

            updateRequest("Area", _importArea, Area.GetAll(), GetUpdateRequestId("area"));
            updateRequest("Hour offset", _hourOffset, null, GetUpdateRequestId("offset"));
        }
Exemplo n.º 2
0
            public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
            {
                base.GetUpdateRequests(updateRequest);

                updateRequest("Area", _importArea, Area.GetForSRID(_importArea.Shapefile.SRID), XmlImporter.GetUpdateRequestId("area"));
                updateRequest("Source SRID", _sourceSRID, null, XmlImporter.GetUpdateRequestId("source_srid"));
            }
        public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            base.GetUpdateRequests(updateRequest);

            updateRequest("Area", _importArea, Area.GetAll(), GetUpdateRequestId("area"));
            updateRequest("Hour offset", _hourOffset, null, GetUpdateRequestId("offset"));
        }
Exemplo n.º 4
0
            public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
            {
                base.GetUpdateRequests(updateRequest);

                updateRequest("Area", _importArea, Area.GetAll(), XmlImporter.GetUpdateRequestId("area"));
                updateRequest("Hour offset", _hourOffset, null, XmlImporter.GetUpdateRequestId("offset"));
                updateRequest("Source SRID", _sourceSRID, null, XmlImporter.GetUpdateRequestId("source_srid"));
            }
        public virtual void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            if (updateRequest == null)
            {
                throw new ArgumentNullException("Must pass a non-null update request delegate");
            }

            updateRequest("Name", _name, null, GetUpdateRequestId("name"));
            updateRequest("Path", _path, null, GetUpdateRequestId("path"));
            updateRequest("Relative path", _relativePath, null, GetUpdateRequestId("relative_path"));
            updateRequest("Source URI", _sourceURI, null, GetUpdateRequestId("uri"));
        }
Exemplo n.º 6
0
        /// <summary>
        ///     For test purposes!
        /// </summary>
        public async Task <Response> ProcessOneMessageAsync(
            GetRequestDelegate getRequestDelegate,
            UpdateRequestDelegate updateRequestDelegate,
            CreateRequestDelegate createRequestDelegate,
            Request.RequestTypeEnum?requestType = null,
            string clientName = null, string entityName = null, string keyValue = null)
        {
            var expectedRequestMessage = String.Format(
                "Expected request of type {0} ({1}/{2}/{3})",
                requestType, clientName, entityName, keyValue);

            BrokeredMessage message;
            var             request = GetOneMessageNoBlocking <Request>(out message);

            if (request == null)
            {
                return(null);
            }
            var queue = new Queue <Request>();

            while (!IsExpectedRequest(request, requestType, clientName, entityName, keyValue))
            {
                Log.Verbose("Received {0} {1}", request, expectedRequestMessage);
                queue.Enqueue(request);
                SafeCompleteAsync(message, request).Wait();
                request = GetOneMessageNoBlocking <Request>(out message);
                if (request == null)
                {
                    break;
                }
            }

            var tasks = queue.Select(SendRequestAsync).ToArray();
            await Task.WhenAll(tasks);

            if (request == null)
            {
                throw new ApplicationException(expectedRequestMessage);
            }

            return
                (await
                 SafeProcessRequestAsync(getRequestDelegate, updateRequestDelegate, createRequestDelegate, request,
                                         message));
        }
Exemplo n.º 7
0
        public void ProcessRequests(GetRequestDelegate getRequestDelegate,
                                    UpdateRequestDelegate updateRequestDelegate,
                                    CreateRequestDelegate createRequestDelegate,
                                    ManualResetEvent stopEvent, int maxConcurrentCalls = 1)
        {
            var options = new OnMessageOptions {
                AutoComplete = false, MaxConcurrentCalls = maxConcurrentCalls
            };

            OnMessageAsync(async message =>
            {
                var request = message.GetBody <Request>(new DataContractSerializer(typeof(Request)));

                await
                SafeProcessRequestAsync(getRequestDelegate, updateRequestDelegate, createRequestDelegate, request,
                                        message);
            }, options);

            stopEvent.WaitOne();
            CloseAsync().Wait();
        }
Exemplo n.º 8
0
        private async Task <Response> SafeProcessRequestAsync(GetRequestDelegate getRequestDelegate,
                                                              UpdateRequestDelegate updateRequestDelegate,
                                                              CreateRequestDelegate createRequestDelegate, Request request, BrokeredMessage message)
        {
            Response responseSent = null;

            try
            {
                Log.Verbose("{0} processing {1}", request.ClientName, request);

                var successResponse = ProcessRequest(
                    getRequestDelegate, updateRequestDelegate, createRequestDelegate,
                    request);
                await SendResponseAsync(successResponse);

                responseSent = successResponse;
            }
            catch (MovedException exception)
            {
                Log.Information(exception.Message);

                var failureResponse = new FailureResponse(request, exception.ErrorType)
                {
                    Value   = exception.NewKeyValue,
                    Message = exception.Message,
                };

                SendResponseAsync(failureResponse).Wait();
                responseSent = failureResponse;
            }
            catch (ClientDataHasBeenUpdated exception)
            {
                Log.Information(exception.Message);

                if (exception.NewClientData != null)
                {
                    exception.NewClientData.CalculateCheckSum(request.KeyValue);
                }

                var failureResponse = new FailureResponse(request, exception.ErrorType)
                {
                    Value   = exception.NewCheckSum,
                    Data    = exception.NewClientData,
                    Message = exception.Message,
                };

                SendResponseAsync(failureResponse).Wait();
                responseSent = failureResponse;
            }
            catch (InternalServerErrorException exception)
            {
                Log.Critical(exception, "An internal server error has occured.");

                var failureResponse = new FailureResponse(request, FailureResponse.ErrorTypeEnum.InternalServerError)
                {
                    Message = exception.ToString()
                };

                SendResponseAsync(failureResponse).Wait();
                responseSent = failureResponse;
            }
            catch (MatchException exception)
            {
                Log.Error(exception, "An error has occured");

                var failureResponse = new FailureResponse(request, exception.ErrorType)
                {
                    Message = exception.Message
                };

                SendResponseAsync(failureResponse).Wait();
                responseSent = failureResponse;
            }
            catch (SilentFailOnlyForTestingException)
            {
#if DEBUG
                Log.Warning("Silent fail. This exception should only occur when running test cases.");
#else
                Log.Critical("Silent fail. This exception should only occur when running test cases.");
#endif
            }
            catch (Exception exception)
            {
                Log.Critical(exception, "An error not handled by the adapter has occured");

                var failureResponse = new FailureResponse(request,
                                                          FailureResponse.ErrorTypeEnum.AdapterDidNotHandleException)
                {
                    Message = exception.ToString()
                };

                SendResponseAsync(failureResponse).Wait();
                responseSent = failureResponse;
            }

            // Try to complete this message since we should have sent a response, either success or failure at
            // this point.

            SafeCompleteAsync(message, request).Wait();

            return(responseSent);
        }
 public virtual void GetUpdateRequests(UpdateRequestDelegate updateRequest)
 {
 }
Exemplo n.º 10
0
 public HttpRequest(Socket clientSocket, DestroyDelegate destroyer, UpdateRequestDelegate updateRequest)
 {
     _clientSocket  = clientSocket;
     _destroyer     = destroyer;
     _updateRequest = updateRequest;
 }
Exemplo n.º 11
0
        public static SuccessResponse ProcessRequest(GetRequestDelegate getRequestDelegate,
                                                     UpdateRequestDelegate updateRequestDelegate,
                                                     CreateRequestDelegate createRequestDelegate, Request request)
        {
            try
            {
                var response = new SuccessResponse(request);

                switch (request.RequestType)
                {
                case Request.RequestTypeEnum.Get:
                    response.Data = getRequestDelegate(request.Key);
                    if (response.Data != null)
                    {
                        response.Data.CalculateCheckSum(request.KeyValue);
                    }
                    break;

                case Request.RequestTypeEnum.Update:
                    var currentClientData = getRequestDelegate(request.Key);
                    if ((currentClientData != null) && !currentClientData.ShouldCheckSumBeIgnored())
                    {
                        currentClientData.CalculateCheckSum(request.KeyValue);
                        if (currentClientData.CheckSum != request.Data.CheckSum)
                        {
                            throw new ClientDataHasBeenUpdated(currentClientData);
                        }
                    }
                    updateRequestDelegate(request.Key, request.Data);
                    break;

                case Request.RequestTypeEnum.Create:
                    var reservationId = request.Key.ReservationId;
                    response.Key = createRequestDelegate(request.Key, request.Data);
                    response.Key.ReservationId = reservationId;
                    break;

                default:
                    throw new BadRequestException(String.Format("Unknown request type: \"{0}\"", request.RequestType));
                }

                return(response);
            }
            catch (MatchException)
            {
                throw;
            }
            catch (SilentFailOnlyForTestingException)
            {
#if DEBUG
                Log.Warning("Silent fail. This exception should only occur when running test cases.");
                throw;
#else
                throw new InternalServerErrorException("Silent fail. This exception should only occur when running test cases.");
#endif
            }
            catch (Exception e)
            {
                throw new InternalServerErrorException(e);
            }
        }
Exemplo n.º 12
0
        public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            base.GetUpdateRequests(updateRequest);

            _xmlRowInserter.GetUpdateRequests(updateRequest);
        }
Exemplo n.º 13
0
        public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            base.GetUpdateRequests(updateRequest);

            updateRequest("Area containment box size (meters)", _areaContainmentBoxSize, null, GetUpdateRequestId("containment_box_size"));
        }
        public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            base.GetUpdateRequests(updateRequest);

            updateRequest("Area containment box size (meters)", _areaContainmentBoxSize, null, GetUpdateRequestId("containment_box_size"));
        }
Exemplo n.º 15
0
 public HttpListener(UpdateRequestDelegate updateRequest)
 {
     _updateRequest = updateRequest;
 }
Exemplo n.º 16
0
 public virtual void GetUpdateRequests(UpdateRequestDelegate updateRequest)
 {
 }
            public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
            {
                base.GetUpdateRequests(updateRequest);

                updateRequest("Area", _importArea, Area.GetForSRID(_importArea.Shapefile.SRID), XmlImporter.GetUpdateRequestId("area"));
                updateRequest("Source SRID", _sourceSRID, null, XmlImporter.GetUpdateRequestId("source_srid"));
            }
            public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
            {
                base.GetUpdateRequests(updateRequest);

                updateRequest("Area", _importArea, Area.GetAll(), XmlImporter.GetUpdateRequestId("area"));
                updateRequest("Hour offset", _hourOffset, null, XmlImporter.GetUpdateRequestId("offset"));
                updateRequest("Source SRID", _sourceSRID, null, XmlImporter.GetUpdateRequestId("source_srid"));
            }
        public override void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            base.GetUpdateRequests(updateRequest);

            _xmlRowInserter.GetUpdateRequests(updateRequest);
        }
        public virtual void GetUpdateRequests(UpdateRequestDelegate updateRequest)
        {
            if (updateRequest == null)
                throw new ArgumentNullException("Must pass a non-null update request delegate");

            updateRequest("Name", _name, null, GetUpdateRequestId("name"));
            updateRequest("Path", _path, null, GetUpdateRequestId("path"));
            updateRequest("Relative path", _relativePath, null, GetUpdateRequestId("relative_path"));
            updateRequest("Source URI", _sourceURI, null, GetUpdateRequestId("uri"));
        }