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));
        }
Exemple #2
0
        public static void SaveTalent(ITalent talent, GameType gameType, out DSAError error)
        {
            error = null;
            #region Talenttype
            List <JSONTalent> jTalentList = null;
            List <ITalent>    talentList  = null;
            var talenttype = talent.GetType().ToString();
            var lastIndex  = talenttype.LastIndexOf(".");
            talenttype = talenttype.Substring(lastIndex + 1);
            #endregion
            #region GameType
            if (gameType == GameType.DSA)
            {
                if (jSON_talentLocal.Talente == null)
                {
                    jSON_talentLocal.Talente = new List <JSONTalent>();
                }
                jTalentList = jSON_talentLocal.Talente;
                talentList  = TalentList;
            }
            else
            {
                throw new Exception();
            }
            #endregion

            try
            {
                var jsonTalent = TalentHelper.CreateJSON(
                    talent: talent);

                #region Doppelte Elemente Entfernen
                var jdoppledID = jTalentList.Where(x => x.ID == talent.ID).ToList();
                if (jdoppledID.Count > 0)
                {
                    jTalentList.Remove(jdoppledID[0]);
                }
                var tdoppledID = talentList.Where(x => x.ID == talent.ID).ToList();
                if (tdoppledID.Count > 0)
                {
                    tdoppledID.Remove(tdoppledID[0]);
                }
                #endregion
                #region Speichern
                jTalentList.Add(jsonTalent);

                if (!talentList.Contains(talent))
                {
                    talentList.Add(talent);
                }
                FileManagment.WriteToFile(jSON_talentLocal.JSONContent, talentSaveFile, Windows.Storage.CreationCollisionOption.ReplaceExisting, out error);
                #endregion
            }
            catch (Exception ex)
            {
                error = new DSAError
                {
                    ErrorCode = ErrorCode.InvalidValue,
                    Message   = ex.Message
                };
            }
        }