Esempio n. 1
0
        public void RequestDB()
        {
            var message = new CollectionMessage {
                action       = "reqDB",
                entry        = "",
                newValue     = "",
                oldValue     = "",
                propertyName = ""
            };

            formatter.Serialize(stream, message);
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
        protected internal void SendDB(List <Entry> list)
        {
            CollectionMessage change = new CollectionMessage
            {
                action       = "reqDB",
                entry        = list,
                newValue     = "",
                oldValue     = "",
                propertyName = ""
            };

            formatter.Serialize(stream, change);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        private void SendResponce(string status)
        {
            CollectionMessage change = new CollectionMessage
            {
                action       = "status",
                entry        = status,
                newValue     = "",
                oldValue     = "",
                propertyName = ""
            };

            formatter.Serialize(stream, change);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 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);
         }
     }
 }
Esempio n. 8
0
        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;
                }
            }
        }
Esempio n. 9
0
 public void SendMessage(CollectionMessage message)
 {
 }
Esempio n. 10
0
        private CollectionMessage GetMessage()
        {
            CollectionMessage message = (CollectionMessage)formatter.Deserialize(stream);

            return(message);
        }