diff --git a/Server/Git/AbstractGit.cs b/Server/Git/AbstractGit.cs index ecfc9a6..d5b6783 100644 --- a/Server/Git/AbstractGit.cs +++ b/Server/Git/AbstractGit.cs @@ -1,4 +1,5 @@ using LibGit2Sharp; +using NLog; using Server.System; using System.Diagnostics; @@ -6,9 +7,12 @@ namespace Server.Git { public abstract class AbstractGit { + private static readonly NLog.ILogger logger = LogManager.GetCurrentClassLogger(); public bool isRestart; string _repositoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "excel"); + public string excel = ""; + public string repositoryPath { get { return _repositoryPath; } } /// @@ -78,7 +82,69 @@ namespace Server.Git private void Push() { + if(excel == "") + { + return; + } + //json 저장 + using (StreamWriter writer = new StreamWriter(repositoryPath + "\\excel.json")) + { + writer.Write(excel); + Console.WriteLine($"파일이 저장되었습니다 : {repositoryPath + "\\excel.json"}"); + } + + + // 스테이징 + RepositorySet("add .", repositoryPath); + + // 커밋 + RepositorySet($"commit -m \"update excel data\"", repositoryPath); + + // 푸시 + RepositorySet("push origin main", repositoryPath); + + } + + /// + /// 모든 파일리스트 반환 + /// + /// 검색할 폴더 경로 + /// 확장자 + /// + public List GetFiles(string directoryPath, string extension) + { + List xlsxFileList = new List(); + + try + { + string[] files = Directory.GetFiles(directoryPath); + + foreach (string file in files) + { + if (Path.GetExtension(file).Equals(".xlsx", StringComparison.OrdinalIgnoreCase)) + { + xlsxFileList.Add(file); + } + } + + string[] subdirectories = Directory.GetDirectories(directoryPath); + foreach (string subdirectory in subdirectories) + { + //git시스템 파일은 뛰어넘기 + if (subdirectory == directoryPath + "\\.git") + continue; + + //제귀 + xlsxFileList.AddRange(GetFiles(subdirectory, extension)); + } + } + catch (Exception ex) + { + logger.Error(ex); + } + + return xlsxFileList; } } } diff --git a/Server/Git/ExcelManager.cs b/Server/Git/ExcelManager.cs index 7d861df..363019d 100644 --- a/Server/Git/ExcelManager.cs +++ b/Server/Git/ExcelManager.cs @@ -31,9 +31,12 @@ namespace Server.Git public List sheets { get { return _sheets; } } string _pathFile; - public ExcelManager(string path, string file) + public ExcelManager(string path, string file = "") { - _pathFile = path + "\\" + file; + if (file == "") + _pathFile = path; + else + _pathFile = path + "\\" + file; } public bool Play() diff --git a/Server/Git/XlsxToJson.cs b/Server/Git/XlsxToJson.cs index a2efcac..c9f21d1 100644 --- a/Server/Git/XlsxToJson.cs +++ b/Server/Git/XlsxToJson.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System.Collections.Generic; +using System.IO; namespace Server.Git { @@ -9,27 +10,32 @@ namespace Server.Git { //저장경로 : repositoryPath //작업할것 - //다운로드된 데이터 json화 //데이터 db에 업로드 //json화된 데이터 push - ExcelManager em = new ExcelManager(repositoryPath, "TESTexl.xlsx"); - if (em.Play()) + List fileList = GetFiles(repositoryPath, ".xlsx"); + + Dictionary>> sheetList = new Dictionary>>(); + + for (int n = 0; n < fileList.Count; n++) { - List sheets = em.sheets; - Dictionary>> sheetList = new Dictionary>>(); - for (int n = 0; n < sheets.Count; n++) + ExcelManager em = new ExcelManager(fileList[n]); + if (em.Play()) { - sheetList.Add(sheets[n].name, sheets[n].dicViewer); + List sheets = em.sheets; + for (int m = 0; m < sheets.Count; m++) + { + sheetList.Add(sheets[m].name, sheets[m].dicViewer); + } + } + else + { + Console.WriteLine("-1 : NotUpdate"); + return; } - string test = JsonConvert.SerializeObject(sheetList); - Console.WriteLine(test); - } - else - { - Console.WriteLine("-1 : NotUpdate"); } + excel = JsonConvert.SerializeObject(sheetList); //db에 데이터를올리는것은 이곳에 작성할 예정 diff --git a/Server/obj/Debug/net6.0/Server.dll b/Server/obj/Debug/net6.0/Server.dll index 027c75c..b30a297 100644 Binary files a/Server/obj/Debug/net6.0/Server.dll and b/Server/obj/Debug/net6.0/Server.dll differ diff --git a/Server/obj/Debug/net6.0/Server.pdb b/Server/obj/Debug/net6.0/Server.pdb index d446981..9dd4b48 100644 Binary files a/Server/obj/Debug/net6.0/Server.pdb and b/Server/obj/Debug/net6.0/Server.pdb differ diff --git a/Server/obj/Debug/net6.0/ref/Server.dll b/Server/obj/Debug/net6.0/ref/Server.dll index 880925f..bd05fd2 100644 Binary files a/Server/obj/Debug/net6.0/ref/Server.dll and b/Server/obj/Debug/net6.0/ref/Server.dll differ diff --git a/Server/obj/Debug/net6.0/refint/Server.dll b/Server/obj/Debug/net6.0/refint/Server.dll index 880925f..bd05fd2 100644 Binary files a/Server/obj/Debug/net6.0/refint/Server.dll and b/Server/obj/Debug/net6.0/refint/Server.dll differ