protected override IEnumerable GetObjectReader(ContentQueryTranslator translator)
    {
      if (translator == null || translator.ReturnType == null || translator.ReturnType == typeof(Contact))
        return new ContactReader(UseRawContacts, translator, content, resources);
      else if (translator.ReturnType == typeof(Phone))
        return new GenericQueryReader<Phone>(translator, content, resources, ContactHelper.GetPhone);
      else if (translator.ReturnType == typeof(Email))
        return new GenericQueryReader<Email>(translator, content, resources, ContactHelper.GetEmail);
      else if (translator.ReturnType == typeof(Address))
        return new GenericQueryReader<Address>(translator, content, resources, ContactHelper.GetAddress);
      else if (translator.ReturnType == typeof(Relationship))
        return new GenericQueryReader<Relationship>(translator, content, resources, ContactHelper.GetRelationship);
      else if (translator.ReturnType == typeof(InstantMessagingAccount))
        return new GenericQueryReader<InstantMessagingAccount>(translator, content, resources, ContactHelper.GetImAccount);
      else if (translator.ReturnType == typeof(Website))
        return new GenericQueryReader<Website>(translator, content, resources, ContactHelper.GetWebsite);
      else if (translator.ReturnType == typeof(Organization))
        return new GenericQueryReader<Organization>(translator, content, resources, ContactHelper.GetOrganization);
      else if (translator.ReturnType == typeof(Note))
        return new GenericQueryReader<Note>(translator, content, resources, ContactHelper.GetNote);
      else if (translator.ReturnType == typeof(string))
        return new ProjectionReader<string>(content, translator, (cur, col) => cur.GetString(col));
      else if (translator.ReturnType == typeof(int))
        return new ProjectionReader<int>(content, translator, (cur, col) => cur.GetInt(col));

      throw new ArgumentException();
    }
 public ContactReader(bool useRawContacts, ContentQueryTranslator translator, ContentResolver content, Resources resources)
 {
     this.rawContacts = useRawContacts;
     this.translator  = translator;
     this.content     = content;
     this.resources   = resources;
 }
        public GenericQueryReader(ContentQueryTranslator translator, ContentResolver content, Resources resources, Func <ICursor, Resources, T> selector, string defaultSort)
            : this(translator, content, resources, selector)
        {
            if (defaultSort == null)
            {
                throw new ArgumentNullException(nameof(defaultSort));
            }

            this.defaultSort = defaultSort;
        }
Example #4
0
        object IQueryProvider.Execute(Expression expression)
        {
            var translator = new ContentQueryTranslator(this, this.tableFinder);

            expression = translator.Translate(expression);

            if (translator.IsCount || translator.IsAny)
            {
                ICursor cursor = null;
                try
                {
                    string[] projections = (translator.Projections != null)
                                            ? translator.Projections
                                           .Where(p => p.Columns != null)
                                           .SelectMany(t => t.Columns)
                                           .ToArray()
                                            : null;

                    cursor = this.content.Query(translator.Table, projections, translator.QueryString,
                                                translator.ClauseParameters, translator.SortString);

                    if (translator.IsCount)
                    {
                        return(cursor.Count);
                    }
                    else
                    {
                        return(cursor.Count > 0);
                    }
                }
                finally
                {
                    if (cursor != null)
                    {
                        cursor.Close();
                    }
                }
            }

            IQueryable q = GetObjectReader(translator).AsQueryable();

            //IQueryable q = GetObjectReader (null).AsQueryable();

            expression = ReplaceQueryable(expression, q);

            if (expression.Type.IsGenericType && expression.Type.GetGenericTypeDefinition() == typeof(IOrderedQueryable <>))
            {
                return(q.Provider.CreateQuery(expression));
            }
            else
            {
                return(q.Provider.Execute(expression));
            }
        }
        protected override IEnumerable GetObjectReader(ContentQueryTranslator translator)
        {
            if (translator == null || translator.ReturnType == null || translator.ReturnType == typeof(Contact))
            {
                return(new ContactReader(UseRawContacts, translator, content, resources));
            }
            else if (translator.ReturnType == typeof(Phone))
            {
                return(new GenericQueryReader <Phone>(translator, content, resources, ContactHelper.GetPhone));
            }
            else if (translator.ReturnType == typeof(Email))
            {
                return(new GenericQueryReader <Email>(translator, content, resources, ContactHelper.GetEmail));
            }
            else if (translator.ReturnType == typeof(Address))
            {
                return(new GenericQueryReader <Address>(translator, content, resources, ContactHelper.GetAddress));
            }
            else if (translator.ReturnType == typeof(Relationship))
            {
                return(new GenericQueryReader <Relationship>(translator, content, resources, ContactHelper.GetRelationship));
            }
            else if (translator.ReturnType == typeof(InstantMessagingAccount))
            {
                return(new GenericQueryReader <InstantMessagingAccount>(translator, content, resources, ContactHelper.GetImAccount));
            }
            else if (translator.ReturnType == typeof(Website))
            {
                return(new GenericQueryReader <Website>(translator, content, resources, ContactHelper.GetWebsite));
            }
            else if (translator.ReturnType == typeof(Organization))
            {
                return(new GenericQueryReader <Organization>(translator, content, resources, ContactHelper.GetOrganization));
            }
            else if (translator.ReturnType == typeof(Note))
            {
                return(new GenericQueryReader <Note>(translator, content, resources, ContactHelper.GetNote));
            }
            else if (translator.ReturnType == typeof(string))
            {
                return(new ProjectionReader <string>(content, translator, (cur, col) => cur.GetString(col)));
            }
            else if (translator.ReturnType == typeof(int))
            {
                return(new ProjectionReader <int>(content, translator, (cur, col) => cur.GetInt(col)));
            }

            throw new ArgumentException();
        }
        public GenericQueryReader(ContentQueryTranslator translator, ContentResolver content, Resources resources, Func <ICursor, Resources, T> selector)
        {
            if (translator == null)
            {
                throw new ArgumentNullException(nameof(translator));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (resources == null)
            {
                throw new ArgumentNullException(nameof(resources));
            }
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            this.translator = translator;
            this.content    = content;
            this.resources  = resources;
            this.selector   = selector;
        }
 protected abstract IEnumerable GetObjectReader(ContentQueryTranslator translator);
Example #8
0
 internal ProjectionReader(ContentResolver content, ContentQueryTranslator translator, Func <ICursor, int, T> selector)
 {
     this.content    = content;
     this.translator = translator;
     this.selector   = selector;
 }