Example #1
0
        public RelayCard ConvertToRelayCard()
        {
            RelayCard card = new RelayCard();

            card.Name         = Name;
            card.MacAddress   = MacAddress;
            card.LocalIp      = IP;
            card.LocalPort    = WebPort.ToString();
            card.ConnectLocal = true;
            return(card);
        }
Example #2
0
 /// <summary>
 /// Generates the url form a RelayCard object
 /// </summary>
 /// <returns>The URL.</returns>
 /// <param name="card">Card.</param>
 public static string GenerateUrl(RelayCard card)
 {
     if (card.ConnectLocal)
     {
         return("http://" + card.Username + ":" + card.Password + "@" + card.LocalIp + ":" + card.LocalPort);
     }
     else
     {
         return("http://" + card.Username + ":" + card.Password + "@" + card.ExternalIp + ":" + card.ExternalPort);
     }
 }
Example #3
0
 public int SaveCard(RelayCard item)
 {
     lock (locker) {
         if (item.ID != 0)
         {
             database.Update(item);
             return(item.ID);
         }
         else
         {
             return(database.Insert(item));
         }
     }
 }
Example #4
0
        public RelayCardListPage()
        {
            Title = "Relay Cards";

            listView = new ListView {
                RowHeight = 40
            };
            listView.ItemTemplate = new DataTemplate(typeof(RelayCardCell));
            listView.ItemTemplate.SetBinding(TextCell.TextProperty, "Name");
            listView.IsPullToRefreshEnabled = true;

            listView.Refreshing += (object sender, EventArgs e) => {
                RefreshList();
            };


            if (Device.OS == TargetPlatform.iOS)
            {
                listView.ItemsSource = new string [1] {
                    ""
                };
            }

            var layout = new StackLayout();

            layout.Children.Add(listView);
            layout.VerticalOptions = LayoutOptions.FillAndExpand;
            Content = layout;

            ToolbarItem tbi = new ToolbarItem("+", null, () => {
                var relayCard                = new RelayCard();
                var relayCardPage            = new RelayCardPage();
                relayCardPage.BindingContext = relayCard;
                Navigation.PushAsync(relayCardPage);
            }, ToolbarItemOrder.Default, 0);

            this.ToolbarItems.Add(tbi);
        }
Example #5
0
        private async void SaveInDatabase(RelayCard card)
        {
            RelayCard foundCard = null;
            var       cards     = App.Database.GetCards();

            foreach (RelayCard c in cards)
            {
                if (c.MacAddress == card.MacAddress)
                {
                    foundCard = c;
                }
            }

            if (foundCard != null)
            {
                card.ID = foundCard.ID;
                App.Database.SaveCard(card);
            }
            else
            {
                App.Database.SaveCard(card);
            }
        }
Example #6
0
        public RelayCardDiscoveryPage()
        {
            Title = "Discovery";

            scanner = new DiscoveryScanner();

            listView = new ListView {
                RowHeight = 50
            };
            listView.HasUnevenRows = true;
            listView.ItemTemplate  = new DataTemplate(typeof(TextCell));
            if (Device.OS == TargetPlatform.iOS)
            {
                listView.ItemsSource = new string [1] {
                    ""
                };
            }
            listView.ItemTemplate.SetBinding(TextCell.TextProperty, "Name");
            listView.ItemTemplate.SetBinding(TextCell.DetailProperty, "LocalIp");
            listView.IsPullToRefreshEnabled = true;
            listView.Refreshing            += (object sender, EventArgs e) => {
                scanner.Scan();
            };

            listView.SetBinding(ListView.IsRefreshingProperty, "isScanning");
            listView.BindingContext = scanner;

            listView.ItemTapped += (object sender, ItemTappedEventArgs e) => {
                SelectedCard = (RelayCard)e.Item;

                if (((RelayCard)Navigation.NavigationStack[1].BindingContext).ID == 0)
                {
                    Navigation.NavigationStack[1].BindingContext = SelectedCard;
                }
                else
                {
                    ((RelayCard)Navigation.NavigationStack[1].BindingContext).LocalIp      = SelectedCard.LocalIp;
                    ((RelayCard)Navigation.NavigationStack[1].BindingContext).LocalPort    = SelectedCard.LocalPort;
                    ((RelayCard)Navigation.NavigationStack[1].BindingContext).Name         = SelectedCard.Name;
                    ((RelayCard)Navigation.NavigationStack[1].BindingContext).ConnectLocal = true;
                }
                Navigation.PopAsync(true);
            };

            discoveries = new List <RelayCard> ();

            scanner.DiscoveryFound += (object sender, DiscoveryFoundEventArgs e) => {
                bool isInList = false;
                foreach (RelayCard d in discoveries)
                {
                    if (d.LocalIp == e.Card.IP)
                    {
                        isInList = true;
                    }
                }
                if (!isInList)
                {
                    discoveries.Add(e.Card.ConvertToRelayCard());
                    listView.ItemsSource = null;
                    listView.ItemsSource = discoveries;
                }
            };

            var layout = new StackLayout();

            layout.Children.Add(listView);

            layout.VerticalOptions = LayoutOptions.FillAndExpand;
            Content = layout;
            scanner.Scan();
        }