private void PrintRows(IEnumerable <T> collection, IItemFormatter <T> formatter)
 {
     foreach (T item in collection)
     {
         Console.WriteLine(formatter.CreateItemText(item));
     }
 }
        private static void CreateStateInstances(IApplicationController applicationController,
                                                 IItemFormatter itemFormatter,
                                                 IMargin labelMargin,
                                                 out IBackgroundState backgroundState,
                                                 out IGridState gridState,
                                                 out IScaleState scaleState,
                                                 out IDataDrawState graphState,
                                                 out IScalingState scalingState,
                                                 out IGraphControlFormState graphControlFormState)
        {
            backgroundState = new BackgroundState();
            applicationController.RegisterInstance <IBackgroundState>(backgroundState);

            gridState = new GridState();
            gridState.LabelPadding  = labelMargin;
            gridState.ItemFormatter = itemFormatter;
            applicationController.RegisterInstance <IGridState>(gridState);

            scaleState = new ScaleState();
            applicationController.RegisterInstance <IScaleState>(scaleState);

            graphState = new DataDrawState();
            applicationController.RegisterInstance <IDataDrawState>(graphState);

            scalingState = new ScalingState();
            applicationController.RegisterInstance <IScalingState>(scalingState);

            graphControlFormState = new GraphControlFormState();
            applicationController.RegisterInstance <IGraphControlFormState>(graphControlFormState);
        }
Exemple #3
0
        public static void CreateBaseServices(IApplicationController applicationController, IDataProviderService provider,
                                              out IGridState gridState, out IDataDrawState graphState,
                                              out IItemFormatter itemFormatter, out IMargin margin,
                                              out IDataService dataService, out IScaleService scaleService, ref IBufferedDrawingService bufferedDrawingService)
        {
            var formView = new TestGraphControlFormView();

            margin        = formView.GraphMargin;
            itemFormatter = formView.ItemFormatter;
            var labelMargin = formView.LabelMargin;

            // Set property and Reset()
            formView.LabelMargin = labelMargin;
            formView.Reset();

            TestFactory.CreateStateInstancees(applicationController,
                                              out IBackgroundState backgroundState, out gridState, out IScaleState scaleState, out graphState, out IGraphControlFormState graphControlFormState);

            TestFactory.CreateServiceInstances(applicationController,
                                               margin, scaleState,
                                               out dataService, out scaleService, ref bufferedDrawingService);

            if (provider != null)
            {
                dataService.RegisterDataProvider(provider);
            }
        }
        public void GenerateReport(IEnumerable <T> collection, IItemFormatter <T> formatter)
        {
            IEnumerable <T> enumeratedCollection = collection.ToList();

            PrintHeader(formatter);
            PrintColumnHeader(formatter);
            PrintRows(enumeratedCollection, formatter);
            PrintFooter(enumeratedCollection, formatter);
        }
        private void PrintHeader(IItemFormatter <T> formatter)
        {
            int    fillerLength = (TotalLineWidth - formatter.CreateDescription().Length) / 2 - 1;
            string filler       = "".PadLeft(fillerLength, '-');

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(filler + " " + formatter.CreateDescription() + " " + filler);
            Console.WriteLine(CreateSeparator());
        }
Exemple #6
0
 public GridState()
 {
     // Fill defaults
     this.MinGridLineDistance = minGridLineDistanceDefault;
     this.AxeColor            = Color.FromArgb(90, 90, 90);
     this.GridColor           = Color.FromArgb(180, 180, 180);
     this.TextXColor          = Color.FromArgb(0, 220, 0);
     this.TextYColor          = Color.FromArgb(0, 0, 222);
     this.LabelPadding        = new Margin(5, 5, 5, 5);
     this.ItemFormatter       = new ItemFormatter();
 }
Exemple #7
0
        internal static string FormatItems(string original, IItemFormatter formatter)
        {
            if (string.IsNullOrEmpty(original))
            {
                return(original);
            }

            return(new Regex("{([^{}]+?)}", RegexOptions.Multiline).Replace(original, Replacer));

            string Replacer(Match match)
            {
                return(formatter?.FormatItem(match.Groups[1].Value) ?? "");
            }
        }
Exemple #8
0
        public static void CreateBaseServices(IApplicationController applicationController, IDataProviderService provider,
                                              out IGridState gridState, out IDataDrawState graphState,
                                              out IItemFormatter itemFormatter, out IMargin margin,
                                              out IDataService dataService, out IScaleService scaleService)
        {
            applicationController = applicationController ?? GraphControlFactory.CreateController();

            IBufferedDrawingService bufferedDrawingService = null;

            TestFactory.CreateBaseServices(applicationController, provider,
                                           out gridState, out graphState,
                                           out itemFormatter, out margin,
                                           out dataService, out scaleService, ref bufferedDrawingService);
        }
        public BetterReportGenerator(
            IItemFormatter <Customer> customerFormatter,
            IItemFormatter <Product> productFormatter,
            IItemFormatter <ShippingBox> shippingBoxFormatter,
            IEnumerableCollectionFactory collectionFactory)
        {
            _customerReportGenerator = new ItemReportGenerator <Customer>(ReportGeneratorSetup.ReportWidth);
            _productReportGenerator  = new ItemReportGenerator <Product>(ReportGeneratorSetup.ReportWidth);
            _shippingBoxGenerator    = new ItemReportGenerator <ShippingBox>(ReportGeneratorSetup.ReportWidth);

            _customerFormatter    = customerFormatter;
            _productFormatter     = productFormatter;
            _shippingBoxFormatter = shippingBoxFormatter;
            _collectionFactory    = collectionFactory;
        }
Exemple #10
0
        public MemcachedClient(IMemcachedCluster cluster, IMemcachedClientOptions?options = null)
        {
            this.cluster = cluster ?? throw new ArgumentNullException(nameof(cluster));
            if (!cluster.IsStarted)
            {
                throw new ArgumentException("Cluster must be started before creating client instances", nameof(cluster));
            }

            this.allocator = cluster.Allocator;

            if (options == null)
            {
                options = new MemcachedClientOptions();
            }
            keyFormatter  = options.KeyFormatter ?? throw PropertyCannotBeNull(nameof(options.KeyFormatter));
            itemFormatter = options.ItemFormatter ?? throw PropertyCannotBeNull(nameof(options.ItemFormatter));
        }
Exemple #11
0
        void OnEnable()
        {
            if (!manualApply)
            {
                if (customTarget)
                {
                    textTarget = customTargetReference;
                }
                else
                {
                    textTarget = GetComponent <TMP_Text>();
                }

                Apply(textTarget);
            }

            itemFormatter = GetComponent <IItemFormatter>();
        }
 public MemcachedClientOptions()
 {
     //allocator = MemoryPool<byte>.Shared;
     keyFormatter  = new Utf8KeyFormatter();
     itemFormatter = new BinaryItemFormatter();
 }
 private void PrintFooter(IEnumerable <T> collection, IItemFormatter <T> formatter)
 {
     Console.WriteLine(CreateSeparator());
     Console.WriteLine(formatter.CreateFooter(collection));
 }
 private void PrintColumnHeader(IItemFormatter <T> formatter)
 {
     Console.WriteLine(formatter.CreateColumnHeader());
 }
Exemple #15
0
        /// <summary>
        /// Returns rounded step for scale grid
        /// </summary>
        /// <param name="axis">For X or Y axis</param>
        /// <param name="minDataValue">min value</param>
        /// <param name="maxDatavakue">max value</param>
        /// <param name="minGridLineDistance">minimal step of grid in screen coordinates</param>
        /// <param name="screenRange">canvas width or height</param>
        /// <param name="formatter">Formatter to show values</param>
        /// <returns>rounded step for scale grid</returns>
        private double ToNearRoundStep(Axis axis, double minDataValue, double maxDatavakue, double minGridLineDistance, int screenRange, IItemFormatter formatter)
        {
            double dataRange    = maxDatavakue - minDataValue;
            double dataMinStep  = dataRange / (screenRange / minGridLineDistance); // log(interval / max lines count, interval / max lines count > 60 ? 60, 10)
            int    order        = (int)(Math.Floor(Math.Log10(Math.Abs(dataRange))));
            double maxStep      = Math.Pow(10, order);
            var    dividers     = formatter.GetScaleDivisions(axis, dataMinStep);
            double foundDivider = 1;

            Array.Sort(dividers, new Comparison <double>((i1, i2) => i2.CompareTo(i1)));
            foreach (var divider in dividers)
            {
                var stepScreen = this.scaleService.ScaleToScreen(axis, maxStep / divider);
                if (stepScreen >= minGridLineDistance)
                {
                    foundDivider = divider;
                    break;
                }
            }
            return(maxStep / foundDivider);
        }