Beispiel #1
0
        /// <summary>
        /// 设置值
        /// </summary>
        public bool SetValue(string _ILanguage, string _IDomain, string _IKey, string _IValue)
        {
            bool reVal = true;

            _IDomain = _IDomain.IsNullOrEmpty() ? _IKey : _IDomain;
            string FilePath = SuperManager.FileFullPath("~/Lang/" + _ILanguage + "/" + _IDomain + ".dll");

            try
            {
                if (_IDomain.IsNullOrEmpty())
                {
                    File.WriteAllText(FilePath, _IValue, Encoding.UTF8);
                }
                else
                {
                    string NodePath = "//root/Item[Name='" + _IKey + "']";
                    XMLHelper.UpdateNodeText(FilePath, NodePath, _IValue);
                }
            }
            catch (Exception ex)
            {
                ex.ToLog();
                reVal = false;
            }
            return(reVal);
        }
Beispiel #2
0
 /// <summary>
 /// 加载缓存策略
 /// </summary>
 public static void Load()
 {
     try
     {
         TargetStrategyInfo TargetStrategy = StrategyManage.GetTargetStrategy("Cache");
         string TargetStrategyFilePath = SuperManager.FileFullPath("~/Strategy/" + TargetStrategy.StrategyFile);
         Assembly _Assembly = Assembly.LoadFile(TargetStrategyFilePath);
         if (_Assembly.IsHasAttributeClass<StrategyCodeAttribute>())
         {
             string StrategyDomainName = TargetStrategy.StrategyFile.RemoveEndChar(".dll");
             string StrategyClassFullName = StrategyDomainName + "." + TargetStrategy.ClassName;
             Assembly asmb = Assembly.LoadFrom(TargetStrategyFilePath);
             var AttributeType = asmb.GetType(StrategyClassFullName);
             _CacheStrategy = (ICacheStrategy)Activator.CreateInstance(AttributeType);
         }
         else
         {
             string StrategyDirectory = SuperManager.FileFullPath("~/Strategy/");
             string[] StrategyFileNameList = Directory.GetFiles(System.Web.HttpRuntime.BinDirectory, "*.Strategy.*.dll", SearchOption.TopDirectoryOnly);
         }
     }
     catch (Exception ex)
     {
         ex.ToLog();
     }
 }
Beispiel #3
0
        /// <summary>
        /// 获取值
        /// </summary>
        public string GetValue(string _ILanguage, string _IDomain, string _IKey)
        {
            string reVal = string.Empty;

            _IDomain = _IDomain.IsNullOrEmpty() ? _IKey : _IDomain;
            string FilePath = SuperManager.FileFullPath("~/Lang/" + _ILanguage + "/" + _IDomain + ".lang");

            if (File.Exists(FilePath))
            {
                if (_IDomain.IsNullOrEmpty())
                {
                    reVal = File.ReadAllText(FilePath);
                }
                else
                {
                    try
                    {
                        string      NodePath = "//root/Item[@Name='" + _IKey + "']";
                        XmlNodeList NodeList = XMLHelper.NodeList(FilePath, NodePath);
                        if (NodeList.Count > 0)
                        {
                            reVal = NodeList[0].InnerText;
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToLog();
                    }
                }
            }

            return(reVal);
        }
Beispiel #4
0
        /// <summary>
        /// 节点属性值
        /// </summary>
        /// <param name="XmlFilePath"></param>
        /// <param name="NodePath"></param>
        /// <param name="xmlAttributeName"></param>
        /// <returns></returns>
        public static XmlAttribute NodeAttribute(string XmlFilePath, string NodePath, string XmlAttributeName)
        {
            XmlAttribute reVal = null;

            try
            {
                string      Content = string.Empty;
                XmlDocument Doc     = new XmlDocument();
                XmlFilePath = SuperManager.FileFullPath(XmlFilePath);
                Doc.Load(XmlFilePath);
                XmlNode Node = Doc.SelectSingleNode(NodePath);
                if (Node != null)
                {
                    if (Node.Attributes.Count > 0)
                    {
                        reVal = Node.Attributes[XmlAttributeName];
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("XmlFilePath", XmlFilePath);
                ex.Data.Add("NodePath", NodePath);
                ex.Data.Add("XmlAttributeName", XmlAttributeName);
                throw ex;
            }
            return(reVal);
        }
Beispiel #5
0
        /// <summary>
        /// 创建日志文件
        /// </summary>
        private static void CreateLogFile(string mode)
        {
            string LogDirectory = SuperManager.FileFullPath("~\\Log\\");

            if (LogDirectory.IsNullOrEmpty())
            {
                LogDirectory = "Log";
            }
            if (SuperManager.WorkingMode == RunMode.Web)
            {
                if (!Directory.Exists(LogDirectory))
                {
                    Directory.CreateDirectory(LogDirectory);
                }
                _LogFile = Path.Combine(LogDirectory, DateTime.Now.ToString("yyyy-MM-dd") + ".log");
            }
            else
            {
                if (!Directory.Exists(LogDirectory))
                {
                    Directory.CreateDirectory(LogDirectory);
                }
                _LogFile = Path.Combine(LogDirectory, DateTime.Now.ToString("yyyy-MM-dd") + ".log");
            }
            if (!File.Exists(_LogFile.Replace(".log", "." + mode + ".log")))
            {
                FileStream fs = File.Create(_LogFile.Replace(".log", "." + mode + ".log"));
                fs.Close();
            }
        }
Beispiel #6
0
        /// <summary>
        ///  删除节点指定属性
        /// </summary>
        /// <param name="XmlFilePath">XML文件路径</param>
        /// <param name="NodePath">节点路径</param>
        /// <param name="AttriteName">属性名称</param>
        /// <returns>返回值:节点属性删除是否成功</returns>
        public static bool DeleteNodeAttrite(string XmlFilePath, string NodePath, string AttriteName)
        {
            bool reVal = false;

            try
            {
                XmlFilePath = SuperManager.FileFullPath(XmlFilePath);
                XmlDocument Doc = new XmlDocument();
                Doc.Load(XmlFilePath);
                XmlNode Node = Doc.SelectSingleNode(NodePath);
                if (Node != null)
                {
                    Node.ParentNode.RemoveChild(Node);
                }
                Doc.Save(XmlFilePath);
                reVal = true;
            }
            catch (Exception ex)
            {
                ex.Data.Add("XmlFilePath", XmlFilePath);
                ex.Data.Add("NodePath", NodePath);
                throw ex;
            }
            return(reVal);
        }
Beispiel #7
0
        /// <summary>
        /// 读取配置信息
        /// </summary>
        public static string ReadData(string _InputConfigType, string _IKey)
        {
            string reVal = string.Empty;

            _InputConfigType = _InputConfigType.TBBRTrim();
            string XmlFilePath = SuperManager.FileFullPath(ConfigBaseDir + "/" + _InputConfigType + ".config");

            if (File.Exists(XmlFilePath))
            {
                XmlNode Node = XMLHelper.SingleNode(XmlFilePath, "//root/config/" + _IKey);
                if (Node != null)
                {
                    reVal = Node.InnerText;
                }
                else
                {
                    WriteData(_InputConfigType, _IKey, "");
                }
            }
            else
            {
                WriteData(_InputConfigType, _IKey, "");
            }
            return(reVal);
        }
Beispiel #8
0
        /// <summary>
        /// 获取命名空间下的所有类型名称列表
        /// </summary>
        /// <param name="InputNameSpace">指定的命名空间</param>
        public static List <string> GetClassList(string InputNameSpace, string FileName = "")
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            if (FileName.IsNotNullOrEmpty())
            {
                asm = Assembly.LoadFrom(SuperManager.FileFullPath("~/bin/" + FileName));
            }
            List <string> NameSpaceList = new List <string>();
            List <string> reVal         = new List <string>();

            foreach (Type type in asm.GetTypes())
            {
                if (type.Namespace == InputNameSpace)
                {
                    NameSpaceList.Add(type.Name);
                }
            }
            foreach (string ClassName in NameSpaceList)
            {
                reVal.Add(ClassName);
            }

            return(reVal);
        }
Beispiel #9
0
        /// <summary>
        /// 获取指定类是否含有指定名称的方法
        /// </summary>
        /// <param name="ClassPath">类的全路径</param>
        /// <param name="InputMethodName">方法名称</param>
        public static bool IsHasMethod(this string ClassPath, string InputMethodName, string FileName = "")
        {
            bool   reVal = false;
            string Key   = ClassPath + "-" + InputMethodName + "-IsHasMethod";

            if (CacheManage.Get(Key) != null)
            {
                reVal = (bool)CacheManage.Get(Key);
            }
            else
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                if (FileName.IsNotNullOrEmpty())
                {
                    asm = Assembly.LoadFrom(SuperManager.FileFullPath("~/bin/" + FileName));
                }
                var           type           = asm.GetType(ClassPath);
                List <string> MethodNameList = GetMethodNameList(type);
                if (MethodNameList.Contains(InputMethodName))
                {
                    reVal = true;
                }
                CacheManage.Insert(Key, reVal);
            }
            return(reVal);
        }
Beispiel #10
0
        /// <summary>
        /// 加载数据文件
        /// </summary>
        /// <param name="XmlFilePath">数据文件路径</param>
        /// <returns>返回值:加载是否成功</returns>
        public bool LoadData(string _DirPath = "")
        {
            bool reVal = true;

            if (_DirPath.IsNullOrEmpty())
            {
                _DirPath = SuperManager.FileFullPath("~/DataModel/");
            }
            if (!_DirPath.EndsWith("\\"))
            {
                _DirPath = _DirPath + "\\";
            }
            if (Directory.Exists(_DirPath))
            {
                #region 加载表数据
                List <string> _DTMF   = SuperIO.SubFileName(_DirPath, ".dtml");
                List <string> _DTList = new List <string>();
                foreach (string _FMF in _DTMF)
                {
                    string _FilePath = _DirPath + _FMF;;
                    List <DataColumnModel> _DCMList = new List <DataColumnModel>();
                    DataTableModel         _DTM     = new DataTableModel();
                    XmlNode _Node = XMLHelper.SingleNode(_FilePath, "//root/Model");
                    _DTM.Name        = _Node.AttriteValue("DataTable");
                    _DTM.DisplayName = _Node.AttriteValue("DName");
                    XmlNodeList _NodeList = XMLHelper.NodeList(_FilePath, "//root/Model/Property");
                    foreach (XmlNode _FXN in _NodeList)
                    {
                        if (_FXN.Attributes["DBColumn"] != null && _FXN.Attributes["Type"] != null)
                        {
                            DataColumnModel _DCM = new DataColumnModel()
                            {
                                Name          = _FXN.AttriteValue("DBColumn"),
                                Length        = _FXN.AttriteValue("Length").ToInt(),
                                IsPrimaryKey  = _FXN.AttriteValue("IsPrimaryKey").ToBool(),
                                DisplayName   = _FXN.AttriteValue("DName"),
                                DataType      = _FXN.AttriteValue("Type"),
                                DecimalDigits = _FXN.AttriteValue("DecimalDigits").ToInt(),
                                DefaultValue  = _FXN.AttriteValue("DefaultValue"),
                                IsAllowNull   = _FXN.AttriteValue("IsAllowNull").ToBool(),
                                IsIdentity    = _FXN.AttriteValue("IsIdentity").ToBool()
                            };
                            _DCMList.Add(_DCM);
                        }
                    }
                    _DTM.ColumnList = _DCMList;
                    DTMList.Add(_DTM);
                }
                #endregion 加载表数据
            }

            return(reVal);
        }
Beispiel #11
0
        /// <summary>
        /// 调用实例的方法
        /// </summary>
        /// <param name="ClassPath">类路径</param>
        /// <param name="MethodName">方法名称</param>
        public static object CallMethod(this string ClassPath, string MethodName, object[] Prams, string FileName = "")
        {
            Assembly asm = Assembly.GetExecutingAssembly();

            if (FileName.IsNotNullOrEmpty())
            {
                asm = Assembly.LoadFrom(SuperManager.FileFullPath("~/bin/" + FileName));
            }
            var RunInstance = asm.CreateInstance(ClassPath);
            var type        = asm.GetType(ClassPath);
            var Method      = type.GetMethod(MethodName);
            var reVal       = Method.Invoke(RunInstance, Prams);

            return(reVal);
        }
Beispiel #12
0
        /// <summary>
        /// 获取列表值
        /// </summary>
        public Dictionary <string, string> GetValueList(string _ILanguage, string _IDomain)
        {
            Dictionary <string, string> reVal = new Dictionary <string, string>();
            string      FilePath = SuperManager.FileFullPath("~/Lang/" + _IDomain + ".dll");
            string      NodePath = "//root/Item";
            XmlNodeList NodeList = XMLHelper.NodeList(FilePath, NodePath);

            foreach (XmlNode Node in NodeList)
            {
                if (!reVal.ContainsKey(Node.AttriteValue("Name")))
                {
                    reVal.Add(Node.AttriteValue("Name"), Node.InnerText);
                }
            }

            return(reVal);
        }
Beispiel #13
0
        /// <summary>
        /// 节点列表
        /// </summary>
        /// <param name="XmlFilePath">XML文件路径</param>
        /// <param name="NodePath">节点路径</param>
        /// <returns>返回值:节点列表</returns>
        public static XmlNodeList NodeList(string XmlFilePath, string NodePath)
        {
            XmlDocument Doc = new XmlDocument();

            try
            {
                XmlFilePath = SuperManager.FileFullPath(XmlFilePath);
                Doc.Load(XmlFilePath);
                XmlNodeList reVal = Doc.SelectNodes(NodePath);

                return(reVal);
            }
            catch (Exception ex)
            {
                ex.Data.Add("XmlFilePath", XmlFilePath);
                ex.Data.Add("NodePath", NodePath);
                throw ex;
            }
        }
Beispiel #14
0
        /// <summary>
        /// 创建XML节点
        /// </summary>
        /// <param name="_IXmlFilePath">XML文件路径</param>
        /// <param name="_INodePath">节点路径</param>
        /// <param name="_INodeInnerText">节点文本</param>
        /// <param name="AttriteName">属性</param>
        /// <param name="AttriteValue">属性值</param>
        /// <returns>返回值:创建是否成功</returns>
        public static bool CreateNode(string _IXmlFilePath, string _INodePath, string _INodeName, string _INodeInnerText, string[] AttriteName, string[] AttriteValue)
        {
            bool reVal = false;

            try
            {
                _IXmlFilePath = SuperManager.FileFullPath(_IXmlFilePath);
                XmlDocument Doc = new XmlDocument();
                Doc.Load(_IXmlFilePath);
                XmlNode Node = Doc.SelectSingleNode(_INodePath);
                if (Node != null)
                {
                    XmlElement SubElement = Doc.CreateElement(_INodeName);
                    SubElement.InnerText = _INodeInnerText;
                    if (AttriteName.Length == AttriteValue.Length)
                    {
                        for (int i = 0; i < AttriteName.Length; i++)
                        {
                            if (!string.IsNullOrEmpty(AttriteName[i]) && !string.IsNullOrEmpty(AttriteValue[i]))
                            {
                                if (!SubElement.HasAttribute(AttriteName[i]))
                                {
                                    XmlAttribute NodeAttribute = Doc.CreateAttribute(AttriteName[i]);
                                    NodeAttribute.Value = AttriteValue[i];
                                    SubElement.Attributes.Append(NodeAttribute);
                                }
                            }
                        }
                    }
                    Node.AppendChild(SubElement);
                    Doc.Save(_IXmlFilePath);
                    reVal = true;
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("XmlFilePath", _IXmlFilePath);
                ex.Data.Add("NodePath", _INodePath);
                throw ex;
            }
            return(reVal);
        }
Beispiel #15
0
        /// <summary>
        /// 获取某个类型的配置项列表
        /// </summary>
        public static Dictionary <string, string> GetItemListByTypeName(string _IConfigTypeName)
        {
            Dictionary <string, string> reVal = new Dictionary <string, string>();
            string      XmlFilePath           = SuperManager.FileFullPath(ConfigBaseDir + "/" + _IConfigTypeName.Trim() + ".config");
            XmlNodeList NodeList = XMLHelper.SingleNode(XmlFilePath, "//root/config").ChildNodes;

            foreach (XmlNode Node in NodeList)
            {
                ConfigItem Item = new ConfigItem()
                {
                    Key   = Node.Name,
                    Value = Node.InnerText
                };
                if (!reVal.ContainsKey(Item.Key))
                {
                    reVal.Add(Item.Key, Item.Value);
                }
            }
            return(reVal);
        }
Beispiel #16
0
        /// <summary>
        /// 写配置信息
        /// </summary>
        public static void WriteData(string _InputConfigType, string _IKey, string _IValue)
        {
            _InputConfigType = _InputConfigType.TBBRTrim();
            string XmlFilePath = SuperManager.FileFullPath(ConfigBaseDir + "/" + _InputConfigType + ".config");

            try
            {
                if (!File.Exists(XmlFilePath))
                {
                    XMLHelper.CreateXMLDocument(XmlFilePath, "root");
                    XMLHelper.CreateNode(XmlFilePath, "//root", "config", null, null, null);
                }
                XMLHelper.CreateNode(XmlFilePath, "//root/config/" + _IKey, _IValue, null, null, null);
                XMLHelper.UpdateNodeText(XmlFilePath, "//root/config/" + _IKey, _IValue);
            }
            catch (Exception ex)
            {
                ex.ToLog();
            }
        }
Beispiel #17
0
        /// <summary>
        /// 修改节点文本值
        /// </summary>
        /// <param name="XmlFilePath">XML文件路径</param>
        /// <param name="NodePath">节点路径</param>
        /// <param name="NodeInnerText">节点文本</param>
        /// <returns>返回值:修改是否成功</returns>
        public static bool UpdateNodeText(string XmlFilePath, string NodePath, string NodeInnerText)
        {
            bool reVal = false;

            try
            {
                XmlFilePath = SuperManager.FileFullPath(XmlFilePath);
                XmlDocument Doc = new XmlDocument();
                Doc.Load(XmlFilePath);
                XmlNode Node = Doc.SelectSingleNode(NodePath);
                Node.InnerText = NodeInnerText;
                Doc.Save(XmlFilePath);
                reVal = true;
            }
            catch (Exception ex)
            {
                ex.Data.Add("XmlFilePath", XmlFilePath);
                ex.Data.Add("NodePath", NodePath);
                throw ex;
            }
            return(reVal);
        }
Beispiel #18
0
        /// <summary>
        /// 写入配置列表项
        /// </summary>
        public static void WriteData(string InputTypeName, List <ConfigItem> _IList)
        {
            string XmlFilePath = SuperManager.FileFullPath(ConfigBaseDir + "/" + InputTypeName.Trim() + ".config");

            try
            {
                if (!File.Exists(XmlFilePath))
                {
                    XMLHelper.CreateXMLDocument(XmlFilePath, "root");
                    XMLHelper.CreateNode(XmlFilePath, "//root", "config", null, null, null);
                }
                foreach (ConfigItem Item in _IList)
                {
                    XMLHelper.CreateNode(XmlFilePath, "//root/config/" + Item.Key, Item.Value, null, null, null);
                    XMLHelper.UpdateNodeText(XmlFilePath, "//root/config/" + Item.Key, Item.Value);
                }
            }
            catch (Exception ex)
            {
                ex.ToLog();
            }
        }
Beispiel #19
0
        /// <summary>
        /// 创建XML文档
        /// </summary>
        /// <param name="_IXmlFilePath">XML文件路径</param>
        /// <param name="_IRootNodeName"> 根节点名称</param>
        /// <returns>返回值:创建XML文档是否成功</returns>
        public static bool CreateXMLDocument(string _IXmlFilePath, string _IRootNodeName)
        {
            bool reVal = true;

            try
            {
                _IXmlFilePath = SuperManager.FileFullPath(_IXmlFilePath);
                XmlDocument    XmlDoc         = new XmlDocument();
                XmlDeclaration XmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
                XmlNode        Root           = XmlDoc.CreateElement(_IRootNodeName);
                XmlDoc.AppendChild(XmlDeclaration);
                XmlDoc.AppendChild(Root);
                XmlDoc.Save(_IXmlFilePath);
                reVal = true;
            }
            catch (Exception ex)
            {
                ex.Data.Add("XmlFilePath", _IXmlFilePath);
                ex.Data.Add("RootNodeName", _IRootNodeName);
                throw ex;
            }
            return(reVal);
        }
Beispiel #20
0
        /// <summary>
        /// 更新或插入XML节点属性
        /// </summary>
        /// <param name="XmlFilePath">XML文件路径</param>
        /// <param name="NodePath">节点路径</param>
        /// <param name="WhereCondition">查询条件</param>
        /// <returns>返回值:更新XML节点属性</returns>
        public static bool UpdateOrCreateNodeAttrite(string XmlFilePath, string NodePath, string AttriteName, string AttriteValue, string WhereNodeText = null, Dictionary <string, string> WhereConditionAttrite = null)
        {
            bool reVal = false;

            try
            {
                XmlDocument Doc = new XmlDocument();
                XmlFilePath = SuperManager.FileFullPath(XmlFilePath);
                Doc.Load(XmlFilePath);
                XmlNodeList SelectNodeList = Doc.SelectNodes(NodePath);
                foreach (XmlNode node in SelectNodeList)
                {
                    bool isExistAttrite = false;
                    if (string.IsNullOrEmpty(WhereNodeText) || (WhereConditionAttrite != null && WhereConditionAttrite.Count > 0))
                    {
                        if (!string.IsNullOrEmpty(WhereNodeText) && node.InnerText.ToLower() == WhereNodeText.ToLower())
                        {
                            foreach (XmlAttribute nodeAttrite in node.Attributes)
                            {
                                if (nodeAttrite.Name.ToLower() == AttriteName.ToLower())
                                {
                                    nodeAttrite.Value = AttriteValue.Trim();
                                    isExistAttrite    = true;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            foreach (string key in WhereConditionAttrite.Keys)
                            {
                                foreach (XmlAttribute nodeAttrite in node.Attributes)
                                {
                                    if (nodeAttrite.Name == key && nodeAttrite.Value == WhereConditionAttrite[key])
                                    {
                                        foreach (XmlAttribute EveryAttrite in node.Attributes)
                                        {
                                            if (EveryAttrite.Name.ToLower() == AttriteName.ToLower())
                                            {
                                                EveryAttrite.Value = AttriteValue.Trim();
                                                isExistAttrite     = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (!isExistAttrite)
                        {
                            XmlAttribute NodeAttribute = Doc.CreateAttribute(AttriteName);
                            NodeAttribute.Value = AttriteValue;
                            node.Attributes.Append(NodeAttribute);
                        }
                    }
                }
                return(reVal);
            }
            catch (Exception ex)
            {
                ex.Data.Add("XmlFilePath", XmlFilePath);
                ex.Data.Add("NodePath", NodePath);
                ex.Data.Add("UpdateAttriteName", AttriteName);
                ex.Data.Add("UpdateAttriteValue", AttriteValue);
                throw ex;
            }
        }
Beispiel #21
0
 /// <summary>
 /// 文件全路径
 /// </summary>
 public static string FileFullPath(string _IFilePath)
 {
     return(SuperManager.FileFullPath(_IFilePath));
 }