private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (LastHostKey != null && HostManagerFactory.GetInstance().FileExists(LastHostKey.Text)) { SaveHost(LastHostKey.Text); } if (this.listView1.SelectedItems.Count == 0) { return; } if (this.listView1.SelectedItems[0].Text == "+新配置") { string newKey = CreateNewContentName(); this.listView1.SelectedItems[0].Text = newKey; SaveNewContent(this.listView1.SelectedItems[0].Text); this.BindHostList(); SelectedKey(newKey); } else { LoadHost(this.listView1.SelectedItems[0].Text); LastHostKey = this.listView1.SelectedItems[0]; } }
public void RenameHostContent() { try { HostManagerFactory.GetInstance().CreateHostContent("key"); } catch { } bool ret = HostManagerFactory.GetInstance().RenameHostContent("key", "key1"); Assert.IsTrue(ret); Assert.IsNotNull( HostManagerFactory.GetInstance().ReadHostContent("key1")); try { HostManagerFactory.GetInstance().RenameHostContent("key1", "key1"); Assert.Fail("不能改名为一个已经存在的文件"); } catch { } finally { HostManagerFactory.GetInstance().DeleteHostContent("key1"); } }
public Form1() { ExitMenu exitMenu = new ExitMenu(); exitMenu.ExitMenuClick += new EventHandler(exitMenu_ExitMenuClick); InitializeComponent(); InitDefaultHost(); HostSelected hostSelected = CreateHostSelected(); EditMenu editMenu = CreateEditMenu(); this.contextMenuStrip1.Items.AddRange( AppMenu.CreateAppMenu(). Builder(HostManagerFactory.GetInstance().GetHostList(), hostSelected, Server.GetInstance().ReadCurrentHostKey()). Builder("-"). Builder("编辑", editMenu). Builder("退出", exitMenu).ToMenuList().ToArray() ); this.Hide(); this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; }
public void FileExistsTest() { Guid fid = Guid.NewGuid(); HostManagerFactory.GetInstance().CreateHostContent(fid.ToString()); HostManagerFactory.GetInstance().FileExists(fid.ToString()); }
private void InitDefaultHost() { if (HostManagerFactory.GetInstance().ReadHostContent("默认HOST文件") == String.Empty) { HostManagerFactory.GetInstance().CreateHostContent("默认HOST文件"); HostManagerFactory.GetInstance().WriteHostContent("默认HOST文件", Server.GetInstance().GetHostFileContent()); Server.GetInstance().RecordCurrentHostKey("默认HOST文件"); } }
public void ReadHostContent() { HostManagerFactory.GetInstance().WriteHostContent("key", "testHost"); string hContent = HostManagerFactory.GetInstance().ReadHostContent("key"); Assert.IsNotNull(hContent); Assert.AreEqual(String.Empty, HostManagerFactory.GetInstance().ReadHostContent(Guid.NewGuid().ToString())); }
public void GetInstanceTest() { IHostManager manager = HostManagerFactory.GetInstance(); Assert.IsNotNull(manager); Assert.IsTrue(manager is HostManager); manager = HostManagerFactory.GetInstance(new HostSwitchConfig()); Assert.IsNotNull(manager); Assert.IsTrue(manager is HostManager); }
private void SaveHost(string LastHostKey) { if (LastHostKey != "") { HostManagerFactory.GetInstance().WriteHostContent(LastHostKey, this.textBox1.Text); if (LastHostKey == Server.GetInstance().ReadCurrentHostKey()) { Server.GetInstance().SwitchHostContent(this.textBox1.Text); } } }
private bool SaveNewContent(string p) { try { HostManagerFactory.GetInstance().CreateHostContent(p); return(true); } catch (Exception ee) { return(false); } }
public void BackUpAndGetDefaultHost() { string ruleContent = Server.GetInstance().GetHostFileContent(); bool ret = HostManagerFactory.GetInstance().BackDefaultHost(ruleContent); Assert.IsTrue(ret); string dHost = HostManagerFactory.GetInstance().ReadHostContent(HostManager.DefaultHostFileName); Assert.AreEqual(ruleContent, dHost); }
private bool RenameContent(string p, string p_2) { try { HostManagerFactory.GetInstance().RenameHostContent(p, p_2); return(true); } catch (Exception ee) { return(false); } }
private void listView1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && listView1.SelectedItems.Count > 0) { if (MessageBox.Show("真的要删除这个配置文件么?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { HostManagerFactory.GetInstance().DeleteHostContent( listView1.SelectedItems[0].Text); BindHostList(); listView1.Items[0].Selected = true; } } }
private static string CreateNewContentName() { string temp = DateTime.Now.ToString("yyyyMMdd") + "新配置"; string ret = temp; int tryNum = 0; while (HostManagerFactory.GetInstance().FileExists(ret)) { tryNum++; ret = temp + "(" + tryNum + ")"; } return(ret); }
public void CreateHostContent() { try { bool ret = HostManagerFactory.GetInstance().CreateHostContent("key"); HostManagerFactory.GetInstance().CreateHostContent("key"); Assert.Fail("不能重复创建HOST文件"); } catch (Exception ee) { // } Assert.IsNotNull(HostManagerFactory.GetInstance().ReadHostContent("key")); }
public void ClickEvent(object sender, EventArgs e) { System.Windows.Forms.ToolStripMenuItem currentMenuItem = ((System.Windows.Forms.ToolStripMenuItem)sender); Server.GetInstance().SwitchHostContent( HostManagerFactory.GetInstance().ReadHostContent( currentMenuItem.Text )); Server.GetInstance().RecordCurrentHostKey(currentMenuItem.Text); if (lastSelectedItem != null) { lastSelectedItem.Checked = false; } currentMenuItem.Checked = true; lastSelectedItem = currentMenuItem; if (HostSelectedClick != null) { HostSelectedClick(); } }
public void WriteHostContent() { if (!HostManagerFactory.GetInstance().FileExists("key")) { HostManagerFactory.GetInstance().CreateHostContent("key"); } bool ret = HostManagerFactory.GetInstance().WriteHostContent("key", "abcdef"); Assert.IsTrue(ret); string c = HostManagerFactory.GetInstance().ReadHostContent("key"); Assert.AreEqual("abcdef", c); try { HostManagerFactory.GetInstance().WriteHostContent(Guid.NewGuid().ToString(), ""); Assert.Fail("创建一个不存在的HOST文件,请用createHostContent函数"); } catch (Exception ee) { } }
public List <HostItem> GetHostList() { return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).GetHostList()); }
public bool WriteHostContent(string key, string content) { return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).WriteHostContent(key, content)); }
public void DeleteHostContent(string p) { HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).DeleteHostContent(p); }
public bool FileExists(string key) { return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).FileExists(key)); }
public string ReadHostContent(string key) { return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).ReadHostContent(key)); }
public bool CreateHostContent(string key) { return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).CreateHostContent(key)); }
public void GetHostList() { List <HostItem> list = HostManagerFactory.GetInstance().GetHostList(); Assert.IsTrue(list.Count > 0); }
private void LoadHost(string key) { this.textBox1.Text = HostManagerFactory.GetInstance().ReadHostContent(key); }
public TemplateController() { this.factory = new HostManagerFactory(); }
public ServerController() { this.factory = new HostManagerFactory(); }
public bool RenameHostContent(string p, string p_2) { return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).RenameHostContent(p, p_2)); }
public bool BackDefaultHost(string content) { return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).BackDefaultHost(content)); }
public DomainController() { this.factory = new HostManagerFactory(); }
public AccountController() { this.factory = new HostManagerFactory(); }