Beispiel #1
0
            public bool LoadConnections(string fileName)
            {
                bool result = false;

                if (fileName == null || fileName == "")
                {
                    fileName = AppDomain.CurrentDomain.BaseDirectory + "\\RDPConnections.xml";
                }

                try
                {
                    connectionList = new List <RDPConnection>();

                    XDocument doc = XDocument.Load(fileName);
                    int       i   = 0;
                    foreach (var item in doc.Root.Elements())
                    {
                        int order = 0;

                        RDPFunctions.RDPConnection rdp = new RDPFunctions.RDPConnection();

                        int.TryParse(Helpers.TryGetElementValue(item, "Order", "0"), out order);

                        rdp.Host     = Helpers.TryGetElementValue(item, "Host", "");
                        rdp.Name     = Helpers.TryGetElementValue(item, "Name", "");
                        rdp.UserName = Helpers.TryGetElementValue(item, "UserName", "");
                        rdp.Password = Helpers.TryGetElementValue(item, "Password", "");
                        rdp.Group    = Helpers.TryGetElementValue(item, "Group", "");

                        bool isdefault = false;
                        bool.TryParse(Helpers.TryGetElementValue(item, "Default", "false"), out isdefault);
                        if (isdefault)
                        {
                            hasDefaultConnection = true;
                            rdp.IsDefault        = true;
                        }

                        i++;
                        if (order > 0)
                        {
                            rdp.Order = order;
                        }
                        else
                        {
                            rdp.Order = i;
                        }

                        connectionList.Add(rdp);
                    }

                    result = true;
                }
                catch (Exception e)
                {
                    lastErrorMessage = e.Message;
                    NotifyPropertyChanged("LastErrorMessage");
                }

                return(result);
            }
Beispiel #2
0
        /// <summary>
        /// load rdp connections from file
        /// </summary>
        /// <param name="confirm">show confirmation dialog</param>
        private void ReadRDPConnections(bool confirm)
        {
            if (confirm)
            {
                MessageBoxResult result = MessageBox.Show("RDP Verbindungen aus Datei laden?", "Laden", MessageBoxButton.YesNo);
                if (result != MessageBoxResult.Yes)
                {
                    return;
                }
            }

            connections.LoadConnections();
            connectionList = new ObservableCollection <RDPFunctions.RDPConnection>(connections.ConnectionList);
            NotifyPropertyChanged("ConnectionList");
            //if (connections.ConnectionList.Count>0)
            //{
            //    selectedRDPConnection = connections.ConnectionList.First();
            //}
            if (connectionList.Count > 0)
            {
                selectedRDPConnection = connectionList.First();
            }
        }