protected void InternalResolve(ArrayList _parents, ModuleInfo _info, bool checking) { if (_info.Dependencies == null) return; if (_parents == null) _parents = new ArrayList (); OpResolve (_info.Dependencies, _parents, _info, checking, DepOps.Null); }
protected void InternalResolve(ArrayList _parents, ModuleInfo _info, bool checking) { if (_info.Dependencies == null) return; DepNode _node = _info.Dependencies; foreach (string _parent in _parents) { if (_node.Constraint.Name == _parent) { throw new CircularDependencyException ( string.Format("The module {0} is depending on {1} which is depending on {0}, causing a circular dependency.", _parent, _info.Name, _parent) ); } } OpResolve (_node, _parents, _info, checking); }
protected void InternalResolve(ArrayList _parents, ModuleInfo _info, bool checking) { if (_info.Dependencies == null) return; if (_parents == null) _parents = new ArrayList (); if (checking) { foreach (DepNode _c in _info.Dependencies.Children) { CheckCircularDeps (_c, _parents); } } Console.WriteLine (">>>>> Beginning OpResolve loop for {0}...", _info.Name); OpResolve (_info.Dependencies, _parents, _info, checking, DepOps.Null); }
public void ResolveCheck(ArrayList _parents, ModuleInfo _info) { InternalResolve (_parents, _info, true); }
public void Resolve(ArrayList _parents, ModuleInfo _info) { InternalResolve (_parents, _info, false); }
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 } }
public AppDomain LoadModule(ArrayList _parents, string _name, out ModuleInfo _info, bool checking, bool depcheck) { // Okay, this is tricky. First, we have to load the module into a temp domain // to retrieve its module info. Then, we have to attempt to resolve the dependencies. // This is going to be fun. Heh. if (_parents == null) _parents = new ArrayList (); // Try to find the module on the search path. string _filename = SearchForModule (_name); if (_filename == null) throw new ModuleNotFoundException (string.Format ("The module {0} was not found along the module search path.", _name)); // Okay, well, now we know the module exists at least in the file (we hope its a proper dll, but we'll see :). Now we // need to create the temporary AppDomain and load it to get the info from it. AppDomainSetup _setup = new AppDomainSetup (); _setup.ApplicationBase = Directory.GetCurrentDirectory (); AppDomain _tempDomain = AppDomain.CreateDomain (_name, new Evidence (), _setup); byte[] _raw_bytes = LoadRawFile (_filename); // set up the search path // Let's there this son of a bitch up. _tempDomain.ClearPrivatePath (); _tempDomain.AppendPrivatePath (Directory.GetCurrentDirectory ()); foreach (string s in _search_path) { _tempDomain.AppendPrivatePath (s); } // The throw here is mostly used from dep resolver calls, although it should also be caught by the immediate caller // (i.e. the application). try { _tempDomain.Load (_raw_bytes); } catch (BadImageFormatException e) { AppDomain.Unload (_tempDomain); throw new ModuleImageException (e.Message); } // Okay, now lets grab the module info from the assembly attributes. Assembly _asm = GetAssembly (_tempDomain, _name); try { _info = new ModuleInfo (_asm); } catch (ModuleInfoException e) { AppDomain.Unload (_tempDomain); throw new InvalidModuleException (e.Message); } // okay, now we've got the info, let's do some magic with the dependencies. // this will recursively load all of the appropriate assemblies as per the parsed // depedency tree. It will take into account dependency operators, such as AND, OR // OPT (optional). Very intelligent stuff. Of course, if there are no depends, // this just simply returns. This will of course continue updating the parents as needed // since each time a new module is loaded, the resolver is recursively called until // a module with no dependencies is found. This is cool. What this will do is call this method with // checking=true, which will cause it to just return if the module suceeds. This way // we can ensure we don't load unneeded module Z that is a dependency of X which depends // on Y, because if Z suceeds but Y fails, we don't want X, Y, or Z to fail. This way, // we can ensure the entire tree can be loaded first (this does take into account already // loaded assemblies). if (depcheck) { DepResolver _resolver = new DepResolver (_controller, _search_path); _parents.Add (_name); try { _resolver.Resolve (_parents, _info); } catch (Exception e) { AppDomain.Unload (_tempDomain); throw e; } } if (checking) { AppDomain.Unload (_tempDomain); return null; } // okay, they're good, lets load the suckers. // alright, we've got them all loaded, they exist in the assembly map. // now we create the *real* app domain. // We can't do any more with this. return _tempDomain; }
public AppDomain LoadModule(ArrayList _parents, string _name, out ModuleInfo _info, bool checking) { return LoadModule (_parents, _name, out _info, checking, true); }
/* * We provide two method signatures for loading for convienence. The first just takes the name of the module (minus the .dll extension), * and attempts to load it. The second takes a list of parents and the name. The first incidentally just calls the second with an empty * parents list. The parents list is used for detecting circular dependencies. */ public AppDomain LoadModule(string _name, out ModuleInfo _info) { return LoadModule (null, _name, out _info, false); }
protected void CallRoleUnregisterHandlers(ModuleInfo _info) { foreach (string _myRole in _info.Roles.Split(',')) { foreach (ModuleRole _role in _roles) { if (_role.RoleName == _myRole) { Assembly _asm = _info.Owner; Type _type = null; foreach (Type __type in _asm.GetTypes ()) { if (_role.BaseType.IsClass) { if (__type.IsSubclassOf (_role.BaseType)) { _type = __type; break; } } else if (_role.BaseType.IsInterface) { if (__type.GetInterface (_role.BaseType.ToString ()) != null) { _type = __type; break; } } } if (_type == null) { continue; // don't have a type for this role. } _role.UnregistrationHandler (_asm); } } } }
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); } } } } }
/// <summary> /// Calls all of the role unregistration handlers for the given /// <see cref="ModuleInfo" /> object. /// </summary> /// <remarks> /// See <see href="roles.html">Roles</see> for an explanation of module roles. /// </remarks> /// <param name="_info">The <see cref="ModuleInfo"/> object to determine which role handlers to call.</param> protected void CallRoleUnregisterHandlers(ModuleInfo _info) { foreach (ModuleRole _role in _roles) { CallRoleUnregisterHandlers (_info, _role); } }
/// <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); } } } } }
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 } }