Esempio n. 1
0
        /// <summary>
        /// Create a generator given a spec.
        /// </summary>
        public static CounterValueGenerator CreateGenerator(UsagePatternSpec inSpec)
        {
            switch (inSpec.Shape)
            {
            case EUsageShape.None:
                return(null);

            case EUsageShape.Zero:
                inSpec.Scale = 0;
                return(new ConstantUsageCounterValueGenerator(inSpec, false));

            case EUsageShape.ZeroPeak:
                inSpec.Scale = 0;
                return(new ConstantUsageCounterValueGenerator(inSpec, true));

            case EUsageShape.Flat:
                return(new ConstantUsageCounterValueGenerator(inSpec, false));

            case EUsageShape.FlatPeak:
                return(new ConstantUsageCounterValueGenerator(inSpec, true));

            case EUsageShape.Random:
                return(new RandomCounterValueGenerator(inSpec));

            case EUsageShape.Block:
                return(new BlockUsageCounterValueGenerator(inSpec, StandardTicksIncrease * 2, StandardTicksIncrease));

            case EUsageShape.BlockHalf:
                return(new BlockUsageCounterValueGenerator(inSpec, StandardTicksIncrease, 0));

            case EUsageShape.Sine:
                return(new SineUsageCounterValueGenerator(inSpec));

            default:
                throw new NotImplementedException("Unknown shape " + inSpec.Shape);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public ConstantUsageCounterValueGenerator(UsagePatternSpec inSpec, bool inHasPeak)
     : base(inSpec)
 {
     HasPeak = inHasPeak;
 }
Esempio n. 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public IncreasingOverMonthCounterValueGenerator(UsagePatternSpec inSpec)
     : base(inSpec)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 protected CounterValueGenerator(UsagePatternSpec inSpec)
 {
     PatternSpec = inSpec;
 }
Esempio n. 5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public SineUsageCounterValueGenerator(UsagePatternSpec inSpec)
     : base(inSpec)
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public BlockUsageCounterValueGenerator(UsagePatternSpec inSpec, uint inHighIncrement, uint inLowIncrement)
     : base(inSpec)
 {
     mHighIncrement = inHighIncrement;
     mLowIncrement  = inLowIncrement;
 }
Esempio n. 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public RandomCounterValueGenerator(UsagePatternSpec inSpec)
     : base(inSpec)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Default constructor, uses default usage pattern spec.
 /// </summary>
 protected CounterValueGenerator()
 {
     PatternSpec = new UsagePatternSpec();
 }
Esempio n. 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public Counter(int inId)
        {
            Id = inId;

            UsagePattern = new UsagePatternSpec();
        }
Esempio n. 10
0
        /// <summary>
        /// Parse one part of a pattern parameter.
        /// </summary>
        /// <returns>A filled out pattern spec on success, null otherwise.</returns>
        public static UsagePatternSpec ParseSpec(string inPatternPart)
        {
            if (string.IsNullOrEmpty(inPatternPart))
            {
                return(null);
            }

            var spec        = new UsagePatternSpec();
            var trimmedPart = inPatternPart.Trim(';');

            var colonPos = trimmedPart.IndexOf(':');

            if (colonPos < 0)
            {
                return(null);
            }

            var counterIdStr = trimmedPart.Substring(0, colonPos);
            int counterId;

            if (!int.TryParse(counterIdStr, out counterId))
            {
                return(null);
            }
            spec.CounterId = counterId;

            var parenthesesOpenPos = trimmedPart.IndexOf('(', colonPos + 1);
            var pos   = parenthesesOpenPos > 0 ? parenthesesOpenPos : trimmedPart.Length;
            var shape = trimmedPart.Substring(colonPos + 1, pos - colonPos - 1);

            spec.Shape = ParseShapeString(shape);

            if (parenthesesOpenPos > 0)
            {
                var parenthesesClosePos = trimmedPart.IndexOf(')');
                if (parenthesesClosePos < 0)
                {
                    return(null);
                }

                var paramsString = trimmedPart.Substring(parenthesesOpenPos + 1, parenthesesClosePos - parenthesesOpenPos - 1);
                var paramStrings = GetParamStrings(paramsString);
                if (paramStrings.Count > 0)
                {
                    float value;
                    if (!float.TryParse(paramStrings[0], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value))
                    {
                        return(null);
                    }
                    spec.Scale = value;
                }
                if (paramStrings.Count > 1)
                {
                    uint value;
                    if (!uint.TryParse(paramStrings[1], out value))
                    {
                        return(null);
                    }
                    spec.Period = value;
                    // An odd number of measurements in a period will lead to strange behaviour, so enforce an even number.
                    if (spec.Period % 2 != 0)
                    {
                        Log.Error("Error: only an even number of measurements in a period is allowed.");
                    }
                }
                if (paramStrings.Count > 2)
                {
                    uint value;
                    if (!uint.TryParse(paramStrings[2], out value))
                    {
                        return(null);
                    }
                    spec.SequenceOffset = value;
                }
                if (paramStrings.Count > 3)
                {
                    uint value;
                    if (!uint.TryParse(paramStrings[3], out value))
                    {
                        return(null);
                    }
                    spec.CounterOffset = value;
                }
            }

            return(spec);
        }