/// <summary>
        ///   Funcţia efectivă de transformare a mesajelor cerere în mesaje raspuns folosind serviciul ataşat.
        ///   Realizează interpretarea tipului cererii şi determină acţiunile necesare pentru a afla răspunsul.
        /// </summary>
        /// <param name="message">Cererea</param>
        /// <param name="from">Adresa de unde provine cererea</param>
        /// <returns>Raspunsul la cerere</returns>
        public Message answer(Message message, IPAddress from)
        {
            if (message.request.Equals("getFunctionalities")) {

                return new Message("receiveFunctionalities", this.domainOntologyService.getAllFunctionalities());
            }
            else {

                if (message.request.Equals("getOntology")) {

                    if (message.numberOfParameters == 1) {

                        string[] ontology = this.domainOntologyService.getSerializedOntology(message.getParameter(0));

                        if (ontology != null) {

                            return new Message("receiveOntology", ontology);
                        }
                        else {

                            return new Message("ERROR", new string[2] { "Unknown functionality", message.getParameter(0) });
                        }
                    }
                    else {

                        return new Message("ERROR", new string[2] { "Missing parameter", "Functionality" });
                    }
                }
                else {

                    return new Message("ERROR", new string[2] { "Unknown request", message.request });
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///   Găseşte toate funcţionalităţile cunoscute serviciului de ontologia domeniului.
        /// </summary>
        /// <returns>Funcţionalităţiile sub forma unui vector</returns>
        public Functionality[] getFunctionalities()
        {
            try
            {

                Message answer = new Message("getFunctionalities", null).deliverAndWaitFeedback(this._domainOntologyServiceAddress);

                if (answer != null)
                {

                    if (answer.request.Equals("noFunctionalities"))
                    {

                        this._lastError = "There are no functionalities.";

                        return null;
                    }
                    else
                    {

                        if (answer.request.Equals("receiveFunctionalities"))
                        {

                            this._lastError = null;

                            Functionality[] result = new Functionality[answer.numberOfParameters / 3];

                            for (int i = 0; i < answer.numberOfParameters; i = i + 3)
                            {

                                result[i / 3] = new Functionality(answer.getParameter(i + 1));
                            }

                            return result;
                        }
                        else
                        {

                            if (answer.request.Equals("ERROR") && answer.numberOfParameters > 0)
                            {

                                this._lastError = String.Join("\n", answer.parameters);

                                return null;
                            }
                        }
                    }
                }

                this._lastError = "The Domain Ontology Service didn't respond.Please check that it is running and that you have the correct address and port set.";

                return null;
            }
            catch (Exception e)
            {

                this._lastError = e.Message;

                return null;
            }
        }
        /// <summary>
        ///   Funcţia efectivă de transformare a mesajelor cerere în mesaje raspuns folosind serviciul ataşat.
        ///   Realizează interpretarea tipului cererii şi determină acţiunile necesare pentru a afla răspunsul.
        /// </summary>
        /// <param name="message">Cererea</param>
        /// <param name="from">Adresa de unde provine cererea</param>
        /// <returns>Raspunsul la cerere</returns>
        public Message answer(Message message, IPAddress from)
        {
            if (message.request.Equals("findServices")) {

                if (message.numberOfParameters == 1) {

                    string[] services = this.functionalityFindingService.findServices(message.getParameter(0));

                    if (services != null) {

                        return new Message("receiveServices", services);
                    }
                    else {

                        return new Message("ERROR", new string[1] { this.functionalityFindingService.lastError });
                    }
                }
                else {

                    return new Message("ERROR", new string[2] { "Missing parameter", "Please send functionality name, followed by request shapes in proper format." });
                }
            }
            else
                if (message.request.Equals("setServerLoadLevel"))
                {

                    if (message.numberOfParameters > 1)
                    {

                        RequestShape[] requestShapes = new RequestShape[message.numberOfParameters - 2];

                        for (int i = 2; i < message.numberOfParameters; ++i)
                        {

                            requestShapes[i - 2] = new RequestShape(message.getParameter(i));
                        }

                        string[] serverLoadLevel = new string[1];

                        serverLoadLevel[0] = this.functionalityFindingService.setServerLoadLevel(int.Parse(message.getParameter(0)), message.getParameter(1), requestShapes);

                        if (serverLoadLevel != null)
                        {
                            return new Message("receiveServerLoad", serverLoadLevel);
                        }
                        else
                        {

                            return new Message("ERROR", new string[1] { this.functionalityFindingService.lastError });
                        }
                    }
                    else
                    {

                        return new Message("ERROR", new string[2] { "Missing parameter", "Please send functionality name, followed by request shapes in proper format." });
                    }
                }
            else {

                return new Message("ERROR", new string[2] { "Unknown request", message.request });
            }
        }
        /// <summary>
        ///   Găseşte toate funcţionalităţile cunoscute serviciului de ontologia domeniului.
        /// </summary>
        /// <returns>Numele funcţionalităţilor sub forma unui vector</returns>
        public string[] getFunctionalityNames()
        {
            try {

                Message answer = new Message("getFunctionalities", null).deliverAndWaitFeedback(this._domainOntologyServiceAddress);

                if (answer != null) {

                    if (answer.request.Equals("receiveFunctionalities")) {

                        string[] functionalityNames = new string[answer.numberOfParameters];

                        for (int i = 0; i < functionalityNames.Length; ++i) {

                            functionalityNames[i] = answer.getParameter(i);
                        }

                        this._lastError = null;

                        return functionalityNames;
                    }
                    else if (answer.request.Equals("ERROR") && answer.numberOfParameters > 0) {

                        this._lastError = string.Join("\n", answer.parameters);

                        return null;
                    }
                }

                this._lastError = resourceManager.GetString("ERROR_NO_RESPONSE");

                return null;

            }
            catch (Exception e) {

                this._lastError = e.Message;

                return null;
            }
        }
        /// <summary>
        ///   Găseşte toate funcţionalităţile cunoscute serviciului de ontologia domeniului.
        /// </summary>
        /// <returns>Numele funcţionalităţilor sub forma unui vector</returns>
        public string[] getFunctionalitiesData()
        {
            try
            {

                Message answer = new Message("getFunctionalities", null).deliverAndWaitFeedback(this._domainOntologyServiceAddress);

                if (answer != null)
                {

                    if (answer.request.Equals("noFunctionalities"))
                    {

                        this._lastError = "There are no functionalities.";

                        return null;
                    }
                    else
                    {

                        if (answer.request.Equals("receiveFunctionalities"))
                        {

                            this._lastError = null;

                            string[] functionalitesData = new string[answer.numberOfParameters];

                            for (int i = 0; i < functionalitesData.Length; ++i)
                            {

                                functionalitesData[i] = answer.getParameter(i);
                            }

                            return functionalitesData;
                        }
                        else
                        {

                            if (answer.request.Equals("ERROR") && answer.numberOfParameters > 0)
                            {

                                this._lastError = string.Join("\n", answer.parameters);

                                return null;
                            }
                        }
                    }
                }

                this._lastError = "The Domain Ontology Service didn't respond.Please check that it is running and that you have the correct address and port set.";

                return null;

            }
            catch (Exception e)
            {

                this._lastError = e.Message;

                return null;
            }
        }