/// <summary> /// Gets the vlan details from the switch ignoring the VLANs with no IP Addresses. /// </summary> /// <param name="activityData">a<see cref="IPConfigurationActivityData"/></param> private static void GetVlanDetails(ref NetworkNamingServiceActivityData activityData) { activityData.VirtualLanDetails.Clear(); try { NetworkNamingServiceActivityData activity = activityData; INetworkSwitch networkSwitch = SwitchFactory.Create(IPAddress.Parse(activityData.SwitchIpAddress)); // Fetch the vlan details for primary DHCP Server, second DHCP Server and Linux Server List <VirtualLAN> vlans = networkSwitch.GetAvailableVirtualLans().Where (item => (null != item.IPAddress) && (!string.IsNullOrEmpty(activity.LinuxServerIPAddress) && item.IPAddress.IsInSameSubnet(IPAddress.Parse(activity.LinuxServerIPAddress)) || !string.IsNullOrEmpty(activity.SecondDhcpServerIPAddress) && item.IPAddress.IsInSameSubnet(IPAddress.Parse(activity.SecondDhcpServerIPAddress)) || !string.IsNullOrEmpty(activity.PrimaryDhcpServerIPAddress) && item.IPAddress.IsInSameSubnet(IPAddress.Parse(activity.PrimaryDhcpServerIPAddress)))).ToList(); foreach (VirtualLAN vlan in vlans) { activityData.VirtualLanDetails.Add(vlan.Identifier, vlan.IPAddress.ToString()); } } catch (FormatException) { // Do nothing } catch (Exception) { // Do Nothing } }
/// <summary> /// Configure the switch with the radius server details /// </summary> /// <param name="activityData"><see cref="DotOneXActivityData"/></param> /// <returns>True for successfull configuration, else false.</returns> private static bool ConfigureSwitch(DotOneXActivityData activityData) { INetworkSwitch networkSwitch = SwitchFactory.Create(IPAddress.Parse(activityData.SwitchIp)); networkSwitch.DeConfigureAllRadiusServer(); return(networkSwitch.ConfigureRadiusServer(IPAddress.Parse(activityData.RadiusServerIp), activityData.SharedSecret)); }
/// <summary> /// Initializes a new instance of the <see cref="WeavingContext"/> class. /// </summary> /// <param name="module">The module that this weaving context is for.</param> public WeavingContext(ModuleDefinition module) { this.module = module ?? throw new ArgumentNullException("module"); baseReference = ReferenceFactory.InitializeBaseReference(module); ExecutionSwitches = SwitchFactory.InitializeSwitchSet(); ReturnSwitches = SwitchFactory.InitializeSwitchSet(); ExecutionContextSwitches = SwitchFactory.InitializeSwitchSet(); ExecutionVariableSwitchableSection = SwitchFactory.InitializeSwitchableSection(); ReturnVariableSwitchableSection = SwitchFactory.InitializeSwitchableSection(); ReturnFinallySwitchableSection = SwitchFactory.InitializeSwitchableSection(); ExecutionContextVariableSwitchableSection = SwitchFactory.InitializeSwitchableSection(); }
/// <inheritdoc/> public IAssemblyWeavingStatistics Weave(string inputAssemblyPath, bool includeSymbol, string outputAssemblyPath, string strongNameKeyFile) { if (string.IsNullOrWhiteSpace(inputAssemblyPath)) { throw new ArgumentNullException("inputAssemblyPath"); } if (string.IsNullOrWhiteSpace(outputAssemblyPath)) { throw new ArgumentNullException("outputAssemblyPath"); } // Mono.Cecil implementation has issues that if we directly pass file name for input assembly, // the assembly can't be overwritten if we give the same file name for output assembly, // So here we directly convert input assembly file to memory stream to ensure that input assembly file handle is release when outputing. var readerParameters = new ReaderParameters(); if (includeSymbol) { readerParameters.ReadSymbols = true; readerParameters.SymbolReaderProvider = new PdbReaderProvider(); readerParameters.SymbolStream = new MemoryStream(File.ReadAllBytes(Path.ChangeExtension(inputAssemblyPath, "pdb"))); } var assembly = AssemblyDefinition.ReadAssembly(new MemoryStream(File.ReadAllBytes(inputAssemblyPath)), readerParameters); var assemblyStatistics = StatisticsFactory.InitializeAssemblyWeavingRecord(assembly.FullName); try { foreach (var module in assembly.Modules) { var moduleStatistics = StatisticsFactory.InitializeModuleWeavingRecord(module.Name); var context = WeaverFactory.InitializeMethodWeavingContext(module); foreach (var clazz in module.GetTypes().Where(tp => tp.IsClass && (tp.HasMethods || tp.HasFields))) { // supporting data structure initialization. var classStatistics = StatisticsFactory.InitializeClassWeavingRecord(clazz.Name, clazz.FullName, clazz.Namespace); var switchHandlerBuilder = SwitchFactory.InitializeSwitchHandler(clazz, context.GetTypeReference(typeof(int))); var classCustomAttributes = GetClassCustomAttributes(clazz); var methodWeaver = new MethodWeaver(classCustomAttributes, context, switchHandlerBuilder); WeaveProperties(clazz, classCustomAttributes, methodWeaver, classStatistics); WeaveMethods(clazz, classCustomAttributes, methodWeaver, classStatistics); WeaveSwitches(switchHandlerBuilder.Build(), clazz, context, classStatistics); // handle statistics var classStatisticsFinished = classStatistics.Build(); if (classStatisticsFinished.WeavedMethodPropertyCount > 0) { moduleStatistics.AddClassWeavingStatistics(classStatisticsFinished); } } AddAssemblyReference(context, module, moduleStatistics); // handle statistics. var moduleStatisticsFinished = moduleStatistics.Build(); if (moduleStatisticsFinished.WeavedClassCount > 0) { assemblyStatistics.AddModuleWeavingStatistics(moduleStatisticsFinished); } } var writerParameters = new WriterParameters(); if (includeSymbol) { writerParameters.WriteSymbols = true; writerParameters.SymbolWriterProvider = new PdbWriterProvider(); } if (!string.IsNullOrWhiteSpace(strongNameKeyFile)) { writerParameters.StrongNameKeyPair = new StrongNameKeyPair(File.ReadAllBytes(strongNameKeyFile)); } assembly.Write(outputAssemblyPath, writerParameters); } catch (Exception e) { assemblyStatistics.Exception = e; } return(assemblyStatistics.Build()); }