Esempio n. 1
0
        public override Task DoWork(CodeFileBuilder pCodeFileBuilder, ISheetConnector pConnector, TypeData[] arrSheetData, Action <string> OnPrintWorkProcess)
        {
            //TypeDataList pTypeDataList = JsonSaveManager.LoadData<TypeDataList>($"{GetRelative_To_AbsolutePath(strExportPath)}/{nameof(TypeDataList)}.json", OnPrintWorkProcess);
            //if (pTypeDataList == null)
            //    pTypeDataList = new TypeDataList(pConnector.strSheetID);

            // 로컬 데이터에 있는 TypeData와 현재 TypeData가 일치하지 않음.
            // 무조건 현재 TypeData기준으로 작업하기
            TypeDataList pTypeDataList = new TypeDataList(pConnector.strSheetID);

            pTypeDataList.listTypeData = arrSheetData.ToList();

            List <Task> listTask = new List <Task>();

            foreach (var pSheet in arrSheetData)
            {
                if (pSheet.eType == ESheetType.Enum)
                {
                    continue;
                }

                listTask.Add(ProcessJson(pConnector, OnPrintWorkProcess, pSheet, pTypeDataList));
            }

            Task.WaitAll(listTask.ToArray(), new TimeSpan(3000));

            return(Task.Run(() =>
            {
                pTypeDataList.listTypeData.Sort((x, y) => x.iOrder.CompareTo(y.iOrder));
                JsonSaveManager.SaveData(pTypeDataList, $"{GetRelative_To_AbsolutePath(strExportPath)}/{nameof(TypeDataList)}.json");
            }));
        }
Esempio n. 2
0
        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
        }
Esempio n. 3
0
        private Task ProcessJson(ISheetConnector pConnector, Action <string> OnPrintWorkProcess, TypeData pSheet,
                                 TypeDataList pTypeDataList)
        {
            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>();
            int iColumnStartIndex = -1;

            return(pSheet.ParsingSheet_UseTask(pConnector,
                                               ((listRow, strText, iRowIndex, 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) == false)
                    {
                        continue;
                    }

                    if (mapFieldData.TryGetValue(mapMemberName[i], out FieldTypeData pFieldTypeData) == false)
                    {
                        OnPrintWorkProcess?.Invoke($"{pSheet.strSheetName}({pSheet.strSheetID}) - mapFieldData.ContainsKey({mapMemberName[i]}) Fail");
                        continue;
                    }

                    string strFieldName = pFieldTypeData.strFieldName;
                    string strValue = (string)listRow[i];
                    pObject.Add(strFieldName, strValue);
                }

                pArray.Add(pObject);
            })).ContinueWith((pTask) =>
            {
                pJson_Instance.Add("array", pArray);

                string strFileName = $"{pSheet.strFileName}.json";
                JsonSaveManager.SaveData(pJson_Instance, $"{GetRelative_To_AbsolutePath(strExportPath)}/{strFileName}");

                var pAlreadyExist = pTypeDataList.listTypeData.FirstOrDefault(p => p.strSheetID == pSheet.strSheetID);
                if (pAlreadyExist != null)
                {
                    pTypeDataList.listTypeData.Remove(pAlreadyExist);
                }

                pTypeDataList.listTypeData.Add(pSheet);
            }));
        }