0

I Try to load cached data via Akavache, but i dont know why i cant get it right. i try to get FullName and Email that i already cached after login , so i getobject in my "CachedUser" model but dont know why its says there is no definition for FullName and Email in there. Here is my CachedUser Model

namespace KGVC.Models
{
    public class CachedUsers
    {
        public string FullName { get; set; }
        public string Email { get; set; }
    }
}

and here is the code to getobject in Akavache that i try to implement

   public void GetDataCache(object sender, EventArgs e)
        {
            var loaded =  BlobCache.LocalMachine.GetObject<CachedUsers>("usercached");

            txtemail.Text = loaded.FullName;
            txtfullname.Text = loaded.FullName.ToString();
        }

and here is the cache user code

 public  void CacheUser(AuthenticationResult ar)
        {
            JObject user = ParseIdToken(ar.IdToken);
            var cache = new CachedUsers
            {
                FullName = user["name"]?.ToString(),
                Email = user["emails"]?.ToString()

            };
             BlobCache.LocalMachine.InsertObject("usercached", cache);

        }

and here is the full error message that i get

'IObservable<CachedUsers>' does not contain a definition for 'FullName' and no extension method 'FullName' accepting a first argument of type 'IObservable<CachedUsers>' could be found (are you missing a using directive or an assembly reference?)

what is the problem in here , because i think there is nothing wrong in my code. can you figure this out ?

Theodorus Agum Gumilang
  • 1,414
  • 4
  • 23
  • 46

1 Answers1

1

You either need to await it

 public async void GetDataCache(object sender, EventArgs e)
 {
    var loaded = await BlobCache.LocalMachine.GetObject<CachedUsers>("usercached");

    txtemail.Text = loaded.FullName;
    txtfullname.Text = loaded.FullName.ToString();
 }

or subscribe to the IObservable:

 public async void GetDataCache(object sender, EventArgs e)
 {
    var loaded = await BlobCache.LocalMachine.GetObject<CachedUsers>("usercached").Subscribe(user => {
        // TODO might need to wrap this in a Device.BeginInvokeOnMainThread
        txtemail.Text = user.FullName;
        txtfullname.Text = user.FullName.ToString();
    });
 }

Look into the concepts of async/await and the IObservable object to get a better understanding of the concepts and what the problem is in this specific case.

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
  • thanks bro its work with the Subscribe, but there is something that make me wonder i cant use await for it and its said IObservable doesnt contain the definition for get Awaiter. but in the end my code is work, I'm just curious here ahahhaha – Theodorus Agum Gumilang Nov 15 '17 at 08:32
  • Ah I don't have actual code right now to check it out for you. From memory I remembered something like this and I thought you could do one of both. So probably an overload of that method. But maybe it got removed in recent versions. Glad it helped! – Gerald Versluis Nov 15 '17 at 08:35
  • 1
    @TheodorusAgumGumilang including a using statement for `System.Reactive.Linq` is what gives you the ability to await an observable – rdavisau Nov 15 '17 at 12:03