예제 #1
0
        private void Client_DataReceived(object sender, Message e)
        {
            var packet = Helper.ByteArrayToObject(e.Data) as Packet;

            lock (Callbacks)
            {
                if (Callbacks.ContainsKey(packet.ID))
                {
                    Callbacks[packet.ID]?.Invoke(packet.Data);
                    Callbacks.Remove(packet.ID);
                }
            }
            (new Thread(new ThreadStart(delegate()
            {
                switch (packet.Type)
                {
                case PacketType.Broadcast_UploadTables:
                    Application.Current.Dispatcher.Invoke(delegate()
                    {
                        Settings.InvokeSchoolsChanged();
                        Settings.InvokeUpload();
                    });
                    break;

                case PacketType.Broadcast_UploadSchools:
                    Application.Current.Dispatcher.Invoke(delegate()
                    {
                        Settings.InvokeSchoolsChanged();
                    });
                    break;

                case PacketType.Broadcast_LocationChanged:
                    Application.Current.Dispatcher.Invoke(delegate()
                    {
                        Settings.Location = packet.Data as Models.LocationModel;
                        Settings.InvokeLocationChanged(null);
                    });
                    break;

                case PacketType.Broadcast_TimerStarted:
                    Application.Current.Dispatcher.Invoke(delegate()
                    {
                        Settings.InvokeTimerStarted();
                    });
                    break;
                }
            }))).Start();
        }
예제 #2
0
        public void Broadcast(PacketType type, object data = null)
        {
            var packet = new Packet()
            {
                Type = type,
                ID   = -100,
                Data = data
            };

            try
            {
                MyBroadcast(Helper.ObjectToByteArray(packet));
            }
            catch (Exception)
            {
                Broadcast(type, data);
            }


            new Thread(new ThreadStart(delegate()
            {
                Application.Current.Dispatcher.Invoke(delegate()
                {
                    switch (type)
                    {
                    case PacketType.Broadcast_UploadTables:
                        Settings.InvokeSchoolsChanged();
                        Settings.InvokeUpload();
                        break;

                    case PacketType.Broadcast_UploadSchools:
                        Settings.InvokeSchoolsChanged();
                        break;
                    }
                });
            })).Start();
        }