public void CanAddModule()
        {
            var config      = new MariCommandsOptions();
            var moduleCache = new ModuleCache(config);

            var commandMock1 = new Mock <ICommand>();

            commandMock1.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                "testCmdAlias",
            });

            var command1 = commandMock1.Object;

            var commands = new List <ICommand>
            {
                command1,
            };

            var moduleMock = new Mock <IModule>();

            moduleMock.SetupGet(a => a.Commands).Returns(commands);
            moduleMock.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                "testModuleAlias"
            });
            moduleMock.SetupGet(a => a.Submodules).Returns(new List <IModule>());

            var module = moduleMock.Object;

            commandMock1.SetupGet(a => a.Module).Returns(module);

            moduleCache.AddModule(module);
        }
Esempio n. 2
0
 /// <inheritdoc/>
 public BitcodeModule CreateBitcodeModule(string moduleId
                                          , SourceLanguage language
                                          , string srcFilePath
                                          , string producer
                                          , bool optimized          = false
                                          , string compilationFlags = ""
                                          , uint runtimeVersion     = 0
                                          )
 {
     return(ModuleCache.CreateBitcodeModule(moduleId, language, srcFilePath, producer, optimized, compilationFlags, runtimeVersion));
 }
        public async Task CalculateCorrectRemainingInput(string alias, string input)
        {
            var config     = new MariCommandsOptions();
            var comparison = StringComparison.Ordinal;

            config.Comparison = comparison;

            var moduleCache = new ModuleCache(config);

            var commandMock1 = new Mock <ICommand>();

            commandMock1.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                alias,
            });

            var command1 = commandMock1.Object;

            var commands = new List <ICommand>
            {
                command1,
            };

            var moduleMock = new Mock <IModule>();

            moduleMock.SetupGet(a => a.Commands).Returns(commands);
            moduleMock.SetupGet(a => a.Aliases).Returns(new List <string>());
            moduleMock.SetupGet(a => a.Submodules).Returns(new List <IModule>());

            var module = moduleMock.Object;

            commandMock1.SetupGet(a => a.Module).Returns(module);

            moduleCache.AddModule(module);

            var matches = await moduleCache.SearchCommandsAsync(input);

            Assert.NotNull(matches);
            Assert.NotEmpty(matches);

            var remainingInput = string.Join(config.Separator,
                                             input
                                             .Split(config.Separator)
                                             .Where(a => !a.Equals(alias, comparison))
                                             .ToList());

            var match = matches.FirstOrDefault();

            Assert.True(remainingInput.Equals(match.RemainingInput, comparison));
        }
Esempio n. 4
0
        internal IBuiltinsPythonModule CreateBuiltinsModule()
        {
            if (BuiltinsModule == null)
            {
                // Initialize built-in
                var moduleName = BuiltinTypeId.Unknown.GetModuleName(_interpreter.LanguageVersion);

                ModuleCache = new ModuleCache(_interpreter, _services);
                var modulePath = ModuleCache.GetCacheFilePath(_interpreter.Configuration.InterpreterPath);

                var b = new BuiltinsPythonModule(moduleName, modulePath, _services);
                BuiltinsModule             = b;
                Modules[BuiltinModuleName] = new ModuleRef(b);
            }
            return(BuiltinsModule);
        }
Esempio n. 5
0
        private string readFromCache()
        {
            if (useCache == "Default")
            {
                useCache = Provider.Configuration.UseCache;
            }
            ModuleCache cache = (ModuleCache)Provider.Database.Read(typeof(ModuleCache), "ModuleId={0}" + (useCache == "Item" ? " AND ContentId={1}" : "") + " AND LangId={2}", this.Id, Provider.Content.Id, Provider.CurrentLanguage.Id);

            DateTime lastCached = new DateTime(1900, 1, 1);

            if (cache != null)
            {
                lastCached = cache.UpdateDate;
            }
            int cacheDuration = Convert.ToInt32(((TimeSpan)(DateTime.Now - lastCached)).TotalMinutes);

            try
            {
                string html = "";
                if (cacheDuration > this.cacheLifeTime)
                {
                    html = this.toHtml();
                    if (cache == null)
                    {
                        cache = new ModuleCache();
                    }
                    cache.ContentId  = Provider.Content.Id;
                    cache.CachedHTML = html;
                    cache.LangId     = Provider.CurrentLanguage.Id;
                    cache.ModuleId   = this.Id;
                    cache.Save();

                    this.CacheHint = "cached now";
                }
                else
                {
                    html           = cache.CachedHTML;
                    this.CacheHint = "cached before at " + cache.UpdateDate;
                }
                return(html);
            }
            catch (Exception ex)
            {
                return(Provider.DesignMode ? "<div><b>" + Provider.GetResource("Cache problem") + "!</b><br/>" + ex.Message + "<br/>" + this.toHtml() : this.toHtml());
            }
        }
        public async Task CanFindCommandModuleWithIgnoreCaseAndOnceAlias(string moduleAlias, string alias, string input)
        {
            var config = new MariCommandsOptions();

            var comparison = StringComparison.InvariantCultureIgnoreCase;

            config.Comparison = comparison;

            var moduleCache = new ModuleCache(config);

            var commandMock1 = new Mock <ICommand>();

            commandMock1.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                alias,
            });

            var command1 = commandMock1.Object;

            var commands = new List <ICommand>
            {
                command1,
            };

            var moduleMock = new Mock <IModule>();

            moduleMock.SetupGet(a => a.Commands).Returns(commands);
            moduleMock.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                moduleAlias,
            });
            moduleMock.SetupGet(a => a.Submodules).Returns(new List <IModule>());

            var module = moduleMock.Object;

            commandMock1.SetupGet(a => a.Module).Returns(module);

            moduleCache.AddModule(module);

            var matches = await moduleCache.SearchCommandsAsync(input);

            Assert.NotNull(matches);
            Assert.NotEmpty(matches);
            Assert.True(input.Equals(matches.FirstOrDefault().Alias, comparison));
        }
Esempio n. 7
0
        internal NativeModule GetModuleFor(LLVMModuleRef moduleRef)
        {
            if (moduleRef.Pointer == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(moduleRef));
            }

            var hModuleContext = NativeMethods.GetModuleContext(moduleRef);

            if (hModuleContext.Pointer != ContextHandle.Pointer)
            {
                throw new ArgumentException("Incorrect context for module");
            }

            if (!ModuleCache.TryGetValue(moduleRef.Pointer, out NativeModule retVal))
            {
                retVal = new NativeModule(moduleRef);
            }

            return(retVal);
        }
        public void CanGetAllModules()
        {
            var config      = new MariCommandsOptions();
            var moduleCache = new ModuleCache(config);

            var commandMock1 = new Mock <ICommand>();

            commandMock1.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                "testCmdAlias",
            });

            var command1 = commandMock1.Object;

            var commands = new List <ICommand>
            {
                command1,
            };

            var moduleMock = new Mock <IModule>();

            moduleMock.SetupGet(a => a.Commands).Returns(commands);
            moduleMock.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                "testModuleAlias"
            });
            moduleMock.SetupGet(a => a.Submodules).Returns(new List <IModule>());

            var module = moduleMock.Object;

            commandMock1.SetupGet(a => a.Module).Returns(module);

            moduleCache.AddModule(module);

            var modules = moduleCache.GetAllModules();

            Assert.NotNull(modules);
            Assert.NotEmpty(modules);
            Assert.Equal(module, modules.FirstOrDefault());
        }
        public async Task CantFindCommandWithoutIgnoreCaseAndOnceAlias(string alias, string input)
        {
            var config = new MariCommandsOptions();

            config.Comparison = StringComparison.Ordinal;

            var moduleCache = new ModuleCache(config);

            var commandMock1 = new Mock <ICommand>();

            commandMock1.SetupGet(a => a.Aliases).Returns(new List <string>
            {
                alias,
            });

            var command1 = commandMock1.Object;

            var commands = new List <ICommand>
            {
                command1,
            };

            var moduleMock = new Mock <IModule>();

            moduleMock.SetupGet(a => a.Commands).Returns(commands);
            moduleMock.SetupGet(a => a.Aliases).Returns(new List <string>());
            moduleMock.SetupGet(a => a.Submodules).Returns(new List <IModule>());

            var module = moduleMock.Object;

            commandMock1.SetupGet(a => a.Module).Returns(module);

            moduleCache.AddModule(module);

            var matches = await moduleCache.SearchCommandsAsync(input);

            Assert.NotNull(matches);
            Assert.Empty(matches);
        }
Esempio n. 10
0
        private bool LoadthisScript(DirectItem scriptToLoad, ModuleCache module)
        {
            if (scriptToLoad != null)
            {
                if (module.IsReloadingAmmo || module.IsActive || module.IsDeactivating || module.IsChangingAmmo || module.InLimboState || module.IsGoingOnline || !module.IsOnline)
                    return false;

                // We have enough ammo loaded
                if (module.Charge != null && module.Charge.TypeId == scriptToLoad.TypeId && module.CurrentCharges == module.MaxCharges)
                {
                    Logging.Log("LoadthisScript", "module is already loaded with the script we wanted", Logging.Teal);
                    NextScriptReload[module.ItemId] = DateTime.UtcNow.AddSeconds(15); //mark this weapon as reloaded... by the time we need to reload this timer will have aged enough...
                    return false;
                }

                // We are reloading, wait 15
                if (NextScriptReload.ContainsKey(module.ItemId) && DateTime.UtcNow < NextScriptReload[module.ItemId].AddSeconds(15))
                {
                    Logging.Log("LoadthisScript", "module was reloaded recently... skipping", Logging.Teal);
                    return false;
                }
                NextScriptReload[module.ItemId] = DateTime.UtcNow.AddSeconds(15);

                // Reload or change ammo
                if (module.Charge != null && module.Charge.TypeId == scriptToLoad.TypeId)
                {
                    if (DateTime.UtcNow.Subtract(Cache.Instance.LastLoggingAction).TotalSeconds > 10)
                    {
                        Cache.Instance.LastLoggingAction = DateTime.UtcNow;
                    }
                    Logging.Log("Defense", "Reloading [" + module.TypeId + "] with [" + scriptToLoad.TypeName + "][TypeID: " + scriptToLoad.TypeId + "]", Logging.Teal);
                    module.ReloadAmmo(scriptToLoad);
                    return true;
                }

                if (DateTime.UtcNow.Subtract(Cache.Instance.LastLoggingAction).TotalSeconds > 10)
                {
                    Cache.Instance.LastLoggingAction = DateTime.UtcNow;
                }
                Logging.Log("Defense", "Changing [" + module.TypeId + "] with [" + scriptToLoad.TypeName + "][TypeID: " + scriptToLoad.TypeId + "]", Logging.Teal);
                module.ChangeAmmo(scriptToLoad);
                return true;
            }
            Logging.Log("LoadthisScript", "script to load was NULL!", Logging.Teal);
            return false;
        }
Esempio n. 11
0
 public void NotifyImportNamesChanged()
 {
     ModuleCache.Clear();
     ImportableModulesChanged?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 12
0
 internal void RemoveModule(NativeModule module)
 {
     ModuleCache.Remove(module.ModuleHandle.Pointer);
 }
Esempio n. 13
0
 internal void AddModule(NativeModule module)
 {
     ModuleCache.Add(module.ModuleHandle.Pointer, module);
 }
Esempio n. 14
0
 /// <inheritdoc/>
 public BitcodeModule CreateBitcodeModule(string moduleId)
 {
     return(ModuleCache.CreateBitcodeModule(moduleId));
 }
Esempio n. 15
0
 /// <inheritdoc/>
 public BitcodeModule CreateBitcodeModule( )
 {
     return(ModuleCache.CreateBitcodeModule( ));
 }