示例#1
0
        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];
            }
        }
示例#2
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");
            }
        }
示例#3
0
        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;
        }
示例#4
0
        public void FileExistsTest()
        {
            Guid fid = Guid.NewGuid();

            HostManagerFactory.GetInstance().CreateHostContent(fid.ToString());
            HostManagerFactory.GetInstance().FileExists(fid.ToString());
        }
示例#5
0
 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文件");
     }
 }
示例#6
0
        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);
        }
示例#8
0
 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);
         }
     }
 }
示例#9
0
 private bool SaveNewContent(string p)
 {
     try
     {
         HostManagerFactory.GetInstance().CreateHostContent(p);
         return(true);
     }
     catch (Exception ee)
     {
         return(false);
     }
 }
示例#10
0
        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);
        }
示例#11
0
 private bool RenameContent(string p, string p_2)
 {
     try
     {
         HostManagerFactory.GetInstance().RenameHostContent(p, p_2);
         return(true);
     }
     catch (Exception ee)
     {
         return(false);
     }
 }
示例#12
0
 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;
         }
     }
 }
示例#13
0
        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);
        }
示例#14
0
        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"));
        }
示例#15
0
        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();
            }
        }
示例#16
0
        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)
            {
            }
        }
示例#17
0
 public List <HostItem> GetHostList()
 {
     return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).GetHostList());
 }
示例#18
0
 public bool WriteHostContent(string key, string content)
 {
     return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).WriteHostContent(key, content));
 }
示例#19
0
 public void DeleteHostContent(string p)
 {
     HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).DeleteHostContent(p);
 }
示例#20
0
 public bool FileExists(string key)
 {
     return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).FileExists(key));
 }
示例#21
0
 public string ReadHostContent(string key)
 {
     return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).ReadHostContent(key));
 }
示例#22
0
 public bool CreateHostContent(string key)
 {
     return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).CreateHostContent(key));
 }
示例#23
0
        public void GetHostList()
        {
            List <HostItem> list = HostManagerFactory.GetInstance().GetHostList();

            Assert.IsTrue(list.Count > 0);
        }
示例#24
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();
 }
示例#27
0
 public bool RenameHostContent(string p, string p_2)
 {
     return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).RenameHostContent(p, p_2));
 }
示例#28
0
 public bool BackDefaultHost(string content)
 {
     return(HostManagerFactory.GetInstance(GetCurrentUser(UserName, Pwd)).BackDefaultHost(content));
 }
示例#29
0
 public DomainController()
 {
     this.factory = new HostManagerFactory();
 }
 public AccountController()
 {
     this.factory = new HostManagerFactory();
 }