Exemple #1
0
        public int CompareTo(MeterMetric other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            var startTimeComparison = _startTime.CompareTo(other._startTime);

            if (startTimeComparison != 0)
            {
                return(startTimeComparison);
            }
            var rateUnitComparison = RateUnit.CompareTo(other.RateUnit);

            if (rateUnitComparison != 0)
            {
                return(rateUnitComparison);
            }
            var eventTypeComparison = string.Compare(EventType, other.EventType, StringComparison.Ordinal);

            if (eventTypeComparison != 0)
            {
                return(eventTypeComparison);
            }
            return(Name.CompareTo(other.Name));
        }
Exemple #2
0
        public int CompareTo(TimerMetric other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            var durationUnitComparison = DurationUnit.CompareTo(other.DurationUnit);

            if (durationUnitComparison != 0)
            {
                return(durationUnitComparison);
            }
            return(RateUnit.CompareTo(other.RateUnit));
        }
Exemple #3
0
 private double ConvertNanosRate(double ratePerNs)
 {
     return(ratePerNs * RateUnit.ToNanos(1));
 }
Exemple #4
0
        /// <summary>
        /// Create a geodetic circle
        /// </summary>
        private IGeometry CreateCircle()
        {
            if (Point1 == null && Point2 == null)
            {
                return(null);
            }

            string unitLabel = "";
            // This section including UpdateDistance serves to handle Diameter appropriately
            var polyLine = (IPolyline) new Polyline();

            polyLine.SpatialReference = Point1.SpatialReference;
            var ptCol = (IPointCollection)polyLine;

            ptCol.AddPoint(Point1);
            ptCol.AddPoint(Point2);

            UpdateDistance(polyLine as IGeometry);

            try
            {
                var construct = (IConstructGeodetic) new Polyline();
                if (construct != null)
                {
                    construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), Distance, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.01);
                    IDictionary <String, System.Object> circleAttributes = new Dictionary <String, System.Object>();
                    double radiusOrDiameterDistance = 0.0;
                    if (CircleType == CircleFromTypes.Diameter)
                    {
                        radiusOrDiameterDistance = Distance * 2;
                    }
                    else
                    {
                        radiusOrDiameterDistance = Distance;
                    }

                    //Construct a polygon from geodesic polyline
                    var newPoly = PolylineToPolygon((IPolyline)construct);
                    if (newPoly != null)
                    {
                        //Get centroid of polygon
                        var area = (IArea)newPoly;

                        int           roundingFactor = 0;
                        DistanceTypes dtVal          = (DistanceTypes)LineDistanceType;
                        // If Distance Calculator is in use, use the unit from the Rate combobox
                        // to label the circle
                        if (IsDistanceCalcExpanded)
                        {
                            // Select appropriate label and number of decimal places
                            switch (RateUnit)
                            {
                            case DistanceTypes.Feet:
                            case DistanceTypes.Meters:
                            case DistanceTypes.Yards:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 0;
                                break;

                            case DistanceTypes.Miles:
                            case DistanceTypes.Kilometers:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            case DistanceTypes.NauticalMiles:
                                var displayValue = new EnumToFriendlyNameConverter();
                                unitLabel      = Convert.ToString(displayValue.Convert(RateUnit, typeof(string), new object(), CultureInfo.CurrentCulture));
                                roundingFactor = 2;
                                break;

                            default:
                                break;
                            }
                        }
                        // Else Distance Calculator not in use, use the unit from the Radius / Diameter combobox
                        // to label the circle
                        else
                        {
                            // Select appropriate number of decimal places
                            switch (LineDistanceType)
                            {
                            case DistanceTypes.Feet:
                            case DistanceTypes.Meters:
                            case DistanceTypes.Yards:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 0;
                                break;

                            case DistanceTypes.Miles:
                            case DistanceTypes.Kilometers:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            case DistanceTypes.NauticalMiles:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            default:
                                break;
                            }


                            var displayValue = new EnumToFriendlyNameConverter();
                            unitLabel = Convert.ToString(displayValue.Convert(dtVal, typeof(string), new object(), CultureInfo.CurrentCulture));
                        }

                        string circleTypeLabel = circleType.ToString();
                        string distanceLabel   = "";
                        // Use the unit from Rate combobox if Distance Calculator is expanded
                        if (IsDistanceCalcExpanded)
                        {
                            radiusOrDiameterDistance = ConvertFromTo(LineDistanceType, RateUnit, radiusOrDiameterDistance);
                            distanceLabel            = (TrimPrecision(radiusOrDiameterDistance, RateUnit, true)).ToString("N" + roundingFactor.ToString());
                        }
                        else
                        {
                            distanceLabel = (TrimPrecision(radiusOrDiameterDistance, LineDistanceType, false)).ToString("N" + roundingFactor.ToString());
                        }

                        //Add text using centroid point
                        this.AddTextToMap(area.LabelPoint, string.Format("{0}:{1} {2}",
                                                                         circleTypeLabel,
                                                                         distanceLabel,
                                                                         StringParser.GetStringValue(dtVal)));
                    }

                    double radiusDistance = radiusOrDiameterDistance;
                    if (CircleType == CircleFromTypes.Diameter)
                    {
                        radiusDistance = radiusOrDiameterDistance / 2;
                    }

                    circleAttributes.Add("radius", radiusDistance);
                    circleAttributes.Add("disttype", CircleType.ToString());
                    circleAttributes.Add("centerx", Point1.X);
                    circleAttributes.Add("centery", Point1.Y);
                    if (IsDistanceCalcExpanded)
                    {
                        circleAttributes.Add("distanceunit", unitLabel.ToString());
                    }
                    else
                    {
                        circleAttributes.Add("distanceunit", unitLabel.ToString());
                    }
                    var color = new RgbColorClass()
                    {
                        Red = 255
                    } as IColor;
                    this.AddGraphicToMap(construct as IGeometry, color, attributes: circleAttributes);
                    Point2    = null;
                    HasPoint2 = false;
                    ResetFeedback();
                }
                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
        /// <summary>
        /// Create a geodetic circle
        /// </summary>
        private IGeometry CreateCircle()
        {
            if (Point1 == null && Point2 == null)
            {
                return(null);
            }

            // This section including UpdateDistance serves to handle Diameter appropriately
            var polyLine = new Polyline() as IPolyline;

            polyLine.SpatialReference = Point1.SpatialReference;
            var ptCol = polyLine as IPointCollection;

            ptCol.AddPoint(Point1);
            ptCol.AddPoint(Point2);

            UpdateDistance(polyLine as IGeometry);

            try
            {
                var construct = new Polyline() as IConstructGeodetic;
                if (construct != null)
                {
                    construct.ConstructGeodesicCircle(Point1, GetLinearUnit(), Distance, esriCurveDensifyMethod.esriCurveDensifyByAngle, 0.01);
                    IDictionary <String, System.Object> circleAttributes = new Dictionary <String, System.Object>();
                    double dist = 0.0;
                    if (CircleType == CircleFromTypes.Diameter)
                    {
                        dist = Distance * 2;
                    }
                    else
                    {
                        dist = Distance;
                    }

                    //circleAttributes.Add("radius", dist);
                    //circleAttributes.Add("disttype", CircleType.ToString());
                    //circleAttributes.Add("centerx", Point1.X);
                    //circleAttributes.Add("centery", Point1.Y);
                    //circleAttributes.Add("distanceunit", LineDistanceType.ToString());
                    //var color = new RgbColorClass() { Red = 255 } as IColor;
                    //this.AddGraphicToMap(construct as IGeometry, color, attributes: circleAttributes);

                    //Construct a polygon from geodesic polyline

                    var newPoly = this.PolylineToPolygon((IPolyline)construct);
                    if (newPoly != null)
                    {
                        //Get centroid of polygon
                        var area = newPoly as IArea;


                        string unitLabel      = "";
                        int    roundingFactor = 0;
                        // If Distance Calculator is in use, use the unit from the Rate combobox
                        // to label the circle
                        if (IsDistanceCalcExpanded)
                        {
                            // Select appropriate label and number of decimal places
                            switch (RateUnit)
                            {
                            case DistanceTypes.Feet:
                            case DistanceTypes.Meters:
                            case DistanceTypes.Yards:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 0;
                                break;

                            case DistanceTypes.Miles:
                            case DistanceTypes.Kilometers:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            case DistanceTypes.NauticalMile:
                                unitLabel      = "Nautical Miles";
                                roundingFactor = 2;
                                break;

                            default:
                                break;
                            }
                        }
                        // Else Distance Calculator not in use, use the unit from the Radius / Diameter combobox
                        // to label the circle
                        else
                        {
                            // Select appropriate number of decimal places
                            switch (LineDistanceType)
                            {
                            case DistanceTypes.Feet:
                            case DistanceTypes.Meters:
                            case DistanceTypes.Yards:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 0;
                                break;

                            case DistanceTypes.Miles:
                            case DistanceTypes.Kilometers:
                                unitLabel      = RateUnit.ToString();
                                roundingFactor = 2;
                                break;

                            case DistanceTypes.NauticalMile:
                                unitLabel      = "Nautical Miles";
                                roundingFactor = 2;
                                break;

                            default:
                                break;
                            }

                            DistanceTypes dtVal = (DistanceTypes)LineDistanceType;
                            unitLabel = dtVal.ToString();
                        }

                        double convertedDistance = Distance;
                        // Distance is storing radius not diameter, so we have to double it to get the correct value
                        // for the label
                        // Only use Diameter when Distance Calculator is not in use
                        if (!IsDistanceCalcExpanded && circleType == CircleFromTypes.Diameter)
                        {
                            convertedDistance *= 2;
                        }

                        string circleTypeLabel = circleType.ToString();
                        string distanceLabel   = "";
                        // Use the unit from Rate combobox if Distance Calculator is expanded
                        if (IsDistanceCalcExpanded)
                        {
                            convertedDistance = ConvertFromTo(LineDistanceType, RateUnit, convertedDistance);
                            distanceLabel     = (TrimPrecision(convertedDistance, RateUnit, true)).ToString("N" + roundingFactor.ToString());
                            // Always label with radius when Distance Calculator is expanded
                            circleTypeLabel = "Radius";
                        }
                        else
                        {
                            distanceLabel = (TrimPrecision(convertedDistance, LineDistanceType, false)).ToString("N" + roundingFactor.ToString());
                        }
                        dist = convertedDistance;
                        //Add text using centroid point
                        this.AddTextToMap(area.Centroid, string.Format("{0}:{1} {2}",
                                                                       circleTypeLabel,
                                                                       distanceLabel,
                                                                       unitLabel));
                    }
                    circleAttributes.Add("radius", dist);
                    circleAttributes.Add("disttype", CircleType.ToString());
                    circleAttributes.Add("centerx", Point1.X);
                    circleAttributes.Add("centery", Point1.Y);
                    if (IsDistanceCalcExpanded)
                    {
                        circleAttributes.Add("distanceunit", RateUnit.ToString());
                    }
                    else
                    {
                        circleAttributes.Add("distanceunit", LineDistanceType.ToString());
                    }
                    var color = new RgbColorClass()
                    {
                        Red = 255
                    } as IColor;
                    this.AddGraphicToMap(construct as IGeometry, color, attributes: circleAttributes);
                    Point2    = null;
                    HasPoint2 = false;
                    ResetFeedback();
                }
                return(construct as IGeometry);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
Exemple #6
0
 private double ConvertNsRate(double ratePerNs)
 {
     return ratePerNs * (double) RateUnit.ToNanos(1);
 }