Esempio n. 1
0
        public async Task<Beacon> Ping(Guid uuid, int major, int minor, int proximity = 0)
        {
            var beaconProvider = TypeResolver.IBeaconProvider;

            var ret = beaconProvider.FindBeacon(uuid, major, minor);

            using (var db = new Context())
            {
                var client = await db.Clients.FindAsync(ClientID);
                db.Beacons.Attach(ret);

                var ping = new BeaconPing
                {
                    Client = client,
                    Date = DateTime.Now,
                    Beacon = ret,
                    Proximity = proximity
                };

                db.BeaconPings.Add(ping);
                await db.SaveChangesAsync();

                await TypeResolver.IScreenManager.UpdateClient(ping);

            }

            return ret;
        }
Esempio n. 2
0
        public async Task UpdateClient(BeaconPing ping)
        {

            var screens = Sockets.Keys.ToList();

            var msg = new
            {
                msg = "client",
                clientid = ping.Client.ClientID,
                uuid = ping.Beacon.UUID,
                major = ping.Beacon.Major,
                minor = ping.Beacon.Minor,
                name = ping.Client.Name ?? "Unnamed"
            };

            
            foreach (var socket in screens)
            {
                WebSocket ws = Sockets[socket];

                try
                {
                    if (ws.State != WebSocketState.Open)
                    {
                        RemoveScreen(socket);
                        continue;
                    }

                    await ws.sendObject(msg);
                }
                catch (ObjectDisposedException)
                {
                    RemoveScreen(socket);
                }
                
            }
        }