protected ControllerBase(ActionInvoker actionInvoker, WebSocketServerBase server, DataContext dataContext, JsonMapperManager jsonMapperManager) : base(actionInvoker, server) { _dataContext = dataContext; _commandMapper = jsonMapperManager.GetMapper <DeviceCommand>(); _notificationMapper = jsonMapperManager.GetMapper <DeviceNotification>(); }
public DeviceController(ActionInvoker actionInvoker, WebSocketServerBase server, DataContext dataContext, JsonMapperManager jsonMapperManager, [Named("DeviceCommand")] DeviceSubscriptionManager subscriptionManager, MessageBus messageBus, IMessageManager messageManager, DeviceService deviceService) : base(actionInvoker, server, dataContext, jsonMapperManager) { _subscriptionManager = subscriptionManager; _messageBus = messageBus; _messageManager = messageManager; _deviceService = deviceService; _deviceMapper = jsonMapperManager.GetMapper <Device>(); }
public DeviceController(ActionInvoker actionInvoker, WebSocketServerBase server, DataContext dataContext, JsonMapperManager jsonMapperManager, [Named("DeviceCommand")] DeviceSubscriptionManager subscriptionManager, MessageBus messageBus, IMessageManager messageManager, DeviceService deviceService) : base(actionInvoker, server, dataContext, jsonMapperManager) { _subscriptionManager = subscriptionManager; _messageBus = messageBus; _messageManager = messageManager; _deviceService = deviceService; _deviceMapper = jsonMapperManager.GetMapper<Device>(); }
public MetadataParameter[] GetTypeParameters(Type type, JsonMapperEntryMode?mode = null, bool patch = false, string prefix = null) { // get JSON mapping manager var mapper = _jsonMapperManager.GetMapper(type); if (mapper == null) { return new MetadataParameter[] { } } ; // create parameters from mapping entries var parameters = new List <MetadataParameter>(); foreach (var parameter in mapper.Entries.Where(e => mode == null || (mode.Value & e.Mode) == mode.Value)) { // add parameter that corresponds to the mapped property var propertyType = parameter.EntityProperty.PropertyType; var isJsonObject = parameter.EntityProperty.IsDefined(typeof(JsonFieldAttribute), false); var param = new MetadataParameter { Name = prefix + parameter.JsonProperty, Type = isJsonObject ? "object" : ToJsonType(propertyType), IsRequred = !patch && IsRequired(parameter.EntityProperty), Documentation = _xmlCommentReader.GetPropertyElement(parameter.EntityProperty).ElementContents("summary"), }; parameters.Add(param); // add child object parameters if (param.Type == "object" && !isJsonObject) { parameters.AddRange(GetTypeParameters(propertyType, mode, false, param.Name + ".")); } else if (param.Type == "array") { var elementType = propertyType.GetInterfaces().First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable <>)).GetGenericArguments().First(); if (ToJsonType(elementType) == "object") { parameters.AddRange(GetTypeParameters(elementType, mode, false, param.Name + "[].")); } } } return(parameters.ToArray()); }
private MetadataParameter[] GetTypeParameters(Type type, JsonMapperEntryMode?exclude = null, string prefix = null) { // get JSON mapping manager var mapper = JsonMapperManager.GetMapper(type); if (mapper == null) { return new MetadataParameter[] { } } ; // create parameters from mapping entries var parameters = new List <MetadataParameter>(); foreach (var parameter in mapper.Entries.Where(e => exclude == null || e.Mode != exclude.Value)) { // add parameter that corresponds to the mapped property var isJsonObject = parameter.EntityProperty.IsDefined(typeof(JsonFieldAttribute), false); var param = new MetadataParameter { Name = (prefix == null ? null : prefix + ".") + parameter.JsonProperty, Type = isJsonObject ? "object" : ToJsonType(parameter.EntityProperty.PropertyType), IsRequred = IsRequired(parameter.EntityProperty), Documentation = DataXmlCommentReader.GetPropertyElement(parameter.EntityProperty).ElementContents("summary"), }; parameters.Add(param); // add child object parameters if (param.Type == "object" && !isJsonObject) { parameters.AddRange(GetTypeParameters(parameter.EntityProperty.PropertyType, exclude, param.Name)); } } return(parameters.ToArray()); }
protected IJsonMapper <T> GetMapper <T>() { return(_jsonMapperManager.GetMapper <T>()); }