public string GetCustomerLocation() { try { Customer customer = GetCustomerFromCache(); if (customer == null) { customer = new Customer() { Name = "Home", Lat = "80.24434500000006", Lang = "12.971105", ServiceType = "TV - DATA -FDV" }; AddCustomerToCache(customer); } DataContractJsonSerializer serializer = new DataContractJsonSerializer(customer.GetType()); MemoryStream memoryStream = new MemoryStream(); serializer.WriteObject(memoryStream, customer); string json = Encoding.Default.GetString(memoryStream.ToArray()); return json; } catch (Exception ex) { return "No Service at availabe"; } }
private void AddCustomerToCache(Customer customer) { ObjectCache cache = MemoryCache.Default; CacheItemPolicy policy = new CacheItemPolicy(); cache.Add("Customer", customer, DateTimeOffset.MaxValue); }
public void SetCustomerLocation(string location) { try { var lanLat = location.Split(new char[] { '|' }); var customer = new Customer() { Name = "John Smith", Lat = lanLat[0], Lang = lanLat[0], ServiceType = "TV - DATA -FDV" }; AddCustomerToCache(customer); } catch (Exception ex) { } }