/// <summary>
 /// Loads the picture data from the record
 /// </summary>
 /// <param name="picture">The picture record</param>
 public void LoadMetaDataFromRecord(ChadderSQLPicture picture)
 {
     if (picture == null)
     {
         return;
     }
     Id           = picture.PictureId;
     ToBeUploaded = picture.ToBeUploaded;
     RecordId     = picture.recordId;
 }
        public async Task <ChadderPicture> LoadPicture(ChadderSQLPicture record, bool preload)
        {
            var picture = GetPicture(record.PictureId);

            picture.LoadMetaDataFromRecord(record);
            Pictures.Add(picture);

            if (preload)
            {
                await picture.LoadPictureAsync(true, record);
            }
            return(picture);
        }
        public async Task <bool> LoadPictureAsync(bool thumbnail, ChadderSQLPicture picture = null)
        {
            try
            {
                if (thumbnail && IsThumbnailLoaded || thumbnail == false && IsLoaded)
                {
                    return(true); // Already Loaded
                }
                if (Id == null)
                {
                    return(true); // Invalid Picture
                }
                if (_loading == true)
                {
                    return(true); // Already Loading
                }
                _loading = true;
                if (picture == null && RecordId != 0)
                {
                    picture = await Source.sqlDB.GetPicture(RecordId);
                }
                if (picture == null)
                {
                    if (await Source.DownloadPicture(this) == ChadderError.OK)
                    {
                        picture = await Source.sqlDB.GetPicture(RecordId);
                    }
                }
                if (picture != null)
                {
                    LoadMetaDataFromRecord(picture);

                    var bmp = await LoadPictureFromData(picture.Bin, thumbnail);

                    Update(bmp, thumbnail);
                    _loading = false;
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                _loading = false;
                Insight.Report(ex);
                return(false);
            }
        }