Exemplo n.º 1
0
        /// <summary>
        /// Process operation request
        /// </summary>
        /// <param name="request"></param>
        /// <returns>Resposne object to be sent back to the client</returns>
        public override OperationResult ProcessRequest(HttpRequest request, OwsRequestBase payload = null)
        {
            var logger = this.ServiceProvider.GetService <ILogger <ExecuteOperation> >();

            logger.LogInformation("Process Execute request");

            string identifier = ((Execute)payload).Identifier;

            logger.LogDebug("identifier = {0}", identifier);

            //  Make sure there is valid request parameter
            if (string.IsNullOrEmpty(identifier))
            {
                throw new NoApplicableCodeException(string.Format(CultureInfo.CurrentCulture, "Process identifier is mandatory for Execute operation.", identifier));
            }

            OperationResult result = new OperationResult(request);

            var processes = this.GetProcesses();

            if (!processes.ContainsKey(identifier))
            {
                throw new InvalidParameterValueException("identifier", identifier);
            }

            var process = processes[identifier];

            process.SetMemoryCache(this.Cache);

            ExecuteResponse executeResponse = process.SubmitExecuteProcess(payload as Execute);

            result.ResultObject = executeResponse;

            return(result);
        }
        /// <summary>
        /// Process operation request
        /// </summary>
        /// <param name="request"></param>
        /// <returns>Resposne object to be sent back to the client</returns>
        public override OperationResult ProcessRequest(HttpRequest request, OwsRequestBase payload = null)
        {
            var    nvc        = System.Web.HttpUtility.ParseQueryString(request.QueryString.Value);
            string identifier = nvc["Identifier"] ?? nvc["identifier"];

            //  Make sure there is valid request parameter
            if (string.IsNullOrEmpty(identifier))
            {
                throw new NoApplicableCodeException(string.Format(CultureInfo.CurrentCulture, "Process identifier is mandatory for DescribeProcess operation.", identifier));
            }

            OperationResult result = new OperationResult(request);

            var processes = this.GetProcesses();

            if (!processes.ContainsKey(identifier))
            {
                throw new InvalidParameterValueException("Identifier", identifier);
            }

            ProcessDescriptions processDescriptions = new ProcessDescriptions();

            processDescriptions.ProcessDescription = new List <ProcessDescriptionType>();

            foreach (var id in identifier.Split(','))
            {
                processDescriptions.ProcessDescription.Add(processes[id].ProcessDescription);
            }

            result.ResultObject = processDescriptions;

            return(result);
        }
        /// <summary>
        /// Process operation request
        /// </summary>
        /// <param name="request"></param>
        /// <returns>Resposne object to be sent back to the client</returns>
        public override OperationResult ProcessRequest(HttpRequest request, OwsRequestBase payload = null)
        {
            Terradue.ServiceModel.Ogc.Swes20.DescribeSensorType dsr = payload as Terradue.ServiceModel.Ogc.Swes20.DescribeSensorType;

            //  Make sure there is valid request parameter
            if (dsr == null)
            {
                throw new NoApplicableCodeException(string.Format(CultureInfo.CurrentCulture, "Type '{0}' is not supported by DescribeRequest operation.", payload.GetType().Name));
            }

            OperationResult result = new OperationResult(request);

            var sensor = this.SosEntitiesFactory.GetSensors();

            if (!sensor.ContainsKey(dsr.procedure))
            {
                throw new InvalidParameterValueException("procedure", dsr.procedure);
            }

            //  Get appropriate output formatter and execute it if available
            if (this.OutputFormatters.ContainsKey(dsr.procedureDescriptionFormat))
            {
                result.ResultObject = this.OutputFormatters[dsr.procedureDescriptionFormat](sensor[dsr.procedure]);
            }
            else
            {
                throw new InvalidParameterValueException("outputFormat", dsr.procedureDescriptionFormat);
            }

            return(result);
        }
        /// <summary>
        /// Process operation request
        /// </summary>
        /// <param name="request"></param>
        /// <returns>Resposne object to be sent back to the client</returns>
        public override OperationResult ProcessRequest(HttpRequest request, OwsRequestBase payload = null)
        {
            GetResourceByIdType grg = payload as GetResourceByIdType;

            //  Make sure there is valid request parameter
            if (grg == null)
            {
                throw new NoApplicableCodeException(string.Format(CultureInfo.CurrentCulture, "Type '{0}' is not supported by DescribeRequest operation.", request.GetType().FullName));
            }

            var result = new Terradue.ServiceModel.Ogc.Gml311.DictionaryType();

            //foreach (var resourceId in grg.ResourceID)
            //{
            //    var nameValue = this.UrnManager.GetUrnNameValue(resourceId);

            //    if (nameValue == null)
            //    {
            //        throw new InvalidParameterValueException("ResourceID", resourceId);
            //    }
            //    else
            //    {
            //        if (nameValue.Name.Equals("property", StringComparison.OrdinalIgnoreCase))
            //        {
            //            //<swe:Phenomenon gml:id="WaterTemperature">
            //            //<gml:description>Temperature of the water.</gml:description>
            //            //<gml:identifier codeSpace="urn:x-noaa:ioos:def:phenomenonNames">WaterTemperature</gml:identifier>
            //            //</swe:Phenomenon>

            //            using (var data = this.GetSosEntities())
            //            {
            //                var property = (from p in data.ObservedProperties
            //                                where p.Code == nameValue.Value
            //                                select p).FirstOrDefault();

            //                if (property == null)
            //                    throw new InvalidParameterValueException("ResourceID", resourceId);

            //                var phenomen = new PhenomenonType
            //                {
            //                    Id = property.Name,
            //                    Description = new StringOrRefType
            //                    {
            //                        Value = property.Description,
            //                    },
            //                };

            //                result.Items.Add(new DefinitionMember
            //                {
            //                    Definition = phenomen,
            //                });
            //            }

            //        }
            //    }
            //}

            return(new OperationResult(request)
            {
                ResultObject = result,
            });
        }
        /// <summary>
        /// Process operation request
        /// </summary>
        /// <param name="request"></param>
        /// <returns>Resposne object to be sent back to the client</returns>
        public override OperationResult ProcessRequest(HttpRequest request, OwsRequestBase payload = null)
        {
            GetCapabilities getCapabilities = payload as GetCapabilities;

            //  Validate request parameter
            if (getCapabilities == null)
            {
                throw new NoApplicableCodeException(string.Format(CultureInfo.CurrentCulture, "Type '{0}' is invalid request type.", request.GetType().FullName));
            }

            OperationResult result = new OperationResult(request);

            //  TODO:   Consider to implement updateSequence as described in OGC 06-121r3 7.3.4

            //  Validate acceptFormats parameter
            if (getCapabilities.AcceptFormats != null)
            {
                var formats = from sf in this._supportedFormats
                              from af in getCapabilities.AcceptFormats
                              where sf.ToStringValue() == af.Trim()
                              select sf;
                if (formats.Count() > 0)
                {
                    result.OutputFormat = formats.First();
                }
            }

            Capabilities capabilities = new Capabilities();

            //  Make sure client can accept current version of response
            if (getCapabilities.AcceptVersions != null && !getCapabilities.AcceptVersions.Contains(capabilities.Version))
            {
                throw new VersionNegotiationException(string.Format(CultureInfo.InvariantCulture, "Only '{0}' version is supported", capabilities.Version));
            }

            //  Make sure client can accept current formats
            if (getCapabilities.AcceptFormats != null)
            {
                bool supportedFormatFound = false;
                foreach (var format in getCapabilities.AcceptFormats)
                {
                    OutputFormat outputFormat;
                    supportedFormatFound = format.TryParseEnum <OutputFormat>(out outputFormat);
                    if (supportedFormatFound)
                    {
                        break;
                    }
                }
                if (!supportedFormatFound)
                {
                    throw new InvalidParameterValueException("Provided accept formats are not supported");
                }
            }

            //  TODO:   updateSequence currently not implemented
            //capabilities.UpdateSequence = DateTime.UtcNow.ToUnicodeStringValue();

            if (getCapabilities.Sections == null || getCapabilities.Sections.Contains("ServiceProvider"))
            {
                capabilities.ServiceProvider = this.GetServiceProvider();
            }

            if (getCapabilities.Sections == null || getCapabilities.Sections.Contains("ServiceIdentification"))
            {
                capabilities.ServiceIdentification = this.GetServiceIdentification();
            }

            if (getCapabilities.Sections == null || getCapabilities.Sections.Contains("OperationsMetadata"))
            {
                capabilities.OperationsMetadata = this.GetOperationsMetadata(this.Accessor, this.Cache, this.ServiceProvider);
            }

            if (getCapabilities.Sections == null || getCapabilities.Sections.Contains("ProcessOfferings"))
            {
                capabilities.ProcessOfferings = this.GetProcessOfferings();
            }

            if (getCapabilities.Sections == null || getCapabilities.Sections.Contains("Languages"))
            {
                capabilities.Languages = this.GetLanguages();
            }

            if (getCapabilities.Sections == null || getCapabilities.Sections.Contains("WSDL"))
            {
                capabilities.WSDL = this.GetWSDL();
            }

            result.ResultObject = capabilities;

            return(result);
        }
 /// <summary>
 /// Process request
 /// </summary>
 /// <param name="request"></param>
 /// <returns>Resposne object to be sent back to the client</returns>
 public override abstract OperationResult ProcessRequest(HttpRequest request, OwsRequestBase payload = null);
        /// <summary>
        /// Proccesses HTTP request
        /// </summary>
        /// <param name="request">Message with request details</param>
        /// <returns>Response to the request.</returns>
        public override OperationResult ProcessRequest()
        {
            OperationResult result = null;

            if (this.HttpAccessor == null || this.HttpAccessor.HttpContext == null || this.HttpAccessor.HttpContext.Request == null)
            {
                throw new Exception("Invalid Http context");
            }

            var request = this.HttpAccessor.HttpContext.Request;

            try {
                XDocument doc = null;

                if (request.Headers.ContentLength > 0)
                {
                    doc = XDocument.Load(request.Body, LoadOptions.None);
                }

                NameValueCollection queryParameters = HttpUtility.ParseQueryString(request.QueryString.Value);

                //  Apply doc or global defaults
                if (queryParameters["service"] == null)
                {
                    if (doc != null && doc.Root.Attribute("service") != null && !string.IsNullOrEmpty(doc.Root.Attribute("service").Value))
                    {
                        queryParameters.Add("service", doc.Root.Attribute("service").Value);
                    }
                    else
                    {
                        queryParameters.Add("service", ServiceConfiguration.Settings.DefaultService);
                    }
                }
                if (queryParameters["version"] == null)
                {
                    if (doc != null && doc.Root.Attribute("version") != null && !string.IsNullOrEmpty(doc.Root.Attribute("version").Value))
                    {
                        queryParameters.Add("version", doc.Root.Attribute("version").Value);
                    }
                    else
                    {
                        queryParameters.Add("version", ServiceConfiguration.Settings.DefaultVersion);
                    }
                }
                if (queryParameters["request"] == null)
                {
                    if (doc != null && !string.IsNullOrEmpty(doc.Root.Name.LocalName))
                    {
                        queryParameters.Add("request", doc.Root.Name.LocalName);
                    }
                    else
                    {
                        queryParameters.Add("request", ServiceConfiguration.Settings.DefaultRequest);
                    }
                }

                var operation = GetServiceOperation(doc, queryParameters);

                //  Apply operation specific defaults
                foreach (var defaultValue in operation.DefaultValues)
                {
                    if (queryParameters[defaultValue.Name] == null)
                    {
                        queryParameters.Add(defaultValue.Name, defaultValue.DefaultValue);
                    }
                }

                string cacheKey = string.Empty;

                if (operation.CacheEnabled)
                {
                    //  Create cache key to be used to store results in cache
                    cacheKey = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(request);

                    if (doc != null)
                    {
                        cacheKey = doc.CreateReader().ReadInnerXml();
                    }

                    //  Get cache results if exists
                    result = this.Cache.Get <OperationResult>(cacheKey);
                }

                if (result == null)
                {
                    //  Get request handler object for selected operation
                    BaseOperation requestHandler = operation.CreateHandlerInstance(this.HttpAccessor, this.Cache, this.ServiceProvider);

                    OwsRequestBase payload = null;

                    //  If xmlRequest is null then use query parameters to build an request object
                    if (doc == null)
                    {
                        payload = ActivatorUtilities.CreateInstance(this.ServiceProvider, requestHandler.RequestType, new object[] { queryParameters }) as OwsRequestBase;
                    }
                    else
                    {
                        XmlSerializer serializer = requestHandler.GetRequestTypeSerializer();
                        payload = serializer.Deserialize(doc.CreateReader()) as OwsRequestBase;
                    }

                    payload.Validate();

                    //  Hanle request and return results back
                    result = requestHandler.ProcessRequest(request, payload);

                    if (result != null && operation.CacheEnabled)
                    {
                        this.Cache.Set <OperationResult>(cacheKey, result);
                    }
                }

                //  Performs special service operation if specified
                if ((from k in queryParameters.AllKeys
                     where k.StartsWith("$$", StringComparison.OrdinalIgnoreCase)
                     select k).Count() > 0)
                {
                    result = HandleCustomAction(result, queryParameters);
                }
            } catch (OgcException exp) {
                //  Handle OGC specific errors
                result = new OperationResult(request)
                {
                    ResultObject = exp.ExceptionReport,
                };
            } catch (System.Exception exp) {
                //  Handle all other .NET errors
                result = new OperationResult(request)
                {
                    ResultObject = new NoApplicableCodeException("Application error.", exp).ExceptionReport,
                };
            }

            return(result);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Process operation request
 /// </summary>
 /// <param name="request"></param>
 /// <returns>Resposne object to be sent back to the client</returns>
 public override OperationResult ProcessRequest(HttpRequest request, OwsRequestBase payload = null)
 {
     throw new NotImplementedException();
 }