public void TestNoResolution() { Resolver<ContentType> resolver = new Resolver<ContentType>(); resolver.Add(new ContentType("*.html", "text/html")); resolver.Add(new ContentType("*.jpg", "image/jpeg")); resolver.Add(new ContentType("/images/*", "image/jpeg")); resolver.Add(new ContentType("/log/**", "text/plain")); resolver.Add(new ContentType("*.exe", "application/octetstream")); resolver.Add(new ContentType("**.txt", "text/plain")); resolver.Add(new ContentType("/html/*", "text/html")); AssertEquals(7, resolver.Count); AssertEquals("text/plain", resolver.Resolve("README.txt").Value); AssertEquals(null, resolver.Resolve("README")); }
Task IIsolated.Run(System.Threading.CancellationToken token) { IResolver resolver = new Resolver(new[] {"CH.IoC."}); var log = resolver.Resolve<ILog>(); log.Log("Isolated 4.0.0.0"); return Task.Delay(1, token); }
async Task IBoot.Run(CancellationToken token) { IResolver resolver = new Resolver(new[] {"CH.IoC."}); _log = resolver.Resolve<ILog>(); _log.Log(1, "Boot 1"); var tasks = new[] { "isolated\\0", "isolated\\1", "isolated\\2" } .Select(path => Run(path, token)) .ToArray(); // force start foreach (var task in tasks) { try { await task; } catch (Exception ex) { _log.Log(2, "Boot 2: " + ex); } } while (!token.IsCancellationRequested) { await Task.Delay(10, token); } }
static void Main(string[] args) { var resolver = new Resolver(); resolver.Register<Shopper, Shopper>(); //resolver.Register<ICreditCard, MasterCard>(); resolver.Register<ICreditCard, Visa>(); var shopper = resolver.Resolve<Shopper>(); shopper.Charge(); Console.Read(); }
public void TestIoc() { Assert.DoesNotThrow( () => { var r = new Resolver(new[] {"CH."}); var mf = r.Resolve<IMemcachedFactory>(); var mc = mf.Create(MemcachedSettings.Settings.Server("localhost", 17325)); mc.Stats(); }); }
public void TestCache() { Resolver<ContentType> resolver = new Resolver<ContentType>(); resolver.Add(new ContentType("*.html", "text/html")); resolver.Add(new ContentType("*.jpg", "image/jpeg")); resolver.Add(new ContentType("/images/*", "image/jpeg")); resolver.Add(new ContentType("/log/**", "text/plain")); resolver.Add(new ContentType("*.exe", "application/octetstream")); resolver.Add(new ContentType("**.txt", "text/plain")); resolver.Add(new ContentType("/html/*", "text/html")); AssertEquals(7, resolver.Count); AssertEquals("image/jpeg", resolver.Resolve("image.jpg").Value); AssertEquals("text/plain", resolver.Resolve("README.txt").Value); int index = 0; for(int i = resolver.Count; i > 0; i--) { ContentType type = resolver[i - 1]; if(type.Value.Equals("text/plain")) { index = i; } } resolver.RemoveAt(index); resolver.Add(new ContentType("*", "application/octetstream")); AssertEquals("application/octetstream", resolver.Resolve("README.txt").Value); AssertEquals("application/octetstream", resolver.Resolve("README.txt").Value); resolver.Add(new ContentType("README.*", "text/html")); resolver.Add(new ContentType("README.txt", "text/plain")); AssertEquals("text/plain", resolver.Resolve("README.txt").Value); AssertEquals("text/html", resolver.Resolve("README.jsp").Value); }
static void Main(string[] args) { //Shopper shopper = new Shopper(new MasterCard()); //shopper.Charge(); // configuration var container = new Resolver(); container.Register<Shopper, Shopper>(); //container.Register<ICreditCard, Visa>(); // get to the Shoppa! Shopper shopper = container.Resolve<Shopper>(); shopper.Charge(); Console.ReadKey(); }
async void IIsolatedRunner.Run() { try { using (_cancellationTokenSource = new CancellationTokenSource()) { IResolver resolver = new Resolver(new[] {"CH.IoC."}); var directories = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath.Split(Path.PathSeparator); resolver.LoadDynamicAssemblies(directories); var log = resolver.Resolve<ILog>(); log.Log(1, "IsolatedRunner 1"); Type isolatedType; try { isolatedType = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .FirstOrDefault( t => !t.IsInterface && t.GetInterface(typeof (IIsolated).FullName) != null); } catch (Exception ex) { log.Log(2, "IsolatedRunner 5: " + ex); return; } if (isolatedType == null) { log.Log(2, "IsolatedRunner 2: Isolated type not found in any of: " + AppDomain.CurrentDomain.SetupInformation.PrivateBinPath); return; } Debug.WriteLine("IsolatedRunner 9 Running: " + isolatedType.AssemblyQualifiedName); var instance = isolatedType.Assembly.CreateInstance(isolatedType.FullName); var isolated = (IIsolated) instance; if (isolated == null) { log.Log(2, "IsolatedRunner 3: Isolated type not found: " + isolatedType.AssemblyQualifiedName); return; } try { Debug.WriteLine("IsolatedRunner 6: Before Run"); await isolated.Run(_cancellationTokenSource.Token); Debug.WriteLine("IsolatedRunner 7: After Run"); } catch (Exception ex) { log.Log(2, "IsolatedRunner 4: " + ex); } Debug.WriteLine("IsolatedRunner 8: After Run Catch"); } } catch (Exception ex) { Debug.WriteLine("IIsolatedRunner.Run: " + ex); } _cancellationTokenSource = null; }
public void TestNonGreedyMatch() { Resolver<ContentType> resolver = new Resolver<ContentType>(); resolver.Add(new ContentType("*.html", "text/html")); resolver.Add(new ContentType("*.jpg", "image/jpeg")); resolver.Add(new ContentType("/images/*", "image/jpeg")); resolver.Add(new ContentType("/log/**", "text/plain")); resolver.Add(new ContentType("*.exe", "application/octetstream")); resolver.Add(new ContentType("**.txt", "text/plain")); resolver.Add(new ContentType("/html/*", "text/html")); AssertEquals(7, resolver.Count); resolver.Add(new ContentType("/*?/html/*", "text/html")); AssertEquals(8, resolver.Count); AssertEquals(null, resolver.Resolve("/a/b/html/index.jsp")); AssertEquals("text/html", resolver.Resolve("/a/html/index.jsp").Value); }
public void TestResolverCache() { Resolver<ContentType> resolver = new Resolver<ContentType>(); for(int i = 0; i <= 2000; i++) { resolver.Add(new ContentType(i.ToString(), i.ToString())); } AssertEquals(resolver.Resolve("1").Value, "1"); AssertEquals(resolver.Resolve("2000").Value, "2000"); }
static void Main(string[] args) { var resolver = new Resolver(); resolver.Resolve(); }
public void ShowModificationImportWindowDialog(string modificationPath) { var rootNodeViewModel = modificationImportViewModelFactory.FromDirectory(modificationPath); var solution = riotSolutionLoader.Load(@"V:\Riot Games\League of Legends\RADS", RiotProjectType.AirClient | RiotProjectType.GameClient); var airResolver = new Resolver(solution.ProjectsByType[RiotProjectType.AirClient].ReleaseManifest.Root); var gameResolver = new Resolver(solution.ProjectsByType[RiotProjectType.GameClient].ReleaseManifest.Root); var fileNodes = rootNodeViewModel.EnumerateFileNodes().ToArray(); var importWindow = new ModificationImportWindow(); var modificationImportViewModel = new ModificationImportViewModel(this, importWindow, rootNodeViewModel); modificationImportViewModel.ModificationFriendlyName = fileSystemProxy.GetDirectoryInfo(modificationPath).Name; importWindow.DataContext = modificationImportViewModel; new Thread(() => { foreach (var fileNode in fileNodes) { var path = fileNode.Path; var airResolution = airResolver.Resolve(path); if (airResolution.Any()) { fileNode.ResolutionPath = airResolution.First().GetPath(); fileNode.ResolutionState = ResolutionState.ResolutionSuccessful; } else { var gameResolutions = gameResolver.Resolve(path); if (gameResolutions.Any()) { fileNode.ResolutionPath = gameResolutions.First().GetPath(); fileNode.ResolutionState = ResolutionState.ResolutionSuccessful; } else { fileNode.ResolutionState = ResolutionState.ResolutionFailed; } } } LeagueModificationCategory modificationType = LeagueModificationCategory.Other; if (fileNodes.Any(node => node.ResolutionState == ResolutionState.ResolutionSuccessful)) { var modificationTypeCounts = new ConcurrentDictionary<LeagueModificationCategory, int>(); foreach (var file in fileNodes) { if (file.ResolutionState == ResolutionState.ResolutionSuccessful) { if (file.ResolutionPath.IndexOf("DATA/Characters", StringComparison.OrdinalIgnoreCase) != -1 || file.ResolutionPath.IndexOf("assets/images/champions", StringComparison.OrdinalIgnoreCase) != -1) { if (file.ResolutionPath.IndexOf("ward", StringComparison.OrdinalIgnoreCase) != -1) { modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Ward, 1, (existing, count) => count + 1); } else { modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Champion, 1, (existing, count) => count + 1); } } else if (file.ResolutionPath.IndexOf("LEVELS") != -1) { modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Map, 1, (existing, count) => count + 1); } else if (file.ResolutionPath.IndexOf("Menu", StringComparison.OrdinalIgnoreCase) != -1) { modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.UserInterface, 1, (existing, count) => count + 1); } else { modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Other, 1, (existing, count) => count + 1); } } } var categorizationCounts = modificationTypeCounts.Sum(x => x.Value); var highestCategorization = modificationTypeCounts.MaxBy(key => key.Value, Comparer<int>.Default); if (highestCategorization.Value >= categorizationCounts * 2.0 / 3.0) { modificationType = modificationTypeCounts.MaxBy(key => key.Value, Comparer<int>.Default).Key; } Console.WriteLine("Highest categorization: " + highestCategorization.Key.Name); modificationTypeCounts.ForEach(x => Console.WriteLine(x.Key.Name + ": " + x.Value)); Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => { modificationImportViewModel.ModificationCategorization = modificationType; })); } }).Start(); importWindow.ShowDialog(); }