コード例 #1
0
        // Da rivedere
        // Loading conventions directive
        public void dload_convention_3(Term assemblyName, Term conventionName, Term id)
        {
            Struct convName = (Struct)conventionName.getTerm();
            Struct asName   = (Struct)assemblyName.getTerm();

            if (convName == null || !convName.isAtom() || asName == null || !asName.isAtom() || (!(id is Var) && !id.isAtom()))
            {
                return;
            }

            try
            {
                Convention newConv = Convention.LoadConvention(asName.getName(), convName.getName());

                // Check if the convention is already registered in the staticObjects
                if (this.getRegisteredObject((Struct)id) != null)
                {
                    return;
                }

                // Register the convention in the staticObjects
                this.register((Struct)id, newConv);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// Load a convention by its assembly and classname
        /// </summary>
        /// <param name="assemblyName">Assembly file that contains the convention</param>
        /// <param name="conventionName">Class name of the convention</param>
        /// <param name="id">Identifier of the convention</param>
        /// <returns>True if the operation is successful</returns>
        public bool load_convention_3(Term assemblyName, Term conventionName, Term id)
        {
            Struct convName = (Struct)conventionName.getTerm();
            Struct asName   = (Struct)assemblyName.getTerm();

            if (convName == null || !convName.isAtom() || asName == null || !asName.isAtom() || (!(id is Var) && !id.isAtom()))
            {
                return(false);
            }

            try
            {
                Convention newConv        = Convention.LoadConvention(asName.getName(), convName.getName());
                Convention alreadyPresent = FindConvention(newConv.Name);

                // Convention not loaded
                if (alreadyPresent == null)
                {
                    _conventionList.Add(newConv, new List <string>());

                    // Id is an atom or a variable bound to an atom
                    if (id.isAtom() || id.getTerm().isAtom())
                    {
                        // Check if the id specified is already in use
                        if (this.getRegisteredObject((Struct)id) == null)
                        {
                            return(this.bindDynamicObject(id.getTerm(), newConv));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (id is Var)
                    {
                        // Id set to Convention.Name and unified with the variable
                        Struct newId = new Struct(newConv.Name);
                        return((this.bindDynamicObject(newId, newConv)) && (this.unify(id, newId)));
                    }
                }
                else
                {
                    // Convention already loaded
                    if (id.isAtom() || id.getTerm().isAtom())
                    {
                        string key  = RemoveApices(id.getTerm().ToString());
                        object conv = this.getRegisteredDynamicObject((Struct)id);
                        if (conv != null && conv is Convention)
                        {
                            Convention found = (Convention)conv;
                            // If convention found in objects and in conventions lists are equals, ok!
                            if (found.Name.Equals(alreadyPresent.Name))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        // TO CHECK -----------------------------------------------------
                        // If id is var then find the atom identifier and bind to id

                        // Here the Convention is already loaded so (in theory) the following call will return the identifier
                        // without register the Convention another time, however this call could be unsafe
                        Struct oldId = this.registerDynamic(alreadyPresent);
                        return(this.unify(id, oldId));

                        #region Albertin Code
                        //if (_currentObjects_inverse.Contains(alreadyPresent))
                        //    return Unify(id, (Struct)_currentObjects_inverse[alreadyPresent]);
                        //else
                        //    return false;
                        #endregion
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }