private void SaveConnectionAppBarButton_Click(object sender, EventArgs e)
        {
            int port;
            if(!IsIpAddressValid(IPTextBox.Text))
            {
                MessageBox.Show("Please, enter a valid IPv4 address.", "Invalid IP Address", MessageBoxButton.OK);
                return;
            }

            if (!int.TryParse(PortTextBox.Text, out port))
            {
                MessageBox.Show("Please, enter a valid port number.", "Invalid Port", MessageBoxButton.OK);
                return;
            }

            var newConnection = new ConnectionItem
            {
                ConnectionName = NameTextBox.Text,
                IpAddress = IPTextBox.Text,
                Port = port,
                Username = UsernameTextBox.Text,
                Password = PasswordTextBox.Text
            };
            App.MainVM.AddConnectionItem(newConnection);
            NavigationService.GoBack();
        }
Example #2
0
        public async static Task<bool> Ping(ConnectionItem connectionItem)
        {
            JObject requestObject = new JObject(
                new JProperty("jsonrpc", "2.0"),
                new JProperty("id", 234),
                new JProperty("method", "JSONRPC.ping"));
                
            string requestData = requestObject.ToString();

            HttpClientHandler handler = new HttpClientHandler();
            HttpClient httpClient = new HttpClient(handler);
            string uriString = "http://" + connectionItem.IpAddress + ":" + connectionItem.Port.ToString() + "/jsonrpc?request=";
            httpClient.BaseAddress = new Uri(uriString);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "");

            request.Content = new StringContent(requestData);
            request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); //Required to be recognized as valid JSON request.

            HttpResponseMessage response = await httpClient.SendAsync(request);
            string responseString = await response.Content.ReadAsStringAsync();
            if (responseString.Length == 0)
                return false;
            dynamic responseObject = JObject.Parse(responseString);
            bool isSuccessful = responseObject.result == "pong";
            return isSuccessful;
        }
        private async Task Connect(ConnectionItem connectionItem)
        {
            SetPageState(PageStates.Connecting);

            bool isSuccessful = await JSONRPC.Ping(connectionItem);
            if (isSuccessful)
            {
                ConnectionManager.CurrentConnection = connectionItem;
                SettingsHelper.SetValue("RecentServerIP", connectionItem.IpAddress);
                NavigationService.Navigate(new Uri("/CoverPage.xaml", UriKind.Relative));
            }
            else
            {
                MessageBox.Show("Could not reach the server.", "Connection Unsuccessful", MessageBoxButton.OK);
            }
            SetPageState(PageStates.Ready);
        }
Example #4
0
 public void UpdateConnectionItem(ConnectionItem itemToUpdate)
 {
     mainDB.SubmitChanges();
 }
Example #5
0
 public void RemoveConnectionItem(ConnectionItem itemToRemove)
 {
     mainDB.ConnectionItems.DeleteOnSubmit(itemToRemove);
     mainDB.SubmitChanges();
     ConnectionItems.Remove(itemToRemove);
 }
Example #6
0
 public void AddConnectionItem(ConnectionItem itemToAdd)
 {
     mainDB.ConnectionItems.InsertOnSubmit(itemToAdd);
     mainDB.SubmitChanges();
     ConnectionItems.Add(itemToAdd);
 }