Example #1
0
        private static void InitLogApender(XmlHelper xml)
        {
            IList<XmlNode> list = xml.GetChildNodesFromCriteria("//log");

            foreach (XmlNode item in list)
            {
                string nodename = item.Attributes["name"].Value;
                string type = item.Attributes["type"].Value;

                string asmfile = "";
                if (item.Attributes["asmfile"] != null && !string.IsNullOrWhiteSpace(item.Attributes["asmfile"].Value))
                    asmfile = item.Attributes["asmfile"].Value;


                Type logtype;
                if (!string.IsNullOrEmpty(asmfile))
                {
                    logtype = CreateType(type, asmfile);
                }
                else
                {
                    logtype = Type.GetType(type);
                }
                if (logtype == null)
                    throw new Exception("logtype=" + type + "不存在");

                object logObj = Activator.CreateInstance(logtype);

                IList<XmlNode> paramlist = XmlHelper.GetChildNodesFromCriteria(item,
                                                                               "//log[@name='" + nodename + "']//param");
                //Console.WriteLine(value);

                //AppDomain.CurrentDomain.BaseDirectory


                foreach (XmlNode param in paramlist)
                {

                    string propertyName = param.Attributes["name"].Value;
                    string propertyValue = param.Attributes["value"].Value;

                    if (AsmUtil.ExistPropertyName(logObj, propertyName))
                        AsmUtil.SetPropertyValue(logObj, propertyName, propertyValue, null);

                    //var pros = logObj.GetType().GetProperties();
                }

                SingletonLogger.Instance.Attach((ILog)logObj);
            }
        }
Example #2
0
        public bool InitConfig(string configfile = "Log.config")
        {
            var xml = new XmlHelper();


            string applicationBaseDirectory = null;
            applicationBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string fullPath2ConfigFile = Path.Combine(applicationBaseDirectory, configfile);
            //如果存在配置文件就进行配置,否则就跳过
            if (!File.Exists(fullPath2ConfigFile))
                return false;

            xml.LoadXML(fullPath2ConfigFile, XmlHelper.LoadType.FromLocalFile);

            InitLogApender(xml);

            InitLogSeverity(xml);

            return true;
        }
Example #3
0
        public void MyTestMethodReadXML()
        {
            var xml = @"<cas:serviceResponse xmlns:cas=""http://www.yale.edu/tp/cas"">
  <cas:authenticationSuccess>
    <cas:user>[email protected]</cas:user>
    <cas:ext>
      <cas:Uid>1</cas:Uid>
      <cas:Sex>1</cas:Sex>
      <cas:NickName>zbw911</cas:NickName>
      <cas:City>170300</cas:City>
      <cas:Province>170000</cas:Province>
      <cas:UserName>[email protected]</cas:UserName>
    </cas:ext>
  </cas:authenticationSuccess>
</cas:serviceResponse>
";


            var xmlh = new XmlHelper();
            xmlh.LoadXML(xml, XmlHelper.LoadType.FromString);

            if (xmlh.RootNode.FirstChild.LocalName == "authenticationSuccess")
            {
                var value = xmlh.GetChildElementValue(xmlh.RootNode.FirstChild, "cas:user");
                Console.WriteLine(value);

                var exts = xmlh.GetFirstChildXmlNode(xmlh.RootNode.FirstChild, "cas:ext");


                var dic = new Dictionary<string, string>();


                for (var i = 0; i < exts.ChildNodes.Count; i++)
                {
                    var ext = exts.ChildNodes.Item(i);

                    dic.Add(ext.LocalName, ext.InnerText);
                }
            }
        }
Example #4
0
        private static void InitLogSeverity(XmlHelper xml)
        {
            XmlNode node = xml.GetFirstChildNodeFromCriteria("//logseverity");

            if (node == null) return;

            string strSeverity = node.Attributes["value"].Value;

            if (string.IsNullOrEmpty(strSeverity))
                return;

            LogSeverity severity;
            if (Enum.TryParse(strSeverity, true, out severity))
            {
                SingletonLogger.Instance.Severity = severity;
                //
                //Console.WriteLine(severity.ToString());
            }
            else
            {
                throw new Exception("日志安全级别配置错误");
            }
        }
Example #5
0
        /// <summary>
        ///   登录,如果这是一个登录的方法,那就直接去调用登录了
        /// </summary>
        /// <param name="strTicket"> </param>
        /// <param name="strService"> </param>
        /// <param name="strRedirectUrl"> </param>
        /// <param name="strUserName"> </param>
        /// <param name="strErrorText"> </param>
        /// <returns> </returns>
        public bool Login(
            string strTicket,
            string strService,
            out string strRedirectUrl,
            out string strUserName,
            out string strErrorText)
        {
            strRedirectUrl = "";
            strUserName = "";
            strErrorText = "";

            //如果没有登录成功就跳转到
            if (String.IsNullOrEmpty(strTicket))
            {
                strRedirectUrl = BuildLoginRequest(StrCasServerUrl, strService);

                return true;
            }

            // when we have a ticket, then validate it
            var strValidateUrl = BuildServiceValidateRequest(StrCasServerUrl, strService, strTicket);

            var isOK = false;
            try
            {
                //var xml = Dev.Comm.Net.Http.GetUrl(strValidateUrl);

                var xmlh = new XmlHelper();
                xmlh.LoadXML(strValidateUrl, XmlHelper.LoadType.FromURL);

                if (xmlh.RootNode.FirstChild.LocalName == "authenticationFailure")
                {
                    strErrorText = xmlh.RootNode.FirstChild.InnerText;
                }
                else if (xmlh.RootNode.FirstChild.LocalName == "authenticationSuccess")
                {
                    strUserName = xmlh.GetChildElementValue(xmlh.RootNode.FirstChild, "cas:user");

                    //ext Infos
                    var exts = xmlh.GetFirstChildXmlNode(xmlh.RootNode.FirstChild, "cas:ext");
                    var dic = new Dictionary<string, string>();

                    if (exts != null)
                    {
                        for (var i = 0; i < exts.ChildNodes.Count; i++)
                        {
                            var ext = exts.ChildNodes.Item(i);

                            dic.Add(ext.LocalName, ext.InnerText);
                        }
                    }

                    //hand User
                    UserAuthenticateManager.Provider.SignUserLogin(strUserName, extDatas: dic);

                    User.UserInfo.SetCurrentUserName(strUserName);

                    isOK = true;
                }
            }
            catch (Exception e)
            {
                strErrorText = e.Message;

                Dev.Log.Loger.Error(e);
            }

            return isOK;
        }