Пример #1
0
        public ActionResult CreateClass(string className)
        {
            var project = Session["project"] as IRuntimeProject;
            if (project == null)
                return HttpNotFound(); //td: right error

            var contents = " ";
            if (string.IsNullOrEmpty(Path.GetExtension(className)))
                contents = string.Format("class {0} \n{{\n}}", className);

            var fileId = -1;
            if (Session["projectId"] != null)
            {
                ProjectRepository repo = new ProjectRepository();
                fileId = repo.CreateFile((int)Session["projectId"], className, contents);
            }

            project.add(className, fileId, contents);

            var node = new TreeNode
            {
                label = className,
                icon = "fa-code",
                action = "select-file",
                data = className,
                actions = new[]
                            {
                                new TreeNodeAction { id = "remove-file", icon = "fa-times-circle-o"       },
                                new TreeNodeAction { id = "open-tab",    icon = "fa-arrow-circle-o-right" },
                            }.Union(project.fileActions(className))
            };

            return Json(new
            {
                node
            }, JsonRequestBehavior.AllowGet);
        }
Пример #2
0
            public void cachedId(string name, int hash)
            {
                ProjectRepository repo = new ProjectRepository();

                var file = _project.Find(name);
                var fileID = -1;
                if (file == null)
                    fileID = repo.GetFileId(name, _project.ID);
                else
                    fileID = file.ID;

                Debug.Assert(fileID >= 0);
                repo.fileCache(fileID, hash);
            }
Пример #3
0
 public int addFile(string name, string contents, bool hidden)
 {
     ProjectRepository repo = new ProjectRepository();
     return repo.AddFile(_project, name, contents, hidden);
 }
Пример #4
0
            public int cachedId(string name)
            {
                var file = _project.Find(name);
                if (file == null)
                    return 0;

                ProjectRepository repo = new ProjectRepository();
                return repo.fileCache(file.ID);
            }
Пример #5
0
        public ActionResult UserProjects()
        {
            if (!User.Identity.IsAuthenticated)
                return HttpNotFound(); //td: right error

            ProjectRepository repo = new ProjectRepository();
            var projects = repo.GetUserProjects(User.Identity.GetUserId());
            return Json(projects, JsonRequestBehavior.AllowGet);
        }
Пример #6
0
        public ActionResult SaveFile(string file, string contents)
        {
            var project = Session["project"] as IRuntimeProject;
            if (project == null)
                return HttpNotFound(); //td: right error

            project.modify(file, contents);

            if (Session["projectId"] != null)
            {
                int fileIdx = project.fileId(file);
                if (fileIdx < 0)
                    return HttpNotFound(); //td: right error

                ProjectRepository repo = new ProjectRepository();
                repo.SaveFile(fileIdx, contents);
            }

            return Content("ok");
        }
Пример #7
0
        public ActionResult LoadProject(int projectId)
        {
            ProjectRepository repo = new ProjectRepository();

            dynamic config;
            Project project = repo.LoadProject(projectId, out config);
            if (project == null)
                return HttpNotFound();

            if (!project.IsSample)
            {
                if (!User.Identity.IsAuthenticated)
                    return HttpNotFound(); //td: right error

                if (User.Identity.GetUserId() != project.UserID)
                    return HttpNotFound(); //td: right error
            }

            var path = new Scope(null) as dynamic;
            path.ToolPath = Path.Combine(Server.MapPath("~/App_Data"), "Tools");

            IRuntimeProject runtime = _manager.createRuntime(project.ProjectType, project.Name, config, path, new ProjectStorage(project));
            foreach (var file in project.ProjectFiles)
                runtime.add(file.Name, file.ID, file.Contents);

            Session["project"] = runtime;

            if (!project.IsSample)
                Session["projectId"] = project.ID;
            else
                Session["SampleProjectId"] = project.ID;

            return Json(new
            {
                defaultFile = runtime.defaultFile(),
                tree        = new[] { projectTree(project, runtime) }
            }, JsonRequestBehavior.AllowGet);
        }
Пример #8
0
        public ActionResult CreateProject(string projectType, string projectName, string projectData)
        {
            if (!User.Identity.IsAuthenticated)
                return HttpNotFound(); //td: right error

            ProjectRepository repo   = new ProjectRepository();
            Project           result = repo.CreateProject(projectType, projectName, projectData, User.Identity.GetUserId());

            return Json(new { projectId = result.ID }, JsonRequestBehavior.AllowGet);
        }
Пример #9
0
 public ActionResult GetSampleProjects()
 {
     ProjectRepository repo = new ProjectRepository();
     return Json(repo.GetSampleProjects(), JsonRequestBehavior.AllowGet);
 }