Example #1
0
 private void OnConnectionClosed(object sender, Exception e, SynchronizationContext context)
 {
     context.Send((object state) =>
     {
         List <RaspberryPiItem> disconnectedList = BackendList.Where(item => item.raspi == (RaspberryPi)sender).ToList();
         RaspberryPiItem piItem = disconnectedList.FirstOrDefault();
         piItem.Status          = "available";
         piItem.Connected       = false;
         CollectionViewSource.GetDefaultView(BackendList).Refresh();
         debugVM.AddDebugInfo(piItem.endpoint.ToString(), "ConnectionClosed: " + e.Message);
     }, null);
 }
Example #2
0
        public void addRaspberryPi(string Address, string status)
        {
            //IsPiConnected = false;
            IPAddress address;

            try
            {
                address = IPAddress.Parse(Address);
            }
            catch (FormatException fx)
            {
                debugVM.AddDebugInfo("[ERROR]", "Invalid IP Address Format: " + fx.Message);
                return;
            }
            IPEndPoint endpoint = new IPEndPoint(address, 54321);

            foreach (var entry in BackendList)
            {
                if (entry.endpoint.Equals(endpoint))
                {
                    debugVM.AddDebugInfo("addRaspberryPi", "Already in the List");
                    return;
                }
            }

            RaspberryPi            raspi     = new RaspberryPi();
            SynchronizationContext uiContext = SynchronizationContext.Current;

            raspi.ConnectionClosed += (object sender, Exception e) => OnConnectionClosed(sender, e, uiContext);
            RaspberryPiItem raspiItem = new RaspberryPiItem()
            {
                endpoint = endpoint, Status = status, raspi = raspi, Connected = false
            };

            BackendList.Add(raspiItem);
            SelectedRaspiItem = raspiItem;
            CollectionViewSource.GetDefaultView(BackendList).Refresh();
        }