Example #1
0
        // add middlewares to pipeline
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IStringFormatter stringFormatter, ShopContext shopContext)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            //app.UseMiddleware<LoggerComponent>("Admin", DateTime.UtcNow); // default middleware adding.
            app.UseLoggerComponent("Admin", DateTime.UtcNow); // adding with using extesion class

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            DbInitializer.Initialize(shopContext);

            // terminus
            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync(stringFormatter.FormatIt(new { Message = "Hello World" }));
            //});
        }
 public WordSelector(
     IWordProvider wordProvider,
     IStringFormatter stringFormatter)
 {
     WordProvider     = wordProvider;
     _stringFormatter = stringFormatter;
 }
        public StringFormatHelper(string text, IStringFormatter formatter = null)
        {
            if (text == null)
                throw new ArgumentNullException("text");

            _formatter = formatter ?? new NamedFieldFormatter();
            _textToFormat = text;
        }
Example #4
0
 public FunnyMessageViewComponent(IStringFormatter stringFormatter)
 {
     if (stringFormatter == null)
     {
         throw new ArgumentNullException("String formatter!");
     }
     _stringFormatter = stringFormatter;
 }
        /// <param name="formatter"><see cref="IStringFormatter"/> instance.</param>
        /// <inheritdoc cref="IStringFormatter.Format(string, IDataRecord, IFormatProvider)"/>
        public static string Format(this IStringFormatter formatter, string format, IDataRecord record)
        {
            _ = formatter ?? throw new ArgumentNullException(nameof(formatter));
            _ = format ?? throw new ArgumentNullException(nameof(format));
            _ = record ?? throw new ArgumentNullException(nameof(record));

            return(formatter.Format(format, record, CultureInfo.InvariantCulture));
        }
Example #6
0
 public Atm(IPrinter printer, IAtmClock clock, ICardReader cardReader,
            IHistory history, IStringFormatter stringFormatter)
 {
     this.stringFormatter = stringFormatter;
     this.printer         = printer;
     this.history         = history;
     this.clock           = clock;
     this.cardReader      = cardReader;
 }
Example #7
0
        public void SetUp()
        {
            //nothing to be mocked with as there is no external service such as data source or web api calling

            //Arrange
            formatter = new StringFormatter();
            checker   = new PalindromeChecker();
            finder    = new PalindromeFinder(formatter, checker);
        }
Example #8
0
        public StringFormatHelper(string text, IStringFormatter formatter = null)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            _formatter    = formatter ?? new NamedFieldFormatter();
            _textToFormat = text;
        }
Example #9
0
        public bool WriteAsCsvFile <TType>(List <TType> list, IStringFormatter <TType> formatter, string filePath) where TType : class, new()
        {
            var result = FileWriter.Write(filePath, formatter.GetFormattedStringFor(list));

            if (result)
            {
                Console.WriteLine("- [Written Successfully] : \"" + filePath + "\".");
            }

            return(result);
        }
Example #10
0
        internal Generator(
            ISentenceTemplateProvider sentenceProvider,
            IWordSelectorFactory wordSelectorFactory,
            IStringFormatter stringFormatter)
        {
            _sentenceTemplateProvider = sentenceProvider;
            _wordSelectorFactory      = wordSelectorFactory;
            _stringFormatter          = stringFormatter;

            _tagExtractor =
                new TagExtractor(
                    tagFactory: new TagFactory());
        }
Example #11
0
        /// <summary>
        /// 格式化参数
        /// </summary>
        /// <param name="parameter">参数</param>
        /// <param name="formater">格式化工具</param>
        /// <param name="encoding">编码</param>
        /// <returns></returns>
        protected string FormatParameter(ApiParameterDescriptor parameter, IStringFormatter formater, Encoding encoding)
        {
            if (parameter.Value == null)
            {
                return(null);
            }

            if (parameter.ParameterType == typeof(string))
            {
                return(parameter.Value.ToString());
            }
            return(formater.Serialize(parameter.Value, encoding));
        }
Example #12
0
        public MessageModelFactory(
            IBasicMessageModelFactory basicMessageModelFactory,
            INoteMessageModelFactory noteMessageModelFactory,
            ISpecialMessageModelFactory specialMessageModelFactory,
            IVisualMessageModelFactory visualMessageModelFactory,
            IStringFormatter stringFormatter)
        {
            _basicMessageModelFactory   = basicMessageModelFactory;
            _noteMessageModelFactory    = noteMessageModelFactory;
            _specialMessageModelFactory = specialMessageModelFactory;
            _visualMessageModelFactory  = visualMessageModelFactory;

            _stringFormatter = stringFormatter;
        }
Example #13
0
    /// <summary>
    ///     Registers type formatters.
    /// </summary>
    /// <param name="formatter">The formatter to register.</param>
    /// <exception cref="InvalidOperationException">
    ///     This method was called after having called <see cref="Interpret" />
    ///     successfully for the first time.
    /// </exception>
    public void RegisterTypeFormatter(IStringFormatter formatter)
    {
        _ = Requires.NotNull(
            formatter,
            nameof(formatter));

        if (interpretationDone != 0)
        {
            throw new InvalidOperationException(
                      Resources
                      .TheExpressionParsingServiceHasAlreadyDoneInterpretationAndCannotHaveAnyMoreFormattersRegistered);
        }

        stringFormatters.Add(formatter);
    }
Example #14
0
        public void Integration_Display_ConditionChecker_AirSpaceFilter()
        {
            stringFormatter  = Substitute.For <IStringFormatter>();
            filter           = new AirspaceFilter(stringFormatter);
            conditionChecker = new ConditionChecker(5000, 300, filter);
            display          = new DisplaySeparator(filter, conditionChecker);

            stringFormatter.DataFormattedEvent +=
                Raise.EventWith(new DataFormattedEventArgs()
            {
                DataFormatted = tracks
            });

            //Assert.That(display.ListOfConditionsToDisplay, Is.EqualTo());
            Assert.That(display.ListOfTracksToDisplay, Is.EqualTo(tracks));
        }
Example #15
0
        static ImmutableBase()
        {
            ordinalIgnoreCase = StringComparer.OrdinalIgnoreCase;
            var propertiesByName = PropertyHelpers.GetPropertyMap <TImmutable>();

            var constructor =
                ConstructorHelpers
                .GetImmutableSetterConstructor <TImmutable>(propertiesByName);

            createImmutable = constructor.CreateArrayFunc <TImmutable>();

            var properties =
                constructor
                .GetParameters()
                .Select(parameter => propertiesByName[parameter.Name])
                .ToImmutableArray();

            var provider = AggregatePropertyHandlerProvider.Create(
                new StringPropertyHandlerProvider(),
                new SinglePropertyHandlerProvider(),
                new DoublePropertyHandlerProvider(),
                new NullablePropertyHandlerProvider <Single>(new SinglePropertyHandlerProvider()),
                new NullablePropertyHandlerProvider <Double>(new DoublePropertyHandlerProvider()),
                new EnumerablePropertyHandlerProvider(),
                new DefaultPropertyHandlerProvider()
                );

            var handlersBuilder       = ImmutableArray.CreateBuilder <IPropertyHandler>();
            var handlersByNameBuilder =
                ImmutableDictionary.CreateBuilder <String, IPropertyHandler>(ordinalIgnoreCase);

            foreach (var property in properties)
            {
                var handler = provider.Create(property);

                handlersBuilder.Add(handler);
                handlersByNameBuilder.Add(handler.PropertyName, handler);
            }

            handlers        = handlersBuilder.ToImmutable();
            handlersByName  = handlersByNameBuilder.ToImmutable();
            stringFormatter = new DefaultStringFormatter();
        }
Example #16
0
        public void SetUp()
        {
            _receivedEventArgs = null;

            _track1    = new Track();
            _track2    = new Track();
            _track3    = new Track();
            _track4    = new Track();
            _tracklist = new List <Track>();

            //Making fakes (Stubs and mocks)
            _fakeFormatter = Substitute.For <IStringFormatter>();
            _uut           = new AirspaceFilter(_fakeFormatter);

            //Fake Event Handler
            _uut.DataFilteredEvent += (o, args) =>
            {
                _receivedEventArgs = args;
            };
        }
Example #17
0
        public void Integration_Display_ConditionChecker_AirSpaceFilter_StringFormatter()
        {
            transponderR            = Substitute.For <ITransponderReceiver>();
            compassCourseCalculator = Substitute.For <ICompassCourseCalculator>();
            velocityCalculator      = Substitute.For <IVelocityCalculator>();

            stringFormatter  = new StringFormatter(transponderR, compassCourseCalculator, velocityCalculator);
            filter           = new AirspaceFilter(stringFormatter);
            conditionChecker = new ConditionChecker(5000, 300, filter);
            display          = new DisplaySeparator(filter, conditionChecker);

            List <string> transponderData = new List <string>();

            transponderData.Add("T1;39045;29000;14000;20191029154852789");
            transponderData.Add("T2;39030;29030;14020;20191029154852789");
            transponderData.Add("T3;20045;29000;14000;20191029154852789");
            transponderData.Add("T4;39045;29000;12000;20191029154852789");

            transponderR.TransponderDataReady += Raise.EventWith(this, new RawTransponderDataEventArgs(transponderData));

            Assert.That(display.ListOfTracksToDisplay.ElementAt(0).Tag, Is.EqualTo("T1"));
            Assert.That(display.ListOfTracksToDisplay.ElementAt(3).PositionX, Is.EqualTo(39045));
        }
Example #18
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IStringFormatter stringFormatter)
        {
            loggerFactory.AddConsole();

            //app.UseEndOfTheWorldComponent();
            app.UseLoggerComponent("Elvis Presley", DateTime.UtcNow);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else if (env.IsProduction())
            {
                //app.UseExceptionHandler("/Error.html");
                app.UseExceptionHandler(new ExceptionHandlerOptions()
                {
                    //ExceptionHandlingPath = new PathString("/Error.html"),
                    ExceptionHandler = context => context.Response.WriteAsync("An exception has occurred. Please contact [email protected] for assistance.")
                });
            }
            else if (env.IsEnvironment("DonaldDuck"))
            {
                Debug.WriteLine("QuackQuack");
            }

            app.UseFileServer();

            /*
             * app.UseFileServer(new FileServerOptions()
             * {
             *      FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Images")),
             *      RequestPath = new PathString("/Img")
             * });*/

            /*
             * DefaultFilesOptions options = new DefaultFilesOptions();
             * options.DefaultFileNames.Clear();
             * options.DefaultFileNames.Add("myhome.html");
             * app.UseDefaultFiles(options);
             * app.UseStaticFiles();
             * app.UseStaticFiles(new StaticFileOptions()
             * {
             *      FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Images")),
             *      RequestPath = new PathString("/Img")
             * });*/

            app.UseWelcomePage("/hello");
            app.UseIdentity();
            app.UseMvc(routeBuilder =>
            {
                //routeBuilder.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
                //routeBuilder.MapRoute("Default", "{controller}/{action}/{id?}", new { controller = "Home", action = "Index"});
                routeBuilder.MapRoute("Default", "{controller}/{action}/{id?}",
                                      defaults: new { controller = "Home", action = "Index", token = "blah" }
                                      , constraints: new { id = new IntRouteConstraint() });

                routeBuilder.MapRoute("Route", "Route/{*whatever}",
                                      defaults: new { controller = "Route", action = "activity" });
                //routeBuilder.MapRoute("NewRoute", "Route/{*whatever}", defaults: new { controller = "Route", action = "activity" });
                //routeBuilder.MapRoute("Route", "routing/{controller}/{action}");
            });

            /*
             * app.Run(async (context) =>
             * {
             *      //throw new ArgumentException("NONO!");
             *      await context.Response.WriteAsync(stringFormatter.FormatMe(new { Message = "Hello World!" }));
             * });*/
        }
Example #19
0
        protected virtual string OnRender(ICsvDefinition defintion, TResult value, CultureInfo formattingCulture, IStringFormatter formatter)
        {
            if (value == null)
            {
                return(string.Empty);
            }

            return(value.ToString());
        }
Example #20
0
        /// <summary>
        /// Renders the specified element contents.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public virtual string[] Render(ICsvDefinition definition, TSource element, CultureInfo formattingCulture, IStringFormatter formatter)
        {
            var value = this.Selector(element);

            return(new[] { this.OnRender(definition, value, formattingCulture.Parent, formatter) });
        }
        public TemporaryFileRepository(IStringFormatter stringFormatter)
        {
            _stringFormatter = stringFormatter;

            Paths = new List <string>();
        }
Example #22
0
 public AssetBank(IStringFormatter stringFormatter)
 {
     _stringFormatter = stringFormatter;
 }
Example #23
0
        /// <summary>
        /// Executed each time the cell/value is written to a file.
        /// </summary>
        /// <param name="defintion"> The CSV definition. </param>
        /// <param name="value"> The value to render. </param>
        /// <param name="culture"> the culture to render in. </param>
        /// <param name="formatter"> The formatter to use for rendering the value into the cell. </param>
        /// <returns>A string that can be directly written into the CSV file. </returns>
        public override string[] Render(ICsvDefinition defintion, TSource value, CultureInfo culture, IStringFormatter formatter)
        {
            var collection = this.Selector(value);

            return((from item in collection
                    let column = converter(item)
                                 select column.Render(defintion, item, culture, formatter))
                   .SelectMany(elements => elements)
                   .ToArray());
        }
Example #24
0
 /// <summary>
 /// Formats a string based on a format string passed in.
 /// The default formatter uses the following format:
 /// # = digits
 /// @ = alpha characters
 /// \ = escape char
 /// </summary>
 /// <param name="Input">Input string</param>
 /// <param name="Format">Format of the output string</param>
 /// <param name="Provider">String formatter provider (defaults to GenericStringFormatter)</param>
 /// <returns>The formatted string</returns>
 public static string FormatString(this string Input, string Format, IStringFormatter Provider = null)
 {
     return(Provider.NullCheck(new GenericStringFormatter()).Format(Input, Format));
 }
 /// <summary>
 ///     Formats a string based on a format string passed in.
 ///     The default formatter uses the following format:
 ///     # = digits
 ///     @ = alpha characters
 ///     \ = escape char
 /// </summary>
 /// <param name="input">Input string</param>
 /// <param name="format">Format of the output string</param>
 /// <param name="provider">String formatter provider (defaults to GenericStringFormatter)</param>
 /// <returns>The formatted string</returns>
 public static string FormatString(this string input, string format, IStringFormatter provider = null)
 {
     return(provider.NullCheck(new GenericStringFormatter()).Format(input, format));
 }
Example #26
0
 /// <summary>Executed each time the cell/value is written to a file.</summary>
 /// <param name="defintion">The CSV definition.</param>
 /// <param name="value">The value to render.</param>
 /// <param name="culture">the culture to render in.</param>
 /// <param name="formatter">The formatter to use for rendering the value into the cell.</param>
 /// <returns>A string that can be directly written into the CSV file.</returns>
 protected override string OnRender(ICsvDefinition defintion, int?value, CultureInfo culture, IStringFormatter formatter)
 {
     return(this.Format(value, culture));
 }
Example #27
0
 /// <summary>
 ///     Formats a string based on a format string passed in.
 ///     The default formatter uses the following format:
 ///     # = digits
 ///     @ = alpha characters
 ///     \ = escape char
 /// </summary>
 /// <param name="input">Input string</param>
 /// <param name="format">Format of the output string</param>
 /// <param name="provider">String formatter provider (defaults to GenericStringFormatter)</param>
 /// <returns>The formatted string</returns>
 public static string FormatString(this string input, string format, IStringFormatter provider = null)
 {
     return provider.NullCheck(new GenericStringFormatter()).Format(input, format);
 }
Example #28
0
 public Formatter(IStringFormatter formatter)
 {
     _formatter = formatter;
 }
Example #29
0
 public AirspaceFilter(IStringFormatter stringFormatter) //Could add all boundaries as parameters, if you wish to be able to change the airspace area
 {
     CurrentListOfTracks = new List <Track>();
     stringFormatter.DataFormattedEvent += HandleDataFormattedEvent;
 }
 /// <summary>
 /// Formats a string based on a format string passed in.
 /// The default formatter uses the following format:
 /// # = digits
 /// @ = alpha characters
 /// \ = escape char
 /// </summary>
 /// <param name="Input">Input string</param>
 /// <param name="Format">Format of the output string</param>
 /// <param name="Provider">String formatter provider (defaults to GenericStringFormatter)</param>
 /// <returns>The formatted string</returns>
 public static string FormatString(this string Input, string Format, IStringFormatter Provider = null)
 {
     return Provider.NullCheck(new GenericStringFormatter()).Format(Input, Format);
 }
Example #31
0
 public SqlQueryPreparator()
 {
     SF = new StringFormatter.StringFormatter();
 }
Example #32
0
 public StringManipulator(IStringFormatter stringFormatter)
 {
     this.stringFormatter = stringFormatter;
 }
Example #33
0
 public SqlQueryPreparator(IStringFormatter sf)
 {
     SF = sf;
 }