Ejemplo n.º 1
0
        public List<Contact> GetContacts( )
        {
            List<Contact> contacts = new List<Contact> ( );
              using ( SQLiteDataReader reader = ExecuteReader ( GETPEOPLE_SQL ) ) {
            while ( reader.Read ( ) ) {
              Contact contact = new Contact ( );
              contact.ID = ( long )reader[ "_id" ];
              contact.SyncAccount = ( string )reader[ "_sync_account" ];
              contact.SyncDirty = reader[ "_sync_dirty" ] == DBNull.Value ? false : ( long )reader[ "_sync_dirty" ] == 1;
              contact.SyncID = reader[ "_sync_id" ] == DBNull.Value ? string.Empty : ( string )reader[ "_sync_id" ];
              contact.SyncLocalID = reader[ "_sync_local_id" ] == DBNull.Value ? string.Empty : ( string )reader[ "_sync_local_id" ];
              contact.SyncMark = reader[ "_sync_mark" ] == DBNull.Value ? false : ( long )reader[ "_sync_mark" ] == 1;
              contact.SyncTime = reader[ "_sync_time" ] == DBNull.Value ? -1 : long.Parse ( ( string )reader[ "_sync_time" ] );
              contact.SyncVersion = reader[ "_sync_version" ] == DBNull.Value ? -1 : long.Parse ( ( string )reader[ "_sync_version" ] );
              contact.CustomRingtone = reader[ "custom_ringtone" ] == DBNull.Value ? false : ( long )reader[ "custom_ringtone" ] == 1;
              contact.IsStarred = reader[ "starred" ] == DBNull.Value ? false : ( long )reader[ "starred" ] == 1;
              contact.LastTimeContacted = reader[ "last_time_contacted" ] == DBNull.Value ? -1 : ( long )reader[ "last_time_contacted" ];
              contact.Name = reader[ "name" ] == DBNull.Value ? string.Empty : ( string )reader[ "name" ];
              contact.Notes = reader[ "notes" ] == DBNull.Value ? string.Empty : ( string )reader[ "notes" ];
              contact.PhoneticName = reader[ "phonetic_name" ] == DBNull.Value ? string.Empty : ( string )reader[ "phonetic_name" ];
              contact.PhotoVersion = reader[ "photo_version" ] == DBNull.Value ? -1 : ( long )reader[ "photo_version" ];
              contact.PrimaryEmail = reader[ "primary_email" ] == DBNull.Value ? -1 : ( long )reader[ "primary_email" ];
              contact.PrimaryOrganization = reader[ "primary_organization" ] == DBNull.Value ? -1 : ( long )reader[ "primary_organization" ];
              contact.PrimaryPhone = reader[ "primary_phone" ] == DBNull.Value ? -1 : ( long )reader[ "primary_phone" ];
              contact.SendToVoiceMail = reader[ "send_to_voicemail" ] == DBNull.Value ? false : ( long )reader[ "send_to_voicemail" ] == 1;
              contact.TimesContacted = reader[ "times_contacted" ] == DBNull.Value ? -1 : ( long )reader[ "times_contacted" ];
              if ( reader["data"] != DBNull.Value ) {
            byte[] buffer = (byte[]) reader["data"];
            using ( MemoryStream ms = new MemoryStream ( buffer, false ) ) {
              contact.Photo = Image.FromStream ( ms, true );
            }
              }
              using ( SQLiteDataReader reader2 = ExecuteReader ( string.Format ( GETPERSONPHONES_SQL, contact.ID ) ) ) {
            while ( reader2.Read ( ) ) {
              Phone phone = new Phone ( );

              phone.ID = ( long )reader2[ "_id" ];
              phone.PersonID = contact.ID;
              phone.Type = reader2[ "type" ] == DBNull.Value ? Phone.PhoneType.CUSTOM : ( Phone.PhoneType )((long)reader2[ "type" ]);
              phone.Number = reader2[ "number" ] == DBNull.Value ? string.Empty : ( string )reader2[ "number" ];
              phone.Key = reader2[ "number_key" ] == DBNull.Value ? string.Empty : ( string )reader2[ "number_key" ];
              phone.Label = reader2[ "label" ] == DBNull.Value ? string.Empty : ( string )reader2[ "label" ];
              phone.IsPrimary = reader2[ "isprimary" ] == DBNull.Value ? false : ( long )reader2[ "isprimary" ] == 1;

              contact.Phones.Add ( phone );
            }
              }
              contacts.Add ( contact );
            }
              }
              return contacts;
        }
        public List<Contact> GetContacts( )
        {
            List<Contact> contacts = new List<Contact> ( );
              using ( SQLiteDataReader reader = ExecuteReader ( GETPEOPLE_SQL ) ) {
            while ( reader.Read ( ) ) {
              Contact contact = new Contact ( );
              if ( reader[ "user_name" ] != DBNull.Value ) {
            contact.Name = reader[ "user_name" ] == DBNull.Value ? string.Empty : ( string )reader[ "user_name" ];
            //contact.Notes = string.Format ( "facebook:{0}", reader[ "user_id" ] == DBNull.Value ? "-1" : (( long )reader[ "user_id" ]).ToString() );

            if ( reader[ "cell" ] != DBNull.Value ) {
              Phone phone = new Phone ( );
              phone.Type = Phone.PhoneType.CUSTOM;
              phone.Label = "Facebook:Cell";
              phone.Number = ( string )reader[ "cell" ];
              phone.Key = ( string )reader[ "cell" ];
              phone.IsPrimary = reader[ "other" ] == DBNull.Value;
              contact.Phones.Add ( phone );
            }

            if ( reader[ "other" ] != DBNull.Value ) {
              Phone phone = new Phone ( );
              phone.Type = Phone.PhoneType.CUSTOM;
              phone.Label = "Facebook:Other";
              phone.Number = ( string )reader[ "other" ];
              phone.Key = ( string )reader[ "other" ];
              phone.IsPrimary = reader[ "cell" ] == DBNull.Value;
              contact.Phones.Add ( phone );
            }

            if ( reader[ "user_image" ] != DBNull.Value ) {
              byte[] buffer = ( byte[ ] )reader[ "user_image" ];
              using ( MemoryStream ms = new MemoryStream ( buffer, false ) ) {
                contact.Photo = Image.FromStream ( ms, true );
              }
            }
              }
              contacts.Add ( contact );
            }
              }
              return contacts;
        }