Esempio n. 1
0
        /// <param name="originalOntology">Ontologia funcționalității la care cererea se referă</param>
        /// <param name="requestShapes">Formele cererilor</param>
        public SelectionRules(Functionality originalOntology, RequestShape[] requestShapes)
        {
            this.numberOfOutcomes = ClientSettings.Default.RULE_GENERATION_NUMBER_OF_OUTCOMES;

            foreach (RequestShape requestShape in requestShapes) {

                foreach (Property property in originalOntology.properties) {

                    if (property.name == requestShape.shape.name) {

                        int exactlyLocation;

                        this._requirementOntologies.Add(this.constructRequirementOntology(requestShape, property.start, property.end, out exactlyLocation));

                        this._exactlyLocations.Add(exactlyLocation);

                        this.requirementImportances.Add(InferenceMachine.calculateImportance(requestShape.importance));

                        break;
                    }
                }
            }

            this.requirements = new int[this._requirementOntologies.Count];
            this.rules = this.bktCombinations(0, null);

            this.constructDecisionOntology();
        }
Esempio n. 2
0
        /// <param name="name">Numele serviciului</param>
        /// <param name="accessPoint">Locatia serviciului</param>
        /// <param name="functionality">Funcţionalitatea implementată de serviciu</param>
        private Service(string name, string accessPoint, Functionality functionality)
        {
            this.name = name;
            this.accessPoint = accessPoint;

            this.functionality = functionality;
            this.functionalityName = functionality.name;

            this.values = new Hashtable();

            foreach (Property property in this.functionality.properties) {

                this.values.Add(property, double.NaN);
            }
        }
Esempio n. 3
0
        /// <param name="name">Numele serviciului</param>
        /// <param name="accessPoint">Locatia serviciului</param>
        /// <param name="functionalityName">Numele funcţionalităţii implementate de serviciu</param>
        /// <param name="propertyNames">Numele proprietăţilor funcţionalităţii</param>
        /// <param name="propertyValues">Valorile pentru proprietăţile funcţionalităţii</param>
        public Service(string name, string accessPoint, string functionalityName, List<string> propertyNames, List<object> propertyValues)
        {
            this.name = name;
            this.accessPoint = accessPoint;

            this.functionality = null;
            this.functionalityName = functionalityName;

            this.values = new Hashtable();

            int max = propertyNames.Count < propertyValues.Count ? propertyNames.Count : propertyValues.Count;

            for (int i = 0; i < max; ++i) {

                this.values.Add(propertyNames[i],propertyValues[i] is string || propertyValues[i] is double ? propertyValues[i] : double.NaN);
            }
        }
        /// <param name="originalOntology">Ontologia funcționalității la care cererea se referă</param>
        /// <param name="requestShapes">Formele cererilor</param>
        public MulticriteriaDecisionMaker(Functionality originalOntology, RequestShape[] requestShapes)
        {
            foreach (RequestShape requestShape in requestShapes) {

                foreach (Property property in originalOntology.properties) {

                    if (property.name == requestShape.shape.name) {

                        Term term = requestShape.shape.clone();

                        this.requestImportances.Add(term, InferenceMachine.calculateImportance(requestShape.importance));

                        break;
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        ///   Interoghează serviciul de găsire a funcţionalităţii pentru a găsii toate serviciile care au o 
        ///   anumita functionalitate si aplica pe acestea algoritmul selectat (FRI sau MCDM).
        /// </summary>
        /// <param name="functionalityName">Numele funcţionalităţii pe care serviciile căutate trebuie să o ofere.</param>
        /// <param name="requestShapes">Formele căutate ale proprietăţilor funcţionalităţii.</param>
        /// <returns>Serviciile găsite.</returns>
        public string[] findServices(Functionality functionality, RequestShape[] reqShapes)
        {
            try {

                List<RequestShape> reqShp = new List<RequestShape>();

                foreach (RequestShape requestShape in reqShapes) {

                    if (requestShape != null) {

                        reqShp.Add(requestShape);
                    }
                }

                if(reqShp.Count == 0) {

                    this._lastError = "No request shapes specified";

                    return null;
                }

                RequestShape[] requestShapes = reqShp.ToArray();

                Message answer = new Message("findServices", new string[1] { functionality.name }).deliverAndWaitFeedback(this._functionalityFindingServiceAddress);

                if (answer != null) {

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

                        this._lastError = null;

                        List<Service> servicesProvidingRequestedFunctionality = new List<Service>();

                        int increment = 3* functionality.propertiesCount + 2;

                        string[] parameters = answer.parameters;

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

                            string name = null;
                            string accessPoint = null;

                            List<string> propertyNames  = new List<string>();
                            List<object> propertyValues = new List<object>();

                            int j = i;
                            int end = i + increment;

                            while(j < end) {

                                if (j % increment == 0) {

                                    name = parameters[j];
                                    j++;
                                }
                                else {

                                    if (j % increment == 1) {

                                        accessPoint = parameters[j];
                                        j++;
                                    }
                                    else {

                                        propertyNames.Add(answer.parameters[j]);

                                        if (parameters[j+1] == "fuzzy") {

                                            propertyValues.Add(parameters[j+2]);

                                        }
                                        else {

                                            if (parameters[j+1] == "crisp") {

                                                propertyValues.Add(double.Parse(parameters[j+2]));
                                            }
                                        }

                                        j=j+3;
                                    }
                                }
                            }

                            servicesProvidingRequestedFunctionality.Add(new Service(name, accessPoint, functionality.name, propertyNames, propertyValues));
                        }

                        List<Service> completeServices = new List<Service>();

                        foreach(Service service in servicesProvidingRequestedFunctionality) {

                            completeServices.Add(service.addActualOntology(functionality));
                        }

                        InferenceMachine.InferenceMachine inferenceMachine = null;

                        switch (ClientSettings.Default.INFERENCE_ALGORITHM) {

                            case (int)InferenceAlgorithms.multicriteriaDecisionMaking:

                                inferenceMachine = new MulticriteriaDecisionMaker(functionality, requestShapes);

                                break;

                            default:

                                inferenceMachine = new SelectionRules(functionality, requestShapes);

                                break;
                        }

                        string[] result = new string[completeServices.Count];

                        for (int i = 0; i < completeServices.Count; ++i) {

                            result[i] = inferenceMachine.applyToServiceInCSVFormat(completeServices[i]);
                        }

                        return result;
                    }
                    else {

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

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

                            return null;
                        }
                    }
                }

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

                return null;
            }
            catch (Exception e) {

                this._lastError = e.Message;

                return null;
            }
        }
Esempio n. 6
0
        /// <summary>
        ///   Interoghează serviciul de ontologia domeniului pentru a găsi ontologia unei anumite funcţionalităţi.
        /// </summary>
        /// <param name="functionality">Funcţionalitatea pentru care se caută o ontologie</param>
        /// <returns>Ontologia funcţionalităţii</returns>
        public Functionality getOntology(Functionality functionality)
        {
            try {

                Message answer = new Message("getOntology", new string[1] { functionality.name }).deliverAndWaitFeedback(this._domainOntologyServiceAddress);

                if (answer != null) {

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

                        this._lastError = null;

                        return new Functionality(functionality.name, answer.parameters);
                    }
                    else {

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

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

                            return null;
                        }
                    }
                }

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

                return null;
            }
            catch (Exception e) {

                this._lastError = e.Message;

                return null;
            }
        }
Esempio n. 7
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;
            }
        }
Esempio n. 8
0
        /// <summary>
        ///   Adaugă ontologia unei funcţionalităţi pentru care momentan se cunoaşte doar numele.
        /// </summary>
        /// <param name="ontology">Ontologia care sa fie adaugată</param>
        /// <returns>Un serviciu cu ontologia adăugată</returns>
        public Service addActualOntology(Functionality ontology)
        {
            if (this.functionality != null) {

                return this;
            }

            Service result = new Service(this.name,this.accessPoint, ontology);

            foreach (Property property in ontology.properties) {

                if (this.values.ContainsKey(property.name)) {

                    if (this.values[property.name] is double) {

                        result.values[property] = this.values[property.name];
                    }
                    else {

                        if (this.values[property.name] is string) {

                            Term term = property.getTerm(this.values[property.name] as string);

                            if (term != null) {

                                result.values[property] = term;
                            }
                        }
                    }
                }
            }

            return result;
        }
Esempio n. 9
0
        /// <summary>
        ///   Indică alegerea unei noi funcţionalităţi.
        ///   Cere clientului să returneze proprietăţile şi reîmprospătează interfaţa.
        /// </summary>
        private void cboFunctionality_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.visualizer != null)
            {

                this.visualizer.closeMe();
            }

            this.btnFind.Enabled = this.tcProperties.Enabled = false;

            if (this.cboFunctionality.SelectedIndex == -1)
            {

                this.tcProperties.TabPages[0].Text = "Choose a functionality first !";

                return;
            }

            this.cboFunctionality.Enabled = false;

            this.currentFunctionality = this.client.getOntology(this.cboFunctionality.SelectedItem as Functionality);

            if (this.currentFunctionality == null)
            {

                if (this.client.lastError != null)
                {

                    MessageBox.Show(this.client.lastError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                this.cboFunctionality.SelectedIndex = -1;
                this.cboFunctionality.Enabled = true;

                return;
            }

            this.propertyTabPageStates = new PropertyTabPageState[this.currentFunctionality.propertiesCount];

            for (int i = 0; i < this.currentFunctionality.propertiesCount; ++i)
            {

                this.propertyTabPageStates[i] = new PropertyTabPageState(this);
            }

            this.tcProperties.SelectedIndex = 0;

            while (this.tcProperties.TabCount > 1)
            {

                this.tcProperties.TabPages.RemoveAt(1);
            }

            if (this.currentFunctionality != null)
            {

                if (this.currentFunctionality.propertiesCount == 0)
                {

                    this.tcProperties.TabPages[0].Text = "This functionality has no properties !";
                    this.panelFunctionality.Visible = false;
                }
                else
                {

                    this.tcProperties.TabPages[0].Text = this.currentFunctionality.properties[0].name;
                    this.panelFunctionality.Visible = true;
                }

                for (int i = 1; i < this.currentFunctionality.propertiesCount; ++i)
                {

                    TabPage tabPage = new TabPage();

                    tabPage.Padding = this.tcProperties.TabPages[0].Padding;
                    tabPage.UseVisualStyleBackColor = true;

                    this.tcProperties.TabPages.Add(tabPage);
                    this.tcProperties.TabPages[i].Text = this.currentFunctionality.properties[i].name;
                }

                this.tcProperties_SelectedIndexChanged(null, null);

                this.btnFind.Enabled = this.cboFunctionality.Enabled = this.tcProperties.Enabled = true;
            }
            else
            {

                this.tcProperties.TabPages[0].Text = "Choose a functionality first !";

                this.panelFunctionality.Visible = false;

                this.cboFunctionality.SelectedIndex = -1;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Seteaza nivelul de incarcare pe FFS, trimite nrul de cereri specificat dupa atingerea nivelului de 
        /// incarcare pe FFS si masoara timpul de raspuns al FFS-ului pentru cererile trimise.
        /// </summary>
        /// <param name="functionalityName">Numele functionalitatii din cadrul configuratiei de testare</param>
        /// <param name="requestShapes">Termenii cererii din cadrul configuratiei de testare</param>
        /// <param name="minLoadLevel">Nivelul de incarcare al FFS din cadrul configuratiei de testare</param>
        /// <param name="nrRequests">Nrul de cereri trimise dupa atingerea 'minLoadLevel' de catre FFS</param>
        /// <returns></returns>
        private TimeSpan spamRequest(string functionalityName, RequestShape[] requestShapes, int minLoadLevel, int nrRequests)
        {
            string actualServerLoadStatus = this.SmartSpammer.setServerLoadLevel(minLoadLevel, functionalityName, requestShapes);

            if (actualServerLoadStatus == null)
            {

                if (this.SmartSpammer.lastError != null)
                {
                    MessageBox.Show(this.SmartSpammer.lastError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    return TimeSpan.Zero;
                }
            }
            else
            {

                TimeSpan results = TimeSpan.Zero;

                Functionality simpleFunctionality = new Functionality(functionalityName);
                Functionality completeFunctionality = this.SmartSpammer.getOntology(simpleFunctionality);

                if (actualServerLoadStatus.Equals("true"))
                {

                    DateTime startTime = DateTime.Now;

                    for (int i = 0; i < nrRequests; i++)
                    {

                        this.SmartSpammer.findServices(completeFunctionality, requestShapes);
                    }

                    DateTime stopTime = DateTime.Now;

                    results = stopTime - startTime;

                    return results;

                }

                else
                {
                    MessageBox.Show("Server Load not achieved !");

                    return TimeSpan.Zero;
                }
            }

            return TimeSpan.Zero;
        }