public CacheEntry(CacheKey key, HttpResponseMessage response) { Key = key; Vary = response.Headers.Vary.Select(v => v.ToLowerInvariant()).ToList(); ResponseVaryHeaders = response.RequestMessage.Headers .Where(h => Vary.Contains(h.Key.ToLowerInvariant())) .ToDictionary(k => k.Key.ToLowerInvariant(), v => v.Value); VariantId = Guid.NewGuid(); HasValidator = response.Headers.ETag != null || (response.Content != null && response.Content.Headers.LastModified != null); CacheControl = response.Headers.CacheControl ?? new CacheControlHeaderValue(); }
public static Distribution FromDoc(Distribution existing, DocNode doc) { // a single number means we want just a fixed value instead of a random distribution if (doc.Type == DocNodeType.Scalar) { var fixedValue = System.Convert.ToSingle(doc.StringValue); if (existing != null && existing is Range) { ((Range)existing).Start = fixedValue; ((Range)existing).End = fixedValue; return existing; } else { return new Range(fixedValue, fixedValue); } } var first = doc[0].StringValue; var resultType = typeof(Range); int startingIndex = 1; if (first == "vary") { resultType = typeof(Vary); } else if (first == "gaussian") { resultType = typeof(Gaussian); } else if (first == "binomial") { resultType = typeof(Binomial); } else if (first == "exponential") { resultType = typeof(Exponential); } else if (first == "range") { resultType = typeof(Range); } else { // we haven't found a tag we know about, so assume that the first value is a number and it's a Range startingIndex = 0; } // all these distributions take two floats as arguments, so let's parse those out first float firstNum = System.Convert.ToSingle(doc[startingIndex].StringValue); float secondNum = System.Convert.ToSingle(doc[startingIndex + 1].StringValue); // set the numbers appropriate to the class if (resultType == typeof(Range)) { if (existing != null && existing is Range) { ((Range)existing).Start = firstNum; ((Range)existing).End = secondNum; } else { existing = new Range(firstNum, secondNum); } } else if (resultType == typeof(Vary)) { if (existing != null && existing is Vary) { ((Vary)existing).Mean = firstNum; ((Vary)existing).Proportion = secondNum; } else { existing = new Vary(firstNum, secondNum); } } else if (resultType == typeof(Gaussian)) { if (existing != null && existing is Gaussian) { ((Gaussian)existing).Mean = firstNum; ((Gaussian)existing).StdDev = secondNum; } else { existing = new Gaussian(firstNum, secondNum); } } else if (resultType == typeof(Binomial)) { if (existing != null && existing is Binomial) { ((Binomial)existing).FlipProb = firstNum; ((Binomial)existing).Max = secondNum; } else { existing = new Binomial(firstNum, secondNum); } } else if (resultType == typeof(Exponential)) { if (existing != null && existing is Exponential) { ((Exponential)existing).InvLambda = firstNum; ((Exponential)existing).Minimum = secondNum; } else { existing = new Exponential(firstNum, secondNum); } } return existing; }