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); }
public CreateProjectResponse CreateProject(CreateProjectRequest request) { CreateProjectResponse response = new CreateProjectResponse(); LogDAL logDAL = new LogDAL(); string projectPath = ProjectBasePath + request.project.ProjectName; string result = null; logDAL.InsertLog(request.project.ToString()); logDAL.InsertLog(projectPath); try { if (!Directory.Exists(projectPath)) { result = Repository.Init(projectPath); if (!string.IsNullOrWhiteSpace(result)) { Repository repo = new Repository(projectPath); //Create README.md file File.WriteAllText(projectPath + "\\README.md", request.project.ProjectName); //Create _Db.config file File.WriteAllText(projectPath + "\\_Db.config", ProjectDomainHelper.ToFileContent(request.project)); //Git add Commands.Stage(repo, "*"); // Create the committer's signature and commit Signature author = new Signature(Properties.AuthorName, Properties.AuthorEmail, DateTime.Now); Signature committer = new Signature(Properties.CommitterName, Properties.CommitterEmail, DateTime.Now); repo.Commit("Project Initialization", author, committer); } else { response.StatusCode = StatusCodes.Status_Error; response.StatusMessage = "Unable to create project"; } } else { logDAL.InsertLog("Project already exists"); response.StatusCode = StatusCodes.Status_Error; response.StatusMessage = "Project already exists"; } } catch (Exception e) { logDAL.InsertLog(e.ToString()); } response.Result = result; return(response); }
public void TestMethod1() { ProjectDomain src = new ProjectDomain(); src.Host = "10.10.10.10"; src.Username = "******"; src.Password = "******"; src.Database = "MyDB"; string actual = ProjectDomainHelper.ToFileContent(src); Assert.AreEqual("", actual); }
public GetAllProjectsResponse GetAllProjects(GetAllProjectsRequest request) { GetAllProjectsResponse response = new GetAllProjectsResponse(); //TODO Get all folder name under BasePath string[] projectPaths = Directory.GetDirectories(ProjectBasePath); List <ProjectDomain> projects = new List <ProjectDomain>(); foreach (string projectPath in projectPaths) { // Read _DBConfig ProjectDomain projectDomain = ProjectDomainHelper.ToProjectDomain(File.ReadAllText(projectPath + "\\_Db.config")); projectDomain.ProjectName = projectPath.Replace(ProjectBasePath, ""); projects.Add(projectDomain); } response.Projects = projects.ToList(); return(response); }
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); }