예제 #1
0
        public string Import([FromBody] TalentImportRequest request)
        {
            var jsonFileTest   = System.IO.File.ReadAllText(this.JsonTalentFile);
            var oldJsonFile    = JSONTalentSaveFile.DeSerializeJson(jsonFileTest, out string error);
            var jsonTalentList = TalentJsonLoader.LoadTalent(oldJsonFile.Talente);

            var importer     = new ExcelImporter();
            var importResult = importer.ExcelImport(
                close: request.Close,
                range: request.Range,
                weaponless: request.Weaponless,
                crafting: request.Crafting,
                knowldage: request.Knowldage,
                nature: request.Nature,
                physical: request.Physical,
                social: request.Social,
                language: request.Language);

            var result = TalentMerger.Test(importResult.TalentList, jsonTalentList, importResult.OldNameDictionary);
            var list   = new List <JSONTalent>();

            foreach (var item in result)
            {
                var talent = TalentHelper.CreateJSON(item);
                list.Add(talent);
                talent.JSONContent = null;
            }

            var languageList = new List <JSONTalentLanguageFamily>();

            foreach (var item in importResult.LanguageFamilyList)
            {
                var jsonLanguageFamilie = new JSONTalentLanguageFamily();
                jsonLanguageFamilie.Languages = new Dictionary <int, System.Guid>();
                jsonLanguageFamilie.Writings  = new Dictionary <int, System.Guid>();
                jsonLanguageFamilie.Name      = item.Name;

                foreach (var langaugeItem in item.Languages)
                {
                    if (langaugeItem.Value != null)
                    {
                        jsonLanguageFamilie.Languages.Add(langaugeItem.Key, langaugeItem.Value.ID);
                    }
                }
                foreach (var writingItems in item.Writings)
                {
                    if (writingItems.Value != null)
                    {
                        jsonLanguageFamilie.Writings.Add(writingItems.Key, writingItems.Value.ID);
                    }
                }
                languageList.Add(jsonLanguageFamilie);
            }

            var saveFile = new JSONTalentSaveFile();

            saveFile.Talente  = list;
            saveFile.Families = languageList;

            //Clear JSONContent
            saveFile.JSONContent = null;


            return(CreateResponse(saveFile.JSONContent));
        }