/// <summary> /// Add module with lifetime manager /// </summary> /// <param name="module"></param> /// <param name="containerControlledLifetimeManager"></param> /// <returns></returns> public IModuleCatalog Add(Type module, IInstanceLifetimeManager containerControlledLifetimeManager) { var moduleName = module.Name; if (_moduleCatalog.ContainsKey(moduleName)) { Throw <Exception>("Module {0} already exists in catalog!", moduleName); } var moduleObj = Container.CreateChildContainer().Resolve(module); // Register with lifetime manager Container.RegisterInstance(moduleObj, containerControlledLifetimeManager); _moduleCatalog.Add(moduleName, (IModule)moduleObj); var args = new ModuleEventArgs { Module = (IModule)moduleObj, ModuleName = moduleName }; // Publish event Logger.Info("PUBLISH:<ProcessEvent>(ModuleAdded): ModuleCatalog.Add: {0} ({1})", moduleObj.GetType().Name, Id); EventAggregator.GetEvent <ProcessEvent>() .Publish(new ProcessEventArgs { EventArgs = args, ProcessType = ProcessType.ModuleAdded }); return(this); }
void ModuleLoaded(object sender, ModuleEventArgs ev) { try { Module module = ev.Module; Console.Error.WriteLine("ModuleLoaded:" + module.FullPath + "|"); /*List<DebugType> types = module.GetDefinedTypes(); * Console.Error.WriteLine("ModuleLoaded:" + types.Count); * for (int t = 0; t < types.Count; t++) * { * try * { * DebugType type = types[t]; * //Console.Error.WriteLine(type + " " + type.FullName); * typeMap.Add(type.FullName, type); * } * catch (ArgumentException) * { * //TODO add support for duplicate values * } * }*/ } catch (System.Exception ex) { Console.Error.WriteLine(ex); } }
public virtual void OnModuleUpdated(object source, ModuleEventArgs e) { if (this.ModuleUpdated != null) { this.ModuleUpdated(source, e); } }
internal void OnModuleInclude(ModuleEventArgs e) { var h = ModuleInclude; if (h != null) h(this, e); }
public void RequestReceived(object sender, ModuleEventArgs args) { HeaderPackage package = args.HeaderPackage; var imageRequestHeader = package.GetHeader<ImageHeader>(); var ipHeader = package.GetHeader<IPHeader>(); RouteMessage(args.DeviceID, new List<IHeader>(new IHeader[] { imageRequestHeader, ipHeader })); }
public virtual void OnModuleUpdated(ModuleEventArgs args) { if (ModuleUpdated != null) { ModuleUpdated(this, args); } }
public virtual void OnModuleRemoved(ModuleEventArgs args) { if (this.ModuleRemoved != null) { this.ModuleRemoved(this, args); } }
/// <summary> /// Toggles between modules, showing documents available to the current /// selected module, while hidding documents relating to other modules. /// </summary> /// <param name="sender">The <see cref="ModulesNavigationView"/>.</param> /// <param name="e">Module event arguments.</param> private void ModuleSelected(object sender, ModuleEventArgs e) { var layoutAnchorablesHide = dockingManager.Layout.Descendents() .OfType <LayoutAnchorable>() .Where(la => !((DocumentViewHost)la.Content).ModuleName.ToUpper().Equals(e.ModuleName.ToUpper())); var anchorablesHide = layoutAnchorablesHide.ToList(); var layoutAnchorablesShow = dockingManager.Layout.Descendents() .OfType <LayoutAnchorable>() .Where(la => ((DocumentViewHost)la.Content).ModuleName.ToUpper().Equals(e.ModuleName.ToUpper())); var anchorablesShow = layoutAnchorablesShow.ToList(); for (int i = 0; i < anchorablesHide.Count(); i++) { anchorablesHide[i].Hide(); var documentViewHost = anchorablesHide[i].Content as DocumentViewHost; documentViewHost.View.OnActiveChanged(false); } for (int i = 0; i < anchorablesShow.Count(); i++) { anchorablesShow[i].Show(); } }
/// <summary> /// Add module /// </summary> /// <param name="moduleName"></param> /// <param name="module"></param> /// <returns></returns> public IModuleCatalog Add(string moduleName, Type module) { if (_moduleCatalog.ContainsKey(moduleName)) { Throw <Exception>("Module {0} already exists in catalog!", moduleName); } var resourceLoader = Container.Resolve <IResourceLoader>(); resourceLoader.LoadResources(module); var moduleObj = Container.CreateChildContainer().Resolve(module); _moduleCatalog.Add(moduleName, (IModule)moduleObj); var args = new ModuleEventArgs { Module = (IModule)moduleObj, ModuleName = moduleName }; // Publish event Logger.Info("PUBLISH:<ProcessEvent>(ModuleAdded) ModuleCatalog.Add: {0} ({1})", moduleObj.GetType().Name, Id); EventAggregator.GetEvent <ProcessEvent>() .Publish(new ProcessEventArgs { EventArgs = args, ProcessType = ProcessType.ModuleAdded }); return(this); }
void ModuleLoaded(object sender, ModuleEventArgs ev) { try { Module module = ev.Module; Console.Error.WriteLine("ModuleLoaded:" + module.Filename + "|"); List <DebugType> types = module.GetDefinedTypes(); Console.Error.WriteLine("ModuleLoaded:" + types.Count); for (int t = 0; t < types.Count; t++) { try { DebugType type = types[t]; //Console.Error.WriteLine(type + " " + type.FullName); typeMap.Add(type.FullName, type); } catch (ArgumentException) { //TODO add support for duplicate values } } } catch (System.Exception ex) { Console.Error.WriteLine(ex); } Console.Error.WriteLine("ModuleLoaded:" + typeMap.Count); }
public void RequestReceived(object sender, ModuleEventArgs args) { //HeaderPackage package = args.HeaderPackage; //var imageRequestHeader = package.GetHeader<ImageRequestHeader>(); //var ipHeader = package.GetHeader<IPHeader>(); //HandleRequest(imageRequestHeader, ipHeader.saddr, args.DeviceID); }
void ModuleLoaded(object sender, ModuleEventArgs e) { DebuggerModuleModel model = new DebuggerModuleModel(e.Module); moduleModels.Add(model); Assemblies.Add(model.AssemblyModel); }
private void Module_StateChanged(object sender, ModuleEventArgs e) { if (e.Module == CurrentModule) { CurrentModuleStateChanged?.Invoke(sender, e); } }
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); }
/// <summary> /// When a module has new stats, it calls this method to update its stats. /// </summary> /// <param name="moduleType">Module type</param> /// <param name="moduleName">Module name</param> /// <param name="newStats">New stats</param> public void ModuleDataUpdated(ModuleType moduleType, string moduleName, string newStats) { ModuleEventArgs args = new ModuleEventArgs(); args.moduleType = moduleType; args.moduleName = moduleName; args.newStats = newStats; OnChangedModuleData(args); }
void ModuleUnloaded(object sender, ModuleEventArgs e) { DebuggerModuleModel deletedModel = moduleModels.FirstOrDefault(mm => mm.Module == e.Module); if (deletedModel != null) { moduleModels.Remove(deletedModel); Assemblies.Remove(deletedModel.AssemblyModel); } }
void process_Modules_Added(object sender, ModuleEventArgs e) { if (ProjectService.OpenSolution == null) { return; } ProjectService.OpenSolution.Projects .Where(p => e.Module.Name.IndexOf(p.Name) >= 0) .ForEach(p => e.Module.LoadSymbolsFromDisk(new [] { Path.GetDirectoryName(p.OutputAssemblyFullPath) })); }
void debuggedProcess_ModulesAdded(object sender, ModuleEventArgs e) { foreach (var bp in debugger.Breakpoints) { var breakpoint = bp as ILBreakpoint; if (breakpoint != null && breakpoint.MethodKey.IsSameModule(e.Module.FullPath)) { breakpoint.SetBreakpoint(e.Module); } } }
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); }
internal void IcmpReceived(object sender, ModuleEventArgs args) { //HeaderPackage package = args.HeaderPackage; //var icmpHeader = package.GetHeader<IcmpHeader>(); //var ipHeader = package.GetHeader<IPHeader>(); //IcmpTypeCode typeCode = IcmpTypeCode.FindByTypeAndCode(icmpHeader.type, icmpHeader.code); //if (typeCode == null) //{ // throw new InvalidOperationException("Invalid ICMP type/code."); //} //typeCode.Action(ipHeader, icmpHeader); }
/// <summary> /// Raises the <see cref="ModuleSelected"/> event which is handled by the <see cref="DockingManagerBehavior"/>. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">Event arguments.</param> private void SelectedModuleListItem(object sender, RoutedEventArgs e) { var navigationPanelItem = (NavigationPanelItem)e.OriginalSource; var moduleSelected = ModuleSelected; if (moduleSelected != null) { var modulePaneEventArgs = new ModuleEventArgs(navigationPanelItem.NavigationPanelItemName); moduleSelected(this, modulePaneEventArgs); } e.Handled = true; }
public void ProcessEcho(object sender, ModuleEventArgs e) { var echoHeader = e.HeaderPackage.GetHeader<IcmpEchoHeader>(); lock (_sequenceTrackingMap) { var id = new Tuple<int, int>(echoHeader.Identifier, echoHeader.SequenceNumber); if (_sequenceTrackingMap.ContainsKey(id)) { _sequenceTrackingMap[id].Stop(); _sequenceTrackingMap.Remove(id); Log.Write("ICMP", "ECHOREPLY", echoHeader.Identifier + "," + echoHeader.SequenceNumber); } } }
void debuggedProcess_ModulesAdded(object sender, ModuleEventArgs e) { var currentModuleTypes = e.Module.GetNamesOfDefinedTypes(); foreach (var bookmark in DebuggerService.Breakpoints) { var breakpoint = debugger.Breakpoints.FirstOrDefault( b => b.Line == bookmark.LineNumber && (b as ILBreakpoint).MetadataToken == bookmark.MemberReference.MetadataToken.ToInt32()); if (breakpoint == null) { continue; } // set the breakpoint only if the module contains the type if (!currentModuleTypes.Contains(breakpoint.TypeName)) { continue; } breakpoint.SetBreakpoint(e.Module); } }
//Includes a module reference (used for user references, Prelude and Components module). private CodeFrame IncludeModule(string alias, string name, string dllName, string[] path, int line, int col, bool reqQual, ElaExpression exp, bool addVar, bool noPrelude) { var modIndex = frame.HandleMap.Count; var modRef = new ModuleReference(frame, name, dllName, path, line, col, reqQual, modIndex); modRef.NoPrelude = noPrelude; frame.AddReference(alias, modRef); //Handles are filled by linker for module indexing at run-time frame.HandleMap.Add(-1); if (exp != null) AddLinePragma(exp); cw.Emit(Op.Runmod, modIndex); var addr = -1; if (addVar) { //Create a variable and bind to it module instance cw.Emit(Op.Newmod, modIndex); addr = AddVariable(alias, exp, ElaVariableFlags.Module | ElaVariableFlags.Private, modIndex); } //An event is handled by linker and a module is compiled/deserialized var ev = new ModuleEventArgs(modRef); comp.OnModuleInclude(ev); refs.Add(ev.Frame); if (addr != -1) PopVar(addr); return ev.Frame; }
private void ModuleCreated(ModuleEventArgs e) { _moduleDomainService.CreateModule(e.Name, e.Tag, e.Resref); }
//Entry point internal void CompileUnit(ElaProgram prog) { frame.Layouts.Add(new MemoryLayout(0, 0, 1)); //top level layout cw.StartFrame(0); //Handles and references should be of the same length. This might not //be the case, if we are resuming in interactive mode. We should "align" them, //so they are of the same length. if (refs.Count != frame.HandleMap.Count) for (var i = 0; i < frame.HandleMap.Count; i++) refs.Add(null); //Determine whether this is fresh session. var scratch = cw.Offset == 0; //We always include prelude, but a module variable is created just once //(We check if we are not resuming in interactive mode (cw.Offset==0) and if yes //we don't create a variable 'prelude'. if (!String.IsNullOrEmpty(options.Prelude) && scratch) IncludePrelude(prog, scratch); //Always include arguments module if (scratch) IncludeArguments(); //Another workaround that is needed for interactive mode. We need //to restore a reference list with correct indices (LogicalHandle). //It can be done by working through the reference map and requesting all referenced //modules one more time. if (cw.Offset != 0) { var arr = new ModuleReference[frame.References.Count]; foreach (var kv in frame.References) arr[kv.Value.LogicalHandle] = kv.Value; for (var i = 0; i < arr.Length; i++) { var e = new ModuleEventArgs(arr[i]); comp.OnModuleInclude(e); refs[i] = e.Frame; } } var map = new LabelMap(); //Main compilation routine CompileProgram(prog, map); //Forcing evaluation of a program retval cw.Emit(Op.Force); //Every Ela module should end with a Stop op typeId cw.Emit(Op.Stop); cw.CompileOpList(); frame.Layouts[0].Size = currentCounter; frame.Layouts[0].StackSize = cw.FinishFrame(); }
void debuggedProcess_ModuleLoaded(object sender, ModuleEventArgs e) { AddModule(e.Module); }
internal void MessageReceived(object sender, ModuleEventArgs args) { HeaderPackage package = args.HeaderPackage; var ripPreambleHeader = package.GetHeader<RipPreambleHeader>(); var ripDataHeaderArray = package.GetHeader<RipDataHeader[]>(); var ipHeader = package.GetHeader<IPHeader>(); if (ripPreambleHeader.command == (byte)RipCommand.Request) { HandleRequest(args.DeviceID, ripPreambleHeader, ripDataHeaderArray); } else if (ripPreambleHeader.command == (byte)RipCommand.Response) { HandleResponse(args.DeviceID, ripPreambleHeader, ripDataHeaderArray, ipHeader); } else { throw new InvalidOperationException("Invalid RIP command. Probably a bad packet."); } }
void TestedClass_ModulePolled(object sender, ModuleEventArgs e) { modulePolledCount++; }
internal void HandleArpResponse(object sender, ModuleEventArgs args) { var arpHeader = args.HeaderPackage.GetHeader<ArpHeader>(); var result = _pendingArpMap.FirstOrDefault(p => p.Value.Item3.Equals(args.DeviceID) && p.Value.Item1 == arpHeader.SourceIPAddress); if (String.IsNullOrEmpty(result.Key)) { return; } lock (_arpTable) { Log.Write("SYSTEM", "ARP", "Adding: " + arpHeader.SourceIPAddress.StandardFormat + ", " + arpHeader.SourceMacAddress.StandardFormat); _arpTable.Add(arpHeader.SourceIPAddress, ArpData.Create(result.Value.Item3, arpHeader.SourceIPAddress, arpHeader.SourceMacAddress, this)); } _pendingArpMap.Remove(result.Key); }
void debuggedProcess_ModuleUnloaded(object sender, ModuleEventArgs e) { RemoveModule(e.Module); }
private void Debugger_ModuleLoaded(object sender, ModuleEventArgs e) { UI.InvokeAsync(() => { _log.Add(new EventLogItem <TargetModule>(EventLogItemType.ModuleLoad, DateTime.Now, e.Module)); }); }
public void HelloReceived(Object sender, ModuleEventArgs args) { OspfInterfaceMap[args.DeviceID].HelloReceived(args); }
public async void unloadModuleAsync(object sender, ModuleEventArgs args) => await unloadModuleAsync(args.assembly);
protected virtual void OnChangedModuleData(ModuleEventArgs e) { EventHandler <ModuleEventArgs> handler = ChangedModuleData; handler?.Invoke(this, e); }
public void HelloReceived(ModuleEventArgs args) { HeaderPackage package = args.HeaderPackage; var ipHeader = package.GetHeader<IPHeader>(); var ospfHeader = package.GetHeader<OspfHeader>(); var ospfHelloHeader = package.GetHeader<OspfHelloHeader>(); if (ospfHelloHeader.Interval != HelloInterval) { Log.Write("OSPF", "INTERFACE", string.Format("Mismatched hello interval. Local:{0}, Remote:{1}", HelloInterval, ospfHelloHeader.Interval)); return; } if (ospfHelloHeader.RouterDeadInterval != RouterDeadInterval) { Log.Write("OSPF", "INTERFACE", string.Format("Mismatched router dead interval. Local:{0}, Remote:{1}", RouterDeadInterval, ospfHelloHeader.RouterDeadInterval)); return; } if (OspfNetworkType != OspfNetworkType.PointToPoint && OspfNetworkType != OspfNetworkType.VirtualLink) { if (ospfHelloHeader.Mask != Mask) { Log.Write("OSPF", "INTERFACE", string.Format("Mismatched mask. Local:{0}, Remote:{1}", Mask, ospfHelloHeader.Mask)); return; } } bool remoteERC = (ospfHelloHeader.OspfOptions & OspfOptions.ExternalRoutingCapable) == OspfOptions.ExternalRoutingCapable; if (remoteERC != Area.ExternalRoutingCapability) { Log.Write("OSPF", "INTERFACE", string.Format("Mismatched external routing capability. Local:{0}, Remote:{1}", Area.ExternalRoutingCapability, remoteERC)); return; } IPAddress source; IPAddress id; GetSourceAndID(ospfHeader, ipHeader, out source, out id); if (!NeighborMap.ContainsKey(id)) { NeighborMap.Add(id, Neighbor.Create(Module, _controller, this, source, id, ospfHelloHeader.OspfOptions, ospfHelloHeader.RouterPriority, ospfHelloHeader.Dr, ospfHelloHeader.Bdr)); } lock (DecisionLock) { if (InterfaceState == InterfaceState.Waiting) { if (ospfHelloHeader.Dr == ipHeader.SourceAddress && ospfHelloHeader.Bdr == IPAddress.GetDefault()) { RaiseEvent(InterfaceEventType.BackupSeen, new Tuple<IPHeader, OspfHeader, OspfHelloHeader>(ipHeader, ospfHeader, ospfHelloHeader)); } else if (ospfHelloHeader.Bdr == ipHeader.SourceAddress) { RaiseEvent(InterfaceEventType.BackupSeen, new Tuple<IPHeader, OspfHeader, OspfHelloHeader>(ipHeader, ospfHeader, ospfHelloHeader)); } } else if ((ospfHelloHeader.Dr == ipHeader.SourceAddress && DR != ipHeader.SourceAddress) || (ospfHelloHeader.Dr != ipHeader.SourceAddress && DR == ipHeader.SourceAddress) ) { RaiseEvent(InterfaceEventType.NeighborChange, new Tuple<IPHeader, OspfHeader, OspfHelloHeader>(ipHeader, ospfHeader, ospfHelloHeader)); } else if ((ospfHelloHeader.Bdr == ipHeader.SourceAddress && BDR != ipHeader.SourceAddress) || (ospfHelloHeader.Bdr != ipHeader.SourceAddress && BDR == ipHeader.SourceAddress) ) { RaiseEvent(InterfaceEventType.NeighborChange, new Tuple<IPHeader, OspfHeader, OspfHelloHeader>(ipHeader, ospfHeader, ospfHelloHeader)); } } Neighbor neighbor = NeighborMap[id]; neighbor.OnHelloReceive(ipHeader, ospfHeader, ospfHelloHeader); }
public void DBDReceived(ModuleEventArgs args) { HeaderPackage package = args.HeaderPackage; var ipHeader = package.GetHeader<IPHeader>(); var ospfHeader = package.GetHeader<OspfHeader>(); var ospfDBDHeader = package.GetHeader<OspfDbdHeader>(); OspfLsaHeader[] ospfLsaHeaderArray = null; if (ospfDBDHeader.LsaHeaderCount > 0) { ospfLsaHeaderArray = (OspfLsaHeader[])package.GetHeaderArray<OspfLsaHeader>(); } IPAddress source; IPAddress id; GetSourceAndID(ospfHeader, ipHeader, out source, out id); Neighbor neighbor = NeighborMap[id]; if (neighbor == null) { return; } neighbor.OnDBDReceive(ipHeader, ospfHeader, new Tuple<OspfDbdHeader, OspfLsaHeader[]>(ospfDBDHeader, ospfLsaHeaderArray)); }