private (Canvas, WebsocketConnection) GetCanvasConnection(byte canvasId)
        {
            if (!Canvases.TryGetValue(canvasId, out var canvas))
            {
                throw new ArgumentException("CanvasId not found");
            }

            if (!_connections.TryGetValue(canvasId, out var connection))
            {
                connection = new WebsocketConnection(
                    new Uri(WsUrl),
                    canvasId,
                    () => new ClientWebSocket
                {
                    Options =
                    {
                        UseDefaultCredentials = _handler.UseDefaultCredentials,
                        Credentials           = _handler.Credentials,
                        Proxy   = _handler.Proxy,
                        Cookies = _handler.CookieContainer
                    }
                });
                connection.PixelChangedEvent += OnPixelChange;

                _connections.Add(canvasId, connection);
            }

            return(canvas, connection);
        }
        public WebSocketClient()
        {
            WebsocketConnection.Link();
            connection = WebSocketFactory.Create();

            ClientWebSocket cws = new ClientWebSocket();
        }
        public async void AddSocket(WebSocket connection, TaskCompletionSource <object> socketFinishedTcs)
        {
            var wsConnection = new WebsocketConnection(connection, socketFinishedTcs);

            _connections.Add(wsConnection);
            await KeepOpen(connection);
        }
        static void Send_ReturnA()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.Open("ws://127.0.0.1:8081", "none", new Dictionary <string, string>());
            websocketConnection.Send("testsend");
        }
        static void Close_Return()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.Open("ws://127.0.0.1:8081", "none", new Dictionary <string, string>());
            websocketConnection.Close();
        }
Ejemplo n.º 6
0
 public void RemoveConnection(WebsocketConnection connection)
 {
     if (this.connectionsInRoom.Contains(connection))
     {
         this.connectionsInRoom.Remove(connection);
     }
 }
Ejemplo n.º 7
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            PrepareRemoteNotification();
            SlideOverKit.iOS.SlideOverKit.Init();
            CarouselViewRenderer.Init();
            ImageCircleRenderer.Init();
            FFImageLoading.Forms.Touch.CachedImageRenderer.Init();
            WebsocketConnection.Link();
            //Getting device screen size
            App.ScreenHeight = (double)UIScreen.MainScreen.Bounds.Height;
            App.ScreenWidth  = (double)UIScreen.MainScreen.Bounds.Width;
            SetupTitleBar();



// You can get the GoogleService-Info.plist file at https://developers.google.com/mobile/add
            var googleServiceDictionary = NSDictionary.FromFile("GoogleService-Info.plist");

            SignIn.SharedInstance.ClientID = googleServiceDictionary["CLIENT_ID"].ToString();

            Firebase.Analytics.App.Configure();
            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
Ejemplo n.º 8
0
        public async Task GetUpdateAsync()
        {
            if (HttpContext.WebSockets.IsWebSocketRequest)
            {
                // keeping it simple I guess
                var ws = await HttpContext.WebSockets.AcceptWebSocketAsync();

                var roomcode = HttpContext.Session.GetStringValue("roomcode");
                var roomkey  = HttpContext.Session.GetStringValue("hostkey");

                WebsocketConnection connection = new WebsocketConnection(ws, manager);
                await connection.StartSession(roomcode, roomkey);

                _ = Task.Run(async() =>
                {
                    try
                    {
                        await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, null, new CancellationTokenSource(TimeSpan.FromSeconds(3)).Token);
                    }
                    catch (Exception)
                    {
                        // just offload a close request, silently catch if fails. no worries
                    }
                });
            }
            else
            {
                HttpContext.Response.StatusCode = 500;
            }
        }
        static void Send_ReturnB()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.Open("ws://127.0.0.1:8081", "none", new Dictionary <string, string>());
            byte[] array = { 0x01, 0x02, 0x03 };
            websocketConnection.Send(array);
        }
        static void OnDispose_Return()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.OnDispose += (args) =>
            {
                OnDispose(args);
            };
        }
Ejemplo n.º 11
0
    void Start()
    {
        websocketConnection = gameObject.AddComponent <WebsocketConnection>();
        connectionAgent     = gameObject.AddComponent <ConnectionAgent>();

        connectionAgent.connection = websocketConnection;

        game = GameObject.FindObjectOfType <Game>();
    }
        static void OnClosed_Return()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.OnClosed += (sender, args) =>
            {
                OnClosed(sender, args);
            };
        }
        static void OnMessage_Return()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.OnError += (sender, args) =>
            {
                OnMessage(sender, args);
            };
        }
Ejemplo n.º 14
0
        private async void InitializeDirectLine()
        {
            _client       = new DirectLineClient(AppConfig.DirectLine);
            _conversation = (await _client.Conversations.StartConversationWithHttpMessagesAsync()).Body;

            //Register the UWP as a Client UWP in database
            var response = _client.Conversations.PostActivity(_conversation.ConversationId, new Activity("message")
            {
                From = new ChannelAccount("Jean"),
                Text = "RegisterApp",
            });

            //WEBSOCKET HERE
            WebsocketConnection.Link();
            connection           = WebSocketFactory.Create();
            connection.OnLog    += Connection_OnLog;
            connection.OnError  += Connection_OnError;
            connection.OnOpened += Connection_OnOpened;

            connection.Open(_conversation.StreamUrl);

            _isDirectLineInitialized = true;
        }
Ejemplo n.º 15
0
 static TestBase()
 {
     WebsocketConnection.Link();
     webApp = WebApp.Start <Startup>(BaseUrl);
 }
 static void IsOpen_Return()
 {
     var websocketConnection = new WebsocketConnection();
     var bopen = websocketConnection.IsOpen;
 }
Ejemplo n.º 17
0
 public void AddConnection(WebsocketConnection connection)
 {
     this.connectionsInRoom.Add(connection);
 }
 static RealtimeConnection()
 {
     System.Net.ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
     WebsocketConnection.Link();
 }
        static void Open_ReturnA()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.Open("ws://127.0.0.1:8081");
        }
 static void Link_Return()
 {
     WebsocketConnection.Link();
 }
        static void Dispose_Return()
        {
            var websocketConnection = new WebsocketConnection();

            websocketConnection.Dispose();
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine(
                    @"Usage:
WeatherDataReplay.exe 221 ""ws://schuecobe5hackdays.azurewebsites.net/WebSocketServer.ashx?"" ""C:\path\to\file.csv""

Where ..
..the first argument is the 'propertyId' (supply 0 for a new one)
..the second argument is the 'endpointUrl'
..the third argument is the 'inputFile'");
                return;
            }

            var propertyId  = int.Parse(args[0]);
            var endpointUrl = args[1];
            var inputFile   = (File.Exists(args[2]) ? args[2] : null) ??
                              throw new Exception(
                                        $"The specified input file doesn't exist or is not accessible: {args[2]}");


            _webSocketConnection = new WebsocketConnection(propertyId, endpointUrl, false);

            var oneSecond = TimeSpan.FromSeconds(1);
            var dateRegex = new Regex(@"\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d.*", RegexOptions.Compiled);

            var thread = new Thread(() =>
            {
                /*
                 * C1	C2	C3	C4	C5	C6	C7	C8	C9	C10	C11	C12	C13	C14	C15	C16	C17	C18
                 * TIMESTAMP	RECORD	year	dayofyear	hours	minutes	BattV_Avg	SWtot_Avg	SWdif_Avg	Wdir_Avg	Wavg_Avg	Wmax_Max	Tair_Avg	RHum_Avg	Pair_Avg	Rain	Rintensity_Avg	Hail
                 * TS	RN	""	""	""	""	Volts	W/meter	W/meter	degrees	m/s	m/s	deg C	%	Pa	mm	mm/h	hits/cm2
                 * ""	""	Smp	Smp	Smp	Smp	Avg	Avg	Avg	Avg	Avg	Max	Avg	Avg	Avg	Smp	Avg	Smp
                 * 2015-09-21 22:23:00	45287	2015	264	22	23	13.45949	0.3366436	0.5049654	266.1667	4.4	6.1	10.9	79.45	989.5	59.97	0	0
                 * 2015-09-21 22:24:00	45288	2015	264	22	24	13.4604	0.3366436	0.5049654	250.1667	3.8	5.5	10.9	79.58333	989.5	59.97	0	0
                 * 2015-09-21 22:25:00	45289	2015	264	22	25	13.46223	0.3226168	0.5049654	258.6667	4.45	6.8	10.9	79.48333	989.5	59.97	0	0
                 */
                using (var streamReader = new StreamReader(inputFile))
                {
                    while (!streamReader.EndOfStream)
                    {
                        var line = streamReader.ReadLine();
                        if (line == null)
                        {
                            continue;
                        }

                        if (!dateRegex.Match(line).Success)
                        {
                            continue;
                        }

                        // 0: timestamp
                        // 1: No.
                        // 2: Year
                        // 3: DayOfYear
                        // 4: Hours
                        // 5: Minutes
                        // 6: Battery voltage
                        // 7: SWtot_Avg ???
                        // 8: SWdif_Avg ???
                        // 9: Wind direction (Wdir_Avg - °)
                        // 10: Wind avg. speed (Wavg_Avg - m/s)
                        // 11: Wind max. speed (Wmax_Max - m/s)
                        // 12: Air temperature (Tair_Avg - °C)
                        // 13: Relative humidity (RHum_Avg - %)
                        // 14: Air pressure (Pair_Avg - pascal)
                        // 15: Rain (Rain - mm)
                        // 16: Rain intensity (Rintensity_Avg - mm/h)
                        // 17: Hail (Hail - hits/cm2)
                        var cells = line.Split(',');

                        if (!DateTime.TryParse(cells[0].Replace("\"", ""), out var time))
                        {
                            continue;
                        }

                        if (!decimal.TryParse(cells[15], out var rain))
                        {
                            continue;
                        }

                        var light = "";
                        if (time.TimeOfDay >= new DateTime(2001, 01, 01, 06, 00, 00).TimeOfDay &&
                            time.TimeOfDay <= new DateTime(2001, 01, 01, 19, 00, 00).TimeOfDay)
                        {
                            // Could be sunny or cloudy
                            if (rain < 1)
                            {
                                light = "Sunny";
                            }
                            else if (rain >= 1)
                            {
                                light = "Cloudy";
                            }
                            else if (rain > 2)
                            {
                                light = "Rainy";
                            }
                        }
                        else
                        {
                            // Dark
                            light = "Dark";
                        }

                        // Timetamp
                        var changeMessage = new { type = "set_value", value_name = "userdefined_string_1", value = cells[0].Replace("\"", "") };
                        _webSocketConnection.Send(changeMessage);

                        changeMessage = new { type = "set_value", value_name = "wind_direction", value = cells[9] };
                        _webSocketConnection.Send(changeMessage);

                        changeMessage = new { type = "set_value", value_name = "wind_speed", value = cells[10] };
                        _webSocketConnection.Send(changeMessage);

                        changeMessage = new { type = "set_value", value_name = "ambient_temperature", value = cells[12] };
                        _webSocketConnection.Send(changeMessage);

                        changeMessage = new { type = "set_value", value_name = "sun_state", value = light };
                        _webSocketConnection.Send(changeMessage);

                        // Custom field: Rain intensity
                        changeMessage = new { type = "set_value", value_name = "userdefined_double_1", value = cells[16] };
                        _webSocketConnection.Send(changeMessage);

                        // Custom field: Relative humidity
                        changeMessage = new { type = "set_value", value_name = "userdefined_double_2", value = cells[13] };
                        _webSocketConnection.Send(changeMessage);

                        // Custom field: Air pressure
                        changeMessage = new { type = "set_value", value_name = "userdefined_double_3", value = cells[14] };
                        _webSocketConnection.Send(changeMessage);


                        Thread.Sleep(oneSecond);
                    }
                }
            });

            thread.Start();

            Console.WriteLine(">> Press enter to cancel");
            Console.ReadLine();
        }
 static void WebsocketConnection_Return()
 {
     var websocketConnection = new WebsocketConnection();
 }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine(
                    @"Usage:
ConsoleSink.exe 221 ""ws://schuecobe5hackdays.azurewebsites.net/WebSocketServer.ashx?"" ""userdefined_string_1,wind_direction,wind_speed,sun_state,userdefined_double_1,userdefined_double_2,userdefined_double_3""

Where ..
..the first argument is the 'propertyId' (supply 0 for a new one)
..the second argument is the 'endpointUrl'
..the third argument is a list of value_names that should be printed");
                return;
            }

            var propertyId  = int.Parse(args[0]);
            var endpointUrl = args[1];
            var filter      = args[2].Split(',').Select(o => o.Trim()).ToHashSet();

            string currentTickTime = null;
            Tick   currentTick     = null;

            Console.WriteLine($"tick,sensor,value");

            _webSocketConnection            = new WebsocketConnection(propertyId, endpointUrl, true);
            _webSocketConnection.OnMessage += (s, e) =>
            {
                var valueName = e.Message["value_name"];
                if (valueName == null)
                {
                    return;
                }

                var value = e.Message["value"].ToString();

                if (valueName.ToString() == "userdefined_string_1")
                {
                    if (value != currentTickTime)
                    {
                        if (currentTick != null && currentTick.Pairs.Count > 1)
                        {
                            foreach (var pair in currentTick.Pairs)
                            {
                                Console.WriteLine($"{currentTick.Key},{pair.Key},{pair.Value}");
                            }
                        }
                        currentTick     = new Tick(value);
                        currentTickTime = value;
                    }
                }

                if (!filter.Contains(valueName.ToString()))
                {
                    return;
                }

                currentTick?.Collect(valueName.ToString(), value);
            };

            Console.ReadLine();
        }