Пример #1
0
        public void StartApplicationTest()
        {
            AppDomainUtils.RunInSeparateAppDomain(
                () =>
            {
                var moduleEvents = new ModuleEvents();
                var app          = new MyHttpApplication();
                WebPageHttpModule.StartApplication(
                    app,
                    moduleEvents.ExecuteStartPage,
                    moduleEvents.ApplicationStart
                    );
                Assert.Equal(1, moduleEvents.CalledExecuteStartPage);
                Assert.Equal(1, moduleEvents.CalledApplicationStart);

                // Call a second time to make sure the methods are only called once
                WebPageHttpModule.StartApplication(
                    app,
                    moduleEvents.ExecuteStartPage,
                    moduleEvents.ApplicationStart
                    );
                Assert.Equal(1, moduleEvents.CalledExecuteStartPage);
                Assert.Equal(1, moduleEvents.CalledApplicationStart);
            }
                );
        }
Пример #2
0
        private bool loadModule(string name, bool isInit)
        {
            if (!ConfigUtils.isModule(name))
            {
                return(false);
            }

            unloadModule(name, true); //we dont need to pass isinit to here, since we are initializing

            AssemblyLoadContext _moduleLoadContext = new AssemblyLoadContext(name, true);
            string   modulePath = ConfigUtils.getModulePath(name);
            Assembly assembly;
            List <ModuleInstance> instances = new List <ModuleInstance>();

            using (var file = File.OpenRead(modulePath))
            {
                assembly = _moduleLoadContext.LoadFromStream(file);
                foreach (Type moduleType in assembly.GetTypes())
                {
                    //_sawmill.Debug("Found module {0}", moduleType);
                    if (moduleType.GetCustomAttribute(typeof(LogModule)) != null)
                    {
                        Console.WriteLine($"Loaded module {moduleType}");
                    }
                    if (moduleType.BaseType == typeof(ModuleInstance))
                    {
                        ModuleInstance t_module = (ModuleInstance)Activator.CreateInstance(moduleType);

                        HasDataFileAttribute hdfa = moduleType.GetCustomAttribute <HasDataFileAttribute>();
                        if (hdfa != null && File.Exists($"{datadir}/{hdfa.datafile}.json"))
                        {
                            string path = $"{datadir}/{hdfa.datafile}.json";

                            if (!Directory.Exists(datadir))
                            {
                                Directory.CreateDirectory(datadir);
                            }

                            string text = File.ReadAllText(path);
                            t_module.load_jobject(JsonConvert.DeserializeObject <JObject>(text));
                        }

                        t_module.mainAsync().GetAwaiter(); //this should never fail cause moduleType NEEDS to have been inherited from CrabModule
                        instances.Add(t_module);
                    }
                }
            }
            _modules.Add(name, new LoadedModule(_moduleLoadContext, instances));

            foreach (Assembly ass in _moduleLoadContext.Assemblies)
            {
                ModuleEventArgs args = new ModuleEventArgs();
                args.name     = name;
                args.assembly = ass;
                ModuleEvents.moduleLoaded(this, args);
            }
            return(true);
        }
Пример #3
0
 public void InitializeApplicationTest()
 {
     AppDomainUtils.RunInSeparateAppDomain(() => {
         var moduleEvents = new ModuleEvents();
         var app          = new MyHttpApplication();
         WebPageHttpModule.InitializeApplication(app,
                                                 moduleEvents.OnApplicationPostResolveRequestCache,
                                                 moduleEvents.Initialize);
         Assert.IsTrue(moduleEvents.CalledInitialize);
     });
 }
Пример #4
0
        public bool unloadModule(string name, bool isreloading = false)
        {
            if (!ConfigUtils.isModule(name))
            {
                return(false);
            }

            if (_modules.ContainsKey(name))
            {
                foreach (Assembly ass in _modules[name].context.Assemblies)
                {
                    foreach (Type t in ass.GetTypes())
                    {
                        if (t.GetCustomAttribute(typeof(LogModule)) != null)
                        {
                            Console.WriteLine($"Unloaded module {t}");
                        }
                    }
                    ModuleEventArgs args = new ModuleEventArgs();
                    args.name     = name;
                    args.assembly = ass;
                    ModuleEvents.moduleUnloaded(this, args);
                }

                _modules[name].context.Unload();

                foreach (ModuleInstance instance in _modules[name].instances)
                {
                    HasDataFileAttribute hdfa = instance.GetType().GetCustomAttribute <HasDataFileAttribute>();
                    if (hdfa != null)
                    {
                        string path = $"{datadir}/{hdfa.datafile}.json";

                        if (!Directory.Exists(datadir))
                        {
                            Directory.CreateDirectory(datadir);
                        }

                        File.WriteAllText(path, instance.get_jobject().ToString());
                    }
                    instance.exit(ModuleInstanceResult.SHUTDOWN);
                    instance.asyncFinished.WaitAsync().GetAwaiter().GetResult();
                }
                _modules.Remove(name);

                //modules that need restarts are vital and cannot be unloaded, only reloaded
                if (ConfigUtils.only_reload(name) && !isreloading)
                {
                    loadModule(name);
                }
                return(true);
            }
            return(false);
        }
        public void InitializeApplicationTest() {
            AppDomainUtils.RunInSeparateAppDomain(() => {
                var moduleEvents = new ModuleEvents();
                var app = new MyHttpApplication();
                WebPageHttpModule.InitializeApplication(app,
                    moduleEvents.OnApplicationPostResolveRequestCache,
                    moduleEvents.Initialize);
                Assert.IsTrue(moduleEvents.CalledInitialize);
            });

        }
        public void StartApplicationTest() {
            AppDomainUtils.RunInSeparateAppDomain(() => {
                var moduleEvents = new ModuleEvents();
                var app = new MyHttpApplication();
                WebPageHttpModule.StartApplication(app, moduleEvents.ExecuteStartPage, moduleEvents.ApplicationStart);
                Assert.AreEqual(1, moduleEvents.CalledExecuteStartPage);
                Assert.AreEqual(1, moduleEvents.CalledApplicationStart);

                // Call a second time to make sure the methods are only called once
                WebPageHttpModule.StartApplication(app, moduleEvents.ExecuteStartPage, moduleEvents.ApplicationStart);
                Assert.AreEqual(1, moduleEvents.CalledExecuteStartPage);
                Assert.AreEqual(1, moduleEvents.CalledApplicationStart);
            });
        }
Пример #7
0
        private void HighlightCommandAtCaret()
        {
            var word = GetAsmWord(ActiveTextAreaControl.Caret.Position);

            if (word == null || word.WordType != AsmWord.AsmWordType.Command)
            {
                return;
            }

            var command = Ca65Parser.GetCommandFromWord(word.Word);

            if (command != null)
            {
                ModuleEvents.HighlightCommand(command);
            }
        }
Пример #8
0
        private void HighlightOpcodeOnLine()
        {
            var lineSegment = Document.GetLineSegment(_caretLine);

            if (lineSegment == null)
            {
                return;
            }
            var word = lineSegment.Words.OfType <AsmWord>().FirstOrDefault(w => w.WordType == AsmWord.AsmWordType.Opcode);

            if (word == null)
            {
                return;
            }
            var opcode = OpcodeParser.GetOpcodeFromWord(word.Word, File.Project.Type);

            if (opcode != null)
            {
                ModuleEvents.HighlightOpcode(opcode);
            }
        }
Пример #9
0
        ModuleEvents IExtensibilityManager.GetModuleEvents()
        {
            ModuleEvents moduleEvents = new ModuleEvents();

            EasyBlogModulesConfigurationElementCollection modules = _ConfigurationFactory.GetModules();

            if (modules != null)
            {
                foreach (EasyBlogModuleConfigurationElement module in modules)
                {
                    IEasyBlogModule moduleType = _Container.Resolve(Type.GetType(module.Type)) as IEasyBlogModule;
                    if (moduleType != null)
                    {
                        moduleType.Initialize(moduleEvents);
                    }
                }
            }

            _ModuleEvents = moduleEvents;

            return(moduleEvents);
        }
Пример #10
0
        ModuleEvents IExtensibilityManager.GetModuleEvents()
        {
            ModuleEvents moduleEvents = new ModuleEvents();

            EasyBlogConfigurationSection config = ConfigurationManager.GetSection("easyBlog")
                                                  as EasyBlogConfigurationSection;

            if (config != null)
            {
                foreach (EasyBlogModuleConfigurationElement module in config.Modules)
                {
                    IEasyBlogModule moduleType = Activator.CreateInstance(Type.GetType(module.Type))
                                                 as IEasyBlogModule;
                    if (moduleType != null)
                    {
                        moduleType.Initialize(moduleEvents);
                    }
                }
            }

            return(moduleEvents);
        }
Пример #11
0
        private void GoToFile(string fileReference)
        {
            AsmProjectFile foundFile = null;

            try
            {
                var matchFiles = new[] {
                    Path.Combine(File.GetRelativeDirectory(), fileReference).Replace('\\', '/'),
                    fileReference.Replace('\\', '/')
                };
                var completeMatch = matchFiles.Select(mf => new DirectoryInfo(Path.Combine(File.Project.Directory.FullName, mf)).FullName);
                foundFile = File.Project.Files.FirstOrDefault(f =>
                                                              completeMatch.Any(mf => mf.Equals(f.File.FullName, StringComparison.InvariantCultureIgnoreCase)) ||
                                                              matchFiles.Any(mf => mf.Equals(f.GetRelativePath(), StringComparison.InvariantCultureIgnoreCase)));
            }
            catch
            {
                return;
            }
            if (foundFile != null)
            {
                ModuleEvents.OpenFile(foundFile);
            }
        }
 void IEasyBlogModule.Initialize(ModuleEvents moduleEvents)
 {
     moduleEvents.PreSubmissionPosting += OnPreSubmissionPosting;
     moduleEvents.PreSubmissionComment += OnPreSubmissionComment;
 }
Пример #13
0
        public override void Save(Func <FileInfo, string> getNewFileName = null)
        {
            if (Pristine && getNewFileName == null)
            {
                return;
            }
            lock (_savingLock)
            {
                SavingFile = true;
            }

            string filename;

            if (getNewFileName != null)
            {
                filename = getNewFileName(ProjectFile.File);
                if (filename == null)
                {
                    return;
                }
                ProjectFile.File             = new FileInfo(filename);
                ProjectFile.Project.Pristine = false;
                ModuleEvents.OnFilenameChanged(ProjectFile);
                if (_fileSystemWatcher != null)
                {
                    _fileSystemWatcher.Dispose();
                }
                WatchFile();
            }
            else
            {
                filename = ProjectFile.File.FullName;
                if (!File.Exists(filename))
                {
                    throw new Exception(string.Format("File {0} does not exist", ProjectFile.File.Name));
                }
            }

            if (_fileSystemWatcher != null)
            {
                _fileSystemWatcher.EnableRaisingEvents = false;
            }
            using (RichTextBox rtb = new RichTextBox())
            {
                rtb.Text = TextEditor.Text;
                File.WriteAllText(filename, "");
                using (var strwriter = File.AppendText(filename))
                {
                    strwriter.Write(rtb.Text);
                    strwriter.Close();
                }
            }
            if (_fileSystemWatcher != null)
            {
                _fileSystemWatcher.EnableRaisingEvents = true;
            }

            lock (_savingLock)
            {
                SavingFile = false;
            }
            Pristine = true;

            RefreshSymbolsInProject();
        }