Esempio n. 1
0
        public void MultiLoad()
        {
            var assemblies = new[]
            {
                Assembly.Load(new AssemblyName("Exor.Core.Tests.ContentB")),
                Assembly.Load(new AssemblyName("Exor.Core.Tests.ContentA"))
            };

            var loader = new ExtensionLoader(_logger, assemblies, TypeRecords, true);

            var noCtor = loader.Load <SimpleTestBase>("A");

            Assert.IsTrue(noCtor.GetType().FullName.Contains("SimpleTestB"));
            Assert.AreEqual(0, noCtor.Value);

            var withCtor = loader.Load <CtorTestBase>("A", 5, DateTime.MinValue);

            Assert.IsTrue(withCtor.GetType().FullName.Contains("CtorTestB"));
            Assert.AreEqual(5, withCtor.Value);
            Assert.AreEqual(DateTime.MinValue, withCtor.Time);

            var deepLoad = loader.DeepEagerLoad <CtorTestBase>("A", 10, DateTime.MaxValue);

            Assert.IsTrue(deepLoad.Count == 2, "didn't find 2 instances");
            Assert.IsTrue(deepLoad[0].GetType().FullName.Contains("CtorTestB"));
            Assert.AreEqual(10, deepLoad[0].Value);
            Assert.AreEqual(DateTime.MaxValue, deepLoad[0].Time);

            Assert.IsTrue(deepLoad[1].GetType().FullName.Contains("CtorTestA"));
            Assert.AreEqual(10, deepLoad[1].Value);
            Assert.AreEqual(DateTime.MaxValue, deepLoad[1].Time);

            var mappedLoad = loader.LoadAll <SimpleTestBase>();

            Assert.IsTrue(mappedLoad.Count == 2, "didn't find 2 instances");

            Assert.IsTrue(mappedLoad.ContainsKey("A"), "has key A");
            Assert.IsTrue(mappedLoad["A"].GetType().FullName.Contains("SimpleTestB"));
            Assert.IsTrue(mappedLoad.ContainsKey("A2"), "has key A2");
            Assert.IsTrue(mappedLoad["A2"].GetType().FullName.Contains("OtherSimpleTestA"));

            var deepMappedLoad = loader.DeepLoadAll <SimpleTestBase>();

            Assert.IsTrue(deepMappedLoad.Count == 2, "didn't find 2 keys");

            Assert.IsTrue(deepMappedLoad.ContainsKey("A"), "has key A");
            Assert.IsTrue(deepMappedLoad["A"][0].GetType().FullName.Contains("SimpleTestB"));
            Assert.IsTrue(deepMappedLoad["A"][1].GetType().FullName.Contains("SimpleTestA"));
            Assert.IsTrue(deepMappedLoad.ContainsKey("A2"), "has key A2");
            Assert.IsTrue(deepMappedLoad["A2"][0].GetType().FullName.Contains("OtherSimpleTestA"));
        }
Esempio n. 2
0
        /// <summary>
        /// Find all assemblies in the subdirectory, and load them into memory
        /// </summary>
        public static void LoadModules()
        {
            List <string> allAssemblies = new List <string>();

#if DEBUG
            string path = Assembly.GetExecutingAssembly().Location;
#else
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\JPP Consulting\\JPP AutoCad Library";
#endif

            //Check if authenticated, otherwise block the auto loading
            if (Authentication.Current.Authenticated())
            {
                //Iterate over every dll found in bin folder
                if (Directory.Exists(path))
                {
                    foreach (string dll in Directory.GetFiles(path, "*.dll"))
                    {
                        string dllPath = dll.Replace('\\', '/');
                        //Load the additional libraries found
                        Assembly module = ExtensionLoader.Load(dll);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Find all assemblies in the subdirectory, and load them into memory
        /// </summary>
        public static void LoadModules()
        {
            #if DEBUG
            string path = Assembly.GetExecutingAssembly().Location;
            #else
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\JPP Consulting\\JPP AutoCad Library";
            #endif

            //Check if authenticated, otherwise block the auto loading
            if (Authentication.Current.Authenticated())
            {
                //Iterate over every dll found in bin folder
                if (Directory.Exists(path))
                {
                    foreach (string dll in Directory.GetFiles(path, "*.dll"))
                    {
                        //Load the additional libraries found
                        ExtensionLoader.Load(dll);
                    }
                }
                else
                {
                    Log.Entry(Resources.Error_ModuleDirectoryMissing, Severity.Error);
                }
            }
            else
            {
                Log.Entry(Resources.Error_ModuleLoadFailedAuthentication, Severity.Error);
            }
        }
Esempio n. 4
0
        void Start()
        {
            try
            {
                if (!Directory.Exists(DefaultPath))
                {
                    Directory.CreateDirectory(DefaultPath);
                }
                if (!Directory.Exists(LoggingPath))
                {
                    Directory.CreateDirectory(LoggingPath);
                }
                if (!Directory.Exists(PluginPath))
                {
                    Directory.CreateDirectory(PluginPath);
                }

                ExtensionLoader.Load();

                DataStore.GetInstance().Save();
                PluginCollector.GetCollector();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(string.Format("[Error] Failed to load Redox, Error: {0}", ex));
            }
        }
Esempio n. 5
0
        public void LoadAssembly()
        {
            Editor ed       = Application.DocumentManager.MdiActiveDocument.Editor;
            string fileName = "C:\\net1_VB.dll";

            ExtensionLoader.Load(fileName);
            ed.WriteMessage("\n" + fileName + "被载入,请输入Hello进行测试!");
        }
Esempio n. 6
0
        public void OptCommand()
        {
            Editor ed       = Application.DocumentManager.MdiActiveDocument.Editor;
            string filename = "C:\\Users\\123\\Desktop\\test\\Hello.dll";

            ExtensionLoader.Load(filename);
            ed.WriteMessage("\n" + filename + "被载入,输入hello进行测试");
        }
Esempio n. 7
0
        public void Initialize()                        //初始化程序。
        {
            AcadNetDllAutoLoader(Registry.CurrentUser); //写入注册表
            var           netDllList   = AutoCADNetDllInfor();
            List <string> localDlllist = new List <string>();

            // 检测本地的dll 并从服务器下载文件
            foreach (string dllFileName in netDllList)
            {
                FileInfo fileCurrent = new FileInfo(currentDllPath + "\\" + Path.GetFileNameWithoutExtension(dllFileName));
                FileInfo fileNet     = new FileInfo(dllFileName);
                if (fileNet.Exists)
                {
                    fileNet.CopyTo(currentDllPath + "\\" + Path.GetFileName(dllFileName), true);
                }
                localDlllist.Add(currentDllPath + "\\" + Path.GetFileName(dllFileName));
            }
            //复制图标
            #region// copy cmd icon to local folder
            if (!Directory.Exists(currentDllPath + "\\KFWH_CMD_ICON"))
            {
                Directory.CreateDirectory(currentDllPath + "\\KFWH_CMD_ICON");
            }
            //
            List <string> listIconFiles = new List <string>();
            string        sqlcommand    = $"select * from tb_PluginUsedFiles where Class_Name='AutoCADPluginICON' and FileName='KFWH_CMD_ICON'";
            SqlDataReader sdr           = SqlHelper.MyExecuteReader(sqlcommand); //调用自己编写的sqlhelper类
            if (sdr.HasRows)                                                     //判断行不为空
            {
                while (sdr.Read())                                               //循环读取数据,知道无数据为止
                {
                    listIconFiles.Add(sdr["Path"].ToString() + "\\" + sdr["FileName"].ToString());
                }
            }
            if (Directory.Exists(listIconFiles[0]))
            {
                string[] fis = Directory.GetFiles(listIconFiles[0]);
                foreach (var item in fis)
                {
                    FileInfo fi = new FileInfo(item);
                    fi.CopyTo(currentDllPath + "\\KFWH_CMD_ICON\\" + Path.GetFileName(item), true);
                }
            }
            #endregion
            //加载dll到cad,提取cad命令
            List <myAutoCADNetDll> listDllcmd = GetACADNetDllCmd(localDlllist);
            foreach (var item in localDlllist)
            {
                ExtensionLoader.Load(item);
            }
            AddMenusToAutoCAD(listDllcmd);//加载cuix菜单
            if (this.mycuiFileName != string.Empty)
            {
                Application.LoadPartialMenu(this.mycuiFileName);
            }
        }
Esempio n. 8
0
        public void OptCommand()
        {
            Editor ed        = Application.DocumentManager.MdiActiveDocument.Editor;
            string fileName1 = "C:\\Users\\Closer\\Desktop\\工作文件\\AutoCAD\\Hello\\Hello\\bin\\Debug\\Hello.dll";
            string fileName2 = "C:\\Users\\Closer\\Desktop\\工作文件\\AutoCAD\\DotNetARX\\DotNetARX\\bin\\Debug\\DotNetARX.dll";

            ExtensionLoader.Load(fileName1);
            ExtensionLoader.Load(fileName2);
            ed.WriteMessage("\n" + fileName1 + " " + fileName2 + "被载入,请输入Hello进行测试!!!!!!");
        }
Esempio n. 9
0
        public void SingleLoad()
        {
            var assemblies = new[]
            {
                Assembly.Load(new AssemblyName("Exor.Core.Tests.ContentA"))
            };

            var loader = new ExtensionLoader(_logger, assemblies, TypeRecords, true);

            var noCtor = loader.Load <SimpleTestBase>("A");

            Assert.IsTrue(noCtor.GetType().FullName.Contains("SimpleTestA"));
            Assert.AreEqual(0, noCtor.Value);

            var withCtor = loader.Load <CtorTestBase>("A", 5, DateTime.MinValue);

            Assert.IsTrue(withCtor.GetType().FullName.Contains("CtorTestA"));
            Assert.AreEqual(5, withCtor.Value);
            Assert.AreEqual(DateTime.MinValue, withCtor.Time);
        }
Esempio n. 10
0
        private void LoadAssembly(string dll)
        {
            //Load the additional libraries found
            if (!ExtensionLoader.IsLoaded(dll))
            {
                Assembly target = ExtensionLoader.Load(dll);
                //TODO: Verify actually loaded

                _loadedModules[dll].Loaded = true;
            }
        }
Esempio n. 11
0
        public void NoContentFailure()
        {
            var loader = new ExtensionLoader(_logger, new Assembly[] {}, TypeRecords, true);

            try
            {
                var obj = loader.Load <SimpleTestBase>("A");
                Assert.Fail("Should not have been able to load a SimpleTestBase.");
            }
            catch
            {
            }
        }
Esempio n. 12
0
        public void Load()
        {
            if (!CoreExtensionApplication.CoreConsole)
            {
                try
                {
                    if (File.Exists(DataPath + "\\IronstoneCoreUI.dll"))
                    {
                        ExtensionLoader.Load(DataPath + "\\IronstoneCoreUI.dll");
                    }
                    else
                    {
                        ExtensionLoader.Load(BinPath + "\\IronstoneCoreUI.dll");
                    }
                    _logger.Entry("Core UI library loaded.", Severity.Debug);
                }
                catch (System.Exception e)
                {
                    _logger.Entry($"Unable to load Core UI library", Severity.Crash);
                    _logger.LogException(e);
                    throw;
                }
            }

            foreach (Module m in _loadedModules.Values.Where(m => m.ObjectModel))
            {
                if (m.Authenticated)
                {
                    LoadAssembly(m.Path);
                }
            }

            //Check if authenticated, otherwise block the auto loading
            if (_authentication.Authenticated())
            {
                foreach (Module m in _loadedModules.Values.Where(m => !m.ObjectModel))
                {
                    if (m.Authenticated)
                    {
                        LoadAssembly(m.Path);
                    }
                }
            }

            //Once modules loaded, create any required stores for documents that might already open.
            _dataService.CreateStoresFromAppDocumentManager();
        }
Esempio n. 13
0
        public void Load()
        {
            if (!CoreExtensionApplication.CoreConsole)
            {
                try
                {
                    if (File.Exists(DataPath + "\\IronstoneCoreUI.dll"))
                    {
                        ExtensionLoader.Load(DataPath + "\\IronstoneCoreUI.dll");
                    }
                    else
                    {
                        ExtensionLoader.Load(BinPath + "\\IronstoneCoreUI.dll");
                    }
                    _logger.LogDebug("Core UI library loaded.");
                }
                catch (System.Exception e)
                {
                    _logger.LogCritical(e, $"Unable to load Core UI library");
                    throw;
                }
            }

            foreach (Module m in _loadedModules.Values.Where(m => m.ObjectModel))
            {
                if (m.Authenticated)
                {
                    LoadAssembly(m.Path);
                }
            }

            //Check if authenticated, otherwise block the auto loading
            if (_authentication.Authenticated())
            {
                foreach (Module m in _loadedModules.Values.Where(m => !m.ObjectModel))
                {
                    if (m.Authenticated)
                    {
                        LoadAssembly(m.Path);
                    }
                }
            }
        }
Esempio n. 14
0
        public void OptCommand()
        {
            Editor ed       = Application.DocumentManager.MdiActiveDocument.Editor;
            string fileName = "C:\\Users\\Administrator\\Desktop\\Chap01\\Hello\\bin\\Debug\\Hello.dll";

            try
            {
                ExtensionLoader.Load(fileName);
                // 在命令行上显示信息,用于提示用户Hello.dll程序集已经被载入
                ed.WriteMessage("\n" + fileName + "被载入,请输入Hello进行测试! ");
            }
            catch (System.Exception ex)      // 捕捉程序异常
            {
                ed.WriteMessage(ex.Message); // 显示异常信息
            }
            finally
            {
                ed.WriteMessage("\nfinally 语句:程序执行完毕! ");
            }
        }
Esempio n. 15
0
        public void SimpleCompile()
        {
            Directory.CreateDirectory(CachePath);
            var compiler = new CSharpCompiler <CodeSource>(new CSharpCompilerOptions(forceRecompile: true,
                                                                                     universalAssemblies: new[] { "Exor.Core.Tests.ContentBase.dll" }, cachePath: Path.Combine(CachePath, "SimpleCompile")));

            var contentA = new CodeSource("A", Version.Parse("1.0.0"),
                                          Directory.GetFiles(Path.Combine(AssetDirectory, "ContentA")).Where(f => Path.GetExtension(f) == ".cs"));

            List <ExorCompilerResults <CodeSource> > results;

            if (!compiler.TryCompileSources(new[] { contentA }, out results))
            {
                Assert.Fail("Compile of ContentA failed.");
            }

            var loader = new ExtensionLoader(_logger, results.Select(r => r.Assembly), TypeRecords);

            var obj = loader.Load <SimpleTestBase>("A");

            Assert.IsTrue(obj.GetType().FullName.Contains("SimpleTestA"));
        }
Esempio n. 16
0
        public void FilterTest()
        {
            var appendString = "moop";
            var v            = new StringBuilder();

            var assemblies = new[]
            {
                Assembly.Load(new AssemblyName("Exor.Core.Tests.ContentB")),
                Assembly.Load(new AssemblyName("Exor.Core.Tests.ContentA"))
            };

            var loader = new ExtensionLoader(_logger, assemblies, TypeRecords, true);

            loader.AfterLoad += (record, loaded) => v.Append(appendString);

            var noCtor = loader.Load <SimpleTestBase>("A");

            Assert.IsTrue(noCtor.GetType().FullName.Contains("SimpleTestB"));
            Assert.AreEqual(0, noCtor.Value);

            Assert.AreEqual(appendString, v.ToString(), "AfterLoad did not fire.");
        }
Esempio n. 17
0
        public async void Initialize()
        {
            try
            {
                if (!string.IsNullOrEmpty(CustomPath))
                {
                    RootPath = CustomPath;
                }
                else
                {
                    RootPath = Directory.GetCurrentDirectory() + "\\Redox\\";
                }

                PluginPath     = Path.Combine(RootPath, "Plugins\\");
                ExtensionPath  = Path.Combine(RootPath, "Extensions\\");
                DependencyPath = Path.Combine(RootPath, "Dependencies\\");
                DataPath       = Path.Combine(RootPath, "Data\\");
                LoggingPath    = Path.Combine(RootPath, "Logs\\");
                AssemblePath   = Path.GetDirectoryName(assembly.Location);



                if (!Directory.Exists(RootPath))
                {
                    Directory.CreateDirectory(RootPath);
                }
                if (!Directory.Exists(LoggingPath))
                {
                    Directory.CreateDirectory(LoggingPath);
                }
                if (!Directory.Exists(ExtensionPath))
                {
                    Directory.CreateDirectory(ExtensionPath);
                }
                if (!Directory.Exists(DependencyPath))
                {
                    Directory.CreateDirectory(DependencyPath);
                }
                if (!Directory.Exists(PluginPath))
                {
                    Directory.CreateDirectory(PluginPath);
                }
                if (!Directory.Exists(DataPath))
                {
                    Directory.CreateDirectory(DataPath);
                }

                Config = new RedoxConfig();
                string path = Path.Combine(RootPath, "Redox.json");
                if (File.Exists(path))
                {
                    Config = Utility.Json.FromFile <RedoxConfig>(path);
                }
                else
                {
                    Utility.Json.ToFile(path, Config.Init());
                }

                this.EnableCertificates();
                this.LoadDependencies();
                ExtensionLoader.Load();
                this.Container = ContainerConfig.Configure();
                this.BuildContainer();
                Logger = Container.Resolve <ILogger>();
                Logger.LogInfo("[Redox] Initializing RedoxMod..");
                PluginEngineManager.Register <CSPluginEngine>();
                Logger.LogInfo("[Redox] Loading data...");

                await PermissionManager.LoadAsync();

                await GroupManager.LoadAsync();

                await RoleManager.LoadAsync();

                await RoleManager.CreateRoleAsync(new Role("default", "default role", 0, false));

                await GroupManager.CreateGroupAsync(new Group("default", "default group for players.", "default", 0, true, false));

                await RoleManager.AddGroupAsync("default", "default");

                Logger.LogInfo("[Redox] Loading standard library..");
                LocalStorage.Load();
                PluginCollector.GetCollector();
                Logger.LogInfo($"[Redox] RedoxMod V{Version} has been initialized.");
            }
            catch (Exception ex)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(string.Format("[Error] Failed to load Redox, Error: {0}", ex));
            }
            LifeTimeWatch   = Stopwatch.StartNew();
            WebRequestTimer = Timers.Create(5, TimerType.Repeat, WebRequestUpdate);
        }