internal object BindForOutput(MobileTableAttribute attribute, Type paramType)
        {
            MobileTableContext context = CreateContext(attribute);

            Type collectorType = typeof(MobileTableAsyncCollector <>).MakeGenericType(paramType);

            return(Activator.CreateInstance(collectorType, context));
        }
        internal Task <IValueBinder> BindForItemAsync(MobileTableAttribute attribute, Type paramType)
        {
            MobileTableContext context = CreateContext(attribute);

            Type         genericType = typeof(MobileTableItemValueBinder <>).MakeGenericType(paramType);
            IValueBinder binder      = (IValueBinder)Activator.CreateInstance(genericType, context);

            return(Task.FromResult(binder));
        }
        internal Task <object> BindForTableAsync(MobileTableAttribute attribute, Type paramType)
        {
            MobileTableContext context = CreateContext(attribute);

            // Assume that the Filter has already run.
            Type tableType = paramType.GetGenericArguments().Single();

            // 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.ResolvedAttribute.TableName))
            {
                context.Client.AddToTableNameCache(tableType, context.ResolvedAttribute.TableName);
            }

            MethodInfo getTableMethod        = GetGenericTableMethod();
            MethodInfo getTableGenericMethod = getTableMethod.MakeGenericMethod(tableType);

            return(Task.FromResult(getTableGenericMethod.Invoke(context.Client, null)));
        }
        internal static async Task SetValueInternalAsync(JObject originalItem, object newItem, MobileTableContext 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.ResolvedAttribute.TableName);
                    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.ResolvedAttribute.TableName))
                    {
                        context.Client.AddToTableNameCache(newItem.GetType(), context.ResolvedAttribute.TableName);
                    }
                    IMobileServiceTable <T> table = context.Client.GetTable <T>();
                    await table.UpdateAsync((T)newItem);
                }
            }
        }
 public MobileTableItemValueBinder(MobileTableContext context)
 {
     _context = context;
 }
        internal IMobileServiceClient BindForClient(MobileTableAttribute attribute)
        {
            MobileTableContext context = CreateContext(attribute);

            return(context.Client);
        }
        internal IMobileServiceTable BindForTable(MobileTableAttribute attribute)
        {
            MobileTableContext context = CreateContext(attribute);

            return(context.Client.GetTable(context.ResolvedAttribute.TableName));
        }
 public MobileTableAsyncCollector(MobileTableContext context)
 {
     _context = context;
 }