public AppDomain createAppDomain(string appDomainName, AppDomainSetup appDomainSetup)
        {
            try
            {
                if (DI.appDomainsControledByO2Kernel.ContainsKey(appDomainName))
                {
                    DI.log.error("in createAppDomain, appDomainName provided has already been used, appDomainNames must be unique: {0}", appDomainName);
                }
                else
                {
                    DI.log.info("Creating AppDomain {0} with Base Directory {1}", appDomainName,
                                appDomainSetup.ApplicationBase);
                    // ensure target directory exits
                    O2Kernel_Files.checkIfDirectoryExistsAndCreateIfNot(appDomainSetup.ApplicationBase);

                    // give our appDomain full trust :)
                    var permissionSet = new PermissionSet(PermissionState.Unrestricted);

                    DI.appDomainsControledByO2Kernel.Add(appDomainName, this);

                    //Create domain
                    appDomain = AppDomain.CreateDomain(appDomainName, null, appDomainSetup, permissionSet);
                    //        appDomain.AssemblyResolve += new ResolveEventHandler(assemblyResolve);
                    BaseDirectory = appDomain.BaseDirectory;
                    return(appDomain);
                }
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "could not load createAppDomain: " + appDomainName);
            }
            return(null);
        }
Exemplo n.º 2
0
        public static RichTextBox           document(string fileToView)
        {
            var title = "RTF file: " + fileToView;

            return(title.popupWindow(800, 400)
                   .add_RichTextBox()
                   .set_Rtf(O2Kernel_Files.getFileContents(fileToView)));
        }
Exemplo n.º 3
0
        public static TextBox               file(string fileToView)
        {
            var title = "Text file: " + fileToView;

            return(title.popupWindow(800, 400)
                   .add_TextBox()
                   .set_Text(O2Kernel_Files.getFileContents(fileToView)));
        }
        public static AppDomain     loadAssembliesIntoAppDomain(this AppDomain appDomain, List <string> assembliesToLoad)
        {
            var assembliesInNewAppDomain = new List <String>();

            // first copy the assemblies
            foreach (var assemblyToLoad in assembliesToLoad)
            {
                if (assemblyToLoad.extension(".dll") || assemblyToLoad.extension().ToLower() == ".exe") // since other wise these might be GAC assemblies
                {
                    if (File.Exists(assemblyToLoad))
                    {
                        var targetFileName = Path.Combine(appDomain.BaseDirectory, assemblyToLoad.fileName());
                        if (targetFileName.fileExists().isFalse())
                        {
                            O2Kernel_Files.Copy(assemblyToLoad, targetFileName);
                        }
                        assembliesInNewAppDomain.Add(targetFileName);
                    }
                    else
                    {
                        var resolvedName = Path.Combine(PublicDI.config.CurrentExecutableDirectory, assemblyToLoad);
                        if (File.Exists(resolvedName))
                        {
                            var targetFileName = Path.Combine(appDomain.BaseDirectory, resolvedName.fileName());
                            if (targetFileName.fileExists().isFalse())
                            {
                                O2Kernel_Files.Copy(resolvedName, targetFileName);
                            }
                            assembliesInNewAppDomain.Add(targetFileName);
                        }
                        else
                        {
                            PublicDI.log.error("in loadAssembliesIntoAppDomain , could not find dll to copy: {0}",
                                               assemblyToLoad);
                        }
                    }
                }
            }
            // then load them (and if there are no missing dependencies ALL should load ok
            foreach (var assemblyToLoad in assembliesInNewAppDomain)
            {
                try
                {
                    appDomain.Load(Path.GetFileNameWithoutExtension(assemblyToLoad));
                }
                catch (Exception ex)
                {
                    PublicDI.log.ex(ex,
                                    "in O2AppDomainFactory.loadAssembliesIntoAppDomain, could not load assembly: " +
                                    assemblyToLoad);
                }
            }

            return(appDomain);
        }
 public bool load(string fullAssemblyName, string pathToAssemblyToLoad,
                  bool copyToAppDomainBaseDirectoryBeforeLoad)
 {
     try
     {
         // copy if asked to
         if (copyToAppDomainBaseDirectoryBeforeLoad)
         {
             try
             {
                 if (File.Exists(pathToAssemblyToLoad))
                 {
                     O2Kernel_Files.Copy(pathToAssemblyToLoad, appDomain.BaseDirectory);
                 }
                 else
                 {
                     DI.log.error(
                         "copyToAppDomainBaseDirectoryBeforeLoad was set but pathToAssemblyToLoad was set to a file that didn't exist: {0}",
                         pathToAssemblyToLoad);
                 }
             }
             catch (Exception ex)
             {
                 ex.log("in load copyToAppDomainBaseDirectoryBeforeLoad");
             }
         }
         // load assembly into AppDomain
         //First try directly
         appDomain.Load(fullAssemblyName);
     }
     catch (Exception ex1)
     {
         //then try using AssemblyName
         try
         {
             appDomain.Load(AssemblyName.GetAssemblyName(fullAssemblyName));
         }
         catch (Exception ex2)
         {
             // last change load assembly into current appdomain to get its full name and try again
             try
             {
                 appDomain.Load(Kernel.ExtensionMethods.Reflection_ExtensionMethods.assembly(fullAssemblyName).FullName);
             }
             catch (Exception ex3)
             {
                 DI.log.ex(ex1, "could not load assembly (method1): " + fullAssemblyName);
                 DI.log.ex(ex2, "could not load assembly (method2): " + fullAssemblyName);
                 DI.log.ex(ex3, "could not load assembly (method3): " + fullAssemblyName);
                 return(false);
             }
         }
     }
     return(true);
 }
 public static string    o2Temp2Dir(this string tempFolderName, bool appendRandomStringToFolderName)
 {
     if (tempFolderName.valid())
     {
         if (appendRandomStringToFolderName)
         {
             return(PublicDI.config.getTempFolderInTempDirectory(tempFolderName));
         }
         else
         {
             var tempFolder = Path.Combine(PublicDI.config.O2TempDir, tempFolderName);
             O2Kernel_Files.checkIfDirectoryExistsAndCreateIfNot(tempFolder);
             return(tempFolder);
         }
     }
     return(PublicDI.config.O2TempDir);
 }
Exemplo n.º 7
0
        public static RichTextBox document(string fileToView)
        {
            var title = "RTF file: " + fileToView;

            return(title.openControlAsForm <RichTextBox>(800, 400, "add_RichTextBox", null, "set_Rtf", O2Kernel_Files.getFileContents(fileToView)));
        }
Exemplo n.º 8
0
        public static TextBox file(string fileToView)
        {
            var title = "Text file: " + fileToView;

            return(title.openControlAsForm <TextBox>(800, 400, "add_TextBox", true, "set_Text", O2Kernel_Files.getFileContents(fileToView)));
        }
 public static bool                                   load(this AppDomain appDomain, string fullAssemblyName, string pathToAssemblyToLoad, bool copyToAppDomainBaseDirectoryBeforeLoad)
 {
     try
     {
         // copy if asked to
         if (copyToAppDomainBaseDirectoryBeforeLoad)
         {
             try
             {
                 if (File.Exists(pathToAssemblyToLoad))
                 {
                     O2Kernel_Files.Copy(pathToAssemblyToLoad, appDomain.BaseDirectory);
                 }
                 else
                 {
                     PublicDI.log.error(
                         "copyToAppDomainBaseDirectoryBeforeLoad was set but pathToAssemblyToLoad was set to a file that didn't exist: {0}",
                         pathToAssemblyToLoad);
                 }
             }
             catch (Exception ex)
             {
                 ex.log("in load copyToAppDomainBaseDirectoryBeforeLoad");
             }
         }
         // load assembly into AppDomain
         //First try directly
         appDomain.Load(fullAssemblyName);
     }
     catch (Exception ex1)
     {
         //then try using AssemblyName
         try
         {
             appDomain.Load(AssemblyName.GetAssemblyName(fullAssemblyName));
         }
         catch (Exception ex2)
         {
             // then load assembly into current appdomain to get its full name and try again
             try
             {
                 appDomain.Load(fullAssemblyName.assembly().FullName);
             }
             catch (Exception ex3)
             {
                 // last change load assembly into current appdomain to try to use the full path of the assembly (if it is known to the current process)
                 var assemblyLocation = fullAssemblyName.assembly_Location();
                 if (assemblyLocation.fileExists())
                 {
                     try
                     {
                         appDomain.Load(assemblyLocation);
                     }
                     catch (Exception ex4)
                     {
                         PublicDI.log.ex(ex1, "could not load assembly (method1): " + fullAssemblyName);
                         PublicDI.log.ex(ex2, "could not load assembly (method2): " + fullAssemblyName);
                         PublicDI.log.ex(ex3, "could not load assembly (method3): " + fullAssemblyName);
                         PublicDI.log.ex(ex4, "could not load assembly (method4): " + assemblyLocation);
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }