public static string GetBoundScope(string scope, IReadOnlyDictionary <string, object> bindingData) { BindingTemplate bindingTemplate = BindingTemplate.FromString(scope); IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); return(bindingTemplate.Bind(parameters)); }
public override string Resolve(string value) { string format = GetFormatOrNull(value); var val = new SystemBindingData().RandGuid; return(BindingDataPathHelper.ConvertParameterValueToString(val, format)); }
private static void Test(string expectedStringValue, JToken obj) { // Act string stringParamValue = BindingDataPathHelper.ConvertParameterValueToString(obj); // Assert Assert.Equal(expectedStringValue, stringParamValue); }
public string Bind(IReadOnlyDictionary <string, object> bindingData) { IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); string tableName = _template.Bind(parameters); TableClient.ValidateAzureTableName(tableName); return(tableName); }
public void ConvertParamValueToString_IfUnupportedType_ReturnsNull() { // Arrange var obj = new { value = 12 }; // Act string stringParamValue = BindingDataPathHelper.ConvertParameterValueToString(obj); // Assert Assert.Null(stringParamValue); }
public void ConvertParamValueToString_IfUnupportedType_ReturnsNull() { // Arrange DateTime dateTimeParam = DateTime.Now; // Act string stringParamValue = BindingDataPathHelper.ConvertParameterValueToString(dateTimeParam); // Assert Assert.Null(stringParamValue); }
public BlobPath Bind(IReadOnlyDictionary <string, object> bindingData) { IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); string containerName = _containerNameTemplate.Bind(parameters); string blobName = _blobNameTemplate.Bind(parameters); BlobClient.ValidateContainerName(containerName); BlobClient.ValidateBlobName(blobName); return(new BlobPath(containerName, blobName)); }
public void ConvertParamValueToString_IfStringParam_ReturnsStringValue() { // Arrange const string expectedStringValue = "Some random test string"; // Act string stringParamValue = BindingDataPathHelper.ConvertParameterValueToString(expectedStringValue); // Assert Assert.NotNull(stringParamValue); Assert.Equal(expectedStringValue, stringParamValue); }
public string Bind(IReadOnlyDictionary <string, object> bindingData) { if (bindingData == null) { throw new ArgumentNullException("bindingData"); } IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); string queueOrTopicName = _template.Bind(parameters); return(queueOrTopicName); }
public string Bind(IReadOnlyDictionary <string, object> bindingData) { if (bindingData == null) { throw new ArgumentNullException("bindingData"); } IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); string queueName = _template.Bind(parameters); return(BindableQueuePath.NormalizeAndValidate(queueName)); }
public void ConvertParamValueToString_IfSupportedType_ReturnsStringValue(Type paramType, string expectedStringValue) { // Arrange var parseMethod = paramType.GetMethod("Parse", new Type[] { typeof(string) }); object paramValue = parseMethod.Invoke(null, new object[] { expectedStringValue }); // Act string stringParamValue = BindingDataPathHelper.ConvertParameterValueToString(paramValue); // Assert Assert.NotNull(stringParamValue); Assert.Equal(expectedStringValue, stringParamValue); }
public TableEntityPath Bind(IReadOnlyDictionary <string, object> bindingData) { IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); string tableName = _tableNameTemplate.Bind(parameters); string partitionKey = _partitionKeyTemplate.Bind(parameters); string rowKey = _rowKeyTemplate.Bind(parameters); TableClient.ValidateAzureTableName(tableName); TableClient.ValidateAzureTableKeyValue(partitionKey); TableClient.ValidateAzureTableKeyValue(rowKey); return(new TableEntityPath(tableName, partitionKey, rowKey)); }
public void ConvertParamValueToString_IfGuidParam_ReturnsStringValue() { // Arrange string expectedStringValue = "c914be08-fae6-4014-a619-c5f7ebf3fe37"; Guid guidParam = Guid.Parse(expectedStringValue); // Act string stringParamValue = BindingDataPathHelper.ConvertParameterValueToString(guidParam); // Assert Assert.NotNull(stringParamValue); Assert.Equal(expectedStringValue, stringParamValue); }
public string Bind(IReadOnlyDictionary <string, object> bindingData) { if (bindingData == null || !_bindingTemplate.ParameterNames.Any()) { return(_bindingTemplate.Pattern); } IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); string path = _bindingTemplate.Bind(parameters); return(path); }
public string GetBoundScopeId(string scopeId, IReadOnlyDictionary <string, object> bindingData = null) { if (_nameResolver != null) { scopeId = _nameResolver.ResolveWholeString(scopeId); } if (bindingData != null) { BindingTemplate bindingTemplate = BindingTemplate.FromString(scopeId); IReadOnlyDictionary <string, string> parameters = BindingDataPathHelper.ConvertParameters(bindingData); return(bindingTemplate.Bind(parameters)); } else { return(scopeId); } }
public override string Evaluate(IReadOnlyDictionary <string, object> bindingData) { object current; if (bindingData.TryGetValue(this._expressionParts[0], out current)) { for (int i = 1; i < _expressionParts.Length; i++) { var propName = _expressionParts[i]; try { current = GetProperty(current, propName); } catch (Exception e) { throw new InvalidOperationException($"Error while accessing '{propName}': {e.Message}"); } } } else { // Not found in binding data. Is this a builtin? if (this._builtin != null) { current = _builtin.Resolve(this.ParameterName); } if (current == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "No value for named parameter '{0}'.", this.ParameterName)); } } var strValue = BindingDataPathHelper.ConvertParameterValueToString(current, _format); return(strValue); }
public static string Format(BindingTemplate template, IReadOnlyDictionary <string, object> bindingData) { if (!template.HasParameters) { return(template.Pattern); } if (template.ParameterNames.Count() == 1) { // Special case where the entire filter expression // is a single parameter. We let this go through as is string parameterName = template.ParameterNames.Single(); if (template.Pattern == $"{{{parameterName}}}") { return(template.Bind(bindingData)); } } // each distinct parameter can occur one or more times in the template // so group by parameter name var parameterGroups = template.ParameterNames.GroupBy(p => p); // for each parameter, classify it as a string literal or other // and perform value validation var convertedBindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); foreach (var kv in bindingData) { convertedBindingData[kv.Key] = kv.Value; } foreach (var parameterGroup in parameterGroups) { // perform any OData specific formatting on the values string parameterName = parameterGroup.Key; object originalValue; if (bindingData.TryGetValue(parameterName, out originalValue)) { if (originalValue is DateTime) { // OData DateTime literals should be ISO 8601 formatted (e.g. 2009-03-18T04:25:03Z) convertedBindingData[parameterName] = ((DateTime)originalValue).ToUniversalTime().ToString("o"); } else if (originalValue is DateTimeOffset) { convertedBindingData[parameterName] = ((DateTimeOffset)originalValue).UtcDateTime.ToString("o"); } } // to classify as a string literal, ALL occurrences in the template // must be string literals (e.g. of the form '{p}') // note that this will also capture OData expressions of the form // datetime'{p}', guid'{p}', X'{p}' which is fine, because single quotes // aren't valid for those values anyways. bool isStringLiteral = true; string stringParameterFormat = $"'{{{parameterName}}}'"; int count = 0, idx = 0; while (idx >= 0 && idx < template.Pattern.Length && count++ < parameterGroup.Count()) { idx = template.Pattern.IndexOf(stringParameterFormat, idx, StringComparison.OrdinalIgnoreCase); if (idx < 0) { isStringLiteral = false; break; } idx++; } // validate and format the value based on its classification object objValue = null; if (convertedBindingData.TryGetValue(parameterName, out objValue)) { string value = BindingDataPathHelper.ConvertParameterValueToString(objValue); if (isStringLiteral) { convertedBindingData[parameterName] = value.Replace("'", "''"); } else if (!TryValidateNonStringLiteral(value)) { throw new InvalidOperationException($"An invalid parameter value was specified for filter parameter '{parameterName}'."); } } } return(template.Bind(convertedBindingData)); }