public EasyTableItemBinding(ParameterInfo parameter, EasyTableContext context, BindingProviderContext bindingContext) { _parameter = parameter; _context = context; // set up binding for '{ItemId}'-type bindings if (_context.ResolvedId != null) { _bindingTemplate = BindingTemplate.FromString(_context.ResolvedId); _bindingTemplate.ValidateContractCompatibility(bindingContext.BindingDataContract); } }
internal static bool IsValidQueryType(Type paramType, EasyTableContext context) { if (paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof(IMobileServiceTableQuery <>)) { // IMobileServiceTableQuery<JObject> is not supported. Type coreType = TypeUtility.GetCoreType(paramType); if (coreType != typeof(JObject) && EasyTableUtility.IsCoreTypeValidItemType(paramType, context)) { return(true); } } return(false); }
internal static bool IsValidCollectorType(Type paramType, EasyTableContext context) { if (paramType.IsGenericType) { Type genericType = paramType.GetGenericTypeDefinition(); if (genericType == typeof(ICollector <>) || genericType == typeof(IAsyncCollector <>)) { Type coreType = TypeUtility.GetCoreType(paramType); if (IsValidEasyTableOutputType(coreType, context)) { return(true); } } } return(false); }
internal static bool IsValidOutType(Type paramType, EasyTableContext context) { if (paramType.IsByRef) { Type coreType = paramType.GetElementType(); if (coreType.IsArray) { coreType = coreType.GetElementType(); } if (IsValidEasyTableOutputType(coreType, context)) { return(true); } } return(false); }
internal static bool IsMobileServiceTableType(Type paramType, EasyTableContext context) { if (paramType == typeof(IMobileServiceTable) && !string.IsNullOrEmpty(context.ResolvedTableName)) { return(true); } if (paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof(IMobileServiceTable <>)) { if (EasyTableUtility.IsCoreTypeValidItemType(paramType, context)) { return(true); } } return(false); }
/// <summary> /// Evaluates whether the specified type is valid for use with EasyTables. /// If the type is <see cref="JObject"/>, then the ResolvedTableName property on /// <see cref="EasyTableAttribute"/> is required. /// If the type is not <see cref="JObject"/>, then it must contain a single public /// string 'Id' property. /// </summary> /// <param name="itemType">The type to evaluate.</param> /// <param name="context">The <see cref="EasyTableContext"/>.</param> /// <returns></returns> public static bool IsValidItemType(Type itemType, EasyTableContext context) { // We cannot support a type of JObject without a TableName. if (itemType == typeof(JObject)) { return(!string.IsNullOrEmpty(context.ResolvedTableName)); } // POCO types must have a string id property (case insensitive). IEnumerable <PropertyInfo> idProperties = itemType.GetProperties() .Where(p => string.Equals("id", p.Name, StringComparison.OrdinalIgnoreCase) && p.PropertyType == typeof(string)); if (idProperties.Count() != 1) { return(false); } return(true); }
public Task <IBinding> TryCreateAsync(BindingProviderContext context) { if (context == null) { throw new ArgumentNullException("context"); } ParameterInfo parameter = context.Parameter; EasyTableAttribute attribute = parameter.GetEasyTableAttribute(); if (attribute == null) { return(Task.FromResult <IBinding>(null)); } if (_easyTableConfig.MobileAppUri == null && string.IsNullOrEmpty(attribute.MobileAppUri)) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, "The Easy Tables Uri must be set either via a '{0}' app setting, via the EasyTableAttribute.MobileAppUri property or via EasyTableConfiguration.MobileAppUri.", EasyTablesConfiguration.AzureWebJobsMobileAppUriName)); } EasyTableContext easyTableContext = CreateContext(_easyTableConfig, attribute, _nameResolver); IBindingProvider compositeProvider = new CompositeBindingProvider(new IBindingProvider[] { new EasyTableOutputBindingProvider(_jobHostConfig, easyTableContext), new EasyTableQueryBinding(context.Parameter, easyTableContext), new EasyTableTableBinding(parameter, easyTableContext), new EasyTableItemBinding(parameter, easyTableContext, context) }); return(compositeProvider.TryCreateAsync(context)); }
public EasyTableTableValueProvider(ParameterInfo parameter, EasyTableContext context) { _parameter = parameter; _context = context; }
public EasyTableTableBinding(ParameterInfo parameter, EasyTableContext context) { _parameter = parameter; _context = context; }
internal static async Task SetValueInternalAsync(JObject originalItem, object newItem, EasyTableContext context) { JObject currentValue = null; bool isJObject = newItem.GetType() == typeof(JObject); if (isJObject) { currentValue = newItem as JObject; } else { currentValue = JObject.FromObject(newItem); } if (HasChanged(originalItem, currentValue)) { // make sure it's not the Id that has changed if (!string.Equals(GetId(originalItem), GetId(currentValue), StringComparison.Ordinal)) { throw new InvalidOperationException("Cannot update the 'Id' property."); } if (isJObject) { IMobileServiceTable table = context.Client.GetTable(context.ResolvedTableName); await table.UpdateAsync((JObject)newItem); } else { // If TableName is specified, add it to the internal table cache. Now items of this type // will operate on the specified TableName. if (!string.IsNullOrEmpty(context.ResolvedTableName)) { context.Client.AddToTableNameCache(newItem.GetType(), context.ResolvedTableName); } IMobileServiceTable <T> table = context.Client.GetTable <T>(); await table.UpdateAsync((T)newItem); } } }
public EasyTableItemValueBinder(ParameterInfo parameter, EasyTableContext context, string id) { _parameter = parameter; _context = context; _id = id; }
public EasyTableAsyncCollector(EasyTableContext context) { _context = context; }
public EasyTableOutputBindingProvider(JobHostConfiguration jobHostConfig, EasyTableContext easyTableContext) { _jobHostConfig = jobHostConfig; _easyTableContext = easyTableContext; }
internal static bool IsValidEasyTableOutputType(Type paramType, EasyTableContext context) { // Output bindings also support objects as long as ResolvedTableName is valid return(EasyTableUtility.IsValidItemType(paramType, context) || (paramType == typeof(object) && !string.IsNullOrEmpty(context.ResolvedTableName))); }
/// <summary> /// Gets the core type of the specified type. Then validates that it is /// usable with Easy Tables. /// </summary> /// <param name="type">The type to evaluate.</param> /// <param name="context">The <see cref="EasyTableContext"/>.</param> /// <returns></returns> public static bool IsCoreTypeValidItemType(Type type, EasyTableContext context) { Type coreType = TypeUtility.GetCoreType(type); return(IsValidItemType(coreType, context)); }