예제 #1
0
        public void TestListItemsByProject()
        {
            ListItemsByProjectRequest request = new ListItemsByProjectRequest();

            request.ProjectName = "Test2";
            ListItemsByProjectResponse response = bal.ListItemsByProject(request);

            Assert.AreEqual(StatusCodes.Status_Success, response.StatusCode);
        }
예제 #2
0
        public ActionResult ListItemsByProject(string ProjectName)
        {
            IProjectBAL projectBAL            = new ProjectBAL();
            ListItemsByProjectRequest request = new ListItemsByProjectRequest();

            request.ProjectName = ProjectName;
            ListItemsByProjectResponse response = projectBAL.ListItemsByProject(request);

            return(Json(response));
        }
예제 #3
0
        public ListItemsByProjectResponse ListItemsByProject(ListItemsByProjectRequest request)
        {
            ListItemsByProjectResponse response = new ListItemsByProjectResponse();
            string projectPath = ProjectBasePath + request.ProjectName;

            Repository repo = new Repository(projectPath);

            if (Directory.Exists(projectPath))
            {
                string[] itemPaths = Directory.GetFiles(projectPath);

                // Get connection string from Project's _Db.config file
                ProjectDomain projectDomain = ProjectDomainHelper.ToProjectDomain(File.ReadAllText(projectPath + "\\_Db.config"));

                // Get all tables
                IDbBAL dbBAL = new DbBAL();
                ListAllTablesRequest listAllTablesRequest = new ListAllTablesRequest();
                listAllTablesRequest.ProjectName = request.ProjectName;
                ListAllTablesResponse listAllTables = dbBAL.ListAllTables(listAllTablesRequest);

                if (listAllTables.Tables.Count > 0)
                {
                    response.TableItems = new List <CommitItemDomain>();
                    foreach (CommitItemDomain commitItem in listAllTables.Tables)
                    {
                        response.TableItems.Add(commitItem);
                        string itemPath = projectPath + "\\" + commitItem.GetCommitItemFileName();
                        if (File.Exists(itemPath))
                        {
                            //

                            // Write create definition to the file
                            File.WriteAllText(itemPath, commitItem.CurrentDefinition + "\n");

                            // Get Diff
                            foreach (PatchEntryChanges c in repo.Diff.Compare <Patch>())
                            {
                                commitItem.Diff = c.Patch;
                            }

                            // Reset to the latest commit since we already got the difference.
                            repo.Reset(ResetMode.Hard);
                        }
                        else
                        {
                            commitItem.Diff = commitItem.CurrentDefinition;
                        }
                    }
                }

                DbObjectDAL dbObjectDAL = new DbObjectDAL(ProjectDomainHelper.ToConnectionString(projectDomain));
                // Get Function
                List <DbObject> functions = dbObjectDAL.GetDbObjectsByType(DbObject.Type_Function);

                if (functions != null && functions.Count > 0)
                {
                    response.FunctionItems = new List <CommitItemDomain>();
                    foreach (DbObject function in functions)
                    {
                        CommitItemDomain item = new CommitItemDomain();
                        item.ItemType          = CommitItemDomain.ItemType_Function;
                        item.Name              = function.Name;
                        item.CurrentDefinition = function.Definition;
                        response.FunctionItems.Add(item);
                    }

                    //TODO
                    foreach (CommitItemDomain commitItem in response.FunctionItems)
                    {
                        string itemPath = projectPath + "\\" + commitItem.GetCommitItemFileName();
                        if (File.Exists(itemPath))
                        {
                            // Write create definition to the file
                            File.WriteAllText(itemPath, commitItem.CurrentDefinition + "\n");

                            // Get Diff
                            foreach (PatchEntryChanges c in repo.Diff.Compare <Patch>())
                            {
                                commitItem.Diff = c.Patch;
                            }

                            // Reset to the latest commit since we already got the difference.
                            repo.Reset(ResetMode.Hard);
                        }
                        else
                        {
                            commitItem.Diff = commitItem.CurrentDefinition;
                        }
                    }
                }

                // Get SP
                List <DbObject> storedProcedures = dbObjectDAL.GetDbObjectsByType(DbObject.Type_Stored_Procedure);
                if (storedProcedures != null && storedProcedures.Count > 0)
                {
                    response.StoredProcedureItems = new List <CommitItemDomain>();
                    foreach (DbObject storedProcedure in storedProcedures)
                    {
                        CommitItemDomain item = new CommitItemDomain();
                        item.ItemType          = CommitItemDomain.ItemType_Function;
                        item.Name              = storedProcedure.Name;
                        item.CurrentDefinition = storedProcedure.Definition;
                        response.StoredProcedureItems.Add(item);
                    }

                    //TODO
                    foreach (CommitItemDomain commitItem in response.StoredProcedureItems)
                    {
                        string itemPath = projectPath + "\\" + commitItem.GetCommitItemFileName();
                        if (File.Exists(itemPath))
                        {
                            // Write create definition to the file
                            File.WriteAllText(itemPath, commitItem.CurrentDefinition + "\n");

                            // Get Diff
                            foreach (PatchEntryChanges c in repo.Diff.Compare <Patch>())
                            {
                                commitItem.Diff = c.Patch;
                            }

                            // Reset to the latest commit since we already got the difference.
                            repo.Reset(ResetMode.Hard);
                        }
                        else
                        {
                            commitItem.Diff = commitItem.CurrentDefinition;
                        }
                    }
                }
            }
            else
            {
                response.StatusCode    = StatusCodes.Status_Error;
                response.StatusMessage = "Project not exists";
            }

            return(response);
        }