コード例 #1
0
        public void Unload(string ruleId)
        {
            InternalValidate(ruleId);

            // check if the rule has associated module rules
            // NOTE this may need to be a checksum instead of the id
            if (LoadedModules.ContainsKey(ruleId))
            {
                LoadedModules[ruleId].UseCount--;

                if (LoadedModules[ruleId].UseCount <= 0)
                {
                    string id = LoadedModules[ruleId].Id;
                    _engine.EPAdministrator.DeploymentAdmin.Undeploy(id);
                    LoadedModules.Remove(ruleId);
                }
            }

            EPStatement statement = _engine.EPAdministrator.GetStatement(ruleId);

            if (statement == null)
            {
                return;
            }

            statement.Stop();
            statement.RemoveAllEventHandlers();
            statement.Dispose();
        }
コード例 #2
0
        public void UnloadAll()
        {
            InternalValidate();

            _engine.EPAdministrator.StopAllStatements();
            _engine.EPAdministrator.DestroyAllStatements();

            LoadedModules.Clear();
        }
コード例 #3
0
        public void Refresh()
        {
            //Logger.Info("loading modules started");
            Stopwatch watch = new Stopwatch();

            watch.Start();
            int current = _pendings.Count;

            while (current != 0)
            {
                int            previous = current;
                IList <string> parsed   = new List <string>();
                foreach (MibModule pending in
                         from pending in _pendings.Values let succeeded = CanParse(pending) where succeeded select pending)
                {
                    Parse(pending);
                    parsed.Add(pending.Name);
                }

                foreach (string file in parsed)
                {
                    _pendings.Remove(file);
                }

                current = _pendings.Count;
                //Logger.InfoFormat(CultureInfo.InvariantCulture, "{0} pending after {1}-ms", current, watch.ElapsedMilliseconds);
                if (current == previous)
                {
                    // cannot parse more
                    break;
                }
            }

            watch.Stop();

            foreach (string loaded in _loaded.Keys)
            {
                //Logger.InfoFormat(CultureInfo.InvariantCulture, "{0} is parsed", loaded);
            }

            foreach (MibModule module in _pendings.Values)
            {
                StringBuilder builder = new StringBuilder(module.Name);
                builder.Append(" is pending. Missing dependencies: ");
                foreach (string depend in module.Dependents.Where(depend => !LoadedModules.Contains(depend)))
                {
                    builder.Append(depend).Append(' ');
                }

                //Logger.Info(builder.ToString());
            }

            //Logger.Info("loading modules ended");
        }
コード例 #4
0
ファイル: ModuleHost.cs プロジェクト: StardustDL/modulight
        public virtual async Task Shutdown(CancellationToken cancellationToken = default)
        {
            Logger.LogInformation("Shutdowning modules.");

            foreach (var module in LoadedModules.Reverse())
            {
                cancellationToken.ThrowIfCancellationRequested();
                await module.Shutdown(cancellationToken).ConfigureAwait(false);
            }

            _LoadedModules = new Dictionary <Type, IModule>();

            Logger.LogInformation("Shutdowned modules.");
        }
コード例 #5
0
        private void Import(MibModule module)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            if (LoadedModules.Contains(module.Name) || PendingModules.Contains(module.Name))
            {
                //Logger.InfoFormat(CultureInfo.InvariantCulture, "{0} ignored", module.Name);
            }
            else
            {
                _pendings.Add(module.Name, module);
            }
        }
コード例 #6
0
        public void Import(IEnumerable <IModule> modules)
        {
            if (modules == null)
            {
                throw new ArgumentNullException("modules");
            }

            foreach (MibModule module in modules)
            {
                if (LoadedModules.Contains(module.Name) || PendingModules.Contains(module.Name))
                {
                    //Logger.InfoFormat(CultureInfo.InvariantCulture, "{0} ignored", module.Name);
                    continue;
                }

                _pendings.Add(module.Name, module);
            }
        }
コード例 #7
0
        private EPStatement InsertEplStatementIntoNesper(string id, string epl)
        {
            _log.Info($"Epl: {epl}");

            InternalValidate();

            // check if the input contains any our delimiters
            // such as [DO NOT FIRE ALERT BLOCK START] ... [DO NOT FIRE ALERT BLOCK STOP]
            var  parser      = new EplParser();
            bool shouldParse = parser.HasSubscriptionMarkers(epl);

            EPStatement epStatement = null;

            // Check if a block is present
            if (shouldParse) // yes
            {
                _log.Info("Scripting block found");

                // read the two parts
                // first should just be imported into NEsper
                // without adding any subscriber
                // second part should contain a single epl that
                // will fire an alert
                EplParsedTuple tuple = parser.Parse(epl);

                var    md5         = new Md5();
                string hash        = md5.GetHashAsHex(tuple.EplScript);
                var    kvp         = LoadedModules.FirstOrDefault(x => x.Value.Checksum == hash);
                bool   isNewModule = kvp.Value == null;

                if (isNewModule)
                {
                    _log.Info("Creating module from script");

                    var result = _engine.EPAdministrator.DeploymentAdmin.ParseDeploy(tuple.EplScript);
                    var mi     = new NesperModuleItem
                    {
                        Id       = result.DeploymentId,
                        UseCount = 1,
                        Checksum = hash
                    };

                    _log.Info($"Scripting block contained {result.Statements.Count} statements");

                    LoadedModules.Add(id, mi);
                }
                else
                {
                    kvp.Value.UseCount++;
                }

                // create epl that will be linked with a subscriber
                _log.Info("Creating statement that fires alert");
                if (!string.IsNullOrWhiteSpace(tuple.StatementToFireAlert)) //we can now potentially have some statements which don't actually need to be attached.
                {
                    epStatement = _engine.EPAdministrator.CreateEPL(tuple.StatementToFireAlert, id);
                }
            }
            else
            {
                _log.Info("Creating statement that fires alert");
                epStatement = _engine.EPAdministrator.CreateEPL(epl, id);
                _log.Info("Created id: " + epStatement.Name);
            }

            return(epStatement);
        }
コード例 #8
0
ファイル: VM.cs プロジェクト: guiprada/lightning
 public Operand AddModule(ModuleUnit p_module)
 {
     LoadedModules.Add(p_module.Name, LoadedModules.Count);
     modules.Add(p_module);
     return((Operand)(LoadedModules.Count - 1));
 }
コード例 #9
0
        public Module Load(string request, Module parent, bool isMain)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (parent != null && parent.Loader != this)
            {
                throw new InvalidOperationException("Parent module is initialized from a different loader.");
            }

            Module module;

            if (NativeModules.TryGetValue(request, out module))
            {
                return(module);
            }

            var virtualPath = PathResolver.Resolve(request, parent);
            var identifier  = virtualPath?.Identifier;

            if (identifier == null)
            {
                throw new InvalidOperationException($"Module '{request}' not found.");
            }

            if (LoadedModules.TryGetValue(identifier, out module))
            {
                return(module);
            }

            module = new Module(identifier, virtualPath, parent, this);
            var oldMain = MainModule;

            if (isMain)
            {
                MainModule = module;
            }

            var extension = virtualPath.ResolveExtension();

            IModuleCompiler compiler;

            if (!Compilers.TryGetValue(extension, out compiler))
            {
                throw new InvalidOperationException($"Invalid file extension {extension}.");
            }

            LoadedModules[identifier] = module;
            try
            {
                compiler.Compile(module);
            }
            catch
            {
                LoadedModules.Remove(identifier);
                if (isMain)
                {
                    MainModule = oldMain;
                }

                throw;
            }

            return(module);
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: rosaskc/gptrees
 /// <summary>
 /// The btn loaded modules click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void BtnLoadedModulesClick(object sender, EventArgs e)
 {
     string applicationPath = Application.ExecutablePath;
     List<string[]> pluginList = this.provider.GetPluginDescription(applicationPath);
     var loadedModules = new LoadedModules();
     loadedModules.GetData(pluginList);
     loadedModules.ShowDialog();
 }
コード例 #11
0
 /// <inheritdoc/>
 public virtual TModule GetModule(Type moduleType) => LoadedModules.Where(x => x.GetType() == moduleType).First();