コード例 #1
0
        private async void ConnectAndForward(int index)
        {
            var local    = Convert.ToInt32(devices_list[index].Item3.Text);
            var remote   = Convert.ToInt32(devices_list[index].Item4.Text);
            var deviceId = deviceDict[devices_list[index].Item2.Text].GetProperty("id").GetInt32();

            var success = await Task.Run(() =>
            {
                try
                {
                    return(SSH.BeginForwarding(deviceId, local, remote));
                }
                catch (FormatException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    return(false);
                }
            });

            if (success)
            {
                var indexes = new Tuple <int, int, string>(local, index, devices_list[index].Item2.Text);
                devices_list[index].Item5.Content = "Disconnect";
                devices_list[index].Item5.Tag     = indexes;
                devices_list[index].Item5.Click  -= Connect_Click;
                devices_list[index].Item5.Click  += Disconnect_Click;
                devices_list[index].Item1.Fill    = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2dbf71"));
                var tooltip = new ToolTip
                {
                    Content = "Connected to " + devices_list[index].Item2.Text + " - Forwarding local port: " + local
                };
                devices_list[index].Item1.ToolTip = tooltip;
                ((App)Application.Current).AddConnectionToContextMenu(index, "Disconnect from " + devices_list[index].Item2.Text);
            }
        }
コード例 #2
0
 private void Disconnect_Click(object sender, EventArgs e)
 {
     foreach (ToolStripMenuItem connection in this.connections.DropDownItems)
     {
         if (connection.Tag == ((ContextMenuStrip)sender).Tag)
         {
             this.connections.DropDownItems.Remove(connection);
             break;
         }
     }
     SSH.StopForwarding((int)((ContextMenuStrip)sender).Tag);
 }
コード例 #3
0
        public static async void CreateTunnelKey()
        {
            var response = await client.PostAsync(api_base + "tunnelkeys", null);

            if (response.IsSuccessStatusCode)
            {
                var jsonresponse = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(await response.Content.ReadAsStringAsync());
                SSH.SaveRSAKey(
                    Encoding.ASCII.GetBytes(jsonresponse["data"].GetProperty("public_key").GetString()),
                    Encoding.ASCII.GetBytes(jsonresponse["data"].GetProperty("private_key").GetString()));
            }
        }
コード例 #4
0
        private void Disconnect_Click(object sender, RoutedEventArgs e)
        {
            var indexes = (Tuple <int, int, string>)((Button)sender).Tag;

            devices_list[indexes.Item2].Item5.Content = "Connect";
            devices_list[indexes.Item2].Item5.Tag     = indexes.Item2;
            devices_list[indexes.Item2].Item5.Click  += Connect_Click;
            devices_list[indexes.Item2].Item5.Click  -= Disconnect_Click;
            devices_list[indexes.Item2].Item1.Fill    = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#f24569"));
            devices_list[indexes.Item2].Item1.ToolTip = null;
            ((App)Application.Current).RemoveConnectionToContextMenu("Disconnect from " + indexes.Item3);
            SSH.StopForwarding(indexes.Item1);
        }