public void ExceptionConstructorTest() { var ex1 = new InjectorException(InjectorErrors.ErrorAmbiguousBinding, "foobar"); var ex2 = new InjectorException(InjectorErrors.ErrorAmbiguousBinding, "something", ex1); Assert.IsNotNull(ex1); Assert.IsNotNull(ex2); }
public void InterfaceExceptionTest() { InjectorException exception = null; try { injector.Resolve <IInterfaceExceptionTest>(); } catch (InjectorException ex) { exception = ex; } Assert.IsNotNull(exception); }
public void TestResolverWithLoopingTypes2() { InjectorException exception = null; var expectedErrorMessage = string.Format(InjectorErrors.ErrorResolutionRecursionDetected.MessageTemplate, typeof(ConcreteSecretLoop).Name); try { var concrete = injector.Resolve <ConcreteSecretLoop>(); } catch (InjectorException ex) { exception = ex; } Assert.IsNotNull(exception); //Assert.AreEqual(expectedErrorMessage, exception.Message); }
public void AddPropertySetterNotMemberExpression() { var binding = injector.Bind <TestClassAddPropertyInjectorTest>(); InjectorException exception = null; try { binding.AddPropertyInjector((TestClassAddPropertyInjectorTest v) => ""); } catch (InjectorException ex) { exception = ex; } Assert.IsNotNull(exception); }
public void TestResolverWithPropertyLooping() { var injector = new Injector(); InjectorException exception = null; var expectedErrorMessage = string.Format(InjectorErrors.ErrorResolutionRecursionDetected.MessageTemplate, typeof(ConcretePropertyLoop).Name); try { var concrete = new ConcretePropertyLoop(); injector.InjectMembers(concrete); } catch (InjectorException ex) { exception = ex; } Assert.IsNotNull(exception); Assert.AreEqual(expectedErrorMessage, exception.Message); }
public void TestErrorOnAmbiguousResolution() { Bind <MyTestClass1>(); Bind <MyInterfaceDerived, MyTestClass2> (); InjectorException exception = null; var expectedErrorMessage = string.Format(InjectorErrors.ErrorAmbiguousBinding.MessageTemplate, typeof(MyInterface).Name); try { Injector.Resolve <MyInterface> (); } catch (InjectorException ex) { exception = ex; } Assert.IsNotNull(exception); Assert.AreEqual(expectedErrorMessage, exception.Message); }
public void TestResolverWithPropertyLooping() { injector.Bind <ConcretePropertyLoop>() .AddPropertyInjector <ConcretePropertyLoop> (v => v.MyTestProperty); //fFastInjector.Injector.InternalResolver<ConcretePropertyLoop>.AddPropertySetter(v => v.MyTestProperty);//, () => Injector.Resolve<ConcretePropertyLoop>()); InjectorException exception = null; var expectedErrorMessage = string.Format(InjectorErrors.ErrorResolutionRecursionDetected.MessageTemplate, typeof(ConcretePropertyLoop).Name); try { var concrete = injector.Resolve <ConcretePropertyLoop>(); } catch (InjectorException ex) { exception = ex; } Assert.IsNotNull(exception); Assert.AreEqual(expectedErrorMessage, exception.Message); }
public static void Monitor(string processName, byte[] dllContent, AutoResetEvent injectionEvent, string namespaceString) { IntPtr assembly = IntPtr.Zero; string lastPid = null; string pidPath = processName + "enabler.lastppid"; string pidfile = Path.Combine(Path.GetTempPath(), pidPath); InjectionManager.minimizeMemory(); if (File.Exists(pidfile)) { lastPid = File.ReadAllText(pidfile); } for (; ;) { try { InjectionManager.minimizeMemory(); Thread.Sleep(1000); Process process = Process.GetProcessesByName(processName).FirstOrDefault <Process>(); if (process != null) { InjectionManager.SetStatus("Game process found.", State.GameProcessFound); injectionEvent.Set(); if (process.Id.ToString() == lastPid) { InjectionManager.SetStatus("Telemetry plugin already running in the current game.", State.Success); injectionEvent.Set(); } else { InjectionManager.SetStatus("Waiting 5s before plugin injection.", State.Waiting); injectionEvent.Set(); Thread.Sleep(5000); Injector injector; Injector enabler = injector = new Injector(process.Id); try { assembly = IntPtr.Zero; try { assembly = enabler.Inject(dllContent, namespaceString, "Loader", "Init"); InjectionManager.minimizeMemory(); } catch (InjectorException ie) { string str = "Failed to add assembly: "; InjectorException ex = ie; InjectionManager.SetStatus(str + ((ex != null) ? ex.ToString() : null), State.Failed); injectionEvent.Set(); } catch (Exception exc) { string str2 = "Failed to add assembly (unknown error): "; Exception ex2 = exc; InjectionManager.SetStatus(str2 + ((ex2 != null) ? ex2.ToString() : null), State.Failed); injectionEvent.Set(); } if (assembly == IntPtr.Zero) { break; } InjectionManager.SetStatus("Telemetry plugin successfully injected", State.Success); File.WriteAllText(pidfile, process.Id.ToString()); injectionEvent.Set(); while (!process.HasExited) { Thread.Sleep(1); } try { if (!process.HasExited) { enabler.Eject(assembly, "TelemetryExporter", "Loader", "Unload"); } File.Delete(pidfile); } catch { } } finally { if (injector != null) { ((IDisposable)injector).Dispose(); } } } Thread.Sleep(1000); } continue; } catch { continue; } break; } }