コード例 #1
0
        public ModuleInfo(Assembly _asm)
        {
            _name = _asm.GetName().Name;
            _version = DepVersion.VersionParse (_asm.GetName().Version.ToString ());

            ModuleDependencyAttribute _depAttr = ((ModuleDependencyAttribute)(_asm.GetCustomAttributes (typeof (ModuleDependencyAttribute), false)[0]));

            if (_depAttr != null) {
                DepLexer _lexer = new DepLexer (new StringReader (_depAttr.DepString));
                DepParser _parser = new DepParser (_lexer);

                // woot...lets do this!
                _dependencies = new DepNode ();

                _parser.expr (_dependencies);
            } else
                _dependencies = null;

            ModuleRoleAttribute _roleAttr = ((ModuleRoleAttribute)(_asm.GetCustomAttributes (typeof (ModuleRoleAttribute), false)[0]));

            if (_roleAttr != null) {
                _roles = _roleAttr.Roles;
            } else
                throw new ModuleInfoException (string.Format ("The module {0} has no defined roles, and is not a valid NModule module.", _asm.GetName ().Name));

            _owner = _asm;
        }
コード例 #2
0
        public ModuleInfo(Assembly _asm)
        {
            _name = _asm.GetName().Name;
            _version = DepVersion.VersionParse (_asm.GetName().Version.ToString ());

            ModuleDependencyAttribute _depAttr;
            ModuleRoleAttribute _roleAttr;

            try {
                _depAttr = ((ModuleDependencyAttribute)(_asm.GetCustomAttributes (typeof (ModuleDependencyAttribute), false)[0]));
            } catch (IndexOutOfRangeException) {
                _depAttr = null;
            }

            if (_depAttr != null) {
                DepLexer _lexer = new DepLexer (new StringReader (_depAttr.DepString));
                DepParser _parser = new DepParser (_lexer);

                // woot...lets do this!
                _dependencies = new DepNode ();

                _parser.expr (_dependencies);

                Console.WriteLine ("Dependency tree for {0}", _name);
                Console.WriteLine ("This should match {0}", _depAttr.DepString);
                Console.WriteLine ("----------------------------------------------------");
                PrintDepTree (_dependencies, 0);
                Console.WriteLine ("----------------------------------------------------");
                _depstring = _depAttr.DepString;
            } else
                _dependencies = null;

            try {
                _roleAttr = ((ModuleRoleAttribute)(_asm.GetCustomAttributes (typeof (ModuleRoleAttribute), false)[0]));
            } catch (IndexOutOfRangeException) {
                _roleAttr = null;
            }

            if (_roleAttr != null) {
                _roles = _roleAttr.Roles;
            } else
                throw new ModuleInfoException (string.Format ("The module {0} has no defined roles, and is not a valid NModule module.", _asm.GetName ().Name));

            _owner = _asm;
        }
コード例 #3
0
        protected void CheckCircularDeps(DepNode _x, ArrayList _parents)
        {
            if (_parents == null)
                return;

            if (_x == null)
                return;

            foreach (DepNode _d in _x.Children) {
                CheckCircularDeps (_d, _parents);
            }

            if (_x.Constraint != null) {
                foreach (string _parent in _parents) {
                    Console.WriteLine ("CIRCULAR DEPENDENCY CHECK:  {0} {1}", _x.Constraint.Name, _parent);
                    if (_x.Constraint.Name == _parent) {
                        throw new CircularDependencyException (string.Format ("{0} depends on {1}, but {1} is depending on {0}.", _x.Constraint.Name, _parent));
                    }
                }
            }
        }
コード例 #4
0
        //throws RecognitionException, TokenStreamException
        public void neqexpr(
		DepNode parent, bool root
	)
        {
            DepNode child = (!root)? parent.CreateNewChild() : parent; child.DepOp = DepOps.NotEqual;

            try {      // for error handling
            match(LPAREN);
            match(NEQ);
            iexpr(child);
            match(RPAREN);
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_1_);
            }
        }
コード例 #5
0
        //throws RecognitionException, TokenStreamException
        public void iexpr(
		DepNode node
	)
        {
            IToken  c = null;
            IToken  v = null;
            node.Constraint = new DepConstraint();

            try {      // for error handling
            c = LT(1);
            match(CLASS);
            {
                switch ( LA(1) )
                {
                case VER:
                {
                    v = LT(1);
                    match(VER);
                    node.Constraint.VersionTmp=v.getText();
                    break;
                }
                case RPAREN:
                {
                    break;
                }
                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                 }
            }
            node.Constraint.Name=c.getText();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_3_);
            }
        }
コード例 #6
0
        //throws RecognitionException, TokenStreamException
        public void expr(
		DepNode root
	)
        {
            try {      // for error handling
            cexpr(root);
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_0_);
            }
        }
コード例 #7
0
        //throws RecognitionException, TokenStreamException
        public void cexpr(
		DepNode parent
	)
        {
            try {      // for error handling
            if ((LA(1)==LPAREN) && (LA(2)==NOTO))
            {
                notexpr(parent);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==AND)) {
                andexpr(parent);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==OR)) {
                orexpr(parent);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==XOR)) {
                xorexpr(parent);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==OPT)) {
                optexpr(parent);
            }
            else if ((LA(1)==LPAREN) && ((LA(2) >= EQ && LA(2) <= LD))) {
                oexpr(parent, true);
            }
            else
            {
                throw new NoViableAltException(LT(1), getFilename());
            }

            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_1_);
            }
        }
コード例 #8
0
 public DepNode(DepNode parent)
 {
     _parent = parent;
     _children = new ArrayList ();
 }
コード例 #9
0
        protected void OpResolve(DepNode _node, ArrayList _parents, ModuleInfo _info, bool checking)
        {
            bool _ret;
            DepOps _op = _node.DepOp;
            DepConstraint _constraint = _node.Constraint;
            if ((_op == DepOps.And) || (_op == DepOps.Not) || (_op == DepOps.Opt) || (_op == DepOps.Or) || (_op == DepOps.Xor)) {
                // combo-operators
                ArrayList _results = new ArrayList ();
                ArrayList _c = new ArrayList ();
                foreach (DepNode _child in _node.Children) {
                    try {
                        OpResolve (_child, _parents, _info, checking);
                        _results.Add (true);
                        _c.Add (_child.Constraint);
                    } catch (Exception e) {
                        _results.Add (false);
                        _c.Add (_child.Constraint);
                    }
                }

                switch (_op) {
                    case DepOps.And:
                        int r = 0;
                        foreach (bool _result in _results) {
                            if (!_result) {
                                throw new UnresolvedDependencyException (
                                    string.Format("The following dependency for the module {0} could not be resolved: (AND operator)\n\t{1} ({2})",
                                        _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version)
                                );
                            }
                            r++;
                        }
                        break;
                    case DepOps.Not:
                        foreach (bool _result in _results) {
                            if (_result)
                                throw new UnresolvedDependencyException (
                                    string.Format("The following dependency for the module {0} could not be resolved: (NOT operator)\n\t{1} ({2})",
                                        _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version)
                                );
                        }
                        break;
                    case DepOps.Opt: // This is optional so stuff is true regardless
                        break;
                    case DepOps.Or:
                        _ret = false;
                        ArrayList _urexc = new ArrayList ();
                        r = 0;
                        foreach (bool _result in _results) {
                            if (_result)
                                _ret = true;
                            else {
                                _urexc.Add (string.Format("{1} ({2})", _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version));
                            }
                            r++;
                        }

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format("The following dependency for the module {0} could not be resolved: (OR operator)\n")
                            );
                            foreach (string _exc in _urexc) {
                                _sb.Append(string.Format("\t{0}\n", _exc));
                            }
                            throw new UnresolvedDependencyException (_sb.ToString ());
                        }
                        break;
                    case DepOps.Xor:
                        bool _xt = true;
                        bool _xf = true;
                        ArrayList _xexc = new ArrayList ();

                        r = 0;
                        _ret = true;

                        foreach (bool _result in _results) {
                            if (_result) {
                                _xf = false;
                                _xexc.Add (string.Format("{1} ({2}) (True)", _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version));
                            }
                            if (!_result) {
                                _xt = false;
                                _xexc.Add (string.Format("{1} ({2}) (False)", _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version));
                            }
                            r++;
                        }

                        if (_xt || _xf)
                            _ret = false;

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format ("The following dependency for the module {0} could not be resolved: (XOR operator)\n")
                            );
                            foreach (string _exc in _xexc) {
                                _sb.Append (string.Format("\t{0}\n", _exc));
                            }
                            throw new UnresolvedDependencyException (_sb.ToString ());
                        }
                        break;
                }
            } else {
                // single operators
                if (SearchForModule (_constraint.Name) == null)
                    _ret = false;

                ModuleInfo _ninfo;

                ModuleLoader _loader = new ModuleLoader (_search_path, this);

                _loader.LoadModule (_parents, _constraint.Name, out _ninfo, true);

                if ((_op == DepOps.Equal) || (_op == DepOps.GreaterThan) || (_op == DepOps.GreaterThanEqual) || (_op == DepOps.LessThan)
                    || (_op == DepOps.LessThanEqual) || (_op == DepOps.NotEqual)) {
                    if (!IsEmptyVersion (_constraint.Version)) {
                        if (!VersionMatch (_constraint.Version, _ninfo.Version, _op)) {
                            throw new UnresolvedDependencyException (
                                string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                    _info.Name, _constraint.Name, _constraint.Version, OpToString (_op))
                            );
                        }
                    }
                    if (!checking) {
                        _controller.LoadModule (_constraint.Name);
                    }
                }
                // we got this far, so obviously it loaded okay
            }
        }
コード例 #10
0
        protected void OpResolve(DepNode _node, ArrayList _parents, ModuleInfo _info, bool checking, DepOps _parentop)
        {
            Console.WriteLine ("-->> OpResolve called with:");
            Console.WriteLine ("---->> _node = {0}", _node == null ? "null" : "not null");
            Console.WriteLine ("---->> _node.DepOp = {0}", OpToString (_node.DepOp));
            Console.WriteLine ("---->> _parents = {0}", _parents == null ? "null" : "not null");
            Console.WriteLine ("---->> _info = {0}", _info == null ? "null" : "not null");
            Console.WriteLine ("---->> checking = {0}", checking);
            bool _ret;
            DepOps _op = _node.DepOp;

            if ((_op == DepOps.And) || (_op == DepOps.Not) || (_op == DepOps.Opt) || (_op == DepOps.Or) || (_op == DepOps.Xor)) {
                // combo-operators
                ArrayList _results = new ArrayList ();
                ArrayList _c = new ArrayList ();
                foreach (DepNode _child in _node.Children) {
                    //try {
                        OpResolve (_child, _parents, _info, checking, _op);
                        _results.Add (true);
                        _c.Add (_child.Constraint);
                    //} catch (Exception e) {
                    //	_results.Add (false);
                    //	_c.Add (_child.Constraint);
                    //}
                }

                switch (_op) {
                    case DepOps.And:
                        int r = 0;
                        if (_results == null) {
                            Console.WriteLine ("_results is NULL!");
                        }

                        foreach (bool _result in _results) {
                            if (!_result) {
                                if (_parentop != DepOps.Null && _parentop != DepOps.Opt) {
                                    throw new UnresolvedDependencyException (
                                        string.Format("The following dependency for the module {0} could not be resolved: (AND operator)\n\t{1} ({2})",
                                            _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version)
                                    );
                                }
                            }
                            r++;
                        }
                        break;
                    case DepOps.Not:
                        foreach (bool _result in _results) {
                            if (_result) {
                                if (_parentop != DepOps.Null && _parentop != DepOps.Opt) {
                                    throw new UnresolvedDependencyException (
                                        string.Format("The following dependency for the module {0} could not be resolved: (NOT operator)\n\t{1} ({2})",
                                            _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version)
                                    );
                                }
                            }
                        }
                        break;
                    case DepOps.Opt: // This is optional so stuff is true regardless
                        break;
                    case DepOps.Or:
                        _ret = false;
                        ArrayList _urexc = new ArrayList ();
                        r = 0;
                        foreach (bool _result in _results) {
                            if (_result)
                                _ret = true;
                            else {
                                _urexc.Add (string.Format("{1} ({2})", _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version));
                            }
                            r++;
                        }

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format("The following dependency for the module {0} could not be resolved: (OR operator)\n")
                            );
                            foreach (string _exc in _urexc) {
                                _sb.Append(string.Format("\t{0}\n", _exc));
                            }
                            if (_parentop != DepOps.Null && _parentop != DepOps.Opt)
                                throw new UnresolvedDependencyException (_sb.ToString ());
                        }
                        break;
                    case DepOps.Xor:
                        bool _xt = true;
                        bool _xf = true;
                        ArrayList _xexc = new ArrayList ();

                        r = 0;
                        _ret = true;

                        foreach (bool _result in _results) {
                            if (_result) {
                                _xf = false;
                                _xexc.Add (string.Format("{1} ({2}) (True)", _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version));
                            }
                            if (!_result) {
                                _xt = false;
                                _xexc.Add (string.Format("{1} ({2}) (False)", _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version));
                            }
                            r++;
                        }

                        if (_xt && _xf)
                            _ret = false;

                        if (!_xt && _xf)
                            _ret = false;

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format ("The following dependency for the module {0} could not be resolved: (XOR operator)\n")
                            );
                            foreach (string _exc in _xexc) {
                                _sb.Append (string.Format("\t{0}\n", _exc));
                            }
                            if (_parentop != DepOps.Null && _parentop != DepOps.Opt) {
                                throw new UnresolvedDependencyException (_sb.ToString ());
                            }
                        }
                        break;
                }
            } else {
                DepConstraint _constraint = _node.Constraint;

                // single operators
                if (SearchForModule (_constraint.Name) == null)
                    _ret = false;

                ModuleInfo _ninfo;

                ModuleLoader _loader = new ModuleLoader (_search_path, _controller);

                _loader.LoadModule (_parents, _constraint.Name, out _ninfo, true, true);

                bool result = true;

                Console.WriteLine ("Checking {0}'s version:  Empty {1}", _constraint.Name, IsEmptyVersion (_constraint.Version));
                Console.WriteLine ("Checking ({0} {1} {2}) Result: {3}", OpToString (_op), _ninfo.Version.ToString(), _constraint.Version.ToString(), VersionMatch (_ninfo.Version, _constraint.Version, _op));

                if (!IsEmptyVersion (_constraint.Version)) {
                    if (!VersionMatch (_ninfo.Version, _constraint.Version, _op)) {
                        result = false;
                    }
                }

                if (!result) {
                    if (_parentop != DepOps.Null && _parentop != DepOps.Opt) {
                        throw new UnresolvedDependencyException (
                                string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                    _info.Name, _constraint.Name, _constraint.Version, OpToString (_op))
                            );
                    }
                    else
                        return;
                }

                if (_controller == null)
                    Console.WriteLine ("_controller is NULL!");

                if (!checking) {
                    _controller.LoadModule (_constraint.Name);
                }

                Console.WriteLine ("Checking {0} for {1} (Result: {2})", OpToString (_op), _info.Name, result);
                // we got this far, so obviously it loaded okay
            }
        }
コード例 #11
0
        protected void DecRefs(DepNode _x)
        {
            if (_x == null)
                return;

            foreach (DepNode _d in _x.Children) {
                DecRefs (_d);
            }
            DecRef ((AppDomain)_app_domain_map[_x.Constraint.Name]);
        }
コード例 #12
0
        protected void OpResolve(DepNode _node, ArrayList _parents, ModuleInfo _info, bool checking, DepOps _parentop)
        {
            bool _ret;
            DepOps _op = _node.DepOp;

            if ((_op == DepOps.And) || (_op == DepOps.Opt) || (_op == DepOps.Or) || (_op == DepOps.Xor)) {
                // combo-operators
                ArrayList _results = new ArrayList ();
                ArrayList _c = new ArrayList ();
                foreach (DepNode _child in _node.Children) {
                    try {
                        OpResolve (_child, _parents, _info, checking, _op);
                        _results.Add (true);
                        _c.Add (_child.Constraint);
                    } catch (Exception e) {
                        _results.Add (false);
                        _c.Add (_child.Constraint);
                    }
                }

                switch (_op) {
                    case DepOps.And:
                        int r = 0;

                        foreach (bool _result in _results) {
                            if (!_result) {
                                if (_parentop != DepOps.Opt) {
                                    if (_c[r] != null) {
                                        throw new UnresolvedDependencyException (
                                            string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                                _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString(), OpToString (DepOps.And))
                                        );
                                    } else {
                                        throw new UnresolvedDependencyException (
                                            string.Format("The following dependency for the module {0} could not be resolved: ({1} operator)",
                                                _info.Name, OpToString (DepOps.And))
                                        );
                                    }
                                }
                            }
                            r++;
                        }
                        break;
                    case DepOps.Opt: // This is optional so stuff is true regardless
                        break;
                    case DepOps.Or:
                        _ret = false;
                        ArrayList _urexc = new ArrayList ();
                        r = 0;
                        foreach (bool _result in _results) {
                            if (_result)
                                _ret = true;
                            else {
                                if (_c[r] != null)
                                    _urexc.Add (string.Format("{0} ({1})", ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString()));
                            }
                            r++;
                        }

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format("The following dependency for the module {0} could not be resolved: (OR operator)\n", _info.Name)
                            );
                            foreach (string _exc in _urexc) {
                                _sb.Append(string.Format("\t{0}\n", _exc));
                            }
                            if (_parentop != DepOps.Opt)
                                throw new UnresolvedDependencyException (_sb.ToString ());
                        }
                        break;

                    case DepOps.Xor:
                        bool _xt = true;
                        bool _xf = true;
                        ArrayList _xexc = new ArrayList ();

                        r = 0;
                        _ret = true;

                        foreach (bool _result in _results) {
                            if (_result) {
                                _xf = false;
                                if (_c[r] != null)
                                    _xexc.Add (string.Format("{0} ({1}) (True)", ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString()));
                            }
                            if (!_result) {
                                _xt = false;
                                if (_c[r] != null)
                                    _xexc.Add (string.Format("{0} ({1}) (False)", ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString()));
                            }
                            r++;
                        }

                        // If one of these is still true, that means all of the other results are true or false.
                        if (_xt || _xf)
                            _ret = false;;

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format ("The following dependency for the module {0} could not be resolved: (XOR operator)\n", _info.Name)
                            );
                            foreach (string _exc in _xexc) {
                                _sb.Append (string.Format("\t{0}\n", _exc));
                            }
                            if (_parentop != DepOps.Opt) {
                                throw new UnresolvedDependencyException (_sb.ToString ());
                            }
                        }
                        break;
                }
            } else {
                DepConstraint _constraint = _node.Constraint;

                foreach (string _parent in _parents) {
                    if (_parent == _constraint.Name) {
                        throw new CircularDependencyException (string.Format ("{0} and {1} have a circular dependency on each other", _parent, _info.Name));
                    }
                }

                // single operators
                if (SearchForModule (_constraint.Name) == null)
                    _ret = false;

                ModuleInfo _ninfo = null;

                ModuleLoader _loader = new ModuleLoader (_search_path, _controller);

                try {
                    if (!_parents.Contains (_info.Name))
                        _parents.Add (_info.Name);

                    _loader.LoadModule (_parents, _constraint.Name, out _ninfo, true, true);
                } catch (CircularDependencyException ce) {
                    throw ce;
                } catch (Exception) {
                    if (_parentop != DepOps.Opt) {
                                throw new UnresolvedDependencyException (
                                    string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                        _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                );
                    }
                }

                if (_op == DepOps.Equal || _op == DepOps.GreaterThan || _op == DepOps.GreaterThanEqual || _op == DepOps.LessThan || _op == DepOps.LessThanEqual || _op == DepOps.NotEqual) {
                    if (!IsEmptyVersion (_constraint.Version)) {
                        if (!VersionMatch (_ninfo.Version, _constraint.Version, _op)) {
                            if (_parentop != DepOps.Opt) {
                                throw new UnresolvedDependencyException (
                                    string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                        _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                );
                            }
                        }
                    }

                    if (!checking) {
                        _controller.LoadModule (_constraint.Name);

                        _parents.Sort ();

                        ArrayList _seen = new ArrayList ();
                        _seen.Add (_info.Name);
                        _seen.Add (_constraint.Name);
                        foreach (string _p in _parents) {
                            if (!_seen.Contains (_p)) {
                                _controller.IncRef (_constraint.Name);
                                _seen.Add (_p);
                            }
                        }
                    }
                }

                if (_op == DepOps.Loaded) {
                    if (_controller.Loader.SearchForModule (_constraint.Name) == null)
                    {
                        if (_parentop != DepOps.Opt) {
                            throw new UnresolvedDependencyException (
                                        string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                            _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                    );
                        }
                    }

                    if (!checking) {
                        _controller.LoadModule (_constraint.Name);

                        _parents.Sort ();

                        ArrayList _seen = new ArrayList ();
                        _seen.Add (_info.Name);
                        _seen.Add (_constraint.Name);
                        foreach (string _p in _parents) {
                            if (!_seen.Contains (_p)) {
                                _controller.IncRef (_constraint.Name);
                                _seen.Add (_p);
                            }
                        }
                    }
                }

                if (_op == DepOps.NotLoaded) {
                    if (_controller.IsLoaded (_constraint.Name)) {
                        if (_controller.RefCount (_constraint.Name) > 1) {
                            if (_parentop != DepOps.Opt) {
                                throw new UnresolvedDependencyException (
                                        string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                            _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                    );
                            }
                        }
                        if (!checking) {
                            _controller.UnloadModule (_constraint.Name);
                        }
                    }
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Recursively resolves dependencies given a dependency tree.
        /// </summary>
        /// <remarks>None.</remarks>
        /// <param name="_node">The root node of the tree to resolve.</param>
        /// <param name="_parents">The parent modules to use when checking for circular dependencies.</param>
        /// <param name="_info">The <see cref="ModuleInfo" /> object representing the module to resolve dependencies for.</param>
        /// <param name="opt">Set to true if this pass is optional, otherwise set to false.</param>
        /// <exception cref="UnresolvedDependencyException">Thrown if the given dependency cannot be resolved and is not optional.</exception>
        /// <exception cref="CircularDependencyException">Thrown if two modules depend on each other.</exception>
        protected void OpResolve(DepNode _node, ArrayList _parents, ModuleInfo _info, bool checking, bool opt)
        {
            bool _ret;
            DepOps _op = _node.DepOp;

            // This is a large process.  I've chosen to use recursion here because it makes sense from a tree
            // point of view.  Our first step is to check our operator to see if its one of the "combination"
            // operators.  If it is, we simply recurse through its children and record their results in a
            // table (true if they suceeded, false if they failed).  Since we're not sure what kind of logic
            // we need (and, or, xor) we can't really make a decision at this point.  When we go through
            // the children, they simply go through this process to until we reach a bottom node, which would
            // be one of the "single" operators.  They are dealt with in the second part of this function.
            if ((_op == DepOps.And) || (_op == DepOps.Opt) || (_op == DepOps.Or) || (_op == DepOps.Xor)) {
                // This is our list of results for the children nodes.
                ArrayList _results = new ArrayList ();

                // This is a list of constraints for the children nodes so we can output sensible information.
                ArrayList _c = new ArrayList ();

                foreach (DepNode _child in _node.Children) {
                    // Try to resolve the child node, if it suceeds, store
                    // true into the results table, if an exception is thrown
                    // store false into the results table.  Store the constraints
                    // into the constraints table regardless of result so the indexes
                    // will be identical.
                    try {
                        OpResolve (_child, _parents, _info, checking, _op == DepOps.Opt ? true : false);
                        _results.Add (true);
                        _c.Add (_child.Constraint);
                    } catch (Exception e) {
                        _results.Add (false);
                        _c.Add (_child.Constraint);
                    }
                }

                // This switch statement is where we go through the results table and apply
                // the operator logic to the table to figure out if the results sastify
                // the given operator.
                switch (_op) {
                    case DepOps.And:
                        int r = 0;

                        foreach (bool _result in _results) {
                            if (!_result) {
                                if (!opt) {
                                    if (_c[r] != null) {
                                        throw new UnresolvedDependencyException (
                                            string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                                _info.Name, ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString(), OpToString (DepOps.And))
                                        );
                                    } else {
                                        throw new UnresolvedDependencyException (
                                            string.Format("The following dependency for the module {0} could not be resolved: ({1} operator)",
                                                _info.Name, OpToString (DepOps.And))
                                        );
                                    }
                                }
                            }
                            r++;
                        }
                        break;
                    case DepOps.Opt: // This is optional so stuff is true regardless
                        break;
                    case DepOps.Or:
                        _ret = false;
                        ArrayList _urexc = new ArrayList ();
                        r = 0;
                        foreach (bool _result in _results) {
                            if (_result)
                                _ret = true;
                            else {
                                if (_c[r] != null)
                                    _urexc.Add (string.Format("{0} ({1})", ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString()));
                            }
                            r++;
                        }

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format("The following dependency for the module {0} could not be resolved: (OR operator)\n", _info.Name)
                            );
                            foreach (string _exc in _urexc) {
                                _sb.Append(string.Format("\t{0}\n", _exc));
                            }
                            if (!opt)
                                throw new UnresolvedDependencyException (_sb.ToString ());
                        }
                        break;

                    case DepOps.Xor:
                        bool _xt = true;
                        bool _xf = true;
                        ArrayList _xexc = new ArrayList ();

                        r = 0;
                        _ret = true;

                        foreach (bool _result in _results) {
                            if (_result) {
                                _xf = false;
                                if (_c[r] != null)
                                    _xexc.Add (string.Format("{0} ({1}) (True)", ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString()));
                            }
                            if (!_result) {
                                _xt = false;
                                if (_c[r] != null)
                                    _xexc.Add (string.Format("{0} ({1}) (False)", ((DepConstraint)_c[r]).Name, ((DepConstraint)_c[r]).Version.ToString()));
                            }
                            r++;
                        }

                        // If one of these is still true, that means all of the other results are true or false.
                        if (_xt || _xf)
                            _ret = false;;

                        if (!_ret) {
                            StringBuilder _sb = new StringBuilder (
                                string.Format ("The following dependency for the module {0} could not be resolved: (XOR operator)\n", _info.Name)
                            );
                            foreach (string _exc in _xexc) {
                                _sb.Append (string.Format("\t{0}\n", _exc));
                            }
                            if (!opt) {
                                throw new UnresolvedDependencyException (_sb.ToString ());
                            }
                        }
                        break;
                }
            } else {
                DepConstraint _constraint = _node.Constraint;

                foreach (string _parent in _parents) {
                    if (_parent == _constraint.Name) {
                        throw new CircularDependencyException (string.Format ("{0} and {1} have a circular dependency on each other", _parent, _info.Name));
                    }
                }

                // single operators
                if (SearchForModule (_constraint.Name) == null)
                    _ret = false;

                ModuleInfo _ninfo = null;

                ModuleLoader _loader = new ModuleLoader (_search_path, _controller);

                try {
                    if (!_parents.Contains (_info.Name))
                        _parents.Add (_info.Name);

                    _loader.LoadModule (_parents, _constraint.Name, out _ninfo, true, true);
                } catch (CircularDependencyException ce) {
                    throw ce;
                } catch (Exception) {
                    if (!opt) {
                                throw new UnresolvedDependencyException (
                                    string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                        _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                );
                    }
                }

                if (_op == DepOps.Equal || _op == DepOps.GreaterThan || _op == DepOps.GreaterThanEqual || _op == DepOps.LessThan || _op == DepOps.LessThanEqual || _op == DepOps.NotEqual) {
                    if (!IsEmptyVersion (_constraint.Version)) {
                        if (!VersionMatch (_ninfo.Version, _constraint.Version, _op)) {
                            if (!opt) {
                                throw new UnresolvedDependencyException (
                                    string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                        _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                );
                            }
                        }
                    }

                    if (!checking) {
                        _controller.LoadModule (_constraint.Name);

                        _parents.Sort ();

                        ArrayList _seen = new ArrayList ();
                        _seen.Add (_info.Name);
                        _seen.Add (_constraint.Name);
                        foreach (string _p in _parents) {
                            if (!_seen.Contains (_p)) {
                                _controller.IncRef (_constraint.Name);
                                _seen.Add (_p);
                            }
                        }
                    }
                }

                if (_op == DepOps.Loaded) {
                    if (_controller.Loader.SearchForModule (_constraint.Name) == null)
                    {
                        if (!opt) {
                            throw new UnresolvedDependencyException (
                                        string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                            _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                    );
                        }
                    }

                    if (!checking) {
                        _controller.LoadModule (_constraint.Name);

                        _parents.Sort ();

                        ArrayList _seen = new ArrayList ();
                        _seen.Add (_info.Name);
                        _seen.Add (_constraint.Name);
                        foreach (string _p in _parents) {
                            if (!_seen.Contains (_p)) {
                                _controller.IncRef (_constraint.Name);
                                _seen.Add (_p);
                            }
                        }
                    }
                }

                if (_op == DepOps.NotLoaded) {
                    if (_controller.IsLoaded (_constraint.Name)) {
                        if (_controller.RefCount (_constraint.Name) > 1) {
                            if (!opt) {
                                throw new UnresolvedDependencyException (
                                        string.Format("The following dependency for the module {0} could not be resolved: ({3} operator)\n\t{1} ({2})",
                                            _info.Name, _constraint.Name, _constraint.Version.ToString(), OpToString (_op))
                                    );
                            }
                        }
                        if (!checking) {
                            _controller.UnloadModule (_constraint.Name);
                        }
                    }
                }
            }
        }
コード例 #14
0
        protected void PrintDepTree(DepNode _x, int nest)
        {
            if (_x == null)
                return;

            for (int i = 0; i < nest; i++)
                Console.Write ("  ");

            Console.Write ("{0}", OpToString (_x.DepOp));

            if (_x.Constraint != null) {
                Console.WriteLine (" {0}", _x.Constraint.Name);
            }
            else
                Console.WriteLine (); // Make the tree pretty.
            foreach (DepNode _d in _x.Children) {
                PrintDepTree (_d, nest + 1);
            }
        }
コード例 #15
0
        //throws RecognitionException, TokenStreamException
        public void oexpr(
		DepNode parent, bool root
	)
        {
            try {      // for error handling
            if ((LA(1)==LPAREN) && (LA(2)==EQ))
            {
                eqexpr(parent, root);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==NEQ)) {
                neqexpr(parent, root);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==LTE)) {
                lteexpr(parent, root);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==LS)) {
                ltexpr(parent, root);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==GTE)) {
                gteexpr(parent, root);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==GT)) {
                gtexpr(parent, root);
            }
            else if ((LA(1)==LPAREN) && (LA(2)==LD)) {
                ldexpr(parent, root);
            }
            else
            {
                throw new NoViableAltException(LT(1), getFilename());
            }

            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_1_);
            }
        }
コード例 #16
0
        //throws RecognitionException, TokenStreamException
        public void xorexpr(
		DepNode parent
	)
        {
            try {      // for error handling
            match(LPAREN);
            match(XOR);
            { // ( ... )+
                int _cnt18=0;
                for (;;)
                {
                    if ((LA(1)==LPAREN) && ((LA(2) >= EQ && LA(2) <= LD)) && (LA(3)==CLASS))
                    {
                        oexpr(parent, false);
                    }
                    else if ((LA(1)==LPAREN) && (tokenSet_2_.member(LA(2))) && (LA(3)==LPAREN||LA(3)==CLASS)) {
                        {
                            DepNode child = parent.CreateNewChild();
                            cexpr(child);
                        }
                    }
                    else
                    {
                        if (_cnt18 >= 1) { goto _loop18_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; }
                    }

                    _cnt18++;
                }
            _loop18_breakloop:				;
            }    // ( ... )+
            match(RPAREN);
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_1_);
            }
        }
コード例 #17
0
 public DepNode CreateNewChild()
 {
     DepNode child = new DepNode (this);
     _children.Add (child);
     return child;
 }
コード例 #18
0
 public DepNode()
 {
     _parent = null;
     _children = new ArrayList ();
 }
コード例 #19
0
        /// <summary>
        /// Creates a new ModuleInfo belonging to the given assembly.
        /// </summary>
        /// <remarks>None.</remarks>
        /// <param name="_asm">The owning assembly.</param>
        public ModuleInfo(Assembly _asm)
        {
            _name = _asm.GetName ().Name;
            _version = DepVersion.VersionParse (_asm.GetName().Version.ToString ());

            ModuleDependencyAttribute _depAttr;
            ModuleRoleAttribute _roleAttr;

            try {
                _depAttr = ((ModuleDependencyAttribute)(_asm.GetCustomAttributes (typeof (ModuleDependencyAttribute), false)[0]));
            } catch (IndexOutOfRangeException) {
                _depAttr = null;
            }

            if (_depAttr != null) {
                DepLexer _lexer = new DepLexer (new StringReader (_depAttr.DepString));
                DepParser _parser = new DepParser (_lexer);

                // woot...lets do this!
                _dependencies = new DepNode ();

                _parser.expr (_dependencies);
            } else
                _dependencies = null;

            try {
                _roleAttr = ((ModuleRoleAttribute)(_asm.GetCustomAttributes (typeof (ModuleRoleAttribute), false)[0]));
            } catch (IndexOutOfRangeException) {
                _roleAttr = null;
            }

            if (_roleAttr != null) {
                _roles = _roleAttr.Roles;
            } else
                _roles = null;

            _owner = _asm;
        }