Esempio n. 1
0
        public ListAllTablesResponse ListAllTables(ListAllTablesRequest request)
        {
            ListAllTablesResponse response = new ListAllTablesResponse();

            string projectPath = ProjectBasePath + request.ProjectName;

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

                DbTableDAL     tableDAL = new DbTableDAL(ProjectDomainHelper.ToConnectionString(projectDomain));
                List <DbTable> tables   = tableDAL.GetTables();
                response.Tables = new List <CommitItemDomain>();
                foreach (DbTable table in tables)
                {
                    CommitItemDomain item = new CommitItemDomain();
                    item.ItemType          = CommitItemDomain.ItemType_Table;
                    item.Name              = table.TABLE_NAME;
                    item.CurrentDefinition = table.Definition;
                    response.Tables.Add(item);
                }
            }
            else
            {
                response.StatusCode    = StatusCodes.Status_Error;
                response.StatusMessage = "Project not exists";
            }

            return(response);
        }
Esempio n. 2
0
        public void TestCommitItem()
        {
            CommitItemRequest request = new CommitItemRequest();

            request.ProjectName = "Test2";
            CommitItemDomain item1 = new CommitItemDomain();

            item1.ItemType = CommitItemDomain.ItemType_Table;
            item1.Name     = "table1";
            request.CommitItems.Add(item1);

            CommitItemDomain item2 = new CommitItemDomain();

            item2.ItemType = CommitItemDomain.ItemType_Table;
            item2.Name     = "table2";
            request.CommitItems.Add(item2);

            CommitItemRequestResponse response = bal.CommitItem(request);

            Assert.AreEqual(StatusCodes.Status_Success, response.StatusCode);
        }
Esempio n. 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);
        }