Example #1
0
 /// <summary>
 /// Used when editing an existing station
 /// </summary>
 /// <param name="main"></param>
 /// <param name="station">The station to edit</param>
 public EditStationWindow(MainWindow main, IStation station)
 {
     InitializeComponent();
     mainWindow    = main;
     stationToEdit = station;
     PopulateElements();
 }
        private void StationList_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is ListView view)
            {
                if (view.SelectedIndex > stationManager.stations.list.Count || view.SelectedIndex == -1)
                {
                    return;
                }

                IStation station = stationManager.stations.list[view.SelectedIndex];
                selectedStation = station;
                SetSelectedStationStatus();

                if (station.Status != "Available")
                {
                    JoinSession_MenuItem.IsEnabled = true;
                    TakeOver_MenuItem.IsEnabled    = true;
                }
                else
                {
                    JoinSession_MenuItem.IsEnabled = false;
                    TakeOver_MenuItem.IsEnabled    = false;
                }
            }
        }
 public void SetStationStatus(IStation station, string status)
 {
     station.Status = status;
     stationManager.SaveLocalStationList();
     UpdateStationStatusListUI();
     if (selectedStation != null)
     {
         StationList.SelectedItem = StationList.Items.IndexOf(station);
     }
 }
        /// <summary>
        /// Updates the station information based on its return status.
        /// </summary>
        /// <param name="station">Which station to check</param>
        /// <param name="mainWindow">Referens to the MainWindow</param>
        public static void UpdateStationStatus(IStation station, MainWindow mainWindow)
        {
            // Get the return status
            string status = StationOccupied(station).ToString();

            // Set the station status for station in list
            mainWindow.SetStationStatus(station, status);

            // Set the station status for selected station box
            mainWindow.SetSelectedStationStatus();
        }
Example #5
0
 /// <summary>
 /// Attempts to add a new station to the list. Returns FALSE if station with given name alread exists.
 /// </summary>
 /// <param name="station"></param>
 /// <returns></returns>
 public bool AddStationToList(IStation station)
 {
     LoadLocalStationList();
     foreach (IStation s in stations.list)
     {
         if (s.Name == station.Name)
         {
             return(false);
         }
     }
     stations.list.Add(station);
     SaveLocalStationList();
     return(true);
 }
        private void Disconnected(IStation station)
        {
            if (connectedStation == null)
            {
                return;
            }

            //Console.WriteLine($"User: {Settings.data.user} disconnected from station: {station.Name}");
            stationManager.stations.list.Find(s => s.Name == station.Name).Status = "Available";

            connectedStation = null;
            UpdateStationStatusListUI();
            stationManager.SaveLocalStationList();
        }
        private void StationList_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is ListView view)
            {
                if (view.SelectedIndex > stationManager.stations.list.Count || view.SelectedIndex == -1)
                {
                    return;
                }

                IStation station = stationManager.stations.list[view.SelectedIndex];
                selectedStation = station;
                SetSelectedStationStatus();
            }
        }
        private void ConnectToStation(IStation station, bool takeover)
        {
            if (station == null)
            {
                return;
            }
            // Reload Station information
            stationManager.LoadLocalStationList();
            Command.UpdateStationStatus(station, this);

            // Update UIs
            UpdateStationStatusListUI();
            SetSelectedStationStatus();

            if (station.Status == "Occupied" && !takeover)
            {
                MessageBox.Show("This station is currently occupied by another user.\nRight-Click allows sesison join/take over", "Session Occupied");
                return;
            }

            string process = "";

            process += " /v:" + station.Ip;

            Process RemoteConnectProcess = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = "mstsc.exe",
                    Arguments              = process,
                    CreateNoWindow         = true,
                    WindowStyle            = ProcessWindowStyle.Maximized,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false
                }
            };

            RemoteConnectProcess.Start();
            RemoteConnectProcess.WaitForInputIdle();
            Connected(station);

            var outputResultPromise = RemoteConnectProcess.StandardOutput.ReadToEndAsync();

            outputResultPromise.ContinueWith(o => Disconnected(station));
        }
        protected override void OnPreviewKeyUp(KeyEventArgs e)
        {
            base.OnPreviewKeyDown(e);
            if (StationList.SelectedItem == null || !IsActive)
            {
                return;
            }

            if (e.Key == Key.Down || e.Key == Key.Up)
            {
                IStation selected = StationList.SelectedItem as IStation;
                if (selected != null)
                {
                    selectedStation = selected;
                    SetSelectedStationStatus();
                }
            }
        }
Example #10
0
        /// <summary>
        /// Checks status of station based on output from the command quser
        /// </summary>
        /// <param name="station"></param>
        /// <returns></returns>
        private static ReturnStatus StationOccupied(IStation station)
        {
            IntPtr val = IntPtr.Zero;

            Wow64DisableWow64FsRedirection(ref val);

            // Setup quser-process info
            Process proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = "cmd.exe",
                    Arguments              = "/c quser /server:" + station.Ip,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true,
                }
            };

            List <string> lines = new List <string>();

            //Start the process
            proc.Start();
            ReturnStatus status = ReturnStatus.Unknown;

            station.SessionID = string.Empty;

            // Listen for all output by process
            while (!proc.StandardOutput.EndOfStream)
            {
                // Read every line that is output, this waits until new line is available.
                string line = proc.StandardOutput.ReadLine();
                if (line != null)
                {
                    lines.Add(line.ToLower());
                }

                // If lines contains more than 1, users listed on station.
                if (lines.Count > 1)
                {
                    // Split all lines between spaces
                    List <string> connectionDetails = new List <string>();
                    connectionDetails.AddRange(lines[1].Split(' '));
                    connectionDetails = connectionDetails.Where(s => !string.IsNullOrWhiteSpace(s)).ToList();

                    // Found what we wanted from the process, it can be disposed
                    proc.Dispose();
                    Wow64EnableWow64FsRedirection(ref val);

                    // If one of the split strings contains 'active', then there is an active connection.
                    if (connectionDetails.Count > 3 && connectionDetails[3] == "active")
                    {
                        // ConnectionDetails[2] contains the RDP-ID for the active session,
                        // needed if we want to join this session.
                        station.SessionID = connectionDetails[2];

                        //connectione exists and is occupied
                        status = ReturnStatus.Occupied;
                        break;
                    }

                    //connection exists and is available, no ID is joinable.
                    status = ReturnStatus.Available;
                    break;
                }
            }

            proc.Dispose();
            Wow64EnableWow64FsRedirection(ref val);

            return(status);
        }
 private void Connected(IStation station)
 {
     connectedStation = station;
     UpdateStationStatusListUI();
     stationManager.SaveLocalStationList();
 }
        public void OpenStationManager(IStation station)
        {
            EditStationWindow popup = new EditStationWindow(this, station);

            popup.ShowDialog();
        }
Example #13
0
        /// <summary>
        /// Saves the information provided to the station list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Click_SaveStation(object sender, RoutedEventArgs e)
        {
            // Used to store multiple 'errors'
            string errorMsg = string.Empty;

            // If no station name has been assigned to the StationNameTextbox
            if (string.IsNullOrEmpty(StationName.Text))
            {
                errorMsg += "Station needs a name!.";
            }

            // If no station Ip has been assigned to the StationIpTextbox
            if (string.IsNullOrEmpty(StationIp.Text))
            {
                errorMsg += "\nStation needs an IP-Adress.";
            }

            // If any errors exist, display them with a MessageBox
            if (!string.IsNullOrEmpty(errorMsg))
            {
                MessageBox.Show(errorMsg, "Invalid Station Settings!", MessageBoxButton.OK);
                return;
            }

            // Type does not have to be specified, default to 'Unspecified' if none has been provided.
            if (string.IsNullOrEmpty(StationType.Text))
            {
                StationType.Text = "Unspecified";
            }

            // StationToEdit is null if we want to CREATE a new station
            if (stationToEdit == null)
            {
                // Create the new station with relevant information
                IStation newStation = new IStation()
                {
                    Name  = StationName.Text,
                    Type  = StationType.Text,
                    Ip    = StationIp.Text,
                    Group = (StationGroup)GroupBox.SelectedIndex
                };

                // Double check that no station with said name exists already.
                if (!mainWindow.stationManager.AddStationToList(newStation))
                {
                    MessageBox.Show("Station with that name already exists!\n Edit existing station or use another name.", "Station already exists!", MessageBoxButton.OK);
                    return;
                }
            }
            // StationToEdit is NOT null if we want to EDIT an exisiting station
            else
            {
                //Update existing station with relevant information.
                stationToEdit.Name  = StationName.Text;
                stationToEdit.Type  = StationType.Text;
                stationToEdit.Ip    = StationIp.Text;
                stationToEdit.Group = (StationGroup)GroupBox.SelectedIndex;
                stationToEdit       = null;
            }

            // Save the station list after adding/editing and close this window.
            mainWindow.stationManager.SaveLocalStationList();
            CloseWindow();
        }