public HubProxy(string address, string hubName)
 {
     _connection = new Microsoft.AspNet.SignalR.Client.HubConnection(address);
     _proxy      = _connection.CreateHubProxy(hubName);
     _connection.Start().Wait();
 }
 void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     var url = new Uri(this.textBox.Text);
      connection = new Microsoft.AspNet.SignalR.Client.HubConnection(url.ToString());
     proxy = connection.CreateHubProxy("HeartRateHub");
 }
        async Task SendData(List <RoomEnvironment> data)
        {
            double   duration   = 10000;
            TimeSpan delta10sec = TimeSpan.FromMilliseconds(duration);

            var avgs = new List <RoomEnvironment>();

            DateTime startTime = data.First().time;
            DateTime endTime   = data.Last().time;

            int      index     = 0;
            DateTime cursor    = startTime;
            DateTime cursorEnd = cursor + delta10sec;
            var      current   = new Dictionary <string, List <RoomEnvironment> >();

            while (cursor <= endTime && index < data.Count)
            {
                var re = data[index++];
                if (re.time > cursorEnd)
                {
                    foreach (var k in current.Keys)
                    {
                        if (current[k].Count > 0)
                        {
                            RoomEnvironment avg = CalcAvg(cursorEnd, current[k], k);
                            avgs.Add(avg);
                        }
                        current[k].Clear();
                    }
                    cursor     = cursorEnd;
                    cursorEnd += delta10sec;
                    current[re.deviceid].Add(re);
                }
                else
                {
                    if (!current.ContainsKey(re.deviceid))
                    {
                        current.Add(re.deviceid, new List <RoomEnvironment>());
                    }
                    current[re.deviceid].Add(re);
                }
            }
            foreach (var k in current.Keys)
            {
                if (current[k].Count > 0)
                {
                    RoomEnvironment avg = CalcAvg(cursorEnd, current[k], k);
                    avgs.Add(avg);
                }
            }
            var hubConnection = new Microsoft.AspNet.SignalR.Client.HubConnection(tbURL.Text);
            var proxy         = hubConnection.CreateHubProxy("EnvHub");
            await hubConnection.Start();

            foreach (var re in avgs)
            {
                tbData.Text = string.Format("{0}@{1}:T={2},H={3}", re.deviceid, re.time, re.temperature, re.humidity);
                await proxy.Invoke("Environment", re);

                Thread.Sleep((int)(duration / currentSpeed));
            }
            tbData.Text = "End";
        }
Esempio n. 4
0
        //Run tests
        public void RunTestCase()
        {
            var hubConnection = new Microsoft.AspNet.SignalR.Client.HubConnection("http://tweetsentiment.azurewebsites.net/");
            var twitterHubProxy = hubConnection.CreateHubProxy("TwitterHub");
            hubConnection.Start().Wait();

            for (int i = 0; i < 100000; i++)
            {
                twitterHubProxy.Invoke("UpdateCounter", i);
                Thread.Sleep(50);
            }


            Dictionary<string, Object> emptyDictionary = new Dictionary<string, object>();
            //Spout tests
            {
                //Get local context
                LocalContext spoutCtx = LocalContext.Get();
                //Get an instance of the spout
                TwitterSpout spout = TwitterSpout.Get(spoutCtx, emptyDictionary);

                // Collect some tweets
                Thread.Sleep(5000);

                //Call NextTuple to emit data
                for (int i = 0; i < 10; i++)
                {
                    spout.NextTuple(emptyDictionary);
                }
                //Store the stream for the next component
                spoutCtx.WriteMsgQueueToFile("spout.txt");
                spout.StopListenerThread();
            }

            //HBaseWriterBolt tests
            //{
            //    LocalContext splitterCtx = LocalContext.Get();
            //    HBaseWriterBolt splitter = HBaseWriterBolt.Get(splitterCtx, emptyDictionary);
            //    //Read from the 'stream' emitted by the spout
            //    splitterCtx.ReadFromFileToMsgQueue("spout.txt");
            //    List<SCPTuple> batch = splitterCtx.RecvFromMsgQueue();
            //    foreach (SCPTuple tuple in batch.Take(batch.Count - 1))
            //    {
            //        splitter.Execute(tuple);
            //    }
            //    Thread.Sleep(100);
            //    splitter.Execute(batch.Last());
            //}

            //HBaseCounterBolt tests
            {
                LocalContext counterCtx = LocalContext.Get();
                HBaseCounterBolt counter = HBaseCounterBolt.Get(counterCtx, emptyDictionary);
                //Read from the 'stream' emitted by the spout
                counterCtx.ReadFromFileToMsgQueue("spout.txt");
                List<SCPTuple> batch = counterCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch.Take(batch.Count - 1))
                {
                    counter.Execute(tuple);
                }
                Thread.Sleep(100);
                counter.Execute(batch.Last());
                counterCtx.WriteMsgQueueToFile("counter.txt");
            }

            //SignalRBroadcastBolt tests
            {
                LocalContext broadcastCtx = LocalContext.Get();
                SignalRBroadcastBolt broadcast = SignalRBroadcastBolt.Get(broadcastCtx, emptyDictionary);
                //Read from the 'stream' emitted by the spout
                broadcastCtx.ReadFromFileToMsgQueue("counter.txt");
                List<SCPTuple> batch = broadcastCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    broadcast.Execute(tuple);
                }
            }
        }
Esempio n. 5
0
        //Run tests
        public void RunTestCase()
        {
            var hubConnection   = new Microsoft.AspNet.SignalR.Client.HubConnection("http://tweetsentiment.azurewebsites.net/");
            var twitterHubProxy = hubConnection.CreateHubProxy("TwitterHub");

            hubConnection.Start().Wait();

            for (int i = 0; i < 100000; i++)
            {
                twitterHubProxy.Invoke("UpdateCounter", i);
                Thread.Sleep(50);
            }


            Dictionary <string, Object> emptyDictionary = new Dictionary <string, object>();
            //Spout tests
            {
                //Get local context
                LocalContext spoutCtx = LocalContext.Get();
                //Get an instance of the spout
                TwitterSpout spout = TwitterSpout.Get(spoutCtx, emptyDictionary);

                // Collect some tweets
                Thread.Sleep(5000);

                //Call NextTuple to emit data
                for (int i = 0; i < 10; i++)
                {
                    spout.NextTuple(emptyDictionary);
                }
                //Store the stream for the next component
                spoutCtx.WriteMsgQueueToFile("spout.txt");
                spout.StopListenerThread();
            }

            //HBaseWriterBolt tests
            //{
            //    LocalContext splitterCtx = LocalContext.Get();
            //    HBaseWriterBolt splitter = HBaseWriterBolt.Get(splitterCtx, emptyDictionary);
            //    //Read from the 'stream' emitted by the spout
            //    splitterCtx.ReadFromFileToMsgQueue("spout.txt");
            //    List<SCPTuple> batch = splitterCtx.RecvFromMsgQueue();
            //    foreach (SCPTuple tuple in batch.Take(batch.Count - 1))
            //    {
            //        splitter.Execute(tuple);
            //    }
            //    Thread.Sleep(100);
            //    splitter.Execute(batch.Last());
            //}

            //HBaseCounterBolt tests
            {
                LocalContext     counterCtx = LocalContext.Get();
                HBaseCounterBolt counter    = HBaseCounterBolt.Get(counterCtx, emptyDictionary);
                //Read from the 'stream' emitted by the spout
                counterCtx.ReadFromFileToMsgQueue("spout.txt");
                List <SCPTuple> batch = counterCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch.Take(batch.Count - 1))
                {
                    counter.Execute(tuple);
                }
                Thread.Sleep(100);
                counter.Execute(batch.Last());
                counterCtx.WriteMsgQueueToFile("counter.txt");
            }

            //SignalRBroadcastBolt tests
            {
                LocalContext         broadcastCtx = LocalContext.Get();
                SignalRBroadcastBolt broadcast    = SignalRBroadcastBolt.Get(broadcastCtx, emptyDictionary);
                //Read from the 'stream' emitted by the spout
                broadcastCtx.ReadFromFileToMsgQueue("counter.txt");
                List <SCPTuple> batch = broadcastCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    broadcast.Execute(tuple);
                }
            }
        }