Exemple #1
0
        public void LongToHexTest()
        {
            var watch = new Stopwatch();

            watch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                //Assert.AreEqual(ByteConverters.LongToHex2(16), "10");
                Assert.AreEqual(ByteConverters.LongToHex(17, 3), "011");
                Assert.AreEqual(ByteConverters.LongToHex(1048576), "100000");
                Assert.AreEqual(ByteConverters.LongToHex(1024, 4), "0400");
            }
            watch.Stop();


            Trace.WriteLine(watch.ElapsedMilliseconds);
        }
Exemple #2
0
 /// <summary>
 /// String representation
 /// </summary>
 /// <returns></returns>
 public override string ToString() => $"({ByteConverters.LongToHex(BytePositionInFile)}h){Description}";
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            void DrawOneStep(long offSet, Point startPoint)
            {
                var str = string.Empty;

                switch (DataVisualType)
                {
                case DataVisualType.Hexadecimal:
                    str = $"0x{ByteConverters.LongToHex(offSet, SavedBits)}";
                    break;

                case DataVisualType.Decimal:
                    str = ByteConverters.LongToString(offSet, SavedBits);
                    break;

                default:
                    break;
                }
#if NET451
                var text = new FormattedText(str, CultureInfo.CurrentCulture,
                                             FlowDirection.LeftToRight, TypeFace, FontSize, Foreground);
#endif
#if NET47
                var text = new FormattedText(str, CultureInfo.CurrentCulture,
                                             FlowDirection.LeftToRight, TypeFace, FontSize, Foreground, PixelPerDip);
#endif
                drawingContext.DrawText(text, startPoint);
            }

            void DrawSteps(Func <int, Point> getOffsetLocation)
            {
                for (int i = 0; i < StepsCount; i++)
                {
                    DrawOneStep(
                        i * StepLength + StartStepIndex,
                        getOffsetLocation(i)
                        );
                }
            }

            if (Orientation == Orientation.Horizontal)
            {
                DrawSteps(step =>
                          new Point(
                              (CellMargin.Left + CellMargin.Right + CellSize.Width) * step + CellMargin.Left + CellPadding.Left,
                              CellMargin.Top + CellPadding.Top
                              )
                          );
            }
            else
            {
#if DEBUG
                //double lastY = 0;
#endif
                DrawSteps(step => new Point(
                              CellMargin.Left + CellPadding.Left,
                              (CellMargin.Top + CellMargin.Bottom + CellSize.Height) * step + CellMargin.Top + CellPadding.Top));

                {
#if DEBUG
                    //if(lastY != pot.Y) {
                    //    lastY = pot.Y;
                    //    System.Diagnostics.Debug.WriteLine(lastY);
                    //}
#endif
                    //return pot;
                }
            }
        }