json데이터 다시 git에 커밋까지 완료
This commit is contained in:
parent
6b92fea565
commit
4d3cafae5d
|
@ -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; } }
|
||||
|
||||
/// <summary>
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 모든 파일리스트 반환
|
||||
/// </summary>
|
||||
/// <param name="directoryPath">검색할 폴더 경로</param>
|
||||
/// <param name="extension">확장자</param>
|
||||
/// <returns></returns>
|
||||
public List<string> GetFiles(string directoryPath, string extension)
|
||||
{
|
||||
List<string> xlsxFileList = new List<string>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,12 @@ namespace Server.Git
|
|||
public List<sheet> 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()
|
||||
|
|
|
@ -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<string> fileList = GetFiles(repositoryPath, ".xlsx");
|
||||
|
||||
Dictionary<string, Dictionary<long, Dictionary<string, object>>> sheetList = new Dictionary<string, Dictionary<long, Dictionary<string, object>>>();
|
||||
|
||||
for (int n = 0; n < fileList.Count; n++)
|
||||
{
|
||||
List<ExcelManager.sheet> sheets = em.sheets;
|
||||
Dictionary<string, Dictionary<long, Dictionary<string, object>>> sheetList = new Dictionary<string, Dictionary<long, Dictionary<string, object>>>();
|
||||
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<ExcelManager.sheet> 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에 데이터를올리는것은 이곳에 작성할 예정
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue