Ejemplo n.º 1
0
        public bool Parse(ProcessDescription processDescription)
        {
            string responseDocumentParam = Utils.DecodeURI(Utils.GetParameter("ResponseDocument"));
            string rawDataOutputParam    = Utils.DecodeURI(Utils.GetParameter("RawDataOutput"));

            if (!String.IsNullOrEmpty(responseDocumentParam))
            {
                if (!String.IsNullOrEmpty(rawDataOutputParam))
                {
                    throw new ExceptionReport("Only one kind of ResponseForm is allowed, but ResponseDocument and RawDataOutput were found!", ExceptionCode.InvalidParameterValue, "ResponseForm");
                }

                responseDocument         = new ResponseDocumentType("wps:ResponseDocument");
                responseDocument.lineage = Boolean.Parse(Utils.GetParameter("lineage", "false"));
                responseDocument.status  = Boolean.Parse(Utils.GetParameter("status", "false"));
                responseDocument.storeExecuteResponse = Boolean.Parse(Utils.GetParameter("storeExecuteResponse", "false"));

                responseDocument.Parse(responseDocumentParam, processDescription);
            }
            else if (!String.IsNullOrEmpty(rawDataOutputParam))
            {
                outputDefinition = new OutputDefinitionType("wps:RawDataOutput");
                outputDefinition.Parse(rawDataOutputParam, processDescription);
            }
            else
            {
                // include all responses because no requested identifier was provided
                responseDocument = new ResponseDocumentType("wps:ResponseDocument");
                responseDocument.Outputs.AddRange(processDescription.GetProcessOutputParameters());
                responseDocument.lineage = Boolean.Parse(Utils.DecodeURI(Utils.GetParameter("lineage", "false")));
                responseDocument.status  = Boolean.Parse(Utils.DecodeURI(Utils.GetParameter("status", "false")));
                responseDocument.storeExecuteResponse = Boolean.Parse(Utils.DecodeURI(Utils.GetParameter("storeExecuteResponse", "false")));
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static ProcessDescription GetProcessDescription(string processId)
        {
            AppDomain mainDomain = AppDomain.CurrentDomain;
            // A secondary operation domain has to be used so that the assemblies can be loaded/unloaded, as the function Assembly
            AppDomain          operationDomain = null;
            ProcessDescription result          = null;

            try
            {
                operationDomain = Utils.CreateDomain();
                Utils.AssemblyLoader assemblyLoader = Utils.AssemblyLoader.Create(operationDomain);
                assemblyLoader.Load(Utils.MapPath(Global.ProcessesBinPath + processId + ".dll"));
                result = (ProcessDescription)assemblyLoader.ExecuteMethod("WPSProcess." + processId, "GetDescription", null, null);
                AppDomain.Unload(operationDomain);
            }
            catch (Exception /*e*/)
            {
                if (operationDomain != null)
                {
                    AppDomain.Unload(operationDomain);
                }
                throw new ExceptionReport("Unable to retrieve the description of the process '" + processId + "'.\nEnsure that the Identifier parameter really is the name of a service proposed on this server. The name is case dependent. The name of the available processes can be get with the GetCapabilities operation.", ExceptionCode.InvalidParameterValue, "Identifier");
            }

            return(result);
        }
Ejemplo n.º 3
0
 public ProcessData(ProcessReturnValue executeResponseValue, ProcessDescription processDescription, AppDomain parentAppDomain, AppDomain processAppDompain, int processProgress, Exception processError = null)
 {
     this.ExecuteResponseValue    = executeResponseValue;
     this.ParentApplicationDomain = parentAppDomain;
     this.ProcessDescription      = processDescription;
     this.Error = processError;
     this.ProcessApplicationDomain = processAppDompain;
     this.Progress = processProgress;
 }
 public ProcessData(ProcessReturnValue executeResponseValue, ProcessDescription processDescription, AppDomain parentAppDomain, AppDomain processAppDompain, int processProgress, Exception processError = null)
 {
     this.ExecuteResponseValue = executeResponseValue;
     this.ParentApplicationDomain = parentAppDomain;
     this.ProcessDescription = processDescription;
     this.Error = processError;
     this.ProcessApplicationDomain = processAppDompain;
     this.Progress = processProgress;
 }
Ejemplo n.º 5
0
        public static XmlDocument Run(string[] processes, string Language)
        {
            StringBuilder retString = new StringBuilder();

            retString.Append(Global.XmlHeader + "<wps:ProcessDescriptions " + Global.WPSServiceVersion + " xml:lang='" + Language + "' " + Global.WPSXmlSchemas + " " + Global.WPSDescribeProcessSchema + ">");

            // On identifier is ALL, catch all the available processes
            if (processes.Length == 1 && Utils.StrICmp(processes[0], "ALL"))
            {
                ProcessDescription[] processDescriptions = GetCapabilities.getAvailableProcesses();
                foreach (ProcessDescription process in processDescriptions)
                {
                    retString.Append(process.GetProcessDescriptionDocument());
                }
            }
            else
            {
                ExceptionReport exception = null;

                // Loop through all the processes and get process description
                foreach (string processId in processes)
                {
                    try
                    {
                        retString.Append(ProcessDescription.GetProcessDescription(processId).GetProcessDescriptionDocument());
                    }
                    catch (ExceptionReport e)
                    {
                        exception = new ExceptionReport(e, exception);
                    }
                }

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

            retString.Append("</wps:ProcessDescriptions>");

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(retString.ToString());
                HttpContext.Current.Response.StatusCode = 200;
                return(doc);
            }
            catch (XmlException ex)
            {
                throw new ExceptionReport("Unable to generate the description document. Contact the administrator." + ex.ToString());
            }
        }
Ejemplo n.º 6
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.º 7
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.º 8
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.º 9
0
        public override bool Parse(XmlNode node, ProcessDescription processDescription)
        {
            if (node == null)
            {
                // include all responses because no requested identifier was provided
                responseDocument = new ResponseDocumentType("wps:ResponseDocument");
                responseDocument.Outputs.AddRange(processDescription.GetProcessOutputParameters());
                return(true);
            }

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

            XmlNode rawDataOutputNode = node.SelectSingleNode("wps:RawDataOutput", nsmgr);
            XmlNode responseDocNode   = node.SelectSingleNode("wps:ResponseDocument", nsmgr);

            if (responseDocNode != null)
            {
                if (rawDataOutputNode != null)
                {
                    throw new ExceptionReport("Only one kind of ResponseForm is allowed, but ResponseDocument and RawDataOutput were found!", ExceptionCode.InvalidParameterValue,
                                              "ResponseForm");
                }

                responseDocument = new ResponseDocumentType("wps:ResponseDocument");
                return(responseDocument.Parse(responseDocNode, processDescription));
            }
            else if (rawDataOutputNode != null)
            {
                outputDefinition = new OutputDefinitionType("wps:RawDataOutput");
                return(outputDefinition.Parse(rawDataOutputNode, processDescription));
            }
            else
            {
                throw new ExceptionReport("A ResponseForm is provided, but neither ResponseDocument nor RawDataOutput element was found!", ExceptionCode.MissingParameterValue, "wps:ResponseForm");
            }
        }
Ejemplo n.º 10
0
        // Return the available processes (for which a dll is present and an xml description file is associated)
        public static ProcessDescription[] getAvailableProcesses()
        {
            // Search all the DLL files could contain process operations
            string[] processDLLPath;
            try
            {
                processDLLPath = Directory.GetFiles(Utils.MapPath(Global.ProcessesBinPath), "*.dll");
            }
            catch
            {
                throw new ExceptionReport("Unable to retrieve the list of assemblies containing the processes available on the server. Contact the administrator.");
            }

            // Retrieve the name of all the available processes
            List <string> processIdList = new List <string>();

            for (int i = 0; i < processDLLPath.Length; i++)
            {
                string processDllName = processDLLPath[i].Substring(processDLLPath[i].LastIndexOf("\\") + 1, processDLLPath[i].IndexOf(".dll") - processDLLPath[i].LastIndexOf("\\") - 1);
                processIdList.Add(processDllName);
            }

            List <ProcessDescription> processes = new List <ProcessDescription>();

            foreach (string processId in processIdList)
            {
                try
                {
                    processes.Add(ProcessDescription.GetProcessDescription(processId));
                }
                catch
                {
                }
            }

            return(processes.ToArray());
        }
Ejemplo n.º 11
0
        public ProcessDescription GetDescription()
        {
            ProcessDescription process = new ProcessDescription("Calculator", "Calculator", "Basic operations through WPS", "1.1");
            LiteralInput oper = new LiteralInput("operator", "operator", "abstract operator", "string", "add");
            oper.AllowedValues.AddRange(new string[] { "add", "sub", "mult", "div"});
            process.inputs.Add(oper);

            process.inputs.Add(new ComplexInput("a", "operand a", "abstract a", new ComplexFormat("text/xml", "uf8", "myschema.xsd")));
            process.inputs.Add(new ComplexInput("b", "operand b", "abstract b", new ComplexFormat("text/xml", "uf8", "myschema.xsd")));
            process.outputs.Add(new ComplexOutput("result", "result of operation as file", "raw abstract result of operation as file", new ComplexFormat("text/xml", "utf8", "myschema.xsd")));
            return process;
        }
Ejemplo n.º 12
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.º 13
0
 public virtual bool Parse(XmlNode node, ProcessDescription processDescription)
 {
     return(false);
 }
Ejemplo n.º 14
0
 public virtual bool Parse(string str, ProcessDescription processDescription)
 {
     return false;
 }
Ejemplo n.º 15
0
 public virtual bool Parse(string str, ProcessDescription processDescription)
 {
     return(false);
 }
Ejemplo n.º 16
0
        public bool Parse(ProcessDescription processDescription)
        {
            string responseDocumentParam = Utils.DecodeURI(Utils.GetParameter("ResponseDocument"));
            string rawDataOutputParam = Utils.DecodeURI(Utils.GetParameter("RawDataOutput"));

            if (!String.IsNullOrEmpty(responseDocumentParam))
            {
                if (!String.IsNullOrEmpty(rawDataOutputParam))
                    throw new ExceptionReport("Only one kind of ResponseForm is allowed, but ResponseDocument and RawDataOutput were found!", ExceptionCode.InvalidParameterValue, "ResponseForm");

                responseDocument = new ResponseDocumentType("wps:ResponseDocument");
                responseDocument.lineage = Boolean.Parse(Utils.GetParameter("lineage", "false"));
                responseDocument.status = Boolean.Parse(Utils.GetParameter("status", "false"));
                responseDocument.storeExecuteResponse = Boolean.Parse(Utils.GetParameter("storeExecuteResponse", "false"));

                responseDocument.Parse(responseDocumentParam, processDescription);
            }
            else if (!String.IsNullOrEmpty(rawDataOutputParam))
            {
                outputDefinition = new OutputDefinitionType("wps:RawDataOutput");
                outputDefinition.Parse(rawDataOutputParam, processDescription);
            }
            else
            {
                // include all responses because no requested identifier was provided
                responseDocument = new ResponseDocumentType("wps:ResponseDocument");
                responseDocument.Outputs.AddRange(processDescription.GetProcessOutputParameters());
                responseDocument.lineage = Boolean.Parse(Utils.DecodeURI(Utils.GetParameter("lineage", "false")));
                responseDocument.status = Boolean.Parse(Utils.DecodeURI(Utils.GetParameter("status", "false")));
                responseDocument.storeExecuteResponse = Boolean.Parse(Utils.DecodeURI(Utils.GetParameter("storeExecuteResponse", "false")));
            }
            return true;
        }
Ejemplo n.º 17
0
 public virtual bool Parse(XmlNode node, ProcessDescription processDescription)
 {
     return false;
 }
Ejemplo n.º 18
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.º 19
0
        public override bool Parse(XmlNode node, ProcessDescription processDescription)
        {
            if (node == null)
            {
                // include all responses because no requested identifier was provided
                responseDocument = new ResponseDocumentType("wps:ResponseDocument");
                responseDocument.Outputs.AddRange(processDescription.GetProcessOutputParameters());
                return true;
            }

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

            XmlNode rawDataOutputNode = node.SelectSingleNode("wps:RawDataOutput", nsmgr);
            XmlNode responseDocNode = node.SelectSingleNode("wps:ResponseDocument", nsmgr);

            if (responseDocNode != null)
            {
                if (rawDataOutputNode != null)
                    throw new ExceptionReport("Only one kind of ResponseForm is allowed, but ResponseDocument and RawDataOutput were found!", ExceptionCode.InvalidParameterValue,
                        "ResponseForm");

                responseDocument = new ResponseDocumentType("wps:ResponseDocument");
                return responseDocument.Parse(responseDocNode, processDescription);
            }
            else if (rawDataOutputNode != null)
            {
                outputDefinition = new OutputDefinitionType("wps:RawDataOutput");
                return outputDefinition.Parse(rawDataOutputNode, processDescription);
            }
            else
                throw new ExceptionReport("A ResponseForm is provided, but neither ResponseDocument nor RawDataOutput element was found!", ExceptionCode.MissingParameterValue, "wps:ResponseForm");
        }
Ejemplo n.º 20
0
        private static XmlDocument FormatResponseMessage(ProcessDescription processDescription, ProcessInputParams args, ResponseFormType responseForm, ProcessReturnValue result, ExceptionReport exception, string xmlHeader = "")
        {
            // Format the response message

            StringBuilder retString = new StringBuilder();

            retString.Append(xmlHeader);

            /*
            if (responseForm.responseDocument.status)
                {*/
                retString.Append("<wps:Status creationTime=\"" + System.DateTime.Now.ToString("s") + "\">");

                if (result.status == ProcessState.Succeeded)
                {
                        retString.Append("<wps:ProcessSucceeded>" + (result.statusMessage != "" ? result.statusMessage : "Process completed successfully.") + "</wps:ProcessSucceeded>");  //TODO: retiré 'wps:'
                }
                else if (result.status == ProcessState.Accepted)
                {
                        retString.Append("<wps:ProcessAccepted>" + (result.statusMessage != "" ? result.statusMessage : "Process has been accepted and is pending execution.") + "</wps:ProcessAccepted>");  //TODO: retiré 'wps:'
                }
                else if (result.status == ProcessState.Paused)
                {
                        retString.Append("<wps:ProcessPaused percentCompleted=\""+result.percentageCompleted+"\" >" + (result.statusMessage != "" ? result.statusMessage : "Process is paused.") + "</wps:ProcessPaused>");
                }
                else if (result.status == ProcessState.Started)
                {
                        retString.Append("<wps:ProcessStarted percentCompleted=\""+result.percentageCompleted+"\" >" + (result.statusMessage != "" ? result.statusMessage : "Process is running.") + "</wps:ProcessStarted>");
                }
                else if (result.status == ProcessState.Failed)
                {
                        retString.Append("<wps:ProcessFailed>" + (exception != null ? exception.GetReport().InnerText + " - " + result.statusMessage
                        : new ExceptionReport("Failed to execute WPS process : "+result.statusMessage, ExceptionCode.NoApplicableCode).GetReport().InnerText)
                    + "</wps:ProcessFailed>");
                }

                retString.Append("</wps:Status>");
             //   }

            if (responseForm.responseDocument.lineage)
            {
                retString.Append("<wps:DataInputs>");
                foreach (KeyValuePair<string, InputData[]> ent in args.parameters)
                    foreach (InputData processInputParam in ent.Value)
                        retString.Append(processInputParam.GetXmlValue());
                retString.Append("</wps:DataInputs>");

                retString.Append("<wps:OutputDefinitions>");
                // TODO do not retrieve output from return values (may not be the same as request)
                //foreach (OutputData processOutputParam in result.returnValues)
                foreach (OutputData processOutputParam in responseForm.responseDocument.Outputs)
                    retString.Append(processOutputParam.GetXmlDescription());
                retString.Append("</wps:OutputDefinitions>");
            }

            if (result.returnValues.Count > 0)
            {
                retString.Append("<wps:ProcessOutputs>");
                foreach (OutputData outputData in result.returnValues)
                    retString.Append(outputData.GetXmlValue());
                retString.Append("</wps:ProcessOutputs>");
            }
            retString.Append("</wps:ExecuteResponse>");

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(retString.ToString());
                return doc;
            }
            catch (Exception e)
            {
                throw new ExceptionReport("The service execution has encountered an error while formatting the result stream. Check the parameters values.\n" + e.ToString());
            }
        }
Ejemplo n.º 21
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.º 22
0
        private static XmlDocument FormatResponseMessage(ProcessDescription processDescription, ProcessInputParams args, ResponseFormType responseForm, ProcessReturnValue result, ExceptionReport exception, string xmlHeader = "")
        {
            // Format the response message

            StringBuilder retString = new StringBuilder();

            retString.Append(xmlHeader);

            /*
             * if (responseForm.responseDocument.status)
             *  {*/
            retString.Append("<wps:Status creationTime=\"" + System.DateTime.Now.ToString("s") + "\">");

            if (result.status == ProcessState.Succeeded)
            {
                retString.Append("<wps:ProcessSucceeded>" + (result.statusMessage != "" ? result.statusMessage : "Process completed successfully.") + "</wps:ProcessSucceeded>");          //TODO: retiré 'wps:'
            }
            else if (result.status == ProcessState.Accepted)
            {
                retString.Append("<wps:ProcessAccepted>" + (result.statusMessage != "" ? result.statusMessage : "Process has been accepted and is pending execution.") + "</wps:ProcessAccepted>");          //TODO: retiré 'wps:'
            }
            else if (result.status == ProcessState.Paused)
            {
                retString.Append("<wps:ProcessPaused percentCompleted=\"" + result.percentageCompleted + "\" >" + (result.statusMessage != "" ? result.statusMessage : "Process is paused.") + "</wps:ProcessPaused>");
            }
            else if (result.status == ProcessState.Started)
            {
                retString.Append("<wps:ProcessStarted percentCompleted=\"" + result.percentageCompleted + "\" >" + (result.statusMessage != "" ? result.statusMessage : "Process is running.") + "</wps:ProcessStarted>");
            }
            else if (result.status == ProcessState.Failed)
            {
                retString.Append("<wps:ProcessFailed>" + (exception != null ? exception.GetReport().InnerText + " - " + result.statusMessage
                        : new ExceptionReport("Failed to execute WPS process : " + result.statusMessage, ExceptionCode.NoApplicableCode).GetReport().InnerText)
                                 + "</wps:ProcessFailed>");
            }

            retString.Append("</wps:Status>");
            //   }

            if (responseForm.responseDocument.lineage)
            {
                retString.Append("<wps:DataInputs>");
                foreach (KeyValuePair <string, InputData[]> ent in args.parameters)
                {
                    foreach (InputData processInputParam in ent.Value)
                    {
                        retString.Append(processInputParam.GetXmlValue());
                    }
                }
                retString.Append("</wps:DataInputs>");

                retString.Append("<wps:OutputDefinitions>");
                // TODO do not retrieve output from return values (may not be the same as request)
                //foreach (OutputData processOutputParam in result.returnValues)
                foreach (OutputData processOutputParam in responseForm.responseDocument.Outputs)
                {
                    retString.Append(processOutputParam.GetXmlDescription());
                }
                retString.Append("</wps:OutputDefinitions>");
            }

            if (result.returnValues.Count > 0)
            {
                retString.Append("<wps:ProcessOutputs>");
                foreach (OutputData outputData in result.returnValues)
                {
                    retString.Append(outputData.GetXmlValue());
                }
                retString.Append("</wps:ProcessOutputs>");
            }
            retString.Append("</wps:ExecuteResponse>");

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(retString.ToString());
                return(doc);
            }
            catch (Exception e)
            {
                throw new ExceptionReport("The service execution has encountered an error while formatting the result stream. Check the parameters values.\n" + e.ToString());
            }
        }
Ejemplo n.º 23
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.º 24
0
        /// <summary>
        /// This method is called by the DescribeProcess part of WPS.NET, it must be implemented.
        /// </summary>
        /// <returns>The process description</returns>
        public override ProcessDescription GetDescription()
        {
            ///This is where we create the process description
            ProcessDescription process = new ProcessDescription("AsyncClock", "Async Clock", "Counts a user-defined number of seconds asynchronously (This is an example of async process for developpers)", "1.1");

            ///This check is meant to make sure everything is in it's place so that the process
            ///can be called asynchronously without failing miserably.
            if (this is IAsyncProcess && this.MainAppDomain != null)
            {
                ///Is this process implements IAsyncProcess and if the Main Application Domain is provided,
                ///we can assume that status will be supported (provided status updates are properly coded).
                process.statusSupported = true;

                if (this.BaseUrlToResultPath != String.Empty && this.StoredResultPath != string.Empty)
                    ///If the necessary informations for responses and results storage are provided
                    ///we can enable storage support.
                    process.storeSupported = true;
            }

            ///This is the declaration of the numberOfSeconds parameter
            ///It has 1 minoccurs and 1 maxoccurs, it is mandatory.
            LiteralInput numberOfSeconds = new LiteralInput("numberOfSeconds", "Number of seconds", "The number of seconds this process will count", "integer", "100");
            numberOfSeconds.MinOccurs = 1;
            numberOfSeconds.MaxOccurs = 1;

            ///Dont forget to add the previously created parameter in the inputs collection of the process.
            process.inputs.Add(numberOfSeconds);

            ///A start date should be also specified
            process.processStartDate = this.startDate;

            ///Specify the output of the process
            LiteralOutput output = new LiteralOutput("AsyncClockResult", "Async Clock Result", "A string containing the start datetime and the end datetime", "string");
            output.Value = String.Empty;
            process.outputs.Add(output);

            ///Return the description of the process.
            return process;
        }
Ejemplo n.º 25
0
 public ProcessDescription GetDescription()
 {
     ProcessDescription process = new ProcessDescription("Add", "Add", "(a + b) through WPS", "1.1");
     LiteralInput a = new LiteralInput("a", "operand a", "abstract a", "integer", "88");
     a.MinOccurs = 0;
     a.MaxOccurs = 3;
     //a.AllowedValues.Add("88");
     //a.AllowedValues.Add("6");
     process.inputs.Add(a);
     process.inputs.Add(new LiteralInput("b", "operand b", "abstract b", "integer", "22"));
     process.outputs.Add(new LiteralOutput("sum", "sum of a + b", "abstract sum a + b", "integer"));
     ComplexOutput sumFile = new ComplexOutput("sumFile", "sum of a + b as file", "raw abstract sum a + b", new ComplexFormat("text/xml", "utf8", ""));
     sumFile.Formats.Add(new ComplexFormat("plain/text", "utf8", ""));
     process.outputs.Add(sumFile);
     return process;
 }
Ejemplo n.º 26
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.º 27
0
        public static XmlDocument RunFromHTTPGet(string language)
        {
            ResponseFormType responseForm = new ResponseFormType("wps:ResponseForm");
            string           processId    = Utils.GetParameter("Identifier");

            if (string.IsNullOrEmpty(processId))
            {
                throw new ExceptionReport(ExceptionCode.MissingParameterValue, "Identifier");
            }

            List <InputData>   processInputParams  = null;
            List <OutputData>  processOutputParams = null;
            ProcessDescription processDescription  = null;

            processDescription  = ProcessDescription.GetProcessDescription(processId);
            processInputParams  = processDescription.GetProcessInputParameters();
            processOutputParams = processDescription.GetProcessOutputParameters();

            List <InputData> inputParams = new List <InputData>();
            //string p = Utils.DecodeURI(Utils.GetParameter("DataInputs"));
            string p = Utils.GetParameter("DataInputs");

            ExceptionReport exception = null;

            if (!String.IsNullOrEmpty(p))
            {
                string[] tokens = p.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string param in tokens)
                {
                    string[] kv = param.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries);
                    if (kv.Length == 2)
                    {
                        InputData input = processDescription.GetProcessInputParameter(kv[0]);
                        if (input != null)
                        {
                            InputData myinput = input.Clone();
                            try
                            {
                                myinput.ParseValue(kv[1]);
                            }
                            catch (ExceptionReport e)
                            {
                                exception = new ExceptionReport(e, exception);
                            }
                            inputParams.Add(myinput);
                        }
                        else
                        {
                            exception = new ExceptionReport(exception, "The parameter " + kv[0] +
                                                            " is not a valid parameter for this execute request!", ExceptionCode.InvalidParameterValue, kv[0]);
                        }
                    }
                }
            }

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

            //List<string> outputIds = new List<string>();

            responseForm.Parse(processDescription);

            return(Run(processDescription, inputParams, responseForm));
        }
Ejemplo n.º 28
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.º 29
0
        public static XmlDocument RunFromHTTPPost(XmlNode requestNode, string language)
        {
            XmlNamespaceManager nsmgr       = Utils.CreateWPSNamespaceManager(requestNode.OwnerDocument);
            XmlNode             processNode = requestNode.SelectSingleNode("ows:Identifier", nsmgr);

            if (processNode == null || string.IsNullOrEmpty(processNode.InnerText))
            {
                throw new ExceptionReport(ExceptionCode.MissingParameterValue, "ows:Identifier");
            }

            string processId = processNode.InnerText;

            //List<InputData> processInputParams = null;
            //List<OutputData> processOutputParams = null;
            ProcessDescription processDescription = null;

            processDescription = ProcessDescription.GetProcessDescription(processId);
            //processInputParams = processDescription.GetProcessInputParameters();
            //processOutputParams = processDescription.GetProcessOutputParameters();

            List <InputData> inputParams = new List <InputData>();

            ExceptionReport exception = null;

            XmlNodeList inputs = requestNode.SelectNodes("wps:DataInputs/wps:Input", nsmgr);

            foreach (XmlNode node in inputs)
            {
                XmlNode nodeid = node.SelectSingleNode("ows:Identifier", nsmgr);
                if (nodeid == null)
                {
                    exception = new ExceptionReport(exception, "The parameter <ows:Identifier> is missing!",
                                                    ExceptionCode.MissingParameterValue, "ows:Identifier");
                    continue;
                }

                InputData input = processDescription.GetProcessInputParameter(nodeid.InnerText);
                if (input == null)
                {
                    exception = new ExceptionReport(exception, "The parameter " + nodeid.InnerText +
                                                    " is not a valid parameter for this execute request!",
                                                    ExceptionCode.InvalidParameterValue, nodeid.InnerText);
                    continue;
                }
                InputData myinput = input.Clone();
                try
                {
                    myinput.ParseValue(node);
                    inputParams.Add(myinput);
                }
                catch (ExceptionReport e)
                {
                    exception = new ExceptionReport(e, exception);
                }
            }

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

            ResponseFormType responseForm = new ResponseFormType("wps:ResponseForm");

            XmlNode responseFormNode = requestNode.SelectSingleNode("wps:ResponseForm", nsmgr);

            responseForm.Parse(responseFormNode, processDescription);

            return(Execute.Run(processDescription, inputParams, responseForm));
        }
Ejemplo n.º 30
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;
        }