/////////////////////////////////////////////////////////////////////// #if APPDOMAINS || ISOLATED_INTERPRETERS || ISOLATED_PLUGINS private static string GetBasePath( Interpreter interpreter, /* OPTIONAL */ string packagePath, ref Result error ) { // // NOTE: Fetch the raw base directory for the currently executing // application binary. It is now possible to override the // value used here via the environment. // string path0 = AssemblyOps.GetAnchorPath(); if (path0 == null) { path0 = GlobalState.GetRawBinaryBasePath(); } // // NOTE: First, try to use the effective path to the core library // assembly. This is used to verify that this candidate // application domain base path contains the core library // assembly somewhere underneath it. // string path1 = GetAssemblyPath(); if (PathOps.IsUnderPath(interpreter, path1, path0)) { if ((packagePath == null) || PathOps.IsUnderPath(interpreter, packagePath, path0)) { return(path0); } } // // NOTE: Second, try to use the raw base path for the assembly. // This is used to verify that this candidate application // domain base path contains the core library assembly // somewhere underneath it. // string path2 = GlobalState.GetRawBasePath(); if (PathOps.IsUnderPath(interpreter, path1, path2)) { if ((packagePath == null) || PathOps.IsUnderPath(interpreter, packagePath, path2)) { return(path2); } } // // NOTE: At this point, we have failed to figure out a base path // for the application domain to be created that actually // contains the core library assembly. // error = String.Format( "cannot determine usable base path for the new application " + "domain for interpreter {0}, with the raw binary base path " + "{1}, assembly path {2}, and raw base path {3}", FormatOps.InterpreterNoThrow(interpreter), FormatOps.DisplayPath(path0), FormatOps.DisplayPath(path1), FormatOps.DisplayPath(path2)); return(null); }
/////////////////////////////////////////////////////////////////////// private static AppDomainSetup CreateSetup( Interpreter interpreter, /* OPTIONAL */ string baseDirectory, string packagePath, bool useBasePath, ref Result error ) { string basePath = baseDirectory; if (useBasePath && (basePath == null) && (interpreter != null)) { basePath = interpreter.PluginBaseDirectory; } Result localError = null; if (useBasePath && (basePath == null)) { basePath = GetBasePath( interpreter, packagePath, ref localError); } if (!useBasePath || (basePath != null)) { // // NOTE: Check if the package path is located under the base // path. // bool packageUnderBasePath = (packagePath != null) ? PathOps.IsUnderPath(interpreter, packagePath, basePath) : false; // // NOTE: Verify that the package path is either usable or // superfluous. // if ((packagePath == null) || !useBasePath || packageUnderBasePath) { // // NOTE: Grab the full path for the Eagle core library // assembly. // string assemblyPath = GetAssemblyPath(); // // NOTE: Check if the assembly path is located under // the base path. // bool assemblyUnderBasePath = (assemblyPath != null) ? PathOps.IsUnderPath(interpreter, assemblyPath, basePath) : false; // // NOTE: Verify that the assembly path is either usable // or superfluous. // if ((assemblyPath == null) || !useBasePath || assemblyUnderBasePath) { AppDomainSetup appDomainSetup = new AppDomainSetup(); // // NOTE: Use the base directory of the Eagle install // as the base directory for the new isolated // application domain. // appDomainSetup.ApplicationBase = useBasePath ? basePath : (packagePath != null) ? packagePath : assemblyPath; // // NOTE: If we are using the base path of the Eagle // core library assembly, then we need to modify // the private binary path so that it includes // both the directory containing that assembly // and the directory containing the package; // otherwise, we can simply skip this step. // if (useBasePath) { // // TODO: May need to add more options here. // string relativeAssemblyPath = (assemblyPath != null) && assemblyUnderBasePath? assemblyPath.Remove(0, basePath.Length).Trim( PathOps.DirectoryChars) : null; string privateBinPath = relativeAssemblyPath; string relativePackagePath = (packagePath != null) && packageUnderBasePath? packagePath.Remove(0, basePath.Length).Trim( PathOps.DirectoryChars) : null; if (!String.IsNullOrEmpty(relativePackagePath)) { if (!String.IsNullOrEmpty(privateBinPath)) { privateBinPath += Characters.SemiColon; } privateBinPath += relativePackagePath; } appDomainSetup.PrivateBinPath = privateBinPath; } return(appDomainSetup); } else { error = "assembly path is not under base path"; } } else { error = "package path is not under base path"; } } else if (localError == null) { error = "invalid base path"; } else { error = localError; } return(null); }
/////////////////////////////////////////////////////////////////////// public static string GetPath( Interpreter interpreter, /* OPTIONAL */ Assembly assembly ) /* CANNOT RETURN NULL */ { // // NOTE: Fetch the base directory for the current application // domain. This will be used to check if the candidate // assembly paths are underneath it. It is now possible // to override the value used here via the environment. // string path0 = GetAnchorPath(); if (path0 == null) { path0 = GlobalState.GetAppDomainBaseDirectory(); } // // NOTE: First, try to use the current path to the assembly, // checking to make sure that it resides underneath the // base directory for the application domain. // string path1 = GetCurrentPath(assembly); if (PathOps.IsUnderPath(interpreter, path1, path0)) { return(path1); } // // NOTE: Second, try to use the original path to the assembly, // checking to make sure that it resides underneath the // base directory for the application domain. // string path2 = GetOriginalPath(assembly); if (PathOps.IsUnderPath(interpreter, path2, path0)) { return(path2); } // // NOTE: At this point, we have failed to figure out a path for // this assembly that actually resides within the current // application domain. This condition is not impossible; // however, it should not happen for the core library // assembly itself. // DebugOps.Complain(interpreter, ReturnCode.Error, String.Format( "could not determine a path for assembly {1} underneath " + "the application domain path {0}", FormatOps.DisplayPath( path0), FormatOps.DisplayAssemblyName(assembly))); // // NOTE: This method cannot return null; therefore, the legacy // return value will be used instead (i.e. the current // path to the assembly). // return(path1); }