public GadgetViewModel() { initalLoadGadgets(); newGadgetCom = new RelayCommand <Gadget>((x) => funcNewGadget(), (x) => true); delGadgetCom = new RelayCommand <Gadget>((x) => funcDelGadget(), (x) => true); client.NotificationReceived += (o, e) => { Console.WriteLine("WebSocket::Notification: " + e.Notification.Target + " > " + e.Notification.Type); // demonstrate how these updates could be further used if (e.Notification.Target == typeof(Gadget).Name.ToLower()) { // deserialize the json representation of the data object to an object of type Gadget var gadget = e.Notification.DataAs <Gadget>(); switch (e.Notification.Type) { case WebSocketClientNotificationTypeEnum.Add: Gadgets.Add(gadget); break; case WebSocketClientNotificationTypeEnum.Delete: Gadgets.Remove(gadget); break; } } }; var bgTask = client.ListenAsync(); }
private void CreateNewGadget() { GadgetNotSaved = true; NewGadget = new Gadget(""); Gadgets.Add(NewGadget); SelectedGadget = NewGadget; }
private void AddAgent() { string address = _br.ReadUInt64Hex(); // 8 bytes: Address int pLower = BitConverter.ToUInt16(_br.ReadBytes(2), 0); // 2 bytes: Prof (lower bytes) int pUpper = BitConverter.ToUInt16(_br.ReadBytes(2), 0); // 2 bytes: prof (upper bytes) int isElite = _br.ReadInt32(); // 4 bytes: IsElite int toughness = _br.ReadInt32(); // 4 bytes: Toughness int healing = _br.ReadInt32(); // 4 bytes: Healing int condition = _br.ReadInt32(); // 4 bytes: Condition string name = _br.ReadUTF8(68); // 68 bytes: Name // Add Agent by Type Profession profession = ParseProfession(pLower, pUpper, isElite); switch (profession) { case Profession.Gadget: Gadgets.Add(new Gadget() { Address = address, PseudoId = pLower, Name = name }); return; case Profession.NPC: NPCs.Add(new NPC() { Address = address, SpeciesId = pLower, Toughness = toughness, Healing = healing, Condition = condition, Name = name }); return; default: Players.Add(new Player(name) { Address = address, Profession = profession, Toughness = toughness, Healing = healing, Condition = condition, }); return; } }
private void RefreshGadgets() { Gadgets.Clear(); service.GetAllGadgets().ForEach(g => Gadgets.Add(g)); }