Exemplo n.º 1
0
        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";
            }
        }
Exemplo n.º 2
0
        private void AddCustomerToCache(Customer customer)
        {
            ObjectCache cache = MemoryCache.Default;

            CacheItemPolicy policy = new CacheItemPolicy();

            cache.Add("Customer", customer, DateTimeOffset.MaxValue);
        }
Exemplo n.º 3
0
        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)
            {

            }
        }