コード例 #1
0
        public RecentComputerList Read( TextReader reader )
        {
            RecentComputerList computers = new RecentComputerList();

            while ( true )
            {
                string line = reader.ReadLine();
                if ( line == null )
                    break;

                string[] pair = line.Split( '\t' );

                // Avoid processing an empty line
                if ( pair[0] == "" )
                    continue;
                string computer = pair[0];

                string alias = pair.Length > 1 ? pair[1] : "";

                bool adminMode = false;
                if ( pair.Length > 2 )
                    bool.TryParse( pair[2], out adminMode );

                computers.Add( new ComputerName( computer, alias, adminMode ) );
            }

            return computers;
        }
コード例 #2
0
        // Does not throw.
        public RecentComputerList ReadFromRegistry( )
        {
            RecentComputerList computers = new RecentComputerList();

            try
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey( "Software" )
                    .OpenSubKey( "Microsoft" )
                    .OpenSubKey( "Terminal Server Client" )
                    .OpenSubKey( "Default", false );

                const int MaxComputerCount = 10;
                for ( int i = 0; i < MaxComputerCount; ++i )
                {
                    string valueName = string.Format( "MRU{0}", i );
                    string computer = (string) key.GetValue( valueName );
                    if ( !string.IsNullOrEmpty( computer ) )
                        computers.Add( new ComputerName( key.GetValue( valueName ).ToString(), null ) );
                }
            }
            catch ( Exception ex )
            {
                Logger.LogException( ex );
            }

            return computers;
        }
コード例 #3
0
        public void Populate( RecentComputerList computers )
        {
            m_computers = computers;

            BeginUpdate();
            this.Items.Clear();
            this.Items.AddRange( computers.ToArray() );
            this.MaxDropDownItems = Config.MaxComboItems;
            EndUpdate();
        }
コード例 #4
0
        public void EditComputerList( )
        {
            var process = new System.Diagnostics.Process();
            process.StartInfo.FileName = "notepad.exe";
            process.StartInfo.Arguments = ComputerListFile.GetComputerListFilePath();
            process.Start();

            process.WaitForExit();

            m_RecentComputerList = LoadRecentComputerList();
            OnComputerListUpdated();
        }
コード例 #5
0
        /// <summary>
        /// Logs the current computer list.
        /// </summary>
        public static void LogComputerList( string message, RecentComputerList computerList )
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat( "{0} {1}:\r\n", DateTime.Now, message );
            foreach ( ComputerName computer in computerList )
            {
                sb.AppendLine( computer.ToString() );
            }

            Logger logger = new Logger();
            logger.Log( sb.ToString() );
        }
コード例 #6
0
        public void Clear( )
        {
            RecentComputerList computers = new RecentComputerList();

            computers.Add( new ComputerName( "cpu1", null ) );
            Assert.AreEqual( new string[] {
                "cpu1" },
                GetComputers( computers ) );

            computers.Clear();

            Assert.AreEqual( new string[0],
                GetComputers( computers ) );
        }
コード例 #7
0
        public void WriteFile( )
        {
            RecentComputerList computers = new RecentComputerList();
            computers.Add( new ComputerName( "1.1.1.1", "alias", true ) );
            computers.Add( new ComputerName( "work", null, false ) );

            StringWriter writer = new StringWriter();
            ComputerListFile serializer = new ComputerListFile();
            serializer.Write( writer, computers );

            Assert.AreEqual(
                "1.1.1.1\talias\tTrue\r\n" +
                "work\t\tFalse\r\n",
                writer.ToString() );
        }
コード例 #8
0
        public void Add( )
        {
            RecentComputerList computers = new RecentComputerList();

            Assert.IsTrue( computers.Add( new ComputerName( "cpu1", null ) ) );
            Assert.AreEqual( new string[] {
                "cpu1" },
                GetComputers( computers ) );

            Assert.IsTrue( computers.Add( new ComputerName( "cpu2", null ) ) );
            Assert.AreEqual( new string[] {
                "cpu1",
                "cpu2" },
                GetComputers( computers ) );

            RecentComputerList fullList = ListFromStrings( new string[]
            {
                "aaaa",
                "bbbb",
                "cccc",
                "dddd",
                "eeee",
                "ffff",
                "gggg",
                "hhhh",
                "iiii",
                "jjjj"
            } );

            Assert.IsFalse( fullList.Add( new ComputerName( "cpu1", null ) ) );

            Assert.AreEqual( new string[]
            {
                "aaaa",
                "bbbb",
                "cccc",
                "dddd",
                "eeee",
                "ffff",
                "gggg",
                "hhhh",
                "iiii",
                "jjjj"
            },
            GetComputers( fullList ) );
        }
コード例 #9
0
 public void Write( TextWriter writer, RecentComputerList computers )
 {
     foreach ( ComputerName cname in computers )
     {
         writer.WriteLine( "{0}\t{1}\t{2}", cname.Computer, cname.Alias, cname.AdminMode );
     }
 }
コード例 #10
0
        public void LoadInitData( )
        {
            var config = new ConfigFileSerializer();
            config.Read();

            m_RecentComputerList = LoadRecentComputerList();

            OnComputerListUpdated();
        }
コード例 #11
0
        private RecentComputerList ListFromStrings( string[] cnames )
        {
            RecentComputerList computers = new RecentComputerList();

            foreach ( string cname in cnames )
            {
                computers.Add( new ComputerName( cname, null ) );
            }

            return computers;
        }
コード例 #12
0
        private string[] GetComputers( RecentComputerList recentList )
        {
            string[] computers = new string[recentList.Count];

            int index = 0;
            foreach ( ComputerName name in recentList )
            {
                computers[index] = name.Computer;
                ++index;
            }

            return computers;
        }
コード例 #13
0
        public void Contains( )
        {
            RecentComputerList computers = new RecentComputerList();

            computers.Add( new ComputerName( "cpu1", null ) );
            computers.Add( new ComputerName( "cpu2", "alias2" ) );

            // Basic check
            Assert.IsTrue( computers.Contains( new ComputerName( "cpu1", null ) ) );
            // Must match both computer and alias.
            Assert.IsFalse( computers.Contains( new ComputerName( "cpu1", "alias1" ) ) );
            Assert.IsTrue( computers.Contains( new ComputerName( "cpu2", "alias2" ) ) );
            // Case insensitive for computer name and alias.
            Assert.IsTrue( computers.Contains( new ComputerName( "CPU2", "alias2" ) ) );
            Assert.IsTrue( computers.Contains( new ComputerName( "cpu2", "ALIAS2" ) ) );
        }
コード例 #14
0
        public void VariableMaxComputerCount( )
        {
            RecentComputerList list = new RecentComputerList( 4, 3 );
            list.Push( new ComputerName( "eeee", null ) );
            list.Push( new ComputerName( "dddd", null ) );
            list.Push( new ComputerName( "cccc", null ) );
            list.Push( new ComputerName( "bbbb", null ) );
            list.Push( new ComputerName( "aaaa", null ) );

            Assert.AreEqual( new string[]
            {
                "aaaa",
                "bbbb",
                "cccc",
                "dddd"
            },
            GetComputers( list ) );

            list.MaxComputerCount = 5;
            list.Push( new ComputerName( "eeee", null ) );

            Assert.AreEqual( new string[]
            {
                "eeee",
                "aaaa",
                "bbbb",
                "cccc",
                "dddd"
            },
            GetComputers( list ) );
        }
コード例 #15
0
        public void CopyCtor( )
        {
            var computers = new RecentComputerList();
            computers.Add( new ComputerName( "1.1.1.1", "work", true ) );
            computers.Add( new ComputerName( "2.2.2.2", "home", false ) );

            var otherComps = new RecentComputerList( computers );

            // Did we copy?
            Assert.AreEqual( new ComputerName[]
                {
                    new ComputerName( "1.1.1.1", "work", true ),
                    new ComputerName( "2.2.2.2", "home", false )
                },
                otherComps.ToArray() );

            // Are the underlying lists different objects?
            computers.Remove( computers.Find( "home" ) );
            Assert.AreEqual( 1, computers.Count );
            Assert.AreEqual( 2, otherComps.Count );

            // Are the underlayng ComputerName different objects?
            foreach ( var name in computers )
            {
                name.Alias = null;
            }
            Assert.IsNull( computers.Find( "work" ) );
            Assert.IsNotNull( otherComps.Find( "work" ) );
        }
コード例 #16
0
 protected void OnComputerListUpdated( )
 {
     if ( ComputerListUpdated != null )
     {
         // We copy the list since this will run on another thread.
         var computers = new RecentComputerList( m_RecentComputerList );
         ComputerListUpdated( this, new DataEventArgs( computers ) );
     }
 }
コード例 #17
0
 public void Write( string filePath, RecentComputerList computers )
 {
     using ( StreamWriter writer = File.CreateText( filePath ) )
     {
         Write( writer, computers );
     }
 }
コード例 #18
0
        public void GetAliases( )
        {
            RecentComputerList computers = new RecentComputerList();
            computers.Add( new ComputerName( "1.1.1.1", null ) );
            computers.Add( new ComputerName( "2.2.2.2", "work" ) );
            computers.Add( new ComputerName( "3.3.3.3", null ) );
            computers.Add( new ComputerName( "4.4.4.4", "home" ) );

            Assert.AreEqual( new string[] { "work", "home" }, computers.GetAliases().ToArray() );

            // Test with no aliases
            computers = new RecentComputerList();
            computers.Add( new ComputerName( "1.1.1.1", null ) );

            Assert.AreEqual( new string[0], computers.GetAliases().ToArray() );

            // Test with no items
            computers = new RecentComputerList();

            Assert.AreEqual( new string[0], computers.GetAliases().ToArray() );
        }
コード例 #19
0
        public void Find( )
        {
            RecentComputerList computers = new RecentComputerList();
            ComputerName withAlias = new ComputerName( "1.1.1.1", "alias" );
            ComputerName justComputer = new ComputerName( "work", null );
            computers.Add( withAlias );
            computers.Add( justComputer );

            // Find by alias
            Assert.AreEqual( withAlias, computers.Find( "alias" ) );
            // Find by computer
            Assert.AreEqual( withAlias, computers.Find( "1.1.1.1" ) );
            // Find with no alias
            Assert.AreEqual( justComputer, computers.Find( "work" ) );
            // Find by alias, case insensitive
            Assert.AreEqual( withAlias, computers.Find( "ALIAS" ) );
            // Find by computer, case insensitive
            Assert.AreEqual( justComputer, computers.Find( "WORK" ) );
            // Not found
            Assert.IsNull( computers.Find( "foobar" ) );
        }
コード例 #20
0
        public void DuplicateAlias( )
        {
            RecentComputerList computers = new RecentComputerList();
            computers.Add( new ComputerName( "1.1.1.1", "work" ) );
            computers.Add( new ComputerName( "2.2.2.2", "CASE" ) );

            computers.Push( new ComputerName( "3.3.3.3", "work" ) );

            // Alias is removed from the old item.
            Assert2.AssertComputerNames( new string[]
            {
                "3.3.3.3", "work",
                "1.1.1.1", null,
                "2.2.2.2", "CASE",
            }, computers.ToArray() );

            // Confirm case sensitive.
            computers.Push( new ComputerName( "4.4.4.4", "case" ) );

            Assert2.AssertComputerNames( new string[]
            {
                "4.4.4.4", "case",
                "3.3.3.3", "work",
                "1.1.1.1", null,
                "2.2.2.2", null,
            }, computers.ToArray() );
        }
コード例 #21
0
        public void Count( )
        {
            RecentComputerList computers = new RecentComputerList();
            Assert.AreEqual( 0, computers.Count );

            computers.Add( new ComputerName( "cpu1", "alias1" ) );
            Assert.AreEqual( 1, computers.Count );

            computers.Add( new ComputerName( "cpu2", "alias2" ) );
            Assert.AreEqual( 2, computers.Count );
        }
コード例 #22
0
        public void CopyTo( )
        {
            ICollection<ComputerName> collection = new RecentComputerList();
            collection.Add( new ComputerName( "cpu1", "alias1" ) );
            collection.Add( new ComputerName( "cpu2", "alias2" ) );

            ComputerName[] array = new ComputerName[3];
            array[0] = new ComputerName( "0.0.0.0", "zero" );
            collection.CopyTo( array, 1 );

            Assert2.AssertComputerNames( new string[]
            {
                "0.0.0.0", "zero",
                "cpu1", "alias1",
                "cpu2", "alias2",
            }, array );
        }
コード例 #23
0
 public void Write( RecentComputerList computers )
 {
     try
     {
         Write( GetComputerListFilePath(), computers );
     }
     catch ( Exception ex )
     {
         Logger.LogException( ex );
     }
 }
コード例 #24
0
        public void Remove( )
        {
            RecentComputerList computers = new RecentComputerList();
            computers.Add( new ComputerName( "cpu1", "alias1" ) );
            computers.Add( new ComputerName( "cpu2", "alias2" ) );
            Assert.AreEqual( 2, computers.Count );

            computers.Remove( new ComputerName( "cpu1", "alias1" ) );
            Assert.AreEqual( 1, computers.Count );

            // Is Remove case insensitive?
            computers.Remove( new ComputerName( "CPU2", "ALIAS2" ) );
            Assert.AreEqual( 0, computers.Count );
        }
コード例 #25
0
        public void ICollectionAdd( )
        {
            ICollection<ComputerName> collection = new RecentComputerList();

            collection.Add( new ComputerName( "cpu1", null ) );
            Assert.AreEqual( new string[] {
                "cpu1" },
                GetComputers( (RecentComputerList) collection ) );

            collection.Add( new ComputerName( "cpu2", null ) );
            Assert.AreEqual( new string[] {
                "cpu1",
                "cpu2" },
                GetComputers( (RecentComputerList) collection ) );

            ICollection<ComputerName> fullCollection = ListFromStrings( new string[]
            {
                "aaaa",
                "bbbb",
                "cccc",
                "dddd",
                "eeee",
                "ffff",
                "gggg",
                "hhhh",
                "iiii",
                "jjjj"
            } );

            fullCollection.Add( new ComputerName( "cpu1", null ) );

            Assert.AreEqual( new string[]
            {
                "aaaa",
                "bbbb",
                "cccc",
                "dddd",
                "eeee",
                "ffff",
                "gggg",
                "hhhh",
                "iiii",
                "jjjj"
            },
            GetComputers( (RecentComputerList) fullCollection ) );
        }
コード例 #26
0
        public void MstscConnect( MstscSettings settings )
        {
            var mstscApp = new MstscApp();
            #if DEBUG
            mstscApp.TestMode = true;
            #endif
            try
            {
                mstscApp.Run( settings );
            }
            catch ( Exception ex )
            {
                Logger.LogException( ex );
            }

            OnMstscAppExited();

            // It is important to read before we write in case we have two instances of RemoteDesktopPlus open.
            // However RemoteDesktop doesn't have special logic for adding an IP address to the list like we
            // do so we need to do an integrate step.
            m_RecentComputerList = LoadRecentComputerList();

            // We use our own logic to determine what the recent computer list should be after a
            // connection was made.
            m_RecentComputerList.Push( settings.Computer );

            ComputerListFile serializer = new ComputerListFile();
            serializer.Write( m_RecentComputerList );

            OnComputerListUpdated();
        }