/// <summary> Set the name of the current transaction. Supports web applications only. </summary> /// /// <exception cref="ArgumentNullException"> Thrown when <paramref name="key"/> is null. </exception> /// /// <param name="category"> The category of this transaction, used to distinguish different types /// of transactions. Only the first 1000 characters are retained. If null is passed, the /// category defaults to "Custom". </param> /// <param name="name"> The name of the transaction starting with a forward slash. example: /// /store/order Only the first 1000 characters are retained. </param> public void SetTransactionName(string category, string name) { name = name ?? throw new ArgumentNullException(nameof(name)); using (new IgnoreWork()) { // Default to "Custom" category if none provided if (string.IsNullOrEmpty(category?.Trim())) { category = MetricNames.Custom; } // Get rid of any slashes category = category.Trim(TrimPathChar); name = name.Trim(TrimPathChar); // Clamp the category and name to a predetermined length category = Clamper.ClampLength(category); name = Clamper.ClampLength(name); var transaction = GetCurrentInternalTransaction(); var currentTransactionName = transaction.CandidateTransactionName.CurrentTransactionName; var newTransactionName = currentTransactionName.IsWeb ? TransactionName.ForWebTransaction(category, name) : TransactionName.ForOtherTransaction(category, name); transaction.CandidateTransactionName.TrySet(newTransactionName, TransactionNamePriority.UserTransactionName); } }
public void Clamper_TestIntegerTooLarge_ReturnsMax() { var val = 4; var min = 2; var max = 3; var result = Clamper.Clamp(val, min, max); Assert.Equal(max, result); }
public void Clamper_TestIntegerTooSmall_ReturnsMin() { var val = 1; var min = 2; var max = 3; var result = Clamper.Clamp(val, min, max); Assert.Equal(min, result); }
public void Clamper_TestFloatTooLarge_ReturnsMax() { var val = 4.0f; var min = 2.0f; var max = 3.0f; var result = Clamper.Clamp(val, min, max); Assert.Equal(max, result); }
public void Clamper_TestFloatTooSmall_ReturnsMin() { var val = 1.0f; var min = 2.0f; var max = 3.0f; var result = Clamper.Clamp(val, min, max); Assert.Equal(min, result); }
public static TransactionName ForCustomTransaction(bool isWeb, string name, int maxLength) { // Note: In our public docs to tells users that they must prefix their metric names with "Custom/", but there's no mechanism that actually enforces this restriction, so there's no way to know whether it'll be there or not. For consistency, we'll just strip off "Custom/" if there's at all and then we know it's consistently not there. if (name.StartsWith("Custom/")) { name = name.Substring(7); } name = Clamper.ClampLength(name.Trim(), maxLength); if (name.Length <= 0) { throw new ArgumentException("A segment name cannot be an empty string."); } return(new TransactionName(isWeb, MetricNames.Custom, name)); }
/// <summary> Gets custom metric suffix. </summary> /// <exception cref="ArgumentException"> Thrown if <paramref name="name"/> is null or empty. </exception> /// <param name="name"> The name to process. </param> /// <returns> The custom metric suffix. </returns> private static string GetCustomMetricSuffix(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("The name parameter must have a value that is not null or empty."); } name = Clamper.ClampLength(name); // If the name provided already contains the "Custom/" prefix, remove it and use the remaining segment as the "name" if (name.StartsWith(CustomMetricNamePrefixAndSeparator, StringComparison.InvariantCultureIgnoreCase)) { name = name.Substring(CustomMetricNamePrefixAndSeparator.Length); } return(name); }
public void SetEffectTransition(ref ColourEffectConfiguration config, ref float transitionSeconds) { transitionSeconds = Clamper.Clamp(transitionSeconds, 0.0f, float.MaxValue); //Might be duplicated clamp for this value if (transitionSeconds == 0.0f) { _current = config; _isTransitioning = false; UpdateBufferAndClearColour(); return; } _previous = _current; _target = config; _transitionTotalTime = transitionSeconds; _transitionCurrentTime = 0.0f; _isTransitioning = true; }
public ITexture CreateRgbaFromData(uint textureWidth, uint textureHeight, Vector4[] pixels, SamplerType samplerType = SamplerType.Anisotropic, bool generateMipMaps = true) { if (pixels == null) { throw new Yak2DException("Surfaces -> CreateRgbaFromData(), pixel data cannot be null", new ArgumentNullException("pixels")); } if (textureWidth == 0 | textureHeight == 0) { throw new Yak2DException("Surfaces -> CreateRgbaFromData(), texture dimensions cannot be zero"); } if (textureWidth * textureHeight != pixels.Length) { throw new Yak2DException("Surfaces -> CreateRgbaFromData(), pixel data array size does not match dimensions"); } var pixelcount = textureWidth * textureHeight; var rgba = new Rgba32[pixelcount]; for (var p = 0; p < pixelcount; p++) { var value = pixels[p]; rgba[p] = new Rgba32( Clamper.Clamp(value.X, 0.0f, 1.0f), Clamper.Clamp(value.Y, 0.0f, 1.0f), Clamper.Clamp(value.Z, 0.0f, 1.0f), Clamper.Clamp(value.W, 0.0f, 1.0f) ); } return(_surfaceManager.CreateRgbaTextureFromPixelData(textureWidth, textureHeight, rgba, samplerType, generateMipMaps, false)); }
private string NormalizeString(string data) { return(Clamper.ClampLength(data.Trim(), 255)); }
protected override IEnumerable <Piece> TryToGetSingleValuePiece(string part, Clamper clamper) { if (!_roundSingle) { return(base.TryToGetSingleValuePiece(part, clamper)); } if (!TryParse(part, out var value)) { return(null); } switch (part.Count(':')) { case 0: return(new[] { new Piece(clamper.Clamp(value), clamper.Clamp(value + 60 * 60 - 1)) }); case 1: return(new[] { new Piece(clamper.Clamp(value), clamper.Clamp(value + 59)) }); default: return(new[] { new Piece(clamper.Clamp(value)) }); } }
protected override IEnumerable <Piece> CreatePiece(int fromValue, int toValue, Clamper clamper) { if (fromValue > toValue) { return(new[] { new Piece(clamper.Minimum, clamper.Clamp(toValue)), new Piece(clamper.Clamp(fromValue), clamper.Maximum), }); } return(base.CreatePiece(fromValue, toValue, clamper)); }
protected override IEnumerable <Piece> TryToGetSingleValuePiece(string part, Clamper clamper) { if (!TryParse(part, out var value)) { return(null); } if (_roundSingle && part.IndexOf('e') == -1 && part.IndexOf('E') == -1) { var match = FloatyPart.Match(part); if (match.Success) { var accuracy = Math.Pow(0.1, match.Length - 1) * 0.99; return(new[] { new Piece(clamper.Clamp(value - accuracy), clamper.Clamp(value + accuracy)) }); } return(new[] { new Piece(clamper.Clamp(value), clamper.Clamp(value + 0.999)) }); } return(new[] { new Piece(clamper.Clamp(value)) }); }