示例#1
0
        public VmServerEditorPage(ProtocolServerBase server, VmServerListPage host, bool isDuplicate = false)
        {
            Server       = (ProtocolServerBase)server.Clone();
            _isDuplicate = isDuplicate;
            if (_isDuplicate)
            {
                Server.Id = 0;
            }
            Host      = host;
            IsAddMode = server.GetType() == typeof(ProtocolServerNone) || Server.Id == 0;

            // decrypt pwd
            if (Server.GetType() != typeof(ProtocolServerNone))
            {
                SystemConfig.Instance.DataSecurity.DecryptPwd(Server);
            }

            var assembly = typeof(ProtocolServerBase).Assembly;
            var types    = assembly.GetTypes();

            // reflect remote protocols
            {
                ProtocolList.Clear();
                ProtocolList = types.Where(item => item.IsSubclassOf(typeof(ProtocolServerBase)) && !item.IsAbstract)
                               .Where(x => x.FullName != typeof(ProtocolServerNone).FullName)
                               .Select(type => (ProtocolServerBase)Activator.CreateInstance(type)).ToList();
            }

            // set selected protocol
            try
            {
                ProtocolSelected = ProtocolList.First(x => x.GetType() == Server.GetType());
            }
            catch (Exception)
            {
                ProtocolSelected = ProtocolList.First();
            }

            if (!IsAddMode)
            {
                ProtocolList.Clear();
                ProtocolList.Add(ProtocolSelected);
            }
            else
            {
                if (string.IsNullOrEmpty(Server.GroupName))
                {
                    Server.GroupName = Host.SelectedGroup;
                }
            }

            Debug.Assert(Server.GetType() != typeof(ProtocolServerNone));
        }
示例#2
0
 public void AddAddsObjectToList()
 {
     _protocolList.Add(_protocol1);
     Assert.That(_protocolList[0] == _protocol1);
 }