public RulesProvider(IRulesLoader loader) { this.loader = loader; rules = new Lazy <Data.Rules>(loader.Load, LazyThreadSafetyMode.ExecutionAndPublication); genderRules = new Lazy <Data.GenderRules>(loader.LoadGender, LazyThreadSafetyMode.ExecutionAndPublication); }
public RulesProvider(IRulesLoader loader) { this.loader = loader; rules = new Lazy<Data.Rules>(loader.Load, LazyThreadSafetyMode.ExecutionAndPublication); genderRules = new Lazy<Data.GenderRules>(loader.LoadGender, LazyThreadSafetyMode.ExecutionAndPublication); }
async Task <RulesCache> LoadRules(IRulesLoader rulesLoader) { RulesCache cache = new RulesCache(new Dictionary <string, RuleEngine>(), new Dictionary <string, string>()); StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFolder rulesFolder = await appInstalledFolder.GetFolderAsync("Rules"); IReadOnlyList <StorageFile> files = await rulesFolder.GetFilesAsync(); Dictionary <string, StorageFile> rules = files.Where(f => f.Name.EndsWith(".module")).ToDictionary(f => Path.GetFileNameWithoutExtension(f.Name).ToLowerInvariant()); Dictionary <string, StorageFile> resources = files.Where(f => f.Name.EndsWith(".resources")).ToDictionary(f => Path.GetFileNameWithoutExtension(f.Name).ToLowerInvariant()); int count = 0; foreach (string key in rules.Keys) { count++; await SetProgressValue(((double)count / rules.Count) * 100); rulesLoader.LoadRules(new RulesModuleModel { Name = key, ResourceSetFile = GetBytes(resources[key]), RuleSetFile = GetBytes(rules[key]) }, cache); } return(cache); }
static async Task <RulesCache> LoadRules(IRulesLoader rulesLoader) { RulesCache cache = new RulesCache(new Dictionary <string, RuleEngine>(), new Dictionary <string, string>()); var assembly = IntrospectionExtensions.GetTypeInfo(typeof(FlowActivity)).Assembly; string[] embeddedResources = GetResourceNames(assembly); Dictionary <string, string> rules = embeddedResources .Where(f => f.EndsWith(".module")) .ToDictionary(f => GetKey(f).ToLowerInvariant()); Dictionary <string, string> resources = embeddedResources .Where(f => f.EndsWith(".resources")) .ToDictionary(f => GetKey(f).ToLowerInvariant()); foreach (string key in rules.Keys) { await rulesLoader.LoadRulesOnStartUp ( new RulesModuleModel { Name = key, ResourceSetFile = GetBytes(resources[key], assembly), RuleSetFile = GetBytes(rules[key], assembly) }, cache ); } return(cache); string GetKey(string fullResourceName) => Path.GetExtension(Path.GetFileNameWithoutExtension(fullResourceName)).Substring(1); }
async Task <RulesCache> LoadRules(IRulesLoader rulesLoader) { RulesCache cache = new RulesCache(new ConcurrentDictionary <string, RuleEngine>(), new ConcurrentDictionary <string, string>()); var assembly = IntrospectionExtensions.GetTypeInfo(typeof(ExtendedSplashViewModel)).Assembly; string[] uwpResources = GetResourceStrings(assembly); Dictionary <string, string> rules = uwpResources .Where(f => f.EndsWith(".module")) .ToDictionary(f => GetKey(f).ToLowerInvariant()); Dictionary <string, string> resources = uwpResources .Where(f => f.EndsWith(".resources")) .ToDictionary(f => GetKey(f).ToLowerInvariant()); int count = 0; DateTime dt = DateTime.Now; await Task.WhenAll ( rules.Keys.Select ( key => LoadRules ( new RulesModuleModel { Name = key, ResourceSetFile = GetBytes(resources[key], assembly), RuleSetFile = GetBytes(rules[key], assembly) } ) ) ); return(cache); Task LoadRules(RulesModuleModel module) { return(Task.Run(() => { rulesLoader.LoadRules(module, cache); count++; Progress = (double)count / rules.Count; })); } string GetKey(string fullResourceName) => Path.GetExtension(Path.GetFileNameWithoutExtension(fullResourceName)).Substring(1); }
public Petrovich(IRulesLoader rulesLoader = null) { loader = rulesLoader ?? new EmbeddedResourceLoader(); provider = new RulesProvider(loader); }
public CaseInflection(Gender gender, IRulesLoader rulesLoader = null) : this(new RulesProvider((rulesLoader ?? new EmbeddedResourceLoader())), gender) { }
public Petrovich(IRulesLoader rulesLoader = null) { loader = rulesLoader; provider = loader != null? new RulesProvider(loader): EmbeddedResourceLoader; _genderDeterminator = rulesLoader == null ? GenderUtils.Determinator : new GenderDeterminator(provider); }
public ExtendedSplashViewModel(IRulesLoader rulesLoader) { this.rulesLoader = rulesLoader; }
public GameEngineRulesResolver(IRulesLoader rulesLoader) { _rulesLoader = rulesLoader; Infantry = new ReadOnlyDictionaryBoxer <string, Infantry>(rulesLoader.Infantry); }
public CaseInflection(Gender gender, IRulesLoader rulesLoader = null) : this(new RulesProvider((rulesLoader ?? new EmbeddedResourceLoader())), gender) { }
public Petrovich(IRulesLoader rulesLoader = null) { loader = rulesLoader; provider = loader != null? new RulesProvider(loader): EmbeddedResourceLoader; _genderDeterminator = rulesLoader == null ? GenderUtils.Determinator : new GenderDeterminator(provider); }
RulesCache GetRulesCache(IRulesLoader rulesLoader) { return(Task.Run(async() => await LoadRules(rulesLoader)).Result); }
public Petrovich(IRulesLoader rulesLoader = null) { loader = rulesLoader ?? new YamlRulesLoader("rules.yml"); provider = new RulesProvider(loader); }