public void RequestDB() { var message = new CollectionMessage { action = "reqDB", entry = "", newValue = "", oldValue = "", propertyName = "" }; formatter.Serialize(stream, message); }
protected internal void BroadcastMessage(CollectionMessage message, string id) { IFormatter formatter = new BinaryFormatter(); foreach (var client in clients) { if (client.Id != id) { formatter.Serialize(client.stream, message); } } }
protected internal void SendDB(List <Entry> list) { CollectionMessage change = new CollectionMessage { action = "reqDB", entry = list, newValue = "", oldValue = "", propertyName = "" }; formatter.Serialize(stream, change); }
private void SendResponce(string status, int oldNumber, int newNumber) { CollectionMessage change = new CollectionMessage { action = "status", entry = status, newValue = oldNumber.ToString(), oldValue = newNumber.ToString(), propertyName = "" }; formatter.Serialize(stream, change); }
private void SendResponce(string status) { CollectionMessage change = new CollectionMessage { action = "status", entry = status, newValue = "", oldValue = "", propertyName = "" }; formatter.Serialize(stream, change); }
public void ItemChanged(Entry entry, PropertyChangedExtendedEventArgs e) { IFormatter formatter = new BinaryFormatter(); CollectionMessage change = new CollectionMessage { action = "cha", entry = entry, newValue = e.NewValue, oldValue = e.OldValue, propertyName = e.PropertyName }; sendQueue.Enqueue(change); formatter.Serialize(stream, change); }
public void CollectionChanged(NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (Entry entry in e.NewItems) { IFormatter formatter = new BinaryFormatter(); CollectionMessage change = new CollectionMessage { action = "add", entry = entry, newValue = "", oldValue = "", propertyName = "" }; sendQueue.Enqueue(change); formatter.Serialize(stream, change); } } if (e.OldItems != null) { foreach (Entry entry in e.OldItems) { IFormatter formatter = new BinaryFormatter(); CollectionMessage change = new CollectionMessage { action = "rem", // Who is Rem? entry = entry, newValue = "", oldValue = "", propertyName = "" }; sendQueue.Enqueue(change); formatter.Serialize(stream, change); } } }
public void RecieveMessage() { RequestDB(); while (true) { try { CollectionMessage message = (CollectionMessage)formatter.Deserialize(stream); switch (message.action) { case "reqDB": if (message.entry is List <Entry> collection) { App.Current.Dispatcher.Invoke((Action) delegate { Entries.AddRange(collection); }); } else { throw new InvalidOperationException("Couldn't load"); } break; case "add": if (message.entry is Entry newEntry) { App.Current.Dispatcher.Invoke((Action) delegate { Entries.RecievedAdd(newEntry); }); } else { throw new InvalidOperationException("Couldn't add entries"); } break; case "cha": if (message.entry is Entry chaEntry) { App.Current.Dispatcher.Invoke((Action) delegate { Entry destination = Entries.First(r => r.Number == chaEntry.Number); if (destination != null && destination[message.propertyName].ToString() == message.oldValue) { destination[message.propertyName] = chaEntry[message.propertyName]; } }); } else { throw new InvalidOperationException("Couldn't change entries"); } break; case "rem": if (message.entry is Entry oldEntry) { App.Current.Dispatcher.Invoke((Action) delegate { Entries.RecievedRemove(oldEntry); }); } else { throw new InvalidOperationException("Couldn't remove entries"); } break; case "status": if ((string)message.entry == "S_OK") { sendQueue.TryDequeue(out CollectionMessage successfulMessage); } else if ((string)message.entry == "S_ADD") { sendQueue.TryDequeue(out CollectionMessage successfulMessage); App.Current.Dispatcher.Invoke((Action) delegate { ((Entry)successfulMessage.entry).Number = Int32.Parse(message.newValue); }); } else { sendQueue.TryDequeue(out CollectionMessage failedMessage); sendQueue.Enqueue(failedMessage); throw new IndexOutOfRangeException(); } break; } } catch (Exception ex) { int i = 0; } } }
public void SendMessage(CollectionMessage message) { }
private CollectionMessage GetMessage() { CollectionMessage message = (CollectionMessage)formatter.Deserialize(stream); return(message); }