Ejemplo n.º 1
0
        public string userResgister(string email, string userPass, string code)
        {
            string      message = "", status = '"' + "200" + '"', msg = '"' + "OK" + '"';
            ErrorMethod error = new ErrorMethod();
            InforMethod infor = new InforMethod();
            //if(code!=CODE)
            //{
            //    msg = '"' + "error" + '"';
            //    message = '"' + "验证错误" + '"';
            //    return $"[{{" + '"' + "status" + '"' + $":{status}," + '"'
            //         + "msg" + '"' + $":{msg},"
            //         + '"' + "data" + '"' + ':' + message + "}]";
            //}
            TB_User user = new TB_User();

            user.U_Email = email;
            //验证邮箱是否注册
            var result = _sugarTable.Where(it => it.U_Email.Contains(user.U_Email)).Any();

            if (result)
            {
                infor.WriteInforLog("邮箱已注册", "userResgister", "注册");
                status  = '"' + "200" + '"';
                msg     = '"' + "error" + '"';
                message = '"' + "邮箱已注册" + '"';
                return($"[{{" + '"' + "status" + '"' + $":{status}," + '"'
                       + "msg" + '"' + $":{msg}," + '"'
                       + "captcha" + '"' + ":" + $"{message}" + "}]");
            }
            user.U_PassWord = userPass;
            user.U_ICO      = "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png";
            Random random = new Random();

            while (true)
            {
                user.U_Id = random.Next(10000000, 100000000);
                if (!_sugarTable.Where(it => it.U_Id == user.U_Id).Any())
                {
                    break;
                }
            }
            while (true)
            {
                user.U_Account = "music_" + Guid.NewGuid().ToString().Substring(0, 6);
                if (!_sugarTable.Where(it => it.U_Account == user.U_Account).Any())
                {
                    break;
                }
            }
            user.U_Regtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            try
            {
                db.Saveable <TB_User>(user).ExecuteCommand();
                message = '"' + $"注册账号为:{ user.U_Account}" + '"';
            }
            catch (Exception e)
            {
                code    = '"' + "500" + '"';
                msg     = '"' + "error" + '"';
                message = '"' + "注册失败" + '"';
                error.WriteErrorLog(e, "GetMusicTypeName()", "TB_Music");
            }
            string ret = "[{" + '"' + "status" + '"' + $":{status},"
                         + '"' + "msg" + '"' + $":{msg}," + '"'
                         + "data" + '"' + $":{message}" + "}]";

            return(ret);
        }
Ejemplo n.º 2
0
        public static InforNameSpace CrawlFile(string pathFile)
        {
            try
            {
                //define regex pattern
                Regex  partternNameSpace = new Regex(@"namespace\s[\w\.]*");
                Regex  comments          = new Regex(@"(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)");
                string classNameRegex    = @"class\s+?([\w.]+)";
                string methodNameRegex   = @"(public|private|protected)\s*(?:static)?\s*[<datatype>\w]*\s+([\w]*)\s*\((\)|([\w\s\,\s*\)])*)";
                Regex  blockErrorPattern = new Regex(@"(ReplacementLog|DiLogger.[\w]+).Error\s?\(([^\;]+)\s?\;");
                Regex  blockClass        = new Regex(@"\b(class)(.+?)(?:(?!(public|private|protected|internal|partial)?\s+class).)*", RegexOptions.Singleline);
                Regex  blockMethod       = new Regex(@"(public|private|protected)\s*(?:static)?\s*[<datatype>\w]*\s+([\w]*)\s*\((\)|([\w\s\,\s*\)])*).*?(?:(?!\}\s*(public|private|protected)).)*");
                Regex  region            = new Regex(@"\#.+?(?:(?!\\r\\n).)*");
                //
                string         text       = System.IO.File.ReadAllText(pathFile);
                string         textFilter = text;
                InforNameSpace rowExcel   = new InforNameSpace();

                //
                MatchCollection matchComment = comments.Matches(text);
                // remove comment
                if (matchComment.Count != 0)
                {
                    textFilter = Regex.Replace(text, @"(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)", " ");
                }
                //get namespace
                MatchCollection nameSpaceMatches = partternNameSpace.Matches(textFilter);
                if (nameSpaceMatches.Count != 0)
                {
                    var temps = nameSpaceMatches[0];
                    rowExcel.nameSpace = temps.Value.Split(' ')[1];
                }
                else
                {
                    rowExcel.nameSpace = "No NameSpace";
                }
                int classCounting  = 1;
                int methodCounting = 1;
                int errorCounting  = 1;
                // get class name
                MatchCollection matchesBlockClass = blockClass.Matches(textFilter);
                if (matchesBlockClass.Count != 0)
                {
                    InforClass classInfor = new InforClass();
                    foreach (Match item in matchesBlockClass)
                    {
                        var itemReplacemented = region.Replace(item.Value, " ");
                        itemReplacemented    = Regex.Replace(itemReplacemented, @"\[.*\]\s*(?:(?!(public|private|protected|internal|partial)).)*", " ");
                        itemReplacemented    = itemReplacemented.Replace("\r\n", " ");
                        classInfor.ClassName = Regex.Match(item.Value, classNameRegex).Value;
                        MatchCollection matchesListMethods = blockMethod.Matches(itemReplacemented);
                        if (matchesListMethods.Count != 0)
                        {
                            foreach (Match m in matchesListMethods)
                            {
                                InforMethod method = new InforMethod();

                                method.methodName = Regex.Match(m.Value, methodNameRegex).Value;
                                MatchCollection ListErrors = blockErrorPattern.Matches(m.Value);
                                if (ListErrors.Count != 0)
                                {
                                    foreach (Match e in ListErrors)
                                    {
                                        InforError error = new InforError();
                                        error.Error  = e.Value;
                                        error.Number = (errorCounting++).ToString("\\'000");
                                        method.ListError.Add(error);
                                    }
                                }

                                method.Number = ListErrors.Count != 0 ? (methodCounting++).ToString("\\'000") : string.Empty;

                                errorCounting = 1;
                                classInfor.ListMethod.Add(method);
                            }
                        }
                        methodCounting    = 1;
                        classInfor.Number = (classCounting++).ToString("\\'000");
                    }
                    rowExcel.ListClass.Add(classInfor);
                }
                rowExcel.path = pathFile;
                return(rowExcel);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }