public async Task DependenciesOutOfOrder() { var container = new BaseResolver(TimeSpan.FromSeconds(5)); await container.ResolveToAsync <ILog, MegaLog>(); var loadingFileProvider = container.ResolveAsync <ILogFileProvider>(); await container.ResolveToAsync <ILogFileProvider, TestLogFileProvider>(); await container.ResolveToAsync <ILogSizeProvider, TestLogSizeProvider>(); var testLogFileProvider = await loadingFileProvider; var fi = testLogFileProvider.GetLogFile(); Assert.NotNull(fi); var testLogSizeProvider = await container.ResolveAsync(typeof(ILogSizeProvider)) as ILogSizeProvider; Assert.NotNull(testLogSizeProvider); var size = testLogSizeProvider !.GetLogSize(); Assert.True(size >= 0); }
public ScriptCompiler(string path, BaseResolver resolver) { var source = File.ReadAllText(path); var grammar = new ScriptGrammar(); var parser = new Parser(grammar); _tree = parser.Parse(source); PrepareParseTree(_tree.Root); _functions = new List <ScriptFunction>(); _resolver = resolver; }
public async Task DependenciesContravariant() { var container = new BaseResolver(TimeSpan.FromSeconds(5)); await container.ResolveToAsync <IMegaLog, MegaLog>(); await container.ResolveToAsync <ILogFileProvider, TestLogFileProvider>(); var fileProvider = await container.ResolveAsync <ILogFileProvider>(); var fi = fileProvider.GetLogFile(); Assert.NotNull(fi); }
public async Task MissingDependencyCannotAutoCtor() { var container = new BaseResolver(); //TimeSpan.FromSeconds(1)); var n = new NeedsCannotCtor(container); await Task.Delay(1000); var cannotCtor = new CannotCtor("bob", 9000); await container.ResolveToAsync(cannotCtor); while (!n.IsFinished) { await Task.Delay(10); } }
public void DuplicateInstantiation() { SlowLoader.Reset(); var container = new BaseResolver(TimeSpan.FromSeconds(10)); container.ResolveTo <IResolver>(container); container.ResolveTo <ILoadSlowly, SlowLoader>(); container.ResolveTo <INeedLoadSlowly2, NeedSlowly2>(); container.ResolveTo <INeedLoadSlowly1, NeedSlowly1>(); var load1 = container.Resolve <INeedLoadSlowly1>(); var load2 = container.Resolve <INeedLoadSlowly2>(); }
static void Main(string[] args) { var resolver = new BaseResolver(false, Game.Ghosts); ushort functionIndex, methodIndex, fieldIndex, stringIndex, OPCodeIndex; functionIndex = 100; methodIndex = 33523; fieldIndex = 50; stringIndex = 50; OPCodeIndex = 30; Opcode testOp = resolver.ResolveOpcodes(); string testFunction, testMethod, testField, testString, testOPCode; testFunction = "setdvar"; testMethod = "giveweapon"; testField = "name"; testString = "j_head"; testOPCode = "OpReturn"; Console.WriteLine("Resolver - ResolveStringById"); Console.WriteLine(String.Format("functionIndex: {0} | methodIndex: {1} | fieldIndex: {2} | stringIndex {3} | OPCodeIndex: {4}", functionIndex, methodIndex, fieldIndex, stringIndex, OPCodeIndex)); Console.WriteLine(); Console.WriteLine(String.Format("Function: {0}", resolver.ResolveFunctionNameById(functionIndex))); Console.WriteLine(String.Format("Method: {0}", resolver.ResolveMethodNameById(methodIndex))); Console.WriteLine(String.Format("Field: {0}", resolver.ResolveFieldNameById(fieldIndex))); Console.WriteLine(String.Format("String: {0}", resolver.ResolveStringNamegById(fieldIndex))); Console.WriteLine(String.Format("OPCode: {0}", resolver.ResolveOpcodeNameById(OPCodeIndex))); Console.WriteLine(); Console.WriteLine("Resolver - ResolveIdByString"); Console.WriteLine(String.Format("functionName: {0} | methodName: {1} | fieldName: {2} | stringName: {3} | OPCodeName: {4}", testFunction, testMethod, testField, testString, testOPCode)); Console.WriteLine(); Console.WriteLine(String.Format("Function: {0}", resolver.ResolveIdOfFunction(testFunction))); Console.WriteLine(String.Format("Method: {0}", resolver.ResolveIdOfMethod(testMethod))); Console.WriteLine(String.Format("Field: {0}", resolver.ResolveIdOfField(testField))); Console.WriteLine(String.Format("String: {0}", resolver.ResolveIdOfString(testString))); Console.WriteLine(String.Format("OPCode: {0}", resolver.ResolveIdOfOpcodeString(testOPCode))); Console.ReadKey(); }
/// <summary> /// Creates instance of disassembler /// </summary> /// <param name="resolver">Resolver</param> /// <param name="fileName">path to target file</param> public Disassembler(BaseResolver resolver, string fileName) { _resolver = resolver; var path = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)); var bytecodePath = path + ".bytecode"; var bufferPath = path + ".buffer"; if (!File.Exists(bytecodePath)) { throw new InvalidOperationException("File with script bytecode is not exists!"); } if (!File.Exists(bufferPath)) { throw new InvalidOperationException("File with script buffer is not exists!"); } _bytecode = new BinaryReader(File.OpenRead(bytecodePath)); _buffer = new BinaryReader(File.OpenRead(bufferPath)); }
public async Task DependenciesCovariant() { Logger.TimeInstantiated = 0; MegaLog.TimeInstantiated = 0; var container = new BaseResolver(TimeSpan.FromHours(5)); await container.ResolveToAsync <IMegaLog, MegaLog>(); await container.ResolveToAsync <INeedMegaLogger, NeedMegaLogger>(); await container.ResolveToAsync <INeedLogger1, NeedLogger1>(); var needLogger = await container.ResolveAsync <INeedLogger1>(); var needMegaLogger = await container.ResolveAsync <INeedMegaLogger>(); Assert.True(Logger.TimeInstantiated <= 1); Assert.True(MegaLog.TimeInstantiated <= 1); }
public async Task MissingDependencyTimeout() { var container = new BaseResolver(TimeSpan.FromSeconds(1)); await container.ResolveToAsync <ILog, MegaLog>(); var loadingFileProvider = container.ResolveAsync <ILogFileProvider>(); ILogFileProvider?testLogFileProvider = null; try { testLogFileProvider = await loadingFileProvider; Assert.False(true); } catch { Assert.True(true); } }
public async Task DuplicateInstantiation() { SlowLoader.Reset(); var container = new BaseResolver(); //TimeSpan.FromSeconds(10)); container.ResolveTo <IResolver>(container); container.ResolveTo <ILoadSlowly, SlowLoader>(); container.ResolveTo <INeedLoadSlowly2, NeedSlowly2>(); container.ResolveTo <INeedLoadSlowly1, NeedSlowly1>(); var load1 = container.ResolveAsync <INeedLoadSlowly1>(); var load2 = container.ResolveAsync <INeedLoadSlowly2>(); await load1; await load2; }
public void ResolveWithoutMapping() { var container = new BaseResolver(); container.ResolveTo <ILog, MegaLog>(); container.ResolveTo <ILogFileProvider, TestLogFileProvider>(); //container.ResolveTo<ILogSizeProvider, TestLogSizeProvider>(); //var testLogFileProvider = container.Resolve<ILogFileProvider>(); //var fi = testLogFileProvider.GetLogFile(); //Assert.NotNull(fi); var testLogSizeProvider = container.Resolve <TestLogSizeProvider>(); Assert.NotNull(testLogSizeProvider); var size = testLogSizeProvider !.GetLogSize(); Assert.True(size >= 0); }
public void SimpleLinearDependencies() { var container = new BaseResolver(); container.ResolveTo <ILog, MegaLog>(); container.ResolveTo <ILogFileProvider, TestLogFileProvider>(); container.ResolveTo <ILogSizeProvider, TestLogSizeProvider>(); var testLogFileProvider = container.Resolve <ILogFileProvider>(); var fi = testLogFileProvider.GetLogFile(); Assert.NotNull(fi); var testLogSizeProvider = container.Resolve(typeof(ILogSizeProvider)) as ILogSizeProvider; Assert.NotNull(testLogSizeProvider); var size = testLogSizeProvider !.GetLogSize(); Assert.True(size >= 0); }
public void TearDown() { BaseResolver.Reset(); BaseResolver2.Reset(); BaseResolver3.Reset(); }