async public Task InitAsync()
        {
            structure = await api.GetAsync();

            if (structure == null)
            {
                throw new Exception("Structure could not be fetched from API!");
            }
        }
Esempio n. 2
0
 public async Task InitAsync()
 {
     using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(RESOURCE_FILE))
         using (StreamReader reader = new StreamReader(stream))
         {
             string json = reader.ReadToEnd();
             structure = JsonConvert.DeserializeObject <DpsgStructure>(json);
         }
 }
Esempio n. 3
0
        private async Task <DpsgStructure> GetRemoteAsync()
        {
            string path = ObjectName();
            HttpResponseMessage response = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                string json = await response.Content.ReadAsStringAsync();

                DpsgStructure structure = JsonConvert.DeserializeObject <DpsgStructure>(json);
                return(structure);
            }
            return(null);
        }
Esempio n. 4
0
        public async Task <DpsgStructure> GetAsync()
        {
            DpsgStructure result        = null;
            string        key           = ObjectName();
            var           cache         = BlobCache.LocalMachine;
            var           cachedPromise = cache.GetAndFetchLatest(
                key,
                () => GetRemoteAsync()
                );

            cachedPromise.Subscribe(subscribedStructure => {
                Debug.WriteLine("Subscribed Object ready");
                result = subscribedStructure;
            });

            result = await cachedPromise.FirstOrDefaultAsync();

            return(result);
        }