Exemple #1
0
    /// <summary>
    /// Page_Load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (UserOperation.CheckLoged(Session) == false)
        {
            SmallScript.goRedirect(Response, Session, "请登录后再浏览本页", "/Login.aspx");
        }
        string id = Request.QueryString["id"].ToString();

        try
        {
            codeEntity = CodeOperation.GetCode(int.Parse(id));
            langEntity = LangOperation.GetLang(codeEntity.Lid);
            userEntity = UserOperation.GetUser(codeEntity.Uid);
            /*Pre += "<pre style=\"margin:auto;\" class=\"brush: " + langEntity.BrushAliases + ";toolbar: false;\">";*/
            Pre += File.ReadAllText(Server.MapPath(AppConfiger.GetProjectsDir(Server) + codeEntity.Path), System.Text.Encoding.GetEncoding("GBK"));
            //取出相关的注释
            List <NoteEntity> assnotes = CodeOperation.GetAssNotes(codeEntity.Id);
            //对注释进行分组
            List <int> index      = new List <int>();
            List <int> indexCount = new List <int>();
            foreach (NoteEntity ne in assnotes)
            {
                if (!index.Contains(ne.StartLine))
                {
                    index.Add(ne.StartLine);
                    indexCount.Add(1);
                }
                else
                {
                    int myindex = 0;
                    while (index[myindex] != ne.StartLine)
                    {
                        myindex++;
                    }
                    indexCount[myindex]++;
                }
            }
            //编译成js支持的数组格式
            jsaLineNum   = complieArray(index);
            jsaLineCount = complieArray(indexCount);
            /* Pre += "</pre>";*/
            if (index.Count == 0)
            {
                jsaLineNum   = "[]";
                jsaLineCount = "[]";
            }
        }
        catch { }
    }
Exemple #2
0
 private static void PopulateOperationsQueue(Queue <UnitTestOperator> queue, CodeOperation codeOperation, int start = 0)
 {
     for (int i = start; i < codeOperation.Methods.Count; i++)
     {
         if (codeOperation.Expected?[i] == null)
         {
             queue.Enqueue(new ActionOperator(
                               codeOperation.Methods[i],
                               codeOperation.Params[i]));
         }
         else
         {
             queue.Enqueue(new FunctionOperator(
                               codeOperation.Methods[i],
                               codeOperation.Params[i],
                               codeOperation.Expected[i]));
         }
     }
 }
Exemple #3
0
    /// <summary>
    /// 获取文件
    /// </summary>
    /// <param name="dir"></param>
    /// <returns></returns>
    private List <TreeNodeEntity> GetDirNode(string dir)
    {
        List <TreeNodeEntity> filesEntities = new List <TreeNodeEntity>();

        string[] dirs = Directory.GetDirectories(dir);
        foreach (string InDir in dirs)
        {
            TreeNodeEntity dirNode = new TreeNodeEntity();
            dirNode.Name     = InDir.Substring(InDir.LastIndexOf("\\") + 1, InDir.Length - InDir.LastIndexOf("\\") - 1);
            dirNode.Open     = false;
            dirNode.Children = GetDirNode(InDir);
            filesEntities.Add(dirNode);
        }
        string[] files = Directory.GetFiles(dir);
        foreach (string InFile in files)
        {
            TreeNodeEntity fileNode = new TreeNodeEntity();
            CodeEntity     ce       = CodeOperation.GetCodeFromPath(dir.Replace(
                                                                        Server.MapPath(AppConfiger.GetProjectsDir(Server)), "") +
                                                                    "\\" + InFile.Substring(InFile.LastIndexOf("\\") + 1, InFile.Length - InFile.LastIndexOf("\\") - 1));
            if (ce != null)
            {
                fileNode.Id         = ce.Id;
                fileNode.Name       = ce.Path.Substring(ce.Path.LastIndexOf("\\") + 1, ce.Path.Length - ce.Path.LastIndexOf("\\") - 1);
                fileNode.TargetName = "sourceFrame";
                fileNode.UrlFormat  = "/Viewer.aspx?id={0}";
                filesEntities.Add(fileNode);
            }
            else
            {
                fileNode.Name = InFile.Substring(InFile.LastIndexOf("\\") + 1, InFile.Length - InFile.LastIndexOf("\\") - 1);
                filesEntities.Add(fileNode);
            }
        }
        return(filesEntities);
    }
Exemple #4
0
        public static object DoMath(string code)
        {
            char[] mathops = { '+', '-', '/', '*' };
            object ret     = null;

            List <CodeOperation> operations = new List <CodeOperation>();

            if (code[0] != '+' && code[0] != '-' && code[0] != '/' && code[0] != '*')
            {
                code = code.Insert(0, "+");
            }
            while (code.Length > 0)
            {
                CodeOperation op   = new CodeOperation();
                int           p    = code.IndexOf('+');
                int           m    = code.IndexOf('-');
                int           d    = code.IndexOf('/');
                int           mp   = code.IndexOf('*');
                int           less = StringUtils.GetLess(-1, p, m, d, mp);
                if (less == p)
                {
                    op.Operation = 0;
                }
                if (less == m)
                {
                    op.Operation = 1;
                }
                if (less == d)
                {
                    op.Operation = 2;
                }
                if (less == mp)
                {
                    op.Operation = 3;
                }
                if (less != int.MaxValue)
                {
                    string subs = StringUtils.CustomSubstring(code, 1, mathops);
                    op.Code  = subs;
                    op.Value = StringUtils.ToPossibleValue(subs, out op.Type);
                    if (string.IsNullOrEmpty(subs))
                    {
                        break;
                    }
                    code = code.Replace(subs, "");
                    code = code.Remove(0, 1);
                }
                else
                {
                    break;
                }
                operations.Add(op);
            }

            var           plus = StringUtils.OnlySplit(code, '+', '-', '/', '*');
            List <object> args = new List <object>();
            Type          t    = null;

            foreach (var p in plus)
            {
                Type nT  = null;
                var  obj = StringUtils.ToPossibleValue(p, out nT);
                if (t != null && nT != null && nT != t)
                {
                    t = null;
                    break;
                }
                else
                {
                    args.Add(obj);
                }
                t = nT;
            }
            if (t != null)
            {
                ret = DoMathOperation(t, 0, args.ToArray());
                t   = null;
            }
            args.Clear();

            return(ret);
        }
Exemple #5
0
    protected void FixUrl(object sender, EventArgs e)
    {
        HyperLink hl = (HyperLink)sender;

        if (hl.NavigateUrl == "..")
        {
            string tempDir = Dir.Substring(0, Dir.LastIndexOf("\\"));
            if (tempDir == AppConfiger.GetProjectsDir(Server))
            {
                hl.NavigateUrl = "";
            }
            else
            {
                hl.NavigateUrl = Request.Url.AbsolutePath + "?dir=" + tempDir;
            }
        }
        else
        {/*如果是是文件夹*/
            if (Directory.Exists(Server.MapPath(Dir + "\\" + hl.NavigateUrl)))
            {
                hl.NavigateUrl = Request.Url.AbsolutePath + "?dir=" + Dir + "\\" + hl.NavigateUrl +
                                 (Request.QueryString["projectname"] != null? "&projectname=" + Request.QueryString["projectname"].ToString():"");
            }
            else
            {
                /*如果是普通文件*/
                dir = Request.QueryString["dir"].ToString();
                dir = dir.Replace(AppConfiger.GetProjectsDir(Server), "");
                CodeEntity ce = CodeOperation.GetCodeFromPath(dir + "\\" + hl.NavigateUrl);
                /*如果该文件已经登记在案*/
                if (ce != null)
                {
                    /*指向*/
                    hl.NavigateUrl = "/Viewer.aspx?id=" + ce.Id.ToString();
                }
                else
                {
                    hl.ForeColor   = System.Drawing.Color.Gray;
                    hl.NavigateUrl = "";
                }
            }
        }


        /*
         * if (btn.Text == "..")
         * {
         *  string tempDir = Dir.Substring(0, Dir.LastIndexOf("\\") + 1);
         *  if (tempDir == Server.MapPath(AppConfiger.GetProjectsDir(Server)))
         *  {
         *      return;
         *  }
         *  else
         *  {
         *      this.Dir = tempDir;
         *  }
         * }
         * else
         * {
         *  this.Dir = dir + "\\" + btn.Text;
         * }
         */
    }
Exemple #6
0
 public CodeOperation UpdateCodeOperation(CodeOperation codeOperation)
 {
     return(_codeOperationDal.Update(codeOperation));
 }
Exemple #7
0
 public void DeleteCodeOperation(CodeOperation codeOperation)
 {
     _codeOperationDal.Delete(codeOperation);
 }
Exemple #8
0
 public CodeOperation AddCodeOperation(CodeOperation codeOperation)
 {
     return(_codeOperationDal.Add(codeOperation));
 }