예제 #1
0
파일: MainForm.cs 프로젝트: yhtsnda/aaasoft
        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);
            }
        }
예제 #2
0
        // 接收AbstractXiepPackage包
        public static AbstractXiepPackage ReceivePackage(NetworkStream ns)
        {
            String xml = ReceiveXml(ns);

            if (String.IsNullOrEmpty(xml))
            {
                return(null);
            }

            AbstractXiepPackage rtnPackage = null;

            XmlTreeNode treeNode    = XmlTreeNode.FromXml(xml);
            String      packageName = treeNode.Key;

            if (packageName.Equals("RequestPackage"))
            {
                rtnPackage = new RequestPackage();
            }
            else if (packageName.Equals("ResponsePackage"))
            {
                rtnPackage = new ResponsePackage();
            }
            else if (packageName.Equals("EventPackage"))
            {
                rtnPackage = new EventPackage();
            }
            else
            {
                return(null);
            }

            rtnPackage.SetRootPackage(treeNode);
            return(rtnPackage);
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
        //从XML得到事件包
        public static EventPackage FromXml(String xml)
        {
            EventPackage rtnPackage = null;

            XmlTreeNode treeNode    = XmlTreeNode.FromXml(xml);
            String      packageName = treeNode.Key;

            if (packageName.Equals("EventPackage"))
            {
                rtnPackage = new EventPackage();
            }
            else
            {
                return(null);
            }

            rtnPackage.SetRootPackage(treeNode);
            return(rtnPackage);
        }