Ejemplo n.º 1
0
        /// <summary>
        /// 根据SQLXML文件路径获取SQL实体
        /// </summary>
        /// <param name="_Path">SQLXML路径</param>
        /// <returns>SQLXML实体</returns>
        public static SQLCodeEntity GetSQLCodeEntityByPath(String _Path)
        {
            SQLCodeEntity _SQLCodeEntity = null;

            try
            {
                if (!File.Exists(_Path))
                {
                    return(null);
                }
                //实例化XML文件操作类
                XmlOperate _XmlOperate = new XmlOperate();
                //判断配置文件是否只读
                FileInfo fi = new FileInfo(_Path);
                //如果只读则修改为普通
                fi.Attributes = FileAttributes.Normal;
                //实例化文件操作类
                DirectoryFileOperate _DirectoryFileOperate = new DirectoryFileOperate();
                //根据指定路径读取文件
                string _XmlContent = _DirectoryFileOperate.ShareReadFile(_Path);
                //把xml转换成对象
                _SQLCodeEntity = _XmlOperate.SimpleXmlToObject <SQLCodeEntity>(_XmlContent);
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(_SQLCodeEntity);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 当目录内SQLXML文件发生变化时被触发。
 /// </summary>
 /// <param name="path">文件路径</param>
 static void _MyFileSystemWatcher_Change(string path)
 {
     try
     {
         //获得发生变化文件的文件名
         string _SqlNum = Path.GetFileNameWithoutExtension(path);
         if (SQLCode != null && SQLCode.ContainsKey(_SqlNum))//如果缓存不为null,并且缓存中存在被修改的文件
         {
             //从缓存移除修改文件
             SQLCode.Remove(_SqlNum);
         }
         if (SQLCodeManager._SQLCodeEntityList == null)//如果SQLXML列表缓存为空
         {
             return;
         }
         //根据SQLXML文件路径获取SQL实体
         SQLCodeEntity _SQLCodeEntity = GetSQLCodeEntityByPath(path);
         //从缓存中获得SQL实体
         var _SQLCodeEntityCache = SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum);
         if (_SQLCodeEntity != null && _SQLCodeEntityCache != null && _SQLCodeEntity.SqlNum == _SQLCodeEntityCache.SqlNum && _SQLCodeEntity.SqlDescription == _SQLCodeEntityCache.SqlDescription && _SQLCodeEntity.SQLString == _SQLCodeEntityCache.SQLString)//如果没有改变
         {
             return;
         }
         if (_SQLCodeEntity == null || _SQLCodeEntity.SqlNum != _SqlNum) //如果不存在本地SQLXML文件,或者序号和文件名不统一
         {
             if (_SQLCodeEntityCache != null)                            //如果缓存中存在发生变化的SLQXML
             {
                 //移除旧的缓存
                 SQLCodeManager._SQLCodeEntityList.Remove(_SQLCodeEntityCache);
             }
             if (!File.Exists(path) || Path.GetExtension(path) != ".xml")//如果文件不存在或者新的扩展名不是XML
             {
                 return;
             }
             FileInfo fi = new FileInfo(path);
             //如果只读则修改为普通
             fi.Attributes = FileAttributes.Normal;
             //重命名为源文件名+.bak扩展名
             fi.MoveTo(path + ".bak");
         }
         else
         {
             if (_SQLCodeEntityCache != null)//如果缓存中存在发生变化的SLQXML
             {
                 //移除旧的缓存
                 SQLCodeManager._SQLCodeEntityList.Remove(_SQLCodeEntityCache);
             }
             //添加新的缓存
             SQLCodeManager._SQLCodeEntityList.Add(_SQLCodeEntity);
         }
     }
     catch (Exception ex)
     {
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加SQLXML文件
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>true:成功,false:失败</returns>
        public object AddSql(Dictionary <String, String> parameters)
        {
            try
            {
                ////XML存储路径
                //string _XmlOutPath = Path.Combine(WorkDir, SQLPath);
                //if (!Directory.Exists(_XmlOutPath))//如果路径不存在
                //{
                //    //创建路径
                //    Directory.CreateDirectory(_XmlOutPath);
                //}

                //检查SQLXML路径是否存在
                CheckPath();
                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";
                //获取SQL说明
                string _SqlDescription = parameters.ContainsKey("SqlDescription") ? _JsonOperate.FromJsonString <string>(parameters["SqlDescription"]) : "";
                //获取SQL语句
                string _SQLString = parameters.ContainsKey("SQLString") ? _JsonOperate.FromJsonString <string>(parameters["SQLString"]) : "";

                //SQL语句所在xml文件路径
                string xmlPath = Path.Combine(SQLPath, _SqlNum + ".xml");
                if (File.Exists(xmlPath))//如果存在文件,返回false
                {
                    return(new { Methods = false });
                }
                if (string.IsNullOrEmpty(_SqlNum) || string.IsNullOrEmpty(_SqlDescription) || string.IsNullOrEmpty(_SQLString))
                {
                    return(new { Methods = false });
                }
                //实例化XML文件操作类
                XmlOperate _XmlOperate = new XmlOperate();
                //实例化SQL实体类
                SQLCodeEntity _SQLCodeEntity = new SQLCodeEntity();
                _SQLCodeEntity.SqlNum         = _SqlNum;
                _SQLCodeEntity.SqlDescription = _SqlDescription;
                _SQLCodeEntity.SQLString      = _SQLString;

                //转换成xml字符串
                string _XmlString = _XmlOperate.ObjectToSimpleXml(_SQLCodeEntity);
                //生成SQLXML文件
                File.WriteAllText(xmlPath, _XmlString);
                return(new { Methods = true });
            }
            catch
            {
                return(new { Methods = false });
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据SQL序号获得SQL信息
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>SQL信息</returns>
        public object GetSqlByNum(Dictionary <String, String> parameters)
        {
            try
            {
                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";

                //SQLCodeEntity _SQLCodeEntity;
                if (_SQLCodeEntityList != null && SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum) != null)
                {
                    //从缓存中获得SQL实体
                    SQLCodeEntity _SQLCodeEntity = SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum);

                    return(new { Methods = _SQLCodeEntity });
                }
                else
                {
                    //SQL语句所在xml文件路径
                    string xmlPath = Path.Combine(SQLPath, _SqlNum + ".xml");
                    //判断是否存在文件
                    if (!File.Exists(xmlPath))
                    {
                        return(new { Methods = "" });
                    }
                    //实例化XML文件操作类
                    //XmlOperate _XmlOperate = new XmlOperate();
                    //判断配置文件是否只读
                    //FileInfo fi = new FileInfo(xmlPath);
                    ////如果只读则修改为普通
                    //if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                    //{
                    //    fi.Attributes = FileAttributes.Normal;
                    //}
                    ////实例化文件操作类
                    //DirectoryFileOperate _DirectoryFileOperate = new DirectoryFileOperate();
                    ////根据指定路径读取文件
                    //string _XmlContent = _DirectoryFileOperate.ShareReadFile(xmlPath);
                    ////把xml转换成对象
                    //SQLCodeEntity _SQLCodeEntity = _XmlOperate.SimpleXmlToObject<SQLCodeEntity>(_XmlContent);
                    SQLCodeEntity _SQLCodeEntity = SQLCodeHelp.GetSQLCodeEntityByPath(xmlPath);

                    return(new { Methods = _SQLCodeEntity });
                }
            }
            catch
            {
                return(new { Methods = "" });
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 当目录内SQLXML文件发生变化时被触发。
        /// </summary>
        /// <param name="sender">事件触发源。</param>
        /// <param name="e">事件信息。</param>
        //static void _SqlXmlFileWatcher_Changed(object sender, FileSystemEventArgs e)
        //{
        //    try
        //    {
        //        //获得发生变化文件的文件名
        //        string _SqlNum = Path.GetFileNameWithoutExtension(e.FullPath);
        //        if (SQLCode != null && SQLCode.ContainsKey(_SqlNum))//如果缓存不为null,并且缓存中存在被修改的文件
        //        {
        //            //从缓存移除修改文件
        //            SQLCode.Remove(_SqlNum);
        //        }
        //        if (SQLCodeManager._SQLCodeEntityList == null)//如果SQLXML列表缓存为空
        //        {
        //            return;
        //        }
        //        //根据SQLXML文件路径获取SQL实体
        //        SQLCodeEntity _SQLCodeEntity = GetSQLCodeEntityByPath(e.FullPath);
        //        //从缓存中获得SQL实体
        //        var _SQLCodeEntityCache = SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum);
        //        if (_SQLCodeEntity != null && _SQLCodeEntityCache != null && _SQLCodeEntity.SqlNum == _SQLCodeEntityCache.SqlNum && _SQLCodeEntity.SqlDescription == _SQLCodeEntityCache.SqlDescription && _SQLCodeEntity.SQLString == _SQLCodeEntityCache.SQLString)//如果没有改变
        //        {
        //            return;
        //        }
        //        if (_SQLCodeEntity == null || _SQLCodeEntity.SqlNum != _SqlNum)//如果不存在本地SQLXML文件,或者序号和文件名不统一
        //        {
        //            if (_SQLCodeEntityCache != null)//如果缓存中存在发生变化的SLQXML
        //            {
        //                //移除旧的缓存
        //                SQLCodeManager._SQLCodeEntityList.Remove(_SQLCodeEntityCache);
        //            }
        //            if (!File.Exists(e.FullPath) || Path.GetExtension(e.FullPath) != ".xml")//如果文件不存在或者新的扩展名不是XML
        //            {
        //                return;
        //            }
        //            FileInfo fi = new FileInfo(e.FullPath);
        //            //如果只读则修改为普通
        //            fi.Attributes = FileAttributes.Normal;
        //            //重命名为源文件名+.bak扩展名
        //            fi.MoveTo(e.FullPath + ".bak");
        //        }
        //        else
        //        {
        //            if (_SQLCodeEntityCache != null)//如果缓存中存在发生变化的SLQXML
        //            {
        //                //移除旧的缓存
        //                SQLCodeManager._SQLCodeEntityList.Remove(_SQLCodeEntityCache);
        //            }
        //            //添加新的缓存
        //            SQLCodeManager._SQLCodeEntityList.Add(_SQLCodeEntity);
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //}
        #endregion

        #region 当目录内SQLXML文件被删除时被触发
        /// <summary>
        /// 当目录内SQLXML文件被删除时被触发。
        /// </summary>
        /// <param name="sender">事件触发源。</param>
        /// <param name="e">事件信息。</param>
        //static void _SqlXmlFileWatcher_Deleted(object sender, FileSystemEventArgs e)
        //{
        //    try
        //    {
        //        //获得发生变化文件的文件名
        //        string _SqlNum = Path.GetFileNameWithoutExtension(e.FullPath);
        //        if (SQLCode != null && SQLCode.ContainsKey(_SqlNum))//如果缓存不为null,并且缓存中存在被修改的文件
        //        {
        //            //从缓存移除修改文件
        //            SQLCode.Remove(_SqlNum);
        //        }
        //        if (SQLCodeManager._SQLCodeEntityList == null)//如果SQLXML列表缓存为空
        //        {
        //            return;
        //        }
        //        //从缓存中获得SQL实体
        //        var _SQLCodeEntityCache = SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum);
        //        if (_SQLCodeEntityCache != null)//如果缓存中存在发生变化的SLQXML
        //        {
        //            //移除旧的缓存
        //            SQLCodeManager._SQLCodeEntityList.Remove(_SQLCodeEntityCache);
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //}
        #endregion

        #region 当目录内SQLXML文件重命名时被触发
        /// <summary>
        /// 当目录内SQLXML文件重命名时被触发。
        /// </summary>
        /// <param name="sender">事件触发源。</param>
        /// <param name="e">事件信息。</param>
        //static void _SqlXmlFileWatcher_Renamed(object sender, RenamedEventArgs e)
        //{
        //    try
        //    {
        //        //获得发生变化文件的文件名
        //        string _SqlNum = Path.GetFileNameWithoutExtension(e.OldFullPath);
        //        string _SqlNumNew = Path.GetFileNameWithoutExtension(e.FullPath);
        //        if (SQLCode != null && SQLCode.ContainsKey(_SqlNum))//如果缓存不为null,并且缓存中存在被修改的文件
        //        {
        //            //从缓存移除修改文件
        //            SQLCode.Remove(_SqlNum);
        //        }
        //        if (SQLCodeManager._SQLCodeEntityList == null)//如果SQLXML列表缓存为空
        //        {
        //            return;
        //        }
        //        //根据SQLXML文件路径获取SQL实体
        //        SQLCodeEntity _SQLCodeEntity = GetSQLCodeEntityByPath(e.FullPath);
        //        //从缓存中获得SQL实体
        //        var _SQLCodeEntityCache = SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum);
        //        if (_SQLCodeEntity == null || _SQLCodeEntity.SqlNum != _SqlNumNew)//如果不存在本地SQLXML文件,或者序号和文件名不统一
        //        {
        //            if (_SQLCodeEntityCache != null)//如果缓存中存在发生变化的SLQXML
        //            {
        //                //移除旧的缓存
        //                SQLCodeManager._SQLCodeEntityList.Remove(_SQLCodeEntityCache);
        //            }
        //            if (!File.Exists(e.FullPath) || Path.GetExtension(e.FullPath) != ".xml")//如果文件不存在或者新的扩展名不是XML
        //            {
        //                return;
        //            }
        //            FileInfo fi = new FileInfo(e.FullPath);
        //            //如果只读则修改为普通
        //            fi.Attributes = FileAttributes.Normal;

        //            //重命名为源文件名+.bak扩展名
        //            fi.MoveTo(e.FullPath + ".bak");
        //        }
        //        else
        //        {
        //            if (_SQLCodeEntityCache != null)//如果缓存中存在发生变化的SLQXML
        //            {
        //                //移除旧的缓存
        //                SQLCodeManager._SQLCodeEntityList.Remove(_SQLCodeEntityCache);
        //            }
        //            //添加新的缓存
        //            SQLCodeManager._SQLCodeEntityList.Add(_SQLCodeEntity);
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //    }
        //}
        #endregion

        #endregion

        #region 根据SQL语句序号获取SQL语句
        /// <summary>
        /// 根据SQL语句序号获取SQL语句
        /// </summary>
        /// <param name="SqlNum">SQL语句序号</param>
        /// <returns>SQL语句</returns>
        public String GetSQLCode(String SqlNum)
        {
            //SQL语句
            string SQLString = "";

            try
            {
                if (SQLCode == null)//如果缓存为null
                {
                    SQLCode = new Dictionary <string, string>();
                }

                if (!SQLCode.ContainsKey(SqlNum))//如果缓存中不存在SQL语句
                {
                    //SQL语句所在xml文件路径
                    string xmlPath = Path.Combine(SQLPath, SqlNum + ".xml");
                    //if (!File.Exists(xmlPath))
                    //{
                    //    return null;
                    //}
                    //实例化XML文件操作类
                    //XmlOperate _XmlOperate = new XmlOperate();
                    //判断配置文件是否只读
                    //FileInfo fi = new FileInfo(xmlPath);
                    //如果只读则修改为普通
                    //fi.Attributes = FileAttributes.Normal;
                    //实例化文件操作类
                    //DirectoryFileOperate _DirectoryFileOperate = new DirectoryFileOperate();
                    ////根据指定路径读取文件
                    //string _XmlContent = _DirectoryFileOperate.ShareReadFile(xmlPath);
                    ////把xml转换成对象
                    //SQLCodeEntity _SQLCodeEntity = _XmlOperate.SimpleXmlToObject<SQLCodeEntity>(_XmlContent);
                    SQLCodeEntity _SQLCodeEntity = SQLCodeHelp.GetSQLCodeEntityByPath(xmlPath);
                    SQLString = _SQLCodeEntity.SQLString;
                    //放入缓存
                    SQLCode.Add(SqlNum, SQLString);
                }
                else//如果缓存中存在SQL语句
                {
                    //从缓存中获取SQL语句
                    SQLString = SQLCode[SqlNum];
                }
            }
            catch (Exception ex)
            {
                return("");
            }
            return(SQLString);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 读取指定目录下的所有xml文件,将其转换为SQL语句实体对象列表
        /// </summary>
        /// <param name="path">xml文件的路径</param>
        /// <returns>SQL语句实体对象列表</returns>
        private List <SQLCodeEntity> ConvertXmlToEntity(String _Path)
        {
            try
            {
                List <SQLCodeEntity> _SQLCodeEntityLsit = new List <SQLCodeEntity>();
                DirectoryInfo        directory          = new DirectoryInfo(_Path);
                //DirectoryFileOperate df = new DirectoryFileOperate();
                XmlOperate _XmlOperate = new XmlOperate();

                if (directory.Exists)//判断目录是否存在
                {
                    List <string> _XmlPathlist = GetAllXmlFilelist(_Path);
                    //将xml文件转为iLogObject对象
                    foreach (string _path in _XmlPathlist)
                    {
                        //判断配置文件是否只读
                        FileInfo fi = new FileInfo(_path);
                        //如果只读则修改为普通
                        //if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                        //{
                        fi.Attributes = FileAttributes.Normal;
                        //}
                        //string _XmlContent = df.ShareReadFile(_path);
                        ////把xml转换成对象
                        //SQLCodeEntity _SQLCodeEntity = _XmlOperate.SimpleXmlToObject<SQLCodeEntity>(_XmlContent);
                        SQLCodeEntity _SQLCodeEntity = SQLCodeHelp.GetSQLCodeEntityByPath(_path);
                        if (_SQLCodeEntity == null || _SQLCodeEntity.SqlNum != Path.GetFileNameWithoutExtension(_path))
                        {
                            //重命名为源文件名+.bak扩展名
                            fi.MoveTo(_path + ".bak");
                            continue;
                        }
                        _SQLCodeEntityLsit.Add(_SQLCodeEntity);
                    }
                }
                return(_SQLCodeEntityLsit);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 根据SQL序号修改SQL文件
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>true:成功,false:失败</returns>
        public object EditSql(Dictionary <String, String> parameters)
        {
            try
            {
                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";
                //获取SQL说明
                string _SqlDescription = parameters.ContainsKey("SqlDescription") ? _JsonOperate.FromJsonString <string>(parameters["SqlDescription"]) : "";
                //获取SQL语句
                string _SQLString = parameters.ContainsKey("SQLString") ? _JsonOperate.FromJsonString <string>(parameters["SQLString"]) : "";

                //SQL语句所在xml文件路径
                string xmlPath = Path.Combine(SQLPath, _SqlNum + ".xml");
                if (!File.Exists(xmlPath))
                {
                    return(new { Methods = false });
                }
                //实例化XML文件操作类
                XmlOperate _XmlOperate = new XmlOperate();
                //实例化SQL实体类
                SQLCodeEntity _SQLCodeEntity = new SQLCodeEntity();
                _SQLCodeEntity.SqlNum         = _SqlNum;
                _SQLCodeEntity.SqlDescription = _SqlDescription;
                _SQLCodeEntity.SQLString      = _SQLString;

                //转换成xml字符串
                string _Xmlstring = _XmlOperate.ObjectToSimpleXml(_SQLCodeEntity);
                bool   _IsSuccess = SaveXml(_Xmlstring, xmlPath);
                return(new { Methods = _IsSuccess });
            }
            catch
            {
                return(new { Methods = false });
            }
        }