Ejemplo n.º 1
0
        public override bool Parse(string str, ProcessDescription processDescription)
        {
            if (String.IsNullOrEmpty(str))
            {
                return(false);
            }

            string[] tokens = str.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            ExceptionReport exception = null;

            foreach (string param in tokens)
            {
                string[] kv = param.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
                if (kv.Length > 0)
                {
                    OutputData output = processDescription.GetProcessOutputParameter(kv[0]);
                    if (output != null)
                    {
                        OutputData myoutput = output.Clone();
                        try
                        {
                            myoutput.Parse(param);
                            Outputs.Add(myoutput);
                        }
                        catch (ExceptionReport e)
                        {
                            exception = new ExceptionReport(e, exception);
                        }
                    }
                    else
                    {
                        exception = new ExceptionReport(exception, "The output "
                                                        + kv[0] + " is not a valid output for the process " + processDescription.Identifier,
                                                        ExceptionCode.InvalidParameterValue, "responseDocument");
                    }
                }
            }

            if (exception != null)
            {
                throw exception;
            }

            return(tokens.Length != 0);
        }
Ejemplo n.º 2
0
        public override bool Parse(string str, ProcessDescription processDescription)
        {
            if (String.IsNullOrEmpty(str))
            {
                return(false);
            }

            string[] tokens = str.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length != 1)
            {
                throw new ExceptionReport("One identifier is mandatory when requesting a raw data output but "
                                          + tokens.Length + " were found.",
                                          ExceptionCode.InvalidParameterValue, "RawDataOutput");
            }

            string[] kv = str.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
            if (kv.Length > 0)
            {
                OutputData outputData = processDescription.GetProcessOutputParameter(kv[0]);
                if (outputData == null)
                {
                    throw new ExceptionReport(String.Format("The output {0} is not a valid output for the process {1}",
                                                            kv[0], processDescription.Identifier), ExceptionCode.InvalidParameterValue, "rawDataOutput");
                }

                ComplexOutput output = outputData.asComplexOutput();
                if (output == null)
                {
                    throw new ExceptionReport(String.Format("Only ComplexOutputs can be requested as rawDataOutput but {0} is a {1}",
                                                            kv[0], outputData.GetType().ToString()), ExceptionCode.InvalidParameterValue, "rawDataOutput");
                }

                Identifier = kv[0];
                Format     = output.Format; // default format
                Format.ParseValue(str);
                if (output.Formats.Find(delegate(ComplexFormat cf) { return(cf.Equals(Format)); }) == null)
                {
                    throw new ExceptionReport(string.Format("Requested format for the output {0} is not supported", kv[0]),
                                              ExceptionCode.InvalidParameterValue, kv[0]);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override bool Parse(XmlNode node, ProcessDescription processDescription)
        {
            if (node == null)
            {
                return(false);
            }

            XmlNamespaceManager nsmgr = Utils.CreateWPSNamespaceManager(node.OwnerDocument);

            XmlNodeList childs = node.SelectNodes("ows:Identifier", nsmgr);

            if (childs.Count != 1)
            {
                throw new ExceptionReport("One identifier is mandatory when requesting a raw data output but " + childs.Count + " were found.",
                                          ExceptionCode.InvalidParameterValue, "wps:RawDataOutput/ows:Identifier");
            }
            Identifier = childs[0].InnerText;
            OutputData outputData = processDescription.GetProcessOutputParameter(Identifier);

            if (outputData == null)
            {
                throw new ExceptionReport(String.Format("The output {0} is not a valid output for the process {1}",
                                                        Identifier, processDescription.Identifier), ExceptionCode.InvalidParameterValue, "rawDataOutput");
            }

            ComplexOutput processOutput = outputData.asComplexOutput();

            if (processOutput == null)
            {
                throw new ExceptionReport(String.Format("Only ComplexOutputs can be requested as rawDataOutput but {0} is a {1}",
                                                        Identifier, outputData.GetType().Name), ExceptionCode.InvalidParameterValue, "rawDataOutput");
            }

            Format = processOutput.Format;
            Format.ParseValue(node);
            return(true);
        }
Ejemplo n.º 4
0
        public static XmlDocument Run(ProcessDescription processDescription, List <InputData> inputParams, ResponseFormType responseForm)
        {
            /* error is unreachable because check (via throwing an exception) is done before
             * if (processDescription == null)
             *  throw new ExceptionReport("The ows:Identifier tag of the process can't be found in the xml file. It must be placed under the root 'Execute' node.",
             *      ExceptionCode.MissingParameterValue);*/

            string processId = processDescription.Identifier;

            List <InputData>  processInputParams  = processDescription.GetProcessInputParameters();
            List <OutputData> processOutputParams = processDescription.GetProcessOutputParameters();

            ExceptionReport exception = null;

            ProcessInputParams args = new ProcessInputParams();

            // Get and check input parameters
            foreach (InputData processInputParam in processInputParams)
            {
                int              occurs = 0;
                bool             loop   = processInputParam.MaxOccurs > 0 || processInputParam.MaxOccurs == -1;
                List <InputData> iargs  = new List <InputData>();
                while (loop)
                {
                    loop = false;
                    foreach (InputData input in inputParams)
                    {
                        if (input.Identifier != processInputParam.Identifier)
                        {
                            continue;
                        }
                        if (!input.IsValueAllowed())
                        {
                            exception = new ExceptionReport(exception, "The parameter "
                                                            + input.Identifier + " has not a valid value!",
                                                            ExceptionCode.InvalidParameterValue, input.Identifier);
                        }
                        occurs++;
                        iargs.Add(input.Clone());
                        inputParams.Remove(input);
                        loop = true;
                        break;
                    }
                }

                if (occurs < processInputParam.MinOccurs || (occurs > processInputParam.MaxOccurs && processInputParam.MaxOccurs != -1))
                {
                    exception = new ExceptionReport(exception, "The parameter "
                                                    + processInputParam.Identifier + " has " + occurs
                                                    + " occurrences but it should have at least " + processInputParam.MinOccurs
                                                    + " and at most " + processInputParam.MaxOccurs + " occurrences.",
                                                    ExceptionCode.InvalidParameterValue, processInputParam.Identifier);
                }

                // default value for LiteralData
                if (occurs == 0 && processInputParam.asLiteralInput() != null &&
                    !String.IsNullOrEmpty(processInputParam.asLiteralInput().Default))
                {
                    iargs.Add(processInputParam);
                }

                args.parameters[processInputParam.Identifier] = iargs.ToArray();
            }

            if (exception != null)
            {
                throw exception;
            }

            ProcessReturnValue result = null;

            try
            {
                processDescription = ProcessDescription.GetProcessDescription(processId);
                if (responseForm.responseDocument != null && responseForm.responseDocument.status && responseForm.responseDocument.storeExecuteResponse)
                {
                    result = processDescription.CallProcess(args, responseForm, true);
                }
                else
                {
                    result = processDescription.CallProcess(args, responseForm, false);
                }
            }
            catch (ExceptionReport e)
            {
                if (responseForm.responseDocument != null && responseForm.responseDocument.status)
                {
                    exception = e;
                }
                else
                {
                    throw;// new ExceptionReport(e, "Error during process...", ExceptionCode.NoApplicableCode);
                }
            }

            int requestedOutputCount = result.GetOutputIdentifiers().Count;
            int returnedOutputCount  = result.returnValues.Count;

            // Problem during the process (validity check is done before launching the process)!
            if (requestedOutputCount != returnedOutputCount)
            {
                throw new ExceptionReport(String.Format("The process has generated {0} output{1} but {2} {3} requested. Contact the administrator to fix the process issue.",
                                                        returnedOutputCount, returnedOutputCount > 1 ? "s" : "",
                                                        requestedOutputCount, requestedOutputCount > 1 ? "were" : "was"),
                                          ExceptionCode.NoApplicableCode);
            }

            if (responseForm.outputDefinition != null)
            {
                OutputData data = result.returnValues[0];

                if (result.fileName == "")
                {
                    result.fileName = processId + "RawDataOuput";
                }
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.StatusCode = 200;
                HttpContext.Current.Response.Buffer     = true;
                // not needed because rawdataoutput can only concern a ComplexOutput
                //string mimeType = (data is ComplexOutput) ? ((ComplexOutput)data).format.mimeType : "text/plain";
                string mimeType = data.asComplexOutput().Format.mimeType;
                HttpContext.Current.Response.ContentType = mimeType;
                string dispo = true ? "inline" : "attachment";
                HttpContext.Current.Response.AddHeader("Content-Disposition", dispo + "; filename=" + System.Uri.EscapeDataString(result.fileName));
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
                byte[] content = data.ToByteArray();
                HttpContext.Current.Response.AddHeader("Content-Length", "" + content.Length);
                HttpContext.Current.Response.AddHeader("cache-control", "must-revalidate");
                HttpContext.Current.Response.OutputStream.Write(content, 0, content.Length);
                HttpContext.Current.Response.Flush();
                HttpContext.Current.ApplicationInstance.CompleteRequest();

                return(new XmlDocument());
            }
            else
            {
                s_processStartDate = DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss_ffff");
                s_processArgs      = args;

                s_responseHeader = Global.XmlHeader + "<wps:ExecuteResponse " + Global.WPSServiceVersion
                                   + " xml:lang='" + processDescription.Language + "' serviceInstance='"
                                   + HttpContext.Current.Request.Url.AbsoluteUri.Split('?')[0]
                                   + "?service=WPS&amp;Request=GetCapabilities' "
                                   + Global.WPSXmlSchemas + " " + Global.WPSExecuteSchema
                                   /** In case of storeExecuteResponse==true : append the absolute url to the stored response file */
                                   /**/ + (responseForm.responseDocument.storeExecuteResponse ? " statusLocation='"
                                           /**/ + Utils.ResolveUrl(Global.StoredResponsesPath
                                                                   /**/ + processDescription.processClass + "/response_"
                                                                   /**/ + s_processStartDate + ".xml' ") : " ")
                                   /************************************************************************************************/
                                   + ">" + Environment.NewLine
                                   + "<wps:Process wps:processVersion=\"" + processDescription.Version + "\"><ows:Identifier>" + processDescription.Identifier + "</ows:Identifier><ows:Title>"
                                   + processDescription.Title + "</ows:Title></wps:Process>"; //TODO: retiré 'wps:'

                XmlDocument xmlResponse = FormatResponseMessage(processDescription, s_processArgs, responseForm, result, exception, s_responseHeader);

                if (responseForm.responseDocument.storeExecuteResponse)
                {
                    if (!Directory.Exists(Global.StoredResponsesPath + "/" + processDescription.processClass))
                    {
                        Directory.CreateDirectory(Global.StoredResponsesPath + "/" + processDescription.processClass);
                    }

                    xmlResponse.Save(Global.StoredResponsesPath + processDescription.processClass + "/response_" + s_processStartDate + ".xml");
                }

                HttpContext.Current.Response.StatusCode = 200;
                return(xmlResponse);
            }
        }
Ejemplo n.º 5
0
 public void AddData(OutputData data)
 {
     returnValues.Add(data);
 }
Ejemplo n.º 6
0
        public override bool Parse(XmlNode node, ProcessDescription processDescription)
        {
            if (node == null)
            {
                return(false);
            }

            // Create an XmlNamespaceManager for resolving namespaces.
            XmlNamespaceManager nsmgr = Utils.CreateWPSNamespaceManager(node.OwnerDocument);

            lineage = Boolean.Parse(Utils.GetXmlAttributesValue(node, "lineage", "false"));
            status  = Boolean.Parse(Utils.GetXmlAttributesValue(node, "status", "false"));
            storeExecuteResponse = Boolean.Parse(Utils.GetXmlAttributesValue(node, "storeExecuteResponse", "false"));

            XmlNodeList outputs = node.SelectNodes("wps:Output", nsmgr);

            if (outputs.Count == 0)
            {
                throw new ExceptionReport(String.Format("No 'wps:Output' node was found inside the 'wps:ResponseDocument' node for the process '{0}'. Please check your request.",
                                                        processDescription.Identifier),
                                          ExceptionCode.MissingParameterValue, processDescription.Identifier);
            }

            ExceptionReport exception = null;

            foreach (XmlNode output in outputs)
            {
                XmlNode id    = output.SelectSingleNode("ows:Identifier", nsmgr);
                XmlNode abst  = output.SelectSingleNode("ows:Abstract", nsmgr);
                XmlNode title = output.SelectSingleNode("ows:Title", nsmgr);

                string identifier = id.InnerText;
                string titleStr   = title != null ? title.InnerText : "";
                string abstStr    = abst != null ? abst.InnerText : "";

                OutputData processOutput = processDescription.GetProcessOutputParameter(identifier);
                if (processOutput != null)
                {
                    OutputData myoutput = processOutput.Clone();
                    myoutput.Title       = titleStr;
                    myoutput.Abstract    = abstStr;
                    myoutput.asReference = Boolean.Parse(Utils.GetXmlAttributesValue(output, "asReference", "false"));
                    if (myoutput.asReference && !processDescription.storeSupported)
                    {
                        exception = new ExceptionReport(exception,
                                                        String.Format("The storage of response is not supported for the process {0} but is requested for the output {1}.",
                                                                      processDescription.Identifier, identifier),
                                                        ExceptionCode.StorageNotSupported);
                    }
                    try
                    {
                        myoutput.Parse(output);
                        Outputs.Add(myoutput);
                    }
                    catch (ExceptionReport e)
                    {
                        exception = new ExceptionReport(e, exception);
                    }
                }
                else
                {
                    exception = new ExceptionReport(exception, String.Format("The output {0} is not a valid output for the process {1}",
                                                                             identifier, processDescription.Identifier), ExceptionCode.InvalidParameterValue, "responseDocument");
                }
            }

            if (exception != null)
            {
                throw exception;
            }

            return(true);
        }
Ejemplo n.º 7
0
 public void AddData(OutputData data)
 {
     returnValues.Add(data);
 }