public DefaultKeyValueCollection(IConverterRepository converters, SettingsBase settings)
 {
     Ensure.NotNull(converters, "converters");
     Ensure.NotNull(settings, "settings");
     this.converters = converters;
     this.settings   = settings;
 }
 public AutoCompleteBasedOnLucene(IDirectoryFactory directoryFactory, SourceStorageFactory sourceStorageFactory, ILog log, IConverterRepository converterRepository)
 {
     _sourceStorageFactory = sourceStorageFactory;
     _log = log;
     _converterRepository = converterRepository;
     _directoryFactory    = directoryFactory;
 }
 public AutoCompleteBasedOnLucene(IDirectoryFactory directoryFactory, SourceStorageFactory sourceStorageFactory, ILog log, IConverterRepository converterRepository)
 {
     _sourceStorageFactory = sourceStorageFactory;
     _log = log;
     _converterRepository = converterRepository;
     _directoryFactory = directoryFactory;
 }
        private static void AddConverter(IConverterRepository repository, Type converterType)
        {
            IEnumerable <object> attributes = converterType.GetCustomAttributes(typeof(ConverterAttribute), true);
            IConverter           converter  = (IConverter)Activator.CreateInstance(converterType);

            foreach (ConverterAttribute attribute in attributes)
            {
                if (attribute.HasTypesDefined)
                {
                    Type sourceType = attribute.SourceType;
                    Type targetType = attribute.TargetType;
                    repository.Add(sourceType, targetType, converter);
                }
                else
                {
                    IEnumerable <Type> interfaceTypes = converterType.GetInterfaces();
                    foreach (Type interfaceType in interfaceTypes)
                    {
                        if (interfaceType.IsGenericType && typeof(IConverter <,>) == interfaceType.GetGenericTypeDefinition())
                        {
                            Type[] parameters = interfaceType.GetGenericArguments();
                            Type   sourceType = parameters[0];
                            Type   targetType = parameters[1];
                            repository.Add(sourceType, targetType, converter);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Adds converters for EventSourcing logging.
 /// </summary>
 /// <param name="repository">A converter repository.</param>
 /// <returns>A converter repository.</returns>
 public static IConverterRepository AddEventSourcingLogging(this IConverterRepository repository)
 {
     Ensure.NotNull(repository, "repository");
     return(repository
            .Add(new EnvelopeMessageConverter())
            .Add(new CommandMessageConverter())
            .Add(new EventMessageConverter()));
 }
예제 #6
0
 /// <summary>
 /// Creates a new instance that uses <paramref name="inner"/> if converter is not found.
 /// </summary>
 /// <param name="inner"></param>
 /// <param name="exceptionHandler">A handler for expcetions raised by converters.</param>
 public DefaultConverterRepository(IConverterRepository inner, Action <Exception> exceptionHandler)
 {
     Ensure.NotNull(inner, "inner");
     Ensure.NotNull(exceptionHandler, "exceptionHandler");
     this.inner             = inner;
     this.exceptionHandler  = exceptionHandler;
     this.onSearchConverter = new OutFuncCollection <ConverterSearchContext, IConverter, bool>();
 }
예제 #7
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="modelDefinitionProvider">A collection of presentation model definitions.</param>
 /// <param name="converters">A repository of converters.</param>
 /// <param name="modelValueGetterFactory">A factory for event value getter.</param>
 public CommandVisualizationFactory(TypeModelDefinitionCollection modelDefinitionProvider, IConverterRepository converters, IFactory <IModelValueGetter, ICommand> modelValueGetterFactory)
 {
     Ensure.NotNull(modelDefinitionProvider, "modelDefinitionProvider");
     Ensure.NotNull(converters, "converters");
     Ensure.NotNull(modelValueGetterFactory, "modelValueGetterFactory");
     this.modelDefinitionProvider = modelDefinitionProvider;
     this.converters = converters;
     this.modelValueGetterFactory = modelValueGetterFactory;
 }
        /// <summary>
        /// Creates new instance with <paramref name="formatting" /> and <paramref name="converters"/>.
        /// </summary>
        /// <param name="formatting">An indention formatting for serialization.</param>
        /// <param name="converters">A custom repository with converters</param>
        public JsonCompositeStorage(Formatting formatting, IConverterRepository converters)
        {
            Ensure.NotNull(converters, "converters");
            this.formatting = formatting;
            this.converters = converters;

            loadSettings = new JsonLoadSettings();
            root         = new JObject();
        }
 /// <summary>
 /// Adds <paramref name="converter"/> for conversion from <typeparamref name="TSource"/> to <typeparamref name="TTarget"/>.
 /// The <paramref name="converter"/> should always success.
 /// </summary>
 /// <typeparam name="TSource">Source type.</typeparam>
 /// <typeparam name="TTarget">Target type.</typeparam>
 /// <param name="repository">The repository to register converter to.</param>
 /// <param name="converter">The converter.</param>
 /// <returns><paramref name="repository"/>.</returns>
 public static IConverterRepository Add <TSource, TTarget>(this IConverterRepository repository, Func <TSource, TTarget> converter)
 {
     Ensure.NotNull(converter, "converter");
     return(Add <TSource, TTarget>(repository, (TSource source, out TTarget target) =>
     {
         target = converter(source);
         return true;
     }));
 }
        /// <summary>
        /// Adds <paramref name="converter"/> for conversion from <typeparamref name="TOne"/> to <typeparamref name="TTwo"/> and from <typeparamref name="TTwo"/> to <typeparamref name="TOne"/>.
        /// </summary>
        /// <typeparam name="TOne">The first type of the vice-versa convertion.</typeparam>
        /// <typeparam name="TTwo">The second type of the vice-versa convertion.</typeparam>
        /// <param name="repository">The repository to register converter to.</param>
        /// <param name="converter">The converter.</param>
        /// <returns><paramref name="repository"/>.</returns>
        public static IConverterRepository Add <TOne, TTwo>(this IConverterRepository repository, TwoWayConverter <TOne, TTwo> converter)
        {
            DefaultConverter <TOne, TTwo> converter1 = converter;
            DefaultConverter <TTwo, TOne> converter2 = converter;

            Add <TOne, TTwo>(repository, converter1);
            Add <TTwo, TOne>(repository, converter2);
            return(repository);
        }
예제 #11
0
 public MainModule(IConverterRepository converterRepository)
 {
     Get["/"] = x => {
         var viewModel = new
         {
             converters = converterRepository.GetAll()
         };
         return(View["index.cshtml", viewModel.AsJson()]);
     };
 }
 /// <summary>
 /// Creates new instance with support for updating values of readonly properties.
 /// </summary>
 /// <param name="model">Instance of model. Can't be <c>null</c>.</param>
 /// <param name="valueUpdater">Readonly property value updater. Can't be <c>null</c>.</param>
 public ReflectionModelValueProvider(TModel model, IReflectionValueUpdater valueUpdater, IConverterRepository converters)
 {
     Ensure.NotNull(model, "model");
     Ensure.NotNull(valueUpdater, "valueUpdater");
     Ensure.NotNull(converters, "converters");
     Model        = model;
     ModelType    = model.GetType();
     ValueUpdater = valueUpdater;
     Converters   = converters;
 }
예제 #13
0
 public MainModule(IConverterRepository converterRepository)
 {
     Get["/"] = x => {
         var viewModel = new
         {
             converters = converterRepository.GetAll()
         };
         return View["index.cshtml", viewModel.AsJson()];
     };
 }
        /// <summary>
        /// Adds <paramref name="tryConvert"/> for convertion of string value separated by <paramref name="separator"/>
        /// to <see cref="List{TTargetItem}"/>, <see cref="IList{TTargetItem}"/>, <see cref="ICollection{TTargetItem}"/> and <see cref="IEnumerable{TTargetItem}"/>.
        /// </summary>
        /// <typeparam name="TTargetItem">Type of collection item.</typeparam>
        /// <param name="repository">The repository to register converter to.</param>
        /// <param name="tryConvert">The converter delegate.</param>
        /// <param name="separator">Item separator.</param>
        /// <returns><paramref name="repository"/>.</returns>
        public static IConverterRepository AddStringToCollection <TTargetItem>(this IConverterRepository repository, OutFunc <string, TTargetItem, bool> tryConvert, string separator = ",")
        {
            Ensure.NotNull(repository, "repository");
            StringToCollectionConverter <TTargetItem> converter = new StringToCollectionConverter <TTargetItem>(separator, new DefaultConverter <string, TTargetItem>(tryConvert));

            return(repository
                   .Add <string, List <TTargetItem> >(converter)
                   .Add <string, IList <TTargetItem> >(converter)
                   .Add <string, ICollection <TTargetItem> >(converter)
                   .Add <string, IEnumerable <TTargetItem> >(converter));
        }
예제 #15
0
        public SourceStorage(Directory indexDirectory,
                             ILearningRepository learningRepository,
                             IConverterRepository converterRepository)
        {
            _indexDirectory = indexDirectory;

            _learningRepository  = learningRepository;
            _converterRepository = converterRepository;

            EnsureIndexExists();
        }
예제 #16
0
        public ModelValueCollection(ReflectionModelValueProvider <ISettings> valueProvider, IModelDefinition modelDefinition, IConverterRepository converters)
        {
            Ensure.NotNull(valueProvider, "valueProvider");
            Ensure.NotNull(modelDefinition, "modelDefinition");
            Ensure.NotNull(converters, "converters");
            this.modelDefinition = modelDefinition;
            this.converters      = converters;

            ValueProvider = valueProvider;
            Keys          = modelDefinition.Fields.Select(f => f.Identifier);
        }
예제 #17
0
        public SourceStorage(Directory indexDirectory,
            ILearningRepository learningRepository,
            IConverterRepository converterRepository)
        {
            _indexDirectory = indexDirectory;

            _learningRepository = learningRepository;
            _converterRepository = converterRepository;

            EnsureIndexExists();
        }
        /// <summary>
        /// Adds <paramref name="tryConvert"/> for conversion from <see cref="String"/> to <typeparamref name="TTarget"/>.
        /// Alse adds support for nullable conversion from <see cref="String"/> to <see cref="Nullable{TTarget}"/>.
        /// </summary>
        /// <typeparam name="TTarget">Target type.</typeparam>
        /// <param name="repository">The repository to register converter to.</param>
        /// <param name="tryConvert">The converter delegate.</param>
        /// <param name="isWhitespaceAccepted">Whether whitespaces should be treated as nulls.</param>
        /// <returns><paramref name="repository"/>.</returns>
        public static IConverterRepository AddStringTo <TTarget>(this IConverterRepository repository, OutFunc <string, TTarget, bool> tryConvert, bool isWhitespaceAccepted = true)
            where TTarget : struct
        {
            Ensure.NotNull(repository, "repository");
            Ensure.NotNull(tryConvert, "tryConvert");

            IConverter <string, TTarget> converter = new DefaultConverter <string, TTarget>(tryConvert);

            return(repository
                   .Add <string, TTarget>(converter)
                   .Add <string, TTarget?>(new StringToNullableConverter <TTarget>(converter, isWhitespaceAccepted)));
        }
        /// <summary>
        /// Adds converter to the <paramref name="repository"/> for converting <see cref="TimeSpan"/> to/from <see cref="JToken"/>.
        /// </summary>
        /// <param name="repository">The repository to add converters to.</param>
        /// <returns>Self (for fluency).</returns>
        public static IConverterRepository AddJsonTimeSpan(this IConverterRepository repository)
        {
            Ensure.NotNull(repository, "repository");

            TimeSpanToJsonConverter converter = new TimeSpanToJsonConverter();

            return(repository
                   .Add <TimeSpan, JToken>(converter)
                   .Add <JToken, TimeSpan>(converter)
                   .Add <JValue, TimeSpan>(converter)
                   .Add <string, TimeSpan>(TimeSpan.TryParse));
        }
 /// <summary>
 /// Adds converter for conversion from <typeparamref name="TSource"/> to <see cref="String"/>.
 /// If <paramref name="format"/> is not <c>null</c>, then it is used as format string, eg. yyyy-MM-dd.
 /// </summary>
 /// <typeparam name="TSource">Source type.</typeparam>
 /// <param name="repository">The repository to register converter to.</param>
 /// <param name="format">Format string, eg. yyyy-MM-dd for datetime.</param>
 /// <returns><paramref name="repository"/>.</returns>
 public static IConverterRepository AddToString <TSource>(this IConverterRepository repository, string format = null)
 {
     Ensure.NotNull(repository, "repository");
     if (format == null)
     {
         return(Add(repository, new ToStringConverter <TSource>()));
     }
     else
     {
         return(Add(repository, new ToStringConverter <TSource>(format)));
     }
 }
예제 #21
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="eventStore">A store of the event streams.</param>
 /// <param name="eventDeserializer">A deserializer for event payload.</param>
 /// <param name="modelDefinitionProvider">A collection of presentation model definitions.</param>
 /// <param name="converters">A repository of converters.</param>
 /// <param name="modelValueGetterFactory">A factory for event value getter.</param>
 public AggregateRootVisualizationFactory(IEventStore eventStore, IDeserializer eventDeserializer, TypeModelDefinitionCollection modelDefinitionProvider, IConverterRepository converters, IFactory <IModelValueGetter, IEvent> modelValueGetterFactory)
 {
     Ensure.NotNull(eventStore, "eventStore");
     Ensure.NotNull(eventDeserializer, "eventDeserializer");
     Ensure.NotNull(modelDefinitionProvider, "modelDefinitionProvider");
     Ensure.NotNull(converters, "converters");
     Ensure.NotNull(modelValueGetterFactory, "modelValueGetterFactory");
     this.eventStore              = eventStore;
     this.eventDeserializer       = eventDeserializer;
     this.converters              = converters;
     this.modelDefinitionProvider = modelDefinitionProvider;
     this.modelValueGetterFactory = modelValueGetterFactory;
 }
        /// <summary>
        /// Adds string to any enum (and any nullable enum) converter search handler.
        /// Any enums types will be converted using <see cref="StringToEnumConverter"/>.
        /// </summary>
        /// <param name="repository">The repository to register converter to.</param>
        /// <param name="isCaseSensitive">Whether parsing should be case-sensitive.</param>
        /// <returns><paramref name="repository"/>.</returns>
        public static IConverterRepository AddEnumSearchHandler(this IConverterRepository repository, bool isCaseSensitive)
        {
            Ensure.NotNull(repository, "repository");

            if (isCaseSensitive)
            {
                return(repository.AddSearchHandler(TryConvertStringToEnumCaseSensitive));
            }
            else
            {
                return(repository.AddSearchHandler(TryConvertStringToEnum));
            }
        }
        /// <summary>
        /// Adds converters from/to <see cref="GuidKey"/>, <see cref="StringKey"/> and <see cref="IKey"/> (of type <see cref="GuidKey"/> or <see cref="StringKey"/>) and <see cref="JToken"/>.
        /// </summary>
        /// <param name="repository">The repository to add converters to.</param>
        /// <returns>Self (for fluency).</returns>
        public static IConverterRepository AddJsonKey(this IConverterRepository repository)
        {
            Ensure.NotNull(repository, "repository");

            GuidKeyToJTokenConverter   guidConverter   = new GuidKeyToJTokenConverter();
            StringKeyToJTokenConverter stringConverter = new StringKeyToJTokenConverter();
            KeyToJTokenConverter       keyConverter    = new KeyToJTokenConverter();

            return(repository
                   .Add <GuidKey, JToken>(guidConverter)
                   .Add <JToken, GuidKey>(guidConverter)
                   .Add(typeof(List <GuidKey>), typeof(JToken), guidConverter)
                   .Add(typeof(JToken), typeof(IEnumerable <GuidKey>), guidConverter)
                   .Add <StringKey, JToken>(stringConverter)
                   .Add <JToken, StringKey>(stringConverter)
                   .Add(typeof(List <StringKey>), typeof(JToken), stringConverter)
                   .Add(typeof(JToken), typeof(IEnumerable <StringKey>), stringConverter)
                   .Add <IKey, JToken>(keyConverter)
                   .Add <JToken, IKey>(keyConverter)
                   .Add(typeof(List <IKey>), typeof(JToken), keyConverter)
                   .Add(typeof(JToken), typeof(IEnumerable <IKey>), keyConverter));
        }
예제 #24
0
 public ConverterHub()
 {
     this.converterRepository = ServiceLocator.Current.GetInstance<IConverterRepository>();
 }
예제 #25
0
 /// <summary>
 /// Creates a new instance with <see cref="Converts.Repository"/> and <see cref="ReflectionModelValueProvider"/>.
 /// </summary>
 /// <param name="eventStore">A store of the event streams.</param>
 /// <param name="eventDeserializer">A deserializer for event payload.</param>
 /// <param name="modelDefinitionProvider">A collection of presentation model definitions.</param>
 /// <param name="converters">A repository of converters.</param>
 public AggregateRootVisualizationFactory(IEventStore eventStore, IDeserializer eventDeserializer, TypeModelDefinitionCollection modelDefinitionProvider, IConverterRepository converters)
     : this(eventStore, eventDeserializer, modelDefinitionProvider, converters, Factory.Getter <IModelValueGetter, IEvent>(e => new ReflectionModelValueProvider(e)))
 {
 }
 /// <summary>
 /// Creates a new instance with <paramref name="converts"/> used to convert messages to string.
 /// </summary>
 /// <param name="converts">A repository of converters.</param>
 public DefaultLogFormatter(IConverterRepository converts)
 {
     Ensure.NotNull(converts, "converts");
     this.converts = converts;
 }
 public SourceStorageFactory(IDirectoryFactory directoryFactory, IConverterRepository converterRepository, ILearningRepository learningRepository)
 {
     _directoryFactory = directoryFactory;
     _converterRepository = converterRepository;
     _learningRepository = learningRepository;
 }
예제 #28
0
 public NumberToWordController(ILogger logger, IConverterRepository converterRepository)
 {
     _logger = logger;
     _converterRepository = converterRepository;
 }
 /// <summary>
 /// Creates new instance.
 /// </summary>
 /// <param name="sourceValue">The original source value.</param>
 /// <param name="repository">The repository, where the conversion was invoked.</param>
 public DefaultConverterContext(TSource sourceValue, IConverterRepository repository)
 {
     Ensure.NotNull(repository, "repository");
     SourceValue = sourceValue;
     Repository  = repository;
 }
예제 #30
0
 public ConverterHub()
 {
     this.converterRepository = ServiceLocator.Current.GetInstance <IConverterRepository>();
 }
 /// <summary>
 /// Adds <paramref name="tryConvert"/> for conversion from <typeparamref name="TSource"/> to <typeparamref name="TTarget"/>.
 /// </summary>
 /// <typeparam name="TSource">Source type.</typeparam>
 /// <typeparam name="TTarget">Target type.</typeparam>
 /// <param name="repository">The repository to register converter to.</param>
 /// <param name="tryConvert">The converter delegate.</param>
 /// <returns><paramref name="repository"/>.</returns>
 public static IConverterRepository Add <TSource, TTarget>(this IConverterRepository repository, OutFunc <TSource, TTarget, bool> tryConvert)
 {
     Ensure.NotNull(repository, "repository");
     Ensure.NotNull(tryConvert, "tryConvert");
     return(Add(repository, new DefaultConverter <TSource, TTarget>(tryConvert)));
 }
 /// <summary>
 /// Creates new instance with <paramref name="converters"/>.
 /// </summary>
 /// <param name="converters">A custom repository with converters</param>
 public JsonCompositeStorage(IConverterRepository converters)
     : this(Formatting.None, converters)
 {
 }
 private JsonCompositeStorage(JObject root, Formatting formatting, IConverterRepository converters)
     : this(formatting, converters)
 {
     Ensure.NotNull(root, "root");
     this.root = root;
 }
 /// <summary>
 /// Adds <paramref name="converter"/> for conversion from <typeparamref name="TSource"/> to <typeparamref name="TTarget"/>.
 /// </summary>
 /// <typeparam name="TSource">Source type.</typeparam>
 /// <typeparam name="TTarget">Target type.</typeparam>
 /// <param name="repository">The repository to register converter to.</param>
 /// <param name="converter">The converter.</param>
 /// <returns><paramref name="repository"/>.</returns>
 public static IConverterRepository Add <TSource, TTarget>(this IConverterRepository repository, IConverter <TSource, TTarget> converter)
 {
     Ensure.NotNull(repository, "repository");
     repository.Add(typeof(TSource), typeof(TTarget), converter);
     return(repository);
 }
 /// <summary>
 /// Adds search handler for converting any type to string.
 /// </summary>
 /// <param name="repository">The repository to register converter to.</param>
 /// <returns><paramref name="repository"/>.</returns>
 public static IConverterRepository AddToStringSearchHandler(this IConverterRepository repository)
 {
     Ensure.NotNull(repository, "repository");
     return(repository.AddSearchHandler(TryConvertToString));
 }