Exemple #1
0
 public object nextCodeLink(int order)
 {
     if (CodeIndex.TryGetValue(order + 1, out KeyValuePair <string, string> entry))
     {
         return(entry);
     }
     return(null);
 }
        public void TestSetup()
        {
            ICodeIndex contractOrderOne = new CodeIndex(PARTY_CODE_DEFAULT, 1);
            ICodeIndex positionOrderOne = new CodeIndex(PARTY_CODE_DEFAULT, 1);

            ICodeIndex contractOrderTwo = new CodeIndex(PARTY_CODE_DEFAULT, 2);
            ICodeIndex positionOrderTwo = new CodeIndex(PARTY_CODE_DEFAULT, 2);

            partyOne = new BookParty(contractOrderOne, positionOrderOne);
            partyTwo = new BookParty(contractOrderTwo, positionOrderTwo);
        }
Exemple #3
0
        public ActionResult PutCode(string codeLanguage, string codeSearchText, string codeSearchCodeBody)
        {
            var result = new JsonResponse
            {
                success = true
            };

            if (codeLanguage.IsNullOrEmpty())
            {
                result.success = false;
                result.message = "请选择编程语言";
            }
            else if (codeSearchText.IsNullOrEmpty())
            {
                result.success = false;
                result.message = "搜索词不能为空";
            }
            else if (codeSearchCodeBody.IsNullOrEmpty())
            {
                result.success = false;
                result.message = "代码不能为空";
            }
            else
            {
                var m = new CodeIndex
                {
                    CodeBody   = codeSearchCodeBody,
                    Id         = codeSearchCodeBody.ToHashText(),
                    Language   = codeLanguage,
                    Operate    = Operate.AddOrUpdate,
                    SearchText = codeSearchText,
                    UserId     = UserId,
                    FileId     = string.Empty
                };

                var indexMgr = this.GetIndexManager();
                indexMgr.Enqueue(m);
            }

            return(Json(result));
        }
        public void SaveIndex(Code code)
        {
            CodeIndex index = new CodeIndex();
            index.Id = code.Id;
            //index.Content = code.Content;
            index.Content = code.Content.Replace("\r\n", string.Empty);
            //index.CodeId = code.Id;

            var pre = Predicates.Field<CodeIndex>(f => f.Id, Operator.Eq, code.Id, false);
            var count = Db.Count<CodeIndex>(pre);
            // var x = Db.Get<CodeIndex>(index.Id);
            if (count > 0)
            {
                Db.Update(index);
            }
            else
            {
                Db.Insert(index);
            }
        }
Exemple #5
0
 protected override void Visit(CodeIndex expression)
 {
     Visit(expression.Object);
     Visit(expression.Index);
 }
Exemple #6
0
        private async Task <List <CodeIndex> > ParseCsharpFile(string fileContent)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("([A-Z]+[a-z]+)");
            List <CodeIndex> result = new List <CodeIndex>();
            await Task.Run((Action)(() =>
            {
                var tree = CSharpSyntaxTree.ParseText(fileContent);
                var node = tree.GetRoot();
                foreach (var n in node.DescendantNodes())
                {
                    if ((n is ClassDeclarationSyntax) ||
                        (n is MethodDeclarationSyntax) &&
                        n.HasLeadingTrivia)
                    {
                        var codeBody = n.GetText().ToString();
                        string methodName = string.Empty;

                        if (n is MethodDeclarationSyntax)
                        {
                            methodName = (n as MethodDeclarationSyntax).Identifier.Text;
                        }

                        if (n is ClassDeclarationSyntax)
                        {
                            methodName = (n as ClassDeclarationSyntax).Identifier.Text;
                        }

                        foreach (var d in n.GetLeadingTrivia())
                        {
                            if (d.HasStructure)
                            {
                                var o = d.GetStructure()
                                        .DescendantNodes()
                                        .Where(p => p is XmlTextSyntax)
                                        .OfType <XmlTextSyntax>()
                                        .Select(p => p.TextTokens);
                                var comment = string.Empty;
                                foreach (var r in o)
                                {
                                    foreach (var w in r)
                                    {
                                        if (w.RawKind == (int)SyntaxKind.XmlTextLiteralToken &&
                                            w.HasLeadingTrivia &&
                                            w.Text.Trim().Length > 0)
                                        {
                                            comment = w.Text;
                                        }
                                    }
                                }

                                var m = new CodeIndex
                                {
                                    Id = codeBody.ToHashText(),
                                    CodeBody = codeBody,
                                    SearchText = comment + " "
                                                 // 将 Pascal 名称拆分成空格连接的单个单词
                                                 + regex.Replace(methodName, s => (s.Value.Length > 3 ? s.Value : s.Value.ToLower()) + " "),
                                    UserId = UserId,
                                    Language = CodeLanguage.Csharp,
                                    FileContent = fileContent,
                                    FileId = fileContent.ToHashText()
                                };

                                result.Add(m);
                            }
                        }
                    }
                }
            }));

            return(result);
        }