protected bool VersionMatch(DepVersion _ver, DepVersion _dver, DepOps _op) { Version _mver, _drver; if (_dver.Major == -1) return true; _mver = new Version (_dver.Major != -1 ? _ver.Major : 0, _dver.Minor != -1 ? _ver.Minor : 0, _dver.Build != -1 ? _ver.Build : 0, _dver.Revision != -1 ? _ver.Revision : 0); _drver = new Version (_dver.Major != -1 ? _dver.Major : 0, _dver.Minor != -1 ? _dver.Minor : 0, _dver.Build != -1 ? _dver.Build : 0, _dver.Revision != -1 ? _dver.Revision : 0); int vres = _mver.CompareTo (_drver); switch (_op) { case DepOps.Equal: return vres == 0; case DepOps.GreaterThan: return vres > 0; case DepOps.GreaterThanEqual: return vres > 0 || vres == 0; case DepOps.LessThan: return vres < 0; case DepOps.LessThanEqual: return vres < 0 || vres == 0; case DepOps.NotEqual: return vres != 0; } return false; }
protected string OpToString(DepOps _op) { switch (_op) { case DepOps.And: return "&&"; case DepOps.Equal: return "=="; case DepOps.GreaterThan: return ">>"; case DepOps.GreaterThanEqual: return ">="; case DepOps.LessThan: return "<<"; case DepOps.LessThanEqual: return "<="; case DepOps.Loaded: return "##"; case DepOps.Not: return "!!"; case DepOps.NotEqual: return "!="; case DepOps.Opt: return "??"; case DepOps.Or: return "||"; case DepOps.Xor: return "^^"; } return ""; }
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 } }
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); } } } } }
protected string ReportUnresolvedException(DepOps _op, DepConstraint _constraint) { // message should look like << Elfblade.Core 1.0 // or ## Elfblade.Net.Base return string.Format ("{0} {1} {2}", OpToString (_op), _constraint.Name, IsEmptyVersion (_constraint.Version) ? "" : _constraint.Version.ToString ()); }
protected bool VersionMatch(DepVersion _dver, DepVersion _ver, DepOps _op) { bool mjgt = false, mngt = false, bgt = false, rgt = false; bool mjeq = false, mneq = false, beq = false, req = false; bool mjlt = false, mnlt = false, blt = false, rlt = false; bool mji = false, mni = false, bi = false, ri = false; if (_dver.Major == -1) { mji = true; } else if (_dver.Major > _ver.Major) { mjgt = true; } else if (_dver.Major == _ver.Major) { mjeq = true; } else { mjlt = true; } if (_dver.Minor == -1) { mni = true; } else if (_dver.Minor > _ver.Minor) { mngt = true; } else if (_dver.Minor == _ver.Minor) { mneq = true; } else { mnlt = true; } if (_dver.Build == -1) { bi = true; } else if (_dver.Build > _ver.Build) { bgt = true; } else if (_dver.Build == _ver.Build) { beq = true; } else { blt = true; } if (_dver.Revision == -1) { ri = true; } else if (_dver.Revision > _ver.Revision) { rgt = true; } else if (_dver.Revision == _ver.Revision) { req = true; } else { rlt = true; } if (mji) return true; if ((_op == DepOps.Equal) || (_op == DepOps.GreaterThanEqual) || (_op == DepOps.LessThanEqual)) { if (mjeq && mni) return true; if (mjeq && mneq && bi) return true; if (mjeq && mneq && beq && ri) return true; if (mjeq && mneq && beq && req) return true; } if (_op == DepOps.NotEqual) { if (!mjeq && mni) return true; if (!mjeq && !mneq && bi) return true; if (!mjeq && !mneq && !beq && ri) return true; if (!mjeq && !mneq && !beq && !req) return true; } if (_op == DepOps.GreaterThan) { if (mjlt) return false; if (mjgt) return true; if (mjeq && mnlt) return false; if (mngt) return true; if (mjeq && mneq && blt) return false; if (bgt) return true; if (mjeq && mneq && beq && rlt) return false; if (rgt) return true; } if (_op == DepOps.LessThan) { if (mjgt) return false; if (mjlt) return true; if (mjeq && mngt) return false; if (mnlt) return true; if (mjeq && mneq && bgt) return false; if (blt) return true; if (mjeq && mneq && beq && rgt) return false; if (rlt) return true; } if (_op == DepOps.Loaded) return true; return false; }