public InjectionWindow(InjectionConfiguration configuration) { this.configuration = configuration; this.InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif this.Position = new PixelPoint(configuration.Window.X, configuration.Window.Y); this.Topmost = configuration.Window.AlwaysOnTop; this.PositionChanged += (sender, e) => { // When user minimizes Avalonia windows then PositionChanged event gets executed first even before changing WindowState property and // position of the window is -32000, -32000. if (this.Position.X >= 0 && this.Position.Y >= 0) { this.configuration.Window.X = this.Position.X; this.configuration.Window.Y = this.Position.Y; } }; Main.ViewModel.WhenAnyValue(x => x.AlwaysOnTop).Subscribe(alwaysOnTop => this.Topmost = alwaysOnTop); }
public void SetServices(InjectionConfiguration configuration, IMainServices mainServices) { this.configuration = configuration; this.mainServices = mainServices; RaisePropertyChanged(nameof(AlwaysOnTop)); }
public void NonGeneratedInjectionConfigurationSerializationTest() { string configurationSerialized = @"<Configuration> <InjecteeAssemblies> <InjecteeAssembly AssemblyPath=""lib1.dll""> </InjecteeAssembly> <InjecteeAssembly AssemblyPath=""lib2.dll""> </InjecteeAssembly> </InjecteeAssemblies> <InjectedMethods> <InjectedMethod AssemblyPath=""TestInjectedLibrary.dll"" MethodFullName=""TestInjectedLibrary.TestInjectedMethods.Complex"" InjectionPosition=""InjecteeMethodStart"" /> </InjectedMethods> </Configuration> "; InjectionConfiguration configurationDeserialized = SimpleXmlSerializationUtility.XmlDeserializeFromString <InjectionConfiguration>(configurationSerialized); string configurationSerializedAgain = SimpleXmlSerializationUtility.XmlSerializeToString(configurationDeserialized); configurationSerializedAgain = NormalizeNewlines(configurationSerializedAgain.Trim()); configurationSerialized = NormalizeNewlines(configurationSerialized.Trim()); Console.WriteLine(configurationSerializedAgain); Assert.AreEqual(configurationSerialized, configurationSerializedAgain); }
public MainWindow() { InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif mainServices = new TestMainServices(); injectionConfiguration = new InjectionConfiguration(configBag, new InjectionOptions()); injectionWindowHandler = new InjectionWindowHandler(); configBag = new ConfigBag(new MemoryConfigBagRepository()); this.FindControl <Button>("OpenInjectionWindow").Click += (sender, e) => OpenWindow(); objectServices = new TestInjectionObjectServices(); objectServices.Set("Initial Object", 0x0000DEAD); objectServices.Set("Second Initial Object", 0x0000BEEF); this.FindControl <Button>("AddObjectButton").Click += (sender, e) => AddObject(); this.FindControl <Button>("RemoveObjectButton").Click += (sender, e) => RemoveObject(); scriptServices = new TestScriptServices(); this.FindControl <Button>("AddRunning").Click += (sender, e) => AddRunning(); this.FindControl <Button>("AddAvailable").Click += (sender, e) => AddAvailable(); this.FindControl <Button>("RemoveRunning").Click += (sender, e) => RemoveRunning(); this.FindControl <Button>("RemoveAvailable").Click += (sender, e) => RemoveAvailable(); OpenWindow(); }
public void InjectComplexToMonoCecilAtReturn() { const string sourceAssemblyName = "Mono.Cecil.dll"; const string targetAssemblyName = "Mono.Cecil_Injectee_AtReturn.dll"; File.Copy(sourceAssemblyName, targetAssemblyName, true); InjectionConfiguration configuration = new InjectionConfiguration( new List <InjecteeAssembly> { new InjecteeAssembly( targetAssemblyName, null, IntegrationTestsHelper.GetStandardAllowedAssemblyReferences().AsReadOnly() ) }.AsReadOnly(), new List <InjectedMethod> { new InjectedMethod( InjectedLibraryPath, $"{InjectedClassName}.{nameof(TestInjectedMethods.Complex)}", MethodInjectionPosition.InjecteeMethodReturn ) }.AsReadOnly() ); ExecuteSimpleInjection(configuration); }
public void HaveConfiguredPropertyWhenPropertyNameIsUsed() { var configurator = new InjectionConfiguration <Foo>(); configurator.FillProperty("Value", () => "lorem"); configurator.IsInjectable("Value").Should().BeTrue(); }
protected static void ExecuteSimpleInjection(InjectionConfiguration configuration) { ResolvedInjectionConfiguration resolvedConfiguration = ResolvedInjectionConfigurationLoader.LoadFromInjectionConfiguration(configuration); IntegrationTestsHelper.ExecuteInjection(resolvedConfiguration); IntegrationTestsHelper.WriteModifiedAssembliesIfRequested(resolvedConfiguration); }
public void NotHaveConfiguredProperty() { var configurator = new InjectionConfiguration <Foo>(); configurator.FillProperty(p => p.Value, () => "lorem"); configurator.IsInjectable("Id").Should().BeFalse(); }
/// <summary> /// Get property injection configuration for model T. /// </summary> /// <example> /// <code source="..\Examples\Kros.KORM.Examples\WelcomeExample.cs" title="Injection" region="InectionConfiguration" lang="C#" /> /// </example> public IInjectionConfigurator <T> InjectionConfigurator <T>() { var injector = new InjectionConfiguration <T>(); _injectors[typeof(T)] = injector; return(injector); }
public void GenerateSchema() { InjectionConfiguration configuration = GetInjectionConfiguration(); string configurationSerialized = SimpleXmlSerializationUtility.GenerateXmlSchemaString(configuration); Console.WriteLine(configurationSerialized); }
public void KnowConfigureInjectionExternal() { var modelMapper = new ConventionModelMapper(); var configurator = new InjectionConfiguration <Foo>() .FillProperty(p => p.PropertyDouble, () => 1); ((IModelMapperInternal)modelMapper).SetInjector <Foo>((IInjector)configurator); modelMapper.GetInjector <Foo>().Should().Be(configurator); }
protected static ResolvedInjectionConfiguration ExecuteSimpleTest( InjectionConfiguration configuration, string[] injecteeMethodNames, bool assertFirstMethodMatch = true) { ResolvedInjectionConfiguration resolvedConfiguration = IntegrationTestsHelper.GetBasicResolvedInjectionConfiguration(configuration, injecteeMethodNames); ExecuteSimpleTest(resolvedConfiguration, assertFirstMethodMatch); return(resolvedConfiguration); }
public void ThrowExceptionIfPropertyIsNotConfigured() { var configurator = new InjectionConfiguration <Foo>(); var foo = new Foo() { Id = 1 }; Action action = () => configurator.GetValue("Value"); action.Should().Throw <InvalidOperationException>(); }
public void ReturnConfiguredValueWhenPropertyNameIsUsed() { var configurator = new InjectionConfiguration <Foo>(); configurator.FillProperty("Value", () => "lorem"); var foo = new Foo() { Id = 1 }; configurator.GetValue("Value").Should().Be("lorem"); }
public void InjectionConfigurationSerializationTest() { InjectionConfiguration configuration = GetInjectionConfiguration(); string configurationSerialized = SimpleXmlSerializationUtility.XmlSerializeToString(configuration); Console.WriteLine(configurationSerialized); Console.WriteLine(); InjectionConfiguration configurationDeserialized = SimpleXmlSerializationUtility.XmlDeserializeFromString <InjectionConfiguration>(configurationSerialized); string configurationSerializedAgain = SimpleXmlSerializationUtility.XmlSerializeToString(configurationDeserialized); Console.WriteLine(configurationSerializedAgain); Assert.AreEqual(configurationSerialized, configurationSerializedAgain); }
private ResolvedInjectionConfiguration ExecuteIgnoreTest( params IIgnoredMemberReference[] ignoredMemberReferences ) { InjectionConfiguration configuration = GetInjectionConfiguration(ignoredMemberReferences.ToList()); // Strip includes configuration = StripIncludesFromConfiguration(configuration); ResolvedInjectionConfiguration resolvedConfiguration = ResolvedInjectionConfigurationLoader.LoadFromInjectionConfiguration(configuration); ExecuteSimpleTest(resolvedConfiguration, false); return(resolvedConfiguration); }
private static InjectionConfiguration StripIncludesFromConfiguration(InjectionConfiguration configuration) { configuration = configuration.WithInjecteeAssemblies( configuration.InjecteeAssemblies.Select(assembly => assembly.WithAllowedAssemblyReferences( assembly.AllowedAssemblyReferences.Where(item => !(item is InjectionConfigurationFileInclude)).ToList().AsReadOnly() ) .WithIgnoredMemberReferences( assembly.IgnoredMemberReferences.Where(item => !(item is InjectionConfigurationFileInclude)).ToList().AsReadOnly() ) ) .ToList().AsReadOnly() ); return(configuration); }
public static InjectionConfiguration GetBasicInjectionConfiguration( bool insertThirdPartyLibraryAssemblyReferences = true, bool insertStandardIgnoredMemberReferences = true, params InjectedMethod[] injectedMethods) { List <IAllowedAssemblyReference> allowedAssemblyReferences = GetStandardAllowedAssemblyReferences(insertThirdPartyLibraryAssemblyReferences); InjectionConfiguration configuration = new InjectionConfiguration( new List <InjecteeAssembly> { new InjecteeAssembly( GetTestProperty <string>(nameof(IntegrationTestsBase.InjecteeLibraryName)), insertStandardIgnoredMemberReferences ? GetStandardIgnoredMemberReferences().AsReadOnly() : null, allowedAssemblyReferences.AsReadOnly()), }.AsReadOnly(), new ReadOnlyCollection <InjectedMethod>(injectedMethods) ); return(configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var dbConn = Configuration.GetValue <string>("ConnectionString"); InjectionConfiguration.Bind(services, dbConn); services.AddAutoMapper(); services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials(); }); }); services.AddMvc() .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>()) .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSwaggerDocument(); }
private void AttemptInjectUsesThirdPartyLibraryBase(bool setThirdPartyLibraryPath) { InjectedMethod injectedMethod = new InjectedMethod( InjectedLibraryPath, $"{typeof(TestInjectedMethods).FullName}.{nameof(TestInjectedMethods.UsesThirdPartyLibrary)}" ); InjectionConfiguration configuration = IntegrationTestsHelper.GetBasicInjectionConfiguration(false, false, injectedMethod); configuration = configuration .WithInjecteeAssemblies( configuration.InjecteeAssemblies.Select( assembly => { List <IAllowedAssemblyReference> list = assembly.AllowedAssemblyReferences.ToList(); list.Add( new AllowedAssemblyReference( "Tests.ThirdPartyLibrary", false, setThirdPartyLibraryPath ? "Tests.ThirdPartyLibrary.Different.dll" : null)); List <IIgnoredMemberReference> list2 = assembly.IgnoredMemberReferences.ToList(); list2.Add(new IgnoredMemberReference("some filter")); assembly = assembly .WithAllowedAssemblyReferences(list.AsReadOnly()) .WithIgnoredMemberReferences(list2.AsReadOnly()); return(assembly); }) .ToList().AsReadOnly() ); ExecuteSimpleTest( configuration, new[] { $"{InjecteeClassName}.{nameof(TestInjectee.SingleStatement)}" }, false ); }
public void Open(IInjectionObjectServices objectServices, IScriptServices scriptServices, IMainServices mainServices, InjectionConfiguration configuration) => InjectionWindow.Open(objectServices, scriptServices, mainServices, configuration);
static Config() { Window = new WindowConfiguration(); Injection = new InjectionConfiguration(); }
private void ExecuteInjection() { #if !DEBUG try { #endif string serializedInjectorConfiguration; if (_commandLineOptions.ReadConfigurationFromStandardInput) { serializedInjectorConfiguration = Console.In.ReadToEnd(); } else { if (!File.Exists(_commandLineOptions.ConfigurationFilePath)) { throw new MethodInlineInjectorException( "Injection configuration file doesn't exists", new FileNotFoundException(_commandLineOptions.ConfigurationFilePath) ); } serializedInjectorConfiguration = File.ReadAllText(_commandLineOptions.ConfigurationFilePath); } Log.Debug($"Input configuration:{Environment.NewLine}{serializedInjectorConfiguration}"); if (String.IsNullOrWhiteSpace(serializedInjectorConfiguration)) { throw new MethodInlineInjectorException("Injector configuration is empty"); } Log.Info("Parsing configuration file"); ValidateConfiguration(serializedInjectorConfiguration); InjectionConfiguration injectionConfiguration = SimpleXmlSerializationUtility.XmlDeserializeFromString <InjectionConfiguration>(serializedInjectorConfiguration); Log.Info("Resolving configuration file"); ResolvedInjectionConfiguration resolvedInjectionConfiguration = ResolvedInjectionConfigurationLoader.LoadFromInjectionConfiguration(injectionConfiguration); Log.Info("Starting injection"); MethodInlineInjector assemblyMethodInjector = new MethodInlineInjector(resolvedInjectionConfiguration); int injectedMethodCount = 0; assemblyMethodInjector.BeforeMethodInjected += tuple => injectedMethodCount++; assemblyMethodInjector.Inject(); Log.InfoFormat("Injected {0} methods", injectedMethodCount); Log.Info("Writing modified assemblies"); foreach (ResolvedInjecteeAssembly injecteeAssembly in resolvedInjectionConfiguration.InjecteeAssemblies) { string path = injecteeAssembly.AssemblyDefinition.MainModule.FullyQualifiedName; Log.DebugFormat("Writing assembly {0} to '{1}'", injecteeAssembly.AssemblyDefinition.FullName, path); injecteeAssembly.AssemblyDefinition.Write(path); } #if !DEBUG } catch (MethodInlineInjectorException e) { string message = "Fatal error: " + e; if (e.InnerException != null) { message += Environment.NewLine; message += "Error details: "; message += e.InnerException; } Log.Fatal(message); Environment.ExitCode = 1; } #endif }
public static ResolvedInjectionConfiguration GetBasicResolvedInjectionConfiguration(InjectionConfiguration injectionConfiguration, params string[] injecteeMethodNames) { InjecteeMethodsOverrideResolvedInjectionConfigurationLoader loader = new InjecteeMethodsOverrideResolvedInjectionConfigurationLoader(injectionConfiguration, injecteeMethodNames); return(loader.Load()); }
public InjecteeMethodsOverrideResolvedInjectionConfigurationLoader(InjectionConfiguration injectionConfiguration, params string[] injecteeMethodNames) : base(injectionConfiguration) { _injecteeMethodNames = injecteeMethodNames; }
public static void Open(IInjectionObjectServices objectServices, IScriptServices scriptServices, IMainServices mainServices, InjectionConfiguration configuration) { Dispatcher.UIThread.InvokeAsync(() => { lock (injectionWindowLock) { if (injectionWindow == null) { injectionWindow = new InjectionWindow(configuration); } injectionWindow.Objects.SetServices(objectServices); injectionWindow.Scripts.SetServices(scriptServices); injectionWindow.Main.ViewModel.SetServices(injectionWindow.configuration, mainServices); injectionWindow.Show(); } }); }
public void ConfigureServices(IServiceCollection services) { InjectionConfiguration.Configure(services); services.AddMvc(); SwaggerConfiguration.ConfigureServices(services); }
protected InjectionConfiguration GetInjectionConfiguration( List <IIgnoredMemberReference> ignoredMemberReference = null, List <IAllowedAssemblyReference> allowedAssemblyReferences = null ) { IgnoredMemberReference skippedMember = new IgnoredMemberReference( "ClassInheritedFromThirdPartyLibraryClass", IgnoredMemberReferenceFlags.SkipTypes | IgnoredMemberReferenceFlags.MatchAncestors ); if (ignoredMemberReference == null) { ignoredMemberReference = new List <IIgnoredMemberReference> { skippedMember, new IgnoredMemberReference( "SomeFilterString", IgnoredMemberReferenceFlags.SkipProperties | IgnoredMemberReferenceFlags.SkipMethods | IgnoredMemberReferenceFlags.IsRegex ), new IgnoredMemberReference( "SomeOtherFilterString", IgnoredMemberReferenceFlags.SkipTypes | IgnoredMemberReferenceFlags.MatchAncestors ), new IgnoredMemberReferenceInclude("SomeIgnoredMemberReferencesFilterInclude.xml") }; } else { ignoredMemberReference.Insert(0, skippedMember); } if (allowedAssemblyReferences == null) { allowedAssemblyReferences = new List <IAllowedAssemblyReference> { new AllowedAssemblyReference("mscorlib", true), new AllowedAssemblyReference("System", false), new AllowedAssemblyReference("Tests.ThirdPartyLibrary", false), new AllowedAssemblyReferenceInclude("SomeInclude.xml") }; } InjectionConfiguration configuration = new InjectionConfiguration( new List <InjecteeAssembly> { new InjecteeAssembly( InjecteeLibraryName, new ReadOnlyCollection <IIgnoredMemberReference>(ignoredMemberReference), new ReadOnlyCollection <IAllowedAssemblyReference>(allowedAssemblyReferences)) }.AsReadOnly(), new ReadOnlyCollection <InjectedMethod>(new List <InjectedMethod> { new InjectedMethod( InjectedLibraryName, $"{typeof(TestInjectedMethods).FullName}.{nameof(TestInjectedMethods.SingleStatement)}", MethodInjectionPosition.InjecteeMethodStart ) }) ); return(configuration); }