Esempio n. 1
0
        public static string WriteFromObject(symbol userSymbol)
        {
            //Create a stream to serialize the object to.
            MemoryStream ms = new MemoryStream();

            // Serializer the User object to the stream.
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(symbol));

            ser.WriteObject(ms, userSymbol);
            byte[] json = ms.ToArray();
            return(Encoding.UTF8.GetString(json, 0, json.Length));
        }
Esempio n. 2
0
        public static void UpdateCounterAsync(string symbolName)
        {
            ConnectDB db = new ConnectDB();

            if (!(who_am_i.Equals("") || symbolName.Equals("")))
            {
                symbol symbol = new symbol
                {
                    email      = who_am_i.ToLower(),
                    symbolName = symbolName,
                    date       = DateTime.Today
                };
                db.UpdateUserCounterAsync(symbol);
            }
        }
Esempio n. 3
0
        public async void UpdateUserCounterAsync(symbol userSymbol)
        {
            string completeUri = "http://childappapiservice.azurewebsites.net/api/counters";

            string json = WriteFromObject(userSymbol);

            try
            {
                //Send the PATCH request
                HttpStringContent stringContent = new HttpStringContent(json.ToString());

                System.Net.Http.HttpRequestMessage request = new System.Net.Http.HttpRequestMessage(new System.Net.Http.HttpMethod("PATCH"), completeUri);
                request.Content = new StringContent(json,
                                                    Encoding.UTF8,
                                                    "application/json");//CONTENT-TYPE header

                System.Net.Http.HttpClient          client   = new System.Net.Http.HttpClient();
                System.Net.Http.HttpResponseMessage response = await client.SendAsync(request);
            }

            catch (Exception ex)
            {
            }
        }