Exemplo n.º 1
0
        private void btnLoadConfig_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "xml文件(*.xml)|*.xml";
                var dr = ofd.ShowDialog();
                if (dr == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }

                String      xml      = File.ReadAllText(ofd.FileName, Encoding.UTF8);
                XmlTreeNode rootNode = XmlTreeNode.FromXml(xml);
                txtHost.Text             = rootNode.GetItemValue("host");
                txtPort.Text             = rootNode.GetItemValue("port");
                txtUserName.Text         = rootNode.GetItemValue("userName");
                txtPassword.Text         = rootNode.GetItemValue("password");
                txtConnectionString.Text = rootNode.GetItemValue("connectionString");
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载配置时出错,原因:" + ex.Message);
            }
        }
Exemplo n.º 2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //初始化图标资源
            DirectoryInfo di = new DirectoryInfo(Path.Combine(Application.StartupPath, "Resources"));

            lock (ilFileIcon)
            {
                foreach (var file in di.GetFiles("*.png"))
                {
                    String key   = Path.GetFileNameWithoutExtension(file.Name);
                    Image  value = Image.FromFile(file.FullName);
                    if (ilFileIcon.Images.ContainsKey(key))
                    {
                        ilFileIcon.Images.RemoveByKey(key);
                    }
                    ilFileIcon.Images.Add(key, value);
                }
            }
            //初始化HttpServer
            httpServer = new HttpServer("", IPAddress.Loopback, 80);
            httpServer.BeforeWriteResponse += new EventHandler <HttpServer.BeforeWriteResponseEventArgs>(httpServer_BeforeWriteResponse);
            try
            {
                httpServer.Start();
            }
            catch
            {
                var dr = MessageBox.Show("本地80端口打开失败,是否以随机端口启动?", Application.ProductName, MessageBoxButtons.OKCancel);
                if (dr == System.Windows.Forms.DialogResult.Cancel)
                {
                    Environment.Exit(0);
                    return;
                }
                httpServer.Port = 0;
                httpServer.Start();
            }
            txtWebRootUrl.Text = httpServer.GetWebRootUrl();

            //读取配置文件
            if (File.Exists(configFilePath))
            {
                String      xml      = File.ReadAllText(configFilePath, Encoding.UTF8);
                XmlTreeNode rootNode = XmlTreeNode.FromXml(xml);
                String      tmpStr   = rootNode.GetItemValue("LastFolderPath");
                if (!String.IsNullOrEmpty(tmpStr))
                {
                    openFolder(tmpStr);
                }
            }
        }
Exemplo n.º 3
0
 //根据path得到参数的值
 public String GetArgumentValue(String path)
 {
     return(rootPackage.GetItemValue(path));
 }