abstract public void DoWork(CodeFileBuilder pCodeFileBuilder, SpreadSheetConnector pConnector, IEnumerable <TypeData> listSheetData, Action <string> OnPrintWorkState);
private static void Parsing_OnEnum(TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder) { Dictionary <int, EEnumHeaderType> mapEnumType = new Dictionary <int, EEnumHeaderType>(); Dictionary <string, CodeTypeDeclaration> mapEnumValue = new Dictionary <string, CodeTypeDeclaration>(); pSheetData.ParsingSheet(pConnector, (listRow, strText, iRow, iColumn) => { EEnumHeaderType eType = EEnumHeaderType.EnumNone; if (Enum.TryParse(strText, out eType)) { if (eType == EEnumHeaderType.EnumType) { if (mapEnumType.ContainsKey(iColumn) == false) { mapEnumType.Add(iColumn, eType); } for (int i = iColumn; i < listRow.Count; i++) { string strTextOtherColumn = (string)listRow[i]; if (Enum.TryParse(strTextOtherColumn, out eType)) { if (mapEnumType.ContainsKey(i) == false) { mapEnumType.Add(i, eType); } } } } return; } try { eType = mapEnumType[iColumn]; } catch { eType = mapEnumType[iColumn]; } if (eType != EEnumHeaderType.EnumType) { return; } if (mapEnumValue.ContainsKey(strText) == false) { mapEnumValue.Add(strText, pCodeFileBuilder.AddCodeType(strText, ESheetType.Enum)); } EnumFieldData pFieldData = new EnumFieldData(); for (int i = iColumn; i < listRow.Count; i++) { if (mapEnumType.TryGetValue(i, out eType)) { string strNextText = (string)listRow[i]; switch (eType) { case EEnumHeaderType.EnumValue: pFieldData.strValue = strNextText; break; case EEnumHeaderType.NumberValue: pFieldData.iNumber = int.Parse(strNextText); break; case EEnumHeaderType.Comment: pFieldData.strComment = strNextText; break; } } } if (string.IsNullOrEmpty(pFieldData.strValue)) { throw new Exception($"이넘인데 값이 없습니다 - 타입 : {mapEnumValue[strText].Name}"); } mapEnumValue[strText].AddEnumField(pFieldData); }); }
public override void DoWork(CodeFileBuilder pCodeFileBuilder, SpreadSheetConnector pConnector, IEnumerable <TypeData> listSheetData, Action <string> OnPrintWorkProcess) { TypeDataList pTypeDataList = new TypeDataList(pConnector.strFileName); foreach (var pSheet in listSheetData) { if (pSheet.eType == ESheetType.Enum) { continue; } JObject pJson_Instance = new JObject(); JArray pArray = new JArray(); Dictionary <string, FieldTypeData> mapFieldData = pSheet.listFieldData.Where(p => p.bIsVirtualField == false).ToDictionary(p => p.strFieldName); Dictionary <int, string> mapMemberName = new Dictionary <int, string>(); Dictionary <int, string> mapMemberType = new Dictionary <int, string>(); int iColumnStartIndex = -1; pSheet.ParsingSheet(pConnector, ((IList <object> listRow, string strText, int iRowIndex, int iColumnIndex) => { if (strText.Contains(':')) // 변수 타입 파싱 { if (mapMemberName.ContainsKey(iColumnIndex)) { return; } string[] arrText = strText.Split(':'); mapMemberName.Add(iColumnIndex, arrText[0]); mapMemberType.Add(iColumnIndex, arrText[1]); if (iColumnStartIndex == -1) { iColumnStartIndex = iColumnIndex; } return; } if (iColumnIndex != iColumnStartIndex) { return; } JObject pObject = new JObject(); // 실제 변수값 for (int i = iColumnIndex; i < listRow.Count; i++) { if (mapMemberName.ContainsKey(i)) { if (mapFieldData.TryGetValue(mapMemberName[i], out var pFieldTypeData) == false) { OnPrintWorkProcess?.Invoke($"{pSheet.strSheetName} - mapFieldData.ContainsKey({mapMemberName[i]}) Fail"); continue; } string strFieldName = pFieldTypeData.strFieldName; string strValue = (string)listRow[i]; pObject.Add(strFieldName, strValue); } } pArray.Add(pObject); })); if (pArray.Count == 0) { continue; } pJson_Instance.Add("array", pArray); string strFileName = $"{pSheet.strFileName}.json"; JsonSaveManager.SaveData(pJson_Instance, $"{GetRelative_To_AbsolutePath(strExportPath)}/{strFileName}"); pTypeDataList.listTypeData.Add(pSheet); } #if !UNITY_EDITOR JsonSaveManager.SaveData(pTypeDataList, $"{GetRelative_To_AbsolutePath(strExportPath)}/{nameof(TypeDataList)}.json"); #endif }
private static void Parsing_OnGlobal(TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder) { // 글로벌 테이블은 데이터를 담는 데이터컨테이너와 글로벌키 Enum타입 2개를 생성한다. var pCodeType_Class = pCodeFileBuilder.AddCodeType(pSheetData.strFileName, pSheetData.eType); var pCodeType_GlobalKey = pCodeFileBuilder.AddCodeType(const_GlobalKey_EnumName, ESheetType.Enum); if (pSheetData.listEnumName.Contains(const_GlobalKey_EnumName) == false) { pSheetData.listEnumName.Add(const_GlobalKey_EnumName); } Dictionary <int, EGlobalColumnType> mapGlobalColumnType = new Dictionary <int, EGlobalColumnType>(); HashSet <string> setGlobalTable_ByType = new HashSet <string>(); string strTypeName = ""; int iColumnIndex_Type = -1; int iColumnIndex_Comment = -1; pSheetData.ParsingSheet(pConnector, (listRow, strText, iRow, iColumn) => { // 변수 선언 형식인경우 if (strText.Contains(":")) { string[] arrText = strText.Split(':'); string strFieldName = arrText[0]; string strFieldName_Lower = strFieldName.ToLower(); for (int i = 0; i < (int)EGlobalColumnType.MAX; i++) { EGlobalColumnType eCurrentColumnType = (EGlobalColumnType)i; if (strFieldName_Lower.Contains(eCurrentColumnType.ToString().ToLower())) { mapGlobalColumnType.Add(iColumn, eCurrentColumnType); switch (eCurrentColumnType) { case EGlobalColumnType.Key: { FieldTypeData pFieldData = pSheetData.listFieldData.Where(p => p.strFieldName == strFieldName).FirstOrDefault(); if (pFieldData != null) { pFieldData.bDeleteThisField_InCode = true; } FieldTypeData pFieldData_Enum = pSheetData.listFieldData.Where(p => p.strFieldName == const_GlobalKey_FieldName).FirstOrDefault(); if (pFieldData_Enum == null) { pFieldData_Enum = new FieldTypeData(const_GlobalKey_FieldName, const_GlobalKey_EnumName); pFieldData_Enum.strDependencyFieldName = pFieldData.strFieldName; pFieldData_Enum.bIsVirtualField = true; pSheetData.listFieldData.Add(pFieldData_Enum); } } break; case EGlobalColumnType.Comment: { FieldTypeData pFieldData = pSheetData.listFieldData.Where(p => p.strFieldName == strFieldName).FirstOrDefault(); if (pFieldData != null) { pFieldData.bDeleteThisField_InCode = true; } iColumnIndex_Comment = iColumn; } break; case EGlobalColumnType.Type: iColumnIndex_Type = iColumn; strTypeName = strFieldName; pCodeType_Class.AddField(new FieldTypeData(strFieldName, arrText[1])); FieldTypeData pFieldData_Type = pSheetData.listFieldData.Where(p => p.strFieldName == strFieldName).FirstOrDefault(); if (pFieldData_Type == null) { pSheetData.listFieldData.Add(new FieldTypeData(strFieldName, arrText[1])); } break; default: pCodeType_Class.AddField(new FieldTypeData(strFieldName, arrText[1])); break; } return; } } } // 변수 선언이 아니라 값을 파싱하면 일단 타입부터 확인한다 EGlobalColumnType eColumnType = EGlobalColumnType.None; if (mapGlobalColumnType.TryGetValue(iColumn, out eColumnType) == false) { return; } switch (eColumnType) { case EGlobalColumnType.Key: string strComment = ""; if (iColumnIndex_Comment != -1 && iColumnIndex_Comment < listRow.Count) { strComment = (string)listRow[iColumnIndex_Comment]; } if (string.IsNullOrEmpty(strComment)) { pCodeType_GlobalKey.AddEnumField(new EnumFieldData(strText)); } else { pCodeType_GlobalKey.AddEnumField(new EnumFieldData(strText, strComment)); } break; case EGlobalColumnType.Type: if (setGlobalTable_ByType.Contains(strText)) { return; } setGlobalTable_ByType.Add(strText); string strFieldType = (string)listRow[iColumnIndex_Type]; FieldTypeData pFieldData = pSheetData.listFieldData.Where(p => p.strFieldName == strTypeName && p.strFieldType == strFieldType).FirstOrDefault(); if (pFieldData == null) { pFieldData = new FieldTypeData(strTypeName, strFieldType); pSheetData.listFieldData.Add(pFieldData); } pFieldData.bIsTemp = true; pFieldData.bDeleteThisField_InCode = true; pFieldData.bIsVirtualField = strFieldType != "string"; pFieldData.bIsKeyField = true; pFieldData.bIsOverlapKey = true; break; } }); }
private static void Parsing_OnCode(TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder, List <CommandLineArg> listCommandLine) { var pCodeType = pCodeFileBuilder.AddCodeType(pSheetData.strFileName, pSheetData.eType); var mapFieldData_ConvertStringToEnum = pSheetData.listFieldData.Where((pFieldData) => pFieldData.bConvertStringToEnum).ToDictionary(((pFieldData) => pFieldData.strFieldName)); var listFieldData_DeleteThisField_OnCode = pSheetData.listFieldData.Where((pFieldData) => pFieldData.bDeleteThisField_InCode).Select((pFieldData) => pFieldData.strFieldName); Dictionary <int, CodeTypeDeclaration> mapEnumType = new Dictionary <int, CodeTypeDeclaration>(); int iDefinedTypeRow = -1; pSheetData.ParsingSheet(pConnector, (listRow, strText, iRow, iColumn) => { // 변수 선언 형식인경우 if (strText.Contains(":")) { if (iDefinedTypeRow == -1) { iDefinedTypeRow = iRow; } if (iDefinedTypeRow != iRow) { return; } string[] arrText = strText.Split(':'); string strFieldName = arrText[0]; if (mapFieldData_ConvertStringToEnum.ContainsKey(strFieldName)) { FieldTypeData pFieldData = mapFieldData_ConvertStringToEnum[strFieldName]; mapEnumType.Add(iColumn, pCodeFileBuilder.AddCodeType(pFieldData.strEnumName, ESheetType.Enum)); if (pSheetData.listEnumName.Contains(pFieldData.strEnumName) == false) { pSheetData.listEnumName.Add(pFieldData.strEnumName); } } // 삭제되는 코드인 경우 if (listFieldData_DeleteThisField_OnCode.Contains(strFieldName)) { return; } pCodeType.AddField(new FieldTypeData(strFieldName, arrText[1])); return; } // 이넘 Column인 경우 이넘 생성 if (mapEnumType.ContainsKey(iColumn)) { mapEnumType[iColumn].AddEnumField(new EnumFieldData(strText)); return; } }); Execute_CommandLine(pCodeType, listCommandLine); }
static public void DoWork(this TypeData pSheetData, SpreadSheetConnector pConnector, CodeFileBuilder pCodeFileBuilder, Action <string> OnError) { List <CommandLineArg> listCommandLine = Parsing_CommandLine(pSheetData.strCommandLine, OnError); switch (pSheetData.eType) { case ESheetType.Class: case ESheetType.Struct: Parsing_OnCode(pSheetData, pConnector, pCodeFileBuilder, listCommandLine); break; case ESheetType.Enum: Parsing_OnEnum(pSheetData, pConnector, pCodeFileBuilder); break; case ESheetType.Global: Parsing_OnGlobal(pSheetData, pConnector, pCodeFileBuilder); break; } }
public override Task DoWork(CodeFileBuilder pCodeFileBuilder, ISheetConnector pConnector, TypeData[] arrSheetData, Action <string> OnPrintWorkProcess) { return(Task.Run(() => pCodeFileBuilder.Generate_CSharpCode($"{GetRelative_To_AbsolutePath(strPath)}/{strFileName}"))); }
public abstract Task DoWork(CodeFileBuilder pCodeFileBuilder, ISheetConnector pConnector, TypeData[] arrSheetData, Action <string> OnPrintWorkState);
private void StartBuild(params TypeData[] arrTypeData) { _pCodeFileBuilder = new CodeFileBuilder(); List <Task> listTask = new List <Task>(); Stopwatch pTimer_Total = new Stopwatch(); pTimer_Total.Start(); Stopwatch pTimer = new Stopwatch(); try { foreach (var pSheetData in arrTypeData) { pTimer.Restart(); // 왜 Update했는지 까먹었다.. 일단 상관없어보이니 주석처리 listView_Field.Items.Clear(); UpdateSheetData(pSheetData, false, true); // 동기버전 // pSheetData.DoWork(pSheetConnector, _pCodeFileBuilder, WriteConsole); // 비동기버전 listTask.Add(pSheetData.DoWork(pSheetConnector, _pCodeFileBuilder, WriteConsole)); pTimer.Stop(); WriteConsole(pSheetData.strFileName + $" 작업완료 \r\n{pTimer.Elapsed}\r\n"); } } catch (Exception pException) { WriteConsole("빌드 실패.." + pException); return; } Task.WaitAll(listTask.ToArray()); listTask.Clear(); var arrSheetData = checkedListBox_SheetList.CheckedItems.Cast <TypeData>().ToArray(); var listWork = checkedListBox_WorkList.CheckedItems; { foreach (WorkBase pWork in listWork) { try { pTimer.Restart(); listTask.Add(pWork.DoWork(_pCodeFileBuilder, pSheetConnector, arrSheetData, WriteConsole)); } catch (Exception pException) { WriteConsole($"빌드 중 에러 - Work : {pWork.pType} // Error : {pException}"); return; } finally { pTimer.Stop(); WriteConsole(pWork.ToString() + $" 작업완료 \r\n{pTimer.Elapsed}\r\n"); } } } Task.WaitAll(listTask.ToArray(), new TimeSpan(10000)); var arrTask_NotCompleted = listTask.Where(pTask => pTask.IsCompleted == false).ToArray(); if (arrTask_NotCompleted.Length != 0) { WriteConsole($"빌드 실패.. 타임아웃!!; \r\n {pTimer_Total.Elapsed}\r\n"); } foreach (WorkBase pWork in listWork) { pWork.DoWorkAfter(); } WriteConsole($"빌드 완료 \r\n {pTimer_Total.Elapsed}\r\n"); }
public override void DoWork(CodeFileBuilder pCodeFileBuilder, SpreadSheetConnector pConnector, IEnumerable <TypeData> listSheetData, Action <string> OnPrintWorkState) { CodeNamespace pNameSpace = new CodeNamespace(); List <CodeNamespaceImport> listDefaultUsing = new List <CodeNamespaceImport>(); listDefaultUsing.Add(new CodeNamespaceImport("UnityEngine")); List <CommandLineArg> listCommandLine = Parsing_CommandLine(strCommandLine, null); for (int i = 0; i < listCommandLine.Count; i++) { ECommandLine eCommandLine = (ECommandLine)Enum.Parse(typeof(ECommandLine), listCommandLine[i].strArgName); switch (eCommandLine) { case ECommandLine.addusing: listDefaultUsing.Add(new CodeNamespaceImport(listCommandLine[i].strArgValue)); break; case ECommandLine.useusing: pNameSpace.Name = listCommandLine[i].strArgValue; break; } } CodeNamespaceImport[] arrDefaultUsing = listDefaultUsing.ToArray(); pNameSpace.Imports.AddRange(arrDefaultUsing); CodeTypeDeclarationCollection arrTypes = pCodeFileBuilder.GetCodeTypeDeclarationCollection(); List <CodeTypeDeclaration> listType = new List <CodeTypeDeclaration>(); foreach (CodeTypeDeclaration pType in arrTypes) { listType.Add(pType); } HashSet <CodeTypeDeclaration> setExecutedType = new HashSet <CodeTypeDeclaration>(); IEnumerable <CodeTypeDeclaration> listUnitySO = listType.Where(p => string.IsNullOrEmpty(p.Name) == false && p.IsClass); foreach (CodeTypeDeclaration pType in listUnitySO) { TypeData pSaveData = listSheetData.Where((pSaveDataSheet) => pSaveDataSheet.strFileName == pType.Name).FirstOrDefault(); if (pSaveData == null) { continue; } Create_SO(pCodeFileBuilder, pNameSpace, pType, pSaveData); IEnumerable <CodeTypeDeclaration> arrEnumTypes = listType.Where(p => pSaveData.listEnumName.Contains(p.Name)); foreach (var pEnumType in arrEnumTypes) { setExecutedType.Add(pEnumType); } if (pSaveData.eType == ESheetType.Global) { Create_GlobalSOContainer(pCodeFileBuilder, pNameSpace, arrDefaultUsing, pType, arrEnumTypes.ToArray(), pSaveData); } else { Create_SOContainer(pCodeFileBuilder, pNameSpace, arrDefaultUsing, pType, arrEnumTypes.ToArray(), pSaveData); } OnPrintWorkState?.Invoke($"UnitySO - Working SO {pType.Name}"); setExecutedType.Add(pType); } // Others pNameSpace.Types.Clear(); IEnumerable <CodeTypeDeclaration> listOthers = listType.Where(p => string.IsNullOrEmpty(p.Name) == false && setExecutedType.Contains(p) == false); foreach (CodeTypeDeclaration pType in listOthers) { OnPrintWorkState?.Invoke($"UnitySO - Working Others {pType.Name}"); pNameSpace.Types.Add(pType); setExecutedType.Add(pType); } if (pNameSpace.Types.Count != 0) { pCodeFileBuilder.Generate_CSharpCode(pNameSpace, $"{GetRelative_To_AbsolutePath(strExportPath)}/Others"); } }