public void ResolveDependenciesTest() { Assert.NotNull(_services.GetService(typeof(IHttpControllerSelector))); Assert.NotNull(_services.GetService(typeof(IHttpActionSelector))); Assert.NotNull(_dependencies.GetService(typeof(IReferenceRepository))); }
private void OnSaveScreenshotToFile() { ISearchResultScreenshotService service = ServicesContainer.GetService <ISearchResultScreenshotService>(); var saveFileDialog = new SaveFileDialog { CheckFileExists = false, CheckPathExists = true, Filter = "PNG Files (*.png)|*.png|All Files (*.*)|*.*", InitialDirectory = AppContext.BaseDirectory, OverwritePrompt = true, Title = "Save screenshot or armor set search result" }; if (saveFileDialog.ShowDialog() != true) { return; } var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(service.RenderToImage(this, root.InParameters.Slots.Select(x => x.Value)))); using (FileStream fs = File.OpenWrite(saveFileDialog.FileName)) encoder.Save(fs); }
private async Task ImportInternal() { ISaveDataService saveDataService = ServicesContainer.GetService <ISaveDataService>(); IList <SaveDataInfo> saveDataInfoItems = saveDataService.GetSaveInfo(); IList <Task <IList <DecorationsSaveSlotInfo> > > allTasks = saveDataInfoItems .Select(ReadSaveData) .ToList(); await Task.WhenAll(allTasks); IList <DecorationsSaveSlotInfo> allSlots = allTasks .SelectMany(x => x.Result) .ToList(); DecorationsSaveSlotInfo selected; if (allSlots.Count > 1) { selected = saveSlotInfoSelector(allSlots); if (selected == null) { return; } } else { selected = allSlots[0]; } MessageBox.Show("Save data import done.", "Import", MessageBoxButton.OK); ApplySaveDataDecorations(selected); }
public async Task <HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) { // TODO: Validate only registered once? var request = controllerContext.Request; if (request != null) { request.RegisterForDispose(this); } HttpControllerDescriptor controllerDescriptor = controllerContext.ControllerDescriptor; ServicesContainer services = controllerDescriptor.Configuration.Services; HttpActionDescriptor httpActionDescriptor = s_actionSelector.SelectAction(controllerContext); var binder = (IActionValueBinder)services.GetService(typeof(IActionValueBinder)); var binding = binder.GetBinding(httpActionDescriptor); ActionContext = new HttpActionContext(controllerContext, httpActionDescriptor); // Parses method arguments await binding.ExecuteBindingAsync(ActionContext, cancellationToken); Initialize(controllerContext); // Invoker handlers result conversion var result = await httpActionDescriptor.ExecuteAsync(controllerContext, ActionContext.ActionArguments, cancellationToken); // Format result return(httpActionDescriptor.ResultConverter.Convert(controllerContext, result)); }
private void DeserializeSelectedEquipments(string value) { string error = null; try { List<Item> items = JsonConvert.DeserializeObject<List<Item>>(value); var eqpErrors = new List<string>(); foreach (ArmorPieceTypesViewModel type in armorPieceTypes) { Item item = items.FirstOrDefault(x => x.Type == (int)type.Type); if (item.Selected == null) { error = "Invalid advanced search data"; break; } foreach (ISolverDataEquipmentModel eqp in type.Equipments) eqp.IsSelected = false; foreach (string eqpName in item.Selected) { ISolverDataEquipmentModel eqp = type.Equipments.FirstOrDefault(x => Core.Localization.GetDefault(x.Equipment.Name) == eqpName); if (eqp == null) eqpErrors.Add(eqpName); else eqp.IsSelected = true; } type.ForceRefreshEquipments(); } if (eqpErrors.Count > 0) { string errMessage = string.Join("\n- ", eqpErrors); error = $"The following equipment(s) could not be selected because unavailable:\n- {errMessage}"; } } catch (Exception ex) { if (error == null) error = ex.Message; } if (error != null) { IMessageBoxService service = ServicesContainer.GetService<IMessageBoxService>(); service.Show(new MessageBoxServiceOptions { Buttons = Core.ServiceContracts.MessageBoxButton.OK, Icon = Core.ServiceContracts.MessageBoxImage.Warning, MessageBoxText = error, Title = "Error", }); } }
public static MongoDbServices Instance(Type type = null) { if (type == null) { return(ServicesContainer.GetService <MongoDbServices>()); } return((MongoDbServices)ServicesContainer.GetService(type)); }
/// <summary> /// /// </summary> protected virtual void InitializeServiceProperties() { Validator = ServicesContainer.GetService <IMigrateValidator>(); DatabaseCreator = ServicesContainer.GetService <IDatabaseCreator>(); DatabaseCommandManager = ServicesContainer.GetService <IDatabaseCommandManager>(); DatabaseTablesManager = ServicesContainer.GetService <IDatabaseTablesManager>(); CodeTablesManager = ServicesContainer.GetService <ICodeTablesManager>(); }
public static IHostPrincipalService GetHostPrincipalService(this ServicesContainer services) { if (services == null) { throw new ArgumentNullException("services"); } return(services.GetService <IHostPrincipalService>()); }
// Runtime code shouldn't call GetService() directly. Instead, have a wrapper (like the ones above) // and call through the wrapper. private static TService GetService <TService>(this ServicesContainer services) { if (services == null) { throw Error.ArgumentNull("services"); } return((TService)services.GetService(typeof(TService))); }
private async Task ImportInternal() { if (gameEquipments == null) { gameEquipments = LoadGameEquipments(); if (gameEquipments == null) { return; } } ISaveDataService saveDataService = ServicesContainer.GetService <ISaveDataService>(); if (saveDataService == null) { return; } IList <SaveDataInfo> saveDataInfoItems = saveDataService.GetSaveInfo(); if (saveDataInfoItems == null) { return; } IList <Task <IList <EquipmentsSaveSlotInfo> > > allTasks = saveDataInfoItems .Select(ReadSaveData) .ToList(); await Task.WhenAll(allTasks); IList <EquipmentsSaveSlotInfo> allSlots = allTasks .SelectMany(x => x.Result) .ToList(); EquipmentsSaveSlotInfo selected; if (allSlots.Count > 1) { selected = saveSlotInfoSelector(allSlots); if (selected == null) { return; } } else { selected = allSlots[0]; } System.Windows.MessageBox.Show("Save data import done.", "Import", System.Windows.MessageBoxButton.OK); ApplySaveDataEquipments(selected); }
public static IClrTypeKeyResolver GetClrTypeKeyResolver(this ServicesContainer services) { var resolver = services.GetService(typeof(IClrTypeKeyResolver)) as IClrTypeKeyResolver; if (resolver == null) { resolver = new DefalutClrTypeKeyResolver(); services.Add(typeof(IClrTypeKeyResolver), resolver); } return(resolver); }
private static T GetServiceOrThrow <T>(this ServicesContainer services) { T result = services.GetService <T>(); if (result == null) { throw Error.InvalidOperation(SRResources.DependencyResolverNoService, typeof(T).FullName); } return(result); }
internal static T GetServiceOrThrow <T>(this ServicesContainer services) where T : class { Contract.Requires(services != null); T service = services.GetService <T>(); if (service == null) { throw Error.InvalidOperation(Resources.DependencyResolverNoService, typeof(T).FullName); } return(service); }
public static T GetService<T>(Context ctx) { if (noRegistered) { RegisterService(); } T service = _mapServer.GetService<T>(typeof(T).AssemblyQualifiedName, ctx.ServerUrl); if (service == null) { throw new KDException("???", "instance == null"); } return service; }
static void GetAllOrders() { var ordersCollection = ServicesContainer.GetService <IMongoCollection <Order> >(); Console.WriteLine("----- Get All Orders -----"); var orders = ordersCollection.Find(p => p.ProductsAndQuantity.Count > 0).ToList(); foreach (var order in orders) { Console.WriteLine("OrderId: {0} | CustomerId: {1} | ProductsAndQuantity: {2} | Status: {3}", order.OrderId, order.CustomerId, order.ProductsAndQuantity.Count, order.Status); } Console.WriteLine("\n"); }
public MySQLService() : base(ServicesContainer.GetService <MySQLServiceDBConfiguration>().Options) { Options = ServicesContainer.GetService <MySQLServiceDBConfiguration>(); var method = this.GetType().GetMethod("Set"); var result = Options.Assembly.GetTypes().Where(x => x.GetInterface("IEntityMySQL", true) != null); foreach (var item in result) { DbSetCollection.Add(item, method.MakeGenericMethod(item).Invoke(this, null)); } }
static void GetAllProducts() { var productsCollection = ServicesContainer.GetService <IMongoCollection <Product> >(); Console.WriteLine("----- Get All Products -----"); var productsForOrder = productsCollection.Find(p => p.InStockAmmount > 0).ToList(); foreach (var product in productsForOrder) { Console.WriteLine("Name: {0} | Description: {1} | InStockAmmount: {2} | ProductId: {3}", product.Name, product.Description, product.InStockAmmount, product.ProductId); } Console.WriteLine("\n"); }
/// <summary> /// /// </summary> public override void Initialize() { var namingManager = ServicesContainer.GetService <INamingManager>(); namingManager.ForeignKeyNamingManager = new SqlForeignKeyNamingManager(); namingManager.PrimaryKeyNamingManager = new SqlPrimaryKeyNamingManager(); namingManager.UniqueKeyNamingManager = new SqlUniqueKeyNamingManager(); SqlTableManager = ServicesContainer.GetService <SqlTableManager>(); SqlColumnManager = ServicesContainer.GetService <SqlColumnManager>(); SqlUniqueKeyManager = ServicesContainer.GetService <SqlUniqueKeyManager>(); SqlPrimaryKeyManager = ServicesContainer.GetService <SqlPrimaryKeyManager>(); SqlForeignKeyManager = ServicesContainer.GetService <SqlForeignKeyManager>(); }
/// <summary> /// /// </summary> public override void Initialize() { var namingManager = ServicesContainer.GetService <INamingManager>(); namingManager.ForeignKeyNamingManager = new PostgresForeignKeyNamingManager(); namingManager.PrimaryKeyNamingManager = new PostgresPrimaryKeyNamingManager(); namingManager.UniqueKeyNamingManager = new PostgresUniqueKeyNamingManager(); PostgresTableManager = ServicesContainer.GetService <PostgresTableManager>(); PostgresColumnManager = ServicesContainer.GetService <PostgresColumnManager>(); PostgresPrimaryKeyManager = ServicesContainer.GetService <PostgresPrimaryKeyManager>(); PostgresUniqueKeyManager = ServicesContainer.GetService <PostgresUniqueKeyManager>(); PostgresForeignKeyManager = ServicesContainer.GetService <PostgresForeignKeyManager>(); }
/// <summary> /// /// </summary> public override void Initialize() { DatabaseConnection = ServicesContainer.GetService <IDatabaseConnection>(); var namingManager = ServicesContainer.GetService <INamingManager>(); namingManager.ForeignKeyNamingManager = new MySqlForeignKeyNamingManager(); namingManager.PrimaryKeyNamingManager = new MySqlPrimaryKeyNamingManager(); namingManager.UniqueKeyNamingManager = new MySqlUniqueKeyNamingManager(); MySqlTableManager = new MySqlTableManager(this); MySqlColumnManager = new MySqlColumnManager(this); MySqlPrimaryKeyManager = new MySqlPrimaryKeyManager(this); MySqlForeignKeyManager = new MySqlForeignKeyManager(this); DefaultSchema = GetDatabaseName(); }
static T GetService <T>(Context ctx, string url) { if (ctx == null) { throw new Exception("{ctx == null}"); } RegisterService(); var instance = _mapServer.GetService <T>(typeof(T), url); if (instance == null) { throw new Exception("获取服务对象失败,请检查己映射该对象!"); } return(instance); }
static void PerformDemoOrder() { var productsCollection = ServicesContainer.GetService <IMongoCollection <Product> >(); var ordersService = ServicesContainer.GetService <OrdersService>(); var productsForOrder = productsCollection.Find(p => p.InStockAmmount > 0).ToList(); var orderProducts = new List <OrderedProduct>(); foreach (var product in productsForOrder) { orderProducts.Add(new OrderedProduct(product, 1)); } ordersService.CreateOrder(Guid.NewGuid(), orderProducts); }
/// <summary> /// 获取请求path 并解码实际路径 /// </summary> /// <param name="request"></param> /// <returns></returns> public string GetRequestPath(HttpRequest request) { string pathPrefix = ""; string defaultIndex = ""; var url = ""; var site = this.GetSourceSite(request); if (site != null) { pathPrefix = site.PathPrefix; defaultIndex = site.DefaultIndex; } if (!string.IsNullOrEmpty(request.Path)) { if (!string.IsNullOrEmpty(request.RawUrl)) { url = request.RawUrl.TrimStart('/'); } if (string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(request.Path)) { url = request.Path.TrimStart('/'); } } else { url = request.QueryString.ToString(); } url = System.Web.HttpUtility.UrlDecode(url, System.Text.Encoding.UTF8); if (StringHelper.IsBase64(url)) { var enService = ServicesContainer.GetService <Rsd.Dudu.Core.IEncryptService>(null); url = enService.DecodeBase64(url); } url = url.Trim('/'); url = url.Substring(pathPrefix == null ? 0 : pathPrefix.Length); // 返回默认首页 if (string.IsNullOrWhiteSpace(url) || string.IsNullOrEmpty(url)) { url = (defaultIndex == null ? "" : defaultIndex); } return(url); }
public bool RenameLoadout(LoadoutViewModel loadoutViewModel) { var renameOptions = new RenameOptions { WindowTitle = $"Rename skill loadout", WindowPrompt = $"Rename skill loadout '{loadoutViewModel.Name}'", WindowDefaultValue = loadoutViewModel.Name, IsInputMandatory = true, IsValid = x => Loadouts.Where(l => l != loadoutViewModel).All(l => l.Name != x) }; if (ServicesContainer.GetService <IRenameService>().Rename(renameOptions, out string newName)) { loadoutViewModel.Name = newName; return(true); } return(false); }
public void WhenClearingOverridedServiceThenReturnsOriginal() { ProcessorConfiguration config = new ProcessorConfiguration(); ServicesContainer global = config.Services; HandlerServices services = new HandlerServices(global); ICommandHandlerTypeResolver newLocalService = new Mock <ICommandHandlerTypeResolver>().Object; services.Replace(typeof(ICommandHandlerTypeResolver), newLocalService); // Act services.Clear(typeof(ICommandHandlerTypeResolver)); // Assert ICommandHandlerTypeResolver localVal = (ICommandHandlerTypeResolver)services.GetService(typeof(ICommandHandlerTypeResolver)); ICommandHandlerTypeResolver globalVal = (ICommandHandlerTypeResolver)global.GetService(typeof(ICommandHandlerTypeResolver)); Assert.Same(globalVal, localVal); }
public static T GetService <T>(Context ctx, string url) { if (ctx == null) { throw new Exception("{ctx == null}"); } if (_noRegistered) { RegisterService(); } T service = _mapServer.GetService <T>(typeof(T).AssemblyQualifiedName, url); if (service == null) { throw new KDException("???", "instance == null"); } return(service); }
public UpdateProductQuantityCommandProcessor() { _productsCollection = ServicesContainer.GetService <IMongoCollection <Product> >(); }
public TransactionsService() { _transactionsCollection = ServicesContainer.GetService <IMongoCollection <Transaction> >(); _commandsProcessors = ServicesContainer.GetService <List <ICommandProcessor> >(); }
public static IBodyModelValidator GetBodyModelValidator(this ServicesContainer services) { return(services.GetService <IBodyModelValidator>()); }
// Get services from the global config. These are normally per-controller services, but we're getting the global fallbacks. private static TService GetService <TService>(ServicesContainer services) { return((TService)services.GetService(typeof(TService))); }