Esempio n. 1
0
        public HttpResponseMessage Post(ClientStatistics clientStatistics)
        {
            try
            {
                if ((!ModelState.IsValid) || (clientStatistics == null))
                {
                    return Request.CreateResponse(HttpStatusCode.ExpectationFailed);
                }

                _repository.AddUserStatistics(
                    new UserStatistic
                    {
                        AgresivityRate = clientStatistics.AgresivityRate,
                        EmailAddress = clientStatistics.EmailAddress,
                        DateTime = DateTime.UtcNow,
                        Location = clientStatistics.Location
                    });

                return Request.CreateResponse(HttpStatusCode.Created);
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.ExpectationFailed);
            }
        }
Esempio n. 2
0
        public string Encode(ClientStatistics clientStatistics)
        {
            var writer = new StringWriter();
            var serializer = new XmlSerializer(typeof(ClientStatistics));

            serializer.Serialize(writer, clientStatistics);

            return writer.ToString();
        }
        public async Task Persist(ClientStatistics statistics)
        {
            var encoder = new XmlEncoder();
            var filename = _dbProvider.BuildDbName(statistics.EmailAddress);

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var writer = new StreamWriter(store.OpenFile(filename, FileMode.Create, FileAccess.Write)))
                {
                    await writer.WriteAsync(encoder.Encode(statistics));                        
                }
            }
        }
Esempio n. 4
0
        //POST /api/automate HTTP/1.1
        //Host: automatewebui.azurewebsites.net
        //Cache-Control: no-cache
        //Content-Type: application/x-www-form-urlencoded
        //
        //EmailAddress=jm_aba%40ahoo.com&Location=Lehliu&AgresivityRate=99
        public async Task<string> Post(ClientStatistics clientStatistics)
        {
            try
            {
                var data = _encoder.Encode(clientStatistics);

                var client = new WebClient();
                client.Headers[HttpRequestHeader.ContentType] = _encoder.ContentType;
                return await client.UploadStringTaskAsync(new Uri(_uri), "POST", data);
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }
        private async void PersistData()
        {
            Agresivity = (int) Math.Abs(Agresivity);
            if (Agresivity <= 0)
                Agresivity = 1;
            if (Agresivity > 100)
                Agresivity = 100;

            var clientStatistics = new ClientStatistics
            {
                EmailAddress = _userContext.Email,
                Location = _userContext.Location,
                AgresivityRate = Agresivity,
            };

            await _repository.Persist(clientStatistics);
        }        
Esempio n. 6
0
 public string Encode(ClientStatistics clientStatistics)
 {
     return Newtonsoft.Json.JsonConvert.SerializeObject(clientStatistics);
 }