Ejemplo n.º 1
0
            public static async Task <List <EventHubToken> > GetEventHubTokens(string url)
            {
                var tokens = new List <EventHubToken>();

                var httpClient = new HttpClient();
                var json       = await httpClient.GetStringAsync(url).ConfigureAwait(false);

                if (!string.IsNullOrEmpty(json))
                {
                    var o = JObject.Parse(json);
                    var a = (JArray)o["AzureEventHubs"];

                    tokens = new List <EventHubToken>();

                    for (int i = 0; i < a.Count; i++)
                    {
                        var eventHubToken = new EventHubToken();

                        eventHubToken.ExpirationDate = (DateTime)a[i]["DateExpires"];
                        eventHubToken.EventHubName   = (string)a[i]["Name"];
                        eventHubToken.SasToken       = (string)a[i]["SasToken"];
                        eventHubToken.Uri            = (string)a[i]["Uri"];

                        tokens.Add(eventHubToken);
                    }
                }

                return(tokens);
            }
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> PostDataAsync(EventHubToken sasTokens, string currentTemp)
        {
            piData tempy = new piData();
            string url   = "https://trollbridgenate.servicebus.windows.net/tbnatehub/messages";

            tempy.temperature = "100";
            var payload = JsonConvert.SerializeObject(tempy);
            var content = new StringContent(payload, Encoding.UTF8, "application/json");

            MessageClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", sasTokens.SasToken);
            return(await MessageClient.PostAsync(url, content));
        }
Ejemplo n.º 3
0
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            this.StartMessage.Text = "Program Initiated";
            StartButton.Content    = "Stop Sending Data";
            buttonClicked          = !buttonClicked;
            //var sas = GetDataAsync().Result;
            //this.StartMessage.Text = sas;
            var tokens = EventHubToken.GetEventHubTokens(tbURL).Result;

            this.StartMessage.Text = tokens[0].Uri;
            var errorResponse = PostDataAsync(tokens[0], "test");

            errorResponse.Wait();
            // Debug.WriteLine(errorResponse.Result.StatusCode);
            // Debugger.Break();
        }
            public static async Task<List<EventHubToken>> GetEventHubTokens(string url)
            {
                var tokens = new List<EventHubToken>();

                var httpClient = new HttpClient();
                var json = await httpClient.GetStringAsync(url).ConfigureAwait(false);

                if (!string.IsNullOrEmpty(json))
                {
                    var o = JObject.Parse(json);
                    var a = (JArray)o["AzureEventHubs"];

                    tokens = new List<EventHubToken>();

                    for (int i = 0; i < a.Count; i++)
                    {
                        var eventHubToken = new EventHubToken();

                        eventHubToken.ExpirationDate = (DateTime)a[i]["DateExpires"];
                        eventHubToken.EventHubName = (string)a[i]["Name"];
                        eventHubToken.SasToken = (string)a[i]["SasToken"];
                        eventHubToken.Uri = (string)a[i]["Uri"];

                        tokens.Add(eventHubToken);
                    }
                }

                return tokens;
            }
       public async Task<HttpResponseMessage> PostDataAsync(EventHubToken sasTokens, string currentTemp)
       {
            piData tempy = new piData();
            string url = "https://trollbridgenate.servicebus.windows.net/tbnatehub/messages";
            tempy.temperature = "100";
            var payload = JsonConvert.SerializeObject(tempy);
            var content = new StringContent(payload, Encoding.UTF8, "application/json");
            MessageClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", sasTokens.SasToken);
            return await MessageClient.PostAsync(url, content);
          
            

       }