public T ParseValue <T>(string value, CultureInfo culture) { DebugGuard.NotNull(culture, nameof(culture)); Type type = typeof(T); ICommandConverter converter = Array.Find(this.converters, x => x.Type.Equals(type)); if (converter != null) { return(((ICommandConverter <T>)converter).ConvertFrom( this, culture, WebUtility.UrlDecode(value), type)); } // This special case allows us to reuse the same converter for infinite enum types // if one has not already been configured. if (type.IsEnum) { converter = Array.Find(this.converters, x => x.Type.Equals(typeof(Enum))); if (converter != null) { return((T)((ICommandConverter <object>)converter).ConvertFrom( this, culture, WebUtility.UrlDecode(value), type)); } } // We don't actually return here. // The compiler just cannot see our exception. ThrowNotSupported(type); return(default);
public ReworkTcpTransport(TcpClient client, ICommandConverter commandConverter, IProtocol protocol) { _client = client; _stream = _client.GetStream(); _commandConverter = commandConverter; _protocol = protocol; }
/// <inheritdoc/> public override object ConvertFrom(CultureInfo culture, string value, Type propertyType) { Type type = typeof(T); ICommandConverter paramConverter = CommandDescriptor.GetConverter(type); if (paramConverter == null) { throw new InvalidOperationException("No type converter exists for type " + type.FullName); } var result = new List <T>(); if (value != null) { string[] items = this.GetStringArray(value, culture); foreach (string s in items) { object item = paramConverter.ConvertFromInvariantString(s, type); if (item != null) { result.Add((T)item); } } } return(result); }
static void CommandRover(Rover rover, ICommandConverter commandConverter) { commandConverter.Commands.ForEach(cc => { var command = CommandManager.GetCommands().First(c => c.Code == cc); CommandManager.Apply(rover, command); }); }
protected BaseServerCommand(IServiceProvider locator, IDataContext context, IDatabaseQuery databaseQuery, IDomainModel domainModel, IWireSerialization serialization, ICommandConverter converter) { //TODO Is it bad to have a base Command like this that injects many of these: this.locator = locator; this.context = context; this.databaseQuery = databaseQuery; this.domainModel = domainModel; this.serialization = serialization; this.converter = converter; }
public CrudCommands( IServiceProvider locator, ICommandConverter converter, IDomainModel domainModel, IWireSerialization serialization) { this.Locator = locator; this.Converter = converter; this.DomainModel = domainModel; this.Serialization = serialization; }
public CrudCommands( IServiceLocator locator, ICommandConverter converter, IDomainModel domainModel, IWireSerialization serialization) { this.Locator = locator; this.Converter = converter; this.DomainModel = domainModel; this.Serialization = serialization; }
public DomainCommands( IServiceLocator locator, ICommandConverter converter, IProcessingEngine processing, IDomainModel domainModel, IWireSerialization serialization) { this.Locator = locator; this.Converter = converter; this.Processing = processing; this.DomainModel = domainModel; this.Serialization = serialization; }
public DomainCommands( IServiceProvider locator, ICommandConverter converter, IProcessingEngine processing, IDomainModel domainModel, IWireSerialization serialization) { this.Locator = locator; this.Converter = converter; this.Processing = processing; this.DomainModel = domainModel; this.Serialization = serialization; }
protected internal TCommand ExecuteCommand <TCommand>(ICommandConverter <TCommand> potentialCommand, Action <TCommand> callback = null) where TCommand : ICommand { if (IsValid(potentialCommand)) { var command = potentialCommand.ToCommand(); if (callback != null) { callback(command); } ExecuteCommand(command); return(command); } return(default(TCommand)); }
/// <summary> /// Parses the given string value converting it to the given type. /// </summary> /// <param name="value">The string value to parse.</param> /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param> /// <typeparam name="T"> /// The <see cref="Type"/> to convert the string to. /// </typeparam> /// <returns>The converted instance or the default.</returns> public T ParseValue <T>(string value, CultureInfo culture) { if (culture == null) { culture = CultureInfo.InvariantCulture; } Type type = typeof(T); ICommandConverter converter = CommandDescriptor.GetConverter(type); try { return((T)converter.ConvertFrom(culture, WebUtility.UrlDecode(value), type)); } catch { return(default);
/// <summary> /// Parses the given string value converting it to the given type. /// </summary> /// <param name="type"> /// The <see cref="Type"/> to convert the string to. /// </param> /// <param name="value"> /// The <see cref="string"/> value to parse. /// </param> /// <param name="culture"> /// The <see cref="CultureInfo"/> to use as the current culture. /// <remarks>If not set will parse using <see cref="CultureInfo.InvariantCulture"/></remarks> /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> internal object ParseValue(Type type, string value, CultureInfo culture) { if (culture == null) { culture = CultureInfo.InvariantCulture; } ICommandConverter converter = CommandDescriptor.GetConverter(type); try { return(converter.ConvertFrom(culture, WebUtility.UrlDecode(value), type)); } catch { // Return the default value return(TypeDefaultsCache.GetOrAdd(type, t => this.GetDefaultValue(type))); } }
public DeleteAllAndInsertDemoData(IServiceProvider locator, IDataContext context, IDatabaseQuery databaseQuery, IDomainModel domainModel, IWireSerialization serialization, ICommandConverter converter) : base(locator, context, databaseQuery, domainModel, serialization, converter) { }
public void Remove(ICommandConverter converter) { // TODO: Efficient removal _converters.Remove(converter); }
public void Add(ICommandConverter converter) { _converters.Add(converter); }
public ReworkTcpTransportManager(IProtocol protocol, ICommandConverter commandConverter) { _protocol = protocol; _commandConverter = commandConverter; }
/// <summary> /// Pass request to the server command. /// Request is casted instead of deserialized. /// Result type is defined with Accept header /// If Accept header is not defined, XML will be used /// </summary> /// <typeparam name="TCommand">server command type</typeparam> /// <typeparam name="TArgument">server command argument</typeparam> /// <param name="converter">command converter</param> /// <param name="argument">argument value</param> /// <returns>result converted to requested mime type</returns> public static Stream PassThrough <TCommand, TArgument>(this ICommandConverter converter, TArgument argument) { var accept = (ThreadContext.Request.Accept ?? "application/xml").ToLowerInvariant(); return(converter.PassThrough <TCommand, TArgument>(argument, accept)); }