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)); }
public static int AddOrUpdate(ProtocolServerBase org, bool isAdd = false) { Init(); var tmp = (ProtocolServerBase)org.Clone(); tmp.SetNotifyPropertyChangedEnabled(false); SystemConfig.Instance.DataSecurity.EncryptInfo(tmp); if (isAdd == false) { var s = FromProtocolServerBase(tmp); return(s.Update() ? 1 : 0); } else { var s = FromProtocolServerBase(tmp); return(s.Insert()); } }