Exemple #1
0
        public static bool ReadConfig(ref WebConfigSetting config)
        {
            doc = new XmlDocument();
            string fileDircetoryPath = Path.GetDirectoryName(Application.StartupPath);
            string filePath          = string.Format("{0}\\SeatManageWebV5\\Web.config", fileDircetoryPath);

            if (File.Exists(filePath))
            {
                doc.Load(filePath);
                foreach (XmlNode node in doc.ChildNodes)
                {
                    if (node.Name == "configuration")
                    {
                        foreach (XmlNode nodeA in node.ChildNodes)
                        {
                            if (nodeA.Name == "connectionStrings")
                            {
                                foreach (XmlNode nodeB in nodeA.ChildNodes)
                                {
                                    if (nodeB.Attributes != null && nodeB.Attributes["name"].Value == "EndpointAddress")
                                    {
                                        config.ConnString = AESAlgorithm.AESDecrypt(nodeB.Attributes["connectionString"].Value);
                                        break;
                                    }
                                }
                            }
                            else if (nodeA.Name == "appSettings")
                            {
                                foreach (XmlNode nodeB in nodeA.ChildNodes)
                                {
                                    if (nodeB.Attributes != null && nodeB.Attributes["key"].Value == "ChangePassWord")
                                    {
                                        if (nodeB.Attributes["value"].Value == "open")
                                        {
                                            config.IsChangePW = true;
                                        }
                                        else
                                        {
                                            config.IsChangePW = false;
                                        }

                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txt_Connstring_PW.Text))
     {
         MessageBox.Show("输入的密文不能为空!");
         return;
     }
     try
     {
         this.txt_ConnString.Text = AESAlgorithm.AESDecrypt(this.txt_Connstring_PW.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("解密出错:{0}", ex.Message));
     }
 }
Exemple #3
0
        /// <summary>
        /// 通过获取服务器时间检查网络是否通畅,获取成功,返回true,否则返回false。
        /// </summary>
        /// <returns></returns>
        private bool CheckNetWork()
        {
            ShowMessage = "正在连接远程服务……";



            if (!CheckInternet.CheckLocal())
            {
                ShowMessage = "连接网络失败,请检查网卡状态或网线是否接好!";
                return(false);
            }
            if (ConfigurationManager.ConnectionStrings["EndpointAddress"] != null)
            {
                string endpointAddress = AESAlgorithm.AESDecrypt(ConfigurationManager.ConnectionStrings["EndpointAddress"].ConnectionString);
                //net.tcp://192.168.1.100:8201/
                string straddress = endpointAddress.Replace("net.tcp://", "");
                straddress = straddress.Substring(0, straddress.Length - 1);
                if (!CheckInternet.CheckPort(straddress.Split(':')[0], straddress.Split(':')[1]))
                {
                    ShowMessage = "服务器连接失败,请检查服务器设置或网络配置!";
                    return(false);
                }
                string    pingip = ConfigurationManager.AppSettings["PingIP"];
                IPAddress ip;
                if (ConfigurationManager.AppSettings["PingServer"] != null && ConfigurationManager.AppSettings["PingServer"] == "1" && IPAddress.TryParse(pingip, out ip))
                {
                    CheckInternet.PingIp(pingip);
                }
            }
            else
            {
                ShowMessage = "获取服务器地址失败,请检查终端配置!";
                return(false);
            }
            try
            {
                DateTime dt = ServiceDateTime.Now;
            }
            catch (Exception ex)
            {
                WriteLog.Write("连接数据传输服务失败:" + ex.Message);
                ShowMessage = "连接远程服务遇到错误,请检查服务器服务是否启动。";
                return(false);
            }
            return(true);
        }
        public ActionResult Index(string msg)
        {
            msg = AESAlgorithm.AESDecrypt(msg.Replace(" ", "+"));//解密参数

            //string path = Server.MapPath("/App_Data/" + Guid.NewGuid().ToString() + ".txt");//将参数写入文件
            //StreamWriter sw = new StreamWriter(path);
            //sw.Write(msg.Replace("&", "\r\n"));//TextBox2中的文本是可以编辑后的。
            //sw.Close();
            //sw.Dispose();

            NameValueCollection param = UrlCommon.GetQueryString(msg);//获取参数
            string  SchoolNum         = param["SchoolNum"].ToString();
            string  StudentNo         = param["StudentNo"].ToString();
            tb_User user    = DbSession.Default.From <tb_User>().Where(tb_User._.SchoolNo == SchoolNum && tb_User._.StudentNo == StudentNo).ToFirst();
            string  MsgType = param["MsgType"].ToString();

            switch (MsgType)
            {
            case "UserOperation":
                var UserOperation = new UserOperation()
                {
                    first    = new TemplateDataItem(user.Name + " 您好"),
                    keyword1 = new TemplateDataItem(param["Room"].ToString()),
                    keyword2 = new TemplateDataItem(param["SeatNo"].ToString()),
                    keyword3 = new TemplateDataItem(param["AddTime"].ToString()),
                    remark   = new TemplateDataItem(param["Msg"].ToString())
                };
                TemplateApi.SendTemplateMessage(WeiXinApi.GetToken(), user.OpenId, "At7HOxsJ5CW81OV81hipLglDV21O46UVU9Gm_nToXGQ", "#7B68EE", GetAppSettings.SysURL + "/User/SeatState", UserOperation);
                break;

            default:
                var UserOperation1 = new UserOperation()
                {
                    first    = new TemplateDataItem(user.Name + " 您好"),
                    keyword1 = new TemplateDataItem(param["Room"].ToString()),
                    keyword2 = new TemplateDataItem(param["SeatNo"].ToString()),
                    keyword3 = new TemplateDataItem(param["AddTime"].ToString()),
                    remark   = new TemplateDataItem(param["Msg"].ToString())
                };
                TemplateApi.SendTemplateMessage(WeiXinApi.GetToken(), user.OpenId, "At7HOxsJ5CW81OV81hipLglDV21O46UVU9Gm_nToXGQ", "#7B68EE", GetAppSettings.SysURL + "/User/SeatState", UserOperation1);
                break;
            }

            return(Content("0"));
        }
        public static bool GetLeaveClientConfig(ref LeaveClientBesicConfig config)
        {
            doc = new XmlDocument();
            string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;
            string filePath          = string.Format("{0}LeaveClient.exe.config", fileDircetoryPath);

            if (File.Exists(filePath))
            {
                try
                {
                    doc.Load(filePath);
                    XmlNodeList nodes = doc.SelectNodes("//configuration/connectionStrings/add");
                    foreach (XmlNode node in nodes)
                    {
                        if (node.Attributes["name"].Value == "EndpointAddress")
                        {
                            config.WCFConnString = AESAlgorithm.AESDecrypt(node.Attributes["connectionString"].Value);
                            break;
                        }
                    }
                    nodes = doc.SelectNodes("//configuration/appSettings/add");
                    foreach (XmlNode node in nodes)
                    {
                        if (node.Attributes["key"].Value == "windowState")
                        {
                            config.SetUpMode = node.Attributes["value"].Value;
                        }
                        else if (node.Attributes["key"].Value == "LeaveState")
                        {
                            config.LeaveMode = node.Attributes["value"].Value;
                        }
                    }
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        private string GetConnSting()
        {
            string      comm = "";
            XmlDocument doc  = new XmlDocument();
            string      fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;
            string      filePath          = string.Format("{0}ServiceHostTimerHost.exe.config", fileDircetoryPath);

            if (File.Exists(filePath))
            {
                doc.Load(filePath);
                XmlNodeList nodes = doc.SelectNodes("//configuration/connectionStrings/add");
                foreach (XmlNode node in nodes)
                {
                    if (node.Attributes["name"].Value == "EndpointAddress")
                    {
                        comm = AESAlgorithm.AESDecrypt(node.Attributes["connectionString"].Value);
                    }
                }
            }
            return(comm);
        }
        public static bool ReadConfig(ref HostConfig hostconfig)
        {
            doc = new XmlDocument();
            string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;
            string filePath          = string.Format("{0}ServiceHostMonitorService.exe.config", fileDircetoryPath);

            if (File.Exists(filePath))
            {
                doc.Load(filePath);
                XmlNodeList nodes = doc.SelectNodes("//configuration/connectionStrings/add");
                foreach (XmlNode node in nodes)
                {
                    if (node.Attributes["name"].Value == "ConnectionString")
                    {
                        string[] db = node.Attributes["connectionString"].Value.Split(';');
                        for (int i = 0; i < db.Length; i++)
                        {
                            switch (db[i].Split('=')[0])
                            {
                            case "Data Source":
                                hostconfig.DBIP = db[i].Split('=')[1];
                                break;

                            case "Initial Catalog":
                                hostconfig.DBName = db[i].Split('=')[1];
                                break;

                            case "User ID":
                                hostconfig.DBUser = db[i].Split('=')[1];
                                break;

                            case "Password":
                                hostconfig.DBPW = db[i].Split('=')[1];
                                break;
                            }
                        }
                    }
                    else if (node.Attributes["name"].Value == "EndpointAddress")
                    {
                        hostconfig.WCFString = AESAlgorithm.AESDecrypt(node.Attributes["connectionString"].Value);
                    }
                }
                nodes = doc.SelectNodes("//configuration/appSettings/add");
                foreach (XmlNode node in nodes)
                {
                    if (node.Attributes["key"].Value == "ServiceAssembly" && (node.Attributes["value"].Value == "SeatService.MonitorService.MonitorService,SeatService.MonitorService" || node.Attributes["value"].Value == "SeatManage.WCFService.WcfHost,SeatManage.WCFService" || node.Attributes["value"].Value == "AMS.DataTransfer.DataTransferService,AMS.DataTransfer"))
                    {
                        hostconfig.HostServer.Add(node.Attributes["value"].Value.Split(',')[0].Split('.')[2]);
                    }
                    else if (node.Attributes["key"].Value == "SaveFilePath")
                    {
                        hostconfig.MediaFilePath = node.Attributes["value"].Value;
                    }
                    else if (node.Attributes["key"].Value == "LogUploadTime")
                    {
                        hostconfig.UploadTime = node.Attributes["value"].Value;
                    }
                    else if (node.Attributes["key"].Value == "Interval")
                    {
                        hostconfig.LoopTime = node.Attributes["value"].Value;
                    }
                    else if (node.Attributes["key"].Value == "SchoolNo")
                    {
                        hostconfig.SchoolNo = node.Attributes["value"].Value;
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #8
0
        /// <summary>
        /// 获取终端的基本配置
        /// </summary>
        /// <returns></returns>
        public static bool GetSeatClientBaseConfig(ref ClientBasicConfig config)
        {
            Updoc = new XmlDocument();
            SCdoc = new XmlDocument();
            MPdoc = new XmlDocument();
            string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;
            string upfilePath        = string.Format("{0}ClientLauncher.exe.config", fileDircetoryPath);
            string scfilePath        = string.Format("{0}SeatClient\\SeatClient.exe.config", fileDircetoryPath);
            string mpfilePath        = string.Format("{0}MediaPlayer\\MediaPlayerClient.exe.config", fileDircetoryPath);

            if (File.Exists(upfilePath) && File.Exists(scfilePath) && File.Exists(mpfilePath))
            {
                try
                {
                    Updoc.Load(upfilePath);
                    SCdoc.Load(scfilePath);
                    MPdoc.Load(mpfilePath);
                    XmlNodeList nodes = Updoc.SelectNodes("//configuration/connectionStrings/add");
                    foreach (XmlNode node in nodes)
                    {
                        if (node.Attributes["name"].Value == "EndpointAddress")
                        {
                            config.WCFConnString = AESAlgorithm.AESDecrypt(node.Attributes["connectionString"].Value);
                            break;
                        }
                    }
                    nodes = MPdoc.SelectNodes("//configuration/appSettings/add");
                    foreach (XmlNode node in nodes)
                    {
                        switch (node.Attributes["key"].Value)
                        {
                        case "ADLoopTime":
                            config.SCLoopTime = node.Attributes["value"].Value;
                            break;

                        case "defaultVideo":
                            config.DefaultMedia = node.Attributes["value"].Value;
                            break;

                        case "SchoolNo":
                            config.SchoolNo = node.Attributes["value"].Value;
                            break;

                        case "CampusNo":
                            config.CampusNo = node.Attributes["value"].Value;
                            break;

                        case "SendMessageInterval":
                            config.SentStatusTime = node.Attributes["value"].Value;
                            break;

                        case "UpdateTime":
                            config.UpdateTime = node.Attributes["value"].Value;
                            break;
                        }
                    }
                    nodes = SCdoc.SelectNodes("//configuration/appSettings/add");
                    foreach (XmlNode node in nodes)
                    {
                        if (node.Attributes["key"].Value == "ClientNo")
                        {
                            config.TerminalNum = node.Attributes["value"].Value;
                            break;
                        }
                    }
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #9
0
        public static bool ReadConfig(ref HostConfig hostconfig)
        {
            docMonitorService = new XmlDocument();
            docTimerHost      = new XmlDocument();
            docWCFHost        = new XmlDocument();
            docWeChar         = new XmlDocument();
            docWeCharWcf      = new XmlDocument();
            string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;

            if (File.Exists(Path.GetDirectoryName(Application.StartupPath) + "\\MonitorService\\ServiceHostMonitorService.exe.config"))
            {
                docMonitorService.Load(Path.GetDirectoryName(Application.StartupPath) + "\\MonitorService\\ServiceHostMonitorService.exe.config");

                if (File.Exists(fileDircetoryPath + "ServiceHostTimerHost.exe.config"))
                {
                    docTimerHost.Load(fileDircetoryPath + "ServiceHostTimerHost.exe.config");
                }
                else
                {
                    return(false);
                }
                if (File.Exists(fileDircetoryPath + "ServiceHostWCFHost.exe.config"))
                {
                    docWCFHost.Load(fileDircetoryPath + "ServiceHostWCFHost.exe.config");
                }
                else
                {
                    return(false);
                }
                if (File.Exists(fileDircetoryPath + "ServiceHostWeChar.exe.config"))
                {
                    docWeChar.Load(fileDircetoryPath + "ServiceHostWeChar.exe.config");
                }
                else
                {
                    return(false);
                }
                if (File.Exists(fileDircetoryPath + "ServiceHostWeChatWCFHost.exe.config"))
                {
                    docWeChar.Load(fileDircetoryPath + "ServiceHostWeChatWCFHost.exe.config");
                }
                else
                {
                    return(false);
                }
                string[] db = docWCFHost.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "ConnectionString").Attributes["connectionString"].Value.Split(';');
                for (int i = 0; i < db.Length; i++)
                {
                    switch (db[i].Split('=')[0])
                    {
                    case "Data Source":
                        hostconfig.DBIP = db[i].Split('=')[1];
                        break;

                    case "Initial Catalog":
                        hostconfig.DBName = db[i].Split('=')[1];
                        break;

                    case "User ID":
                        hostconfig.DBUser = db[i].Split('=')[1];
                        break;

                    case "Password":
                        hostconfig.DBPW = db[i].Split('=')[1];
                        break;
                    }
                }
                XmlNode xmlNode = docTimerHost.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "EndpointAddress");
                hostconfig.WCFString = AESAlgorithm.AESDecrypt(xmlNode.Attributes["connectionString"].Value);

                xmlNode = docMonitorService.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "WeChatEndpointAddress");
                hostconfig.WeChatWCFString = AESAlgorithm.AESDecrypt(xmlNode.Attributes["connectionString"].Value);
                XmlNodeList nodes = docTimerHost.SelectNodes("//configuration/appSettings/add");
                foreach (XmlNode node in nodes)
                {
                    if (node.Attributes["key"].Value == "ServiceAssembly" && (node.Attributes["value"].Value == "SeatService.MonitorService.MonitorService,SeatService.MonitorService" || node.Attributes["value"].Value == "SeatManage.WCFService.WcfHost,SeatManage.WCFService" || node.Attributes["value"].Value == "AMS.DataTransfer.DataTransferService,AMS.DataTransfer"))
                    {
                        hostconfig.HostServer.Add(node.Attributes["value"].Value.Split(',')[0].Split('.')[2]);
                    }
                    else
                    {
                        switch (node.Attributes["key"].Value)
                        {
                        case "SaveFilePath":
                            hostconfig.MediaFilePath = node.Attributes["value"].Value;
                            break;

                        case "LogUploadTime":
                            hostconfig.UploadTime = node.Attributes["value"].Value;
                            break;

                        case "Interval":
                            hostconfig.LoopTime = node.Attributes["value"].Value;
                            break;

                        case "SchoolNo":
                            hostconfig.SchoolNo = node.Attributes["value"].Value;
                            break;
                        }
                    }
                }
                return(true);
            }

            else
            {
                return(false);
            }
        }