Exemple #1
0
        /// <summary>
        /// Exports an object
        /// </summary>
        /// <param name="template">Template to use</param>
        /// <param name="objectData">Object data</param>
        /// <returns>Export Result</returns>
        public Task <ExportObjectResult> ExportObject(ExportTemplate template, ExportObjectData objectData)
        {
            ExportObjectResult result = new ExportObjectResult();

            result.FileExtension = "json";

            object exportResult = null;

            if (template.TemplateType == TemplateType.ObjectNpc)
            {
                NpcJsonExportObject exportObject = new NpcJsonExportObject((KortistoNpc)objectData.ExportData[ExportConstants.ExportDataObject]);
                exportObject.Dialog = objectData.ExportData[ExportConstants.ExportDataDialog] as TaleDialog;
                exportResult        = exportObject;
            }
            else
            {
                exportResult = objectData.ExportData[ExportConstants.ExportDataObject];
            }

            JsonSerializerSettings serializerSettings = new JsonSerializerSettings();

            serializerSettings.ContractResolver = new JsonExportContractResolver();
            serializerSettings.Formatting       = Formatting.Indented;

            result.Code = JsonConvert.SerializeObject(exportResult, serializerSettings);
            return(Task.FromResult(result));
        }
Exemple #2
0
        /// <summary>
        /// Exports an object
        /// </summary>
        /// <param name="template">Template to use</param>
        /// <param name="objectData">Object data</param>
        /// <returns>Export Result</returns>
        public async Task <ExportObjectResult> ExportObject(ExportTemplate template, ExportObjectData objectData)
        {
            ExportObjectResult result = new ExportObjectResult();

            result.FileExtension = "json";

            object exportResult = null;

            if (template.TemplateType == TemplateType.ObjectNpc)
            {
                NpcJsonExportObject exportObject = new NpcJsonExportObject((KortistoNpc)objectData.ExportData[ExportConstants.ExportDataObject]);
                exportObject.Dialog         = objectData.ExportData[ExportConstants.ExportDataDialog] as TaleDialog;
                exportObject.StateMachine   = objectData.ExportData[ExportConstants.ExportDataStateMachine] as StateMachine;
                exportObject.ExportSnippets = await _objectExportSnippetDbAccess.GetExportSnippets(exportObject.Id);

                exportResult = exportObject;
            }
            else if (template.TemplateType == TemplateType.ObjectItem)
            {
                ItemJsonExportObject exportObject = new ItemJsonExportObject((StyrItem)objectData.ExportData[ExportConstants.ExportDataObject]);
                exportObject.ExportSnippets = await _objectExportSnippetDbAccess.GetExportSnippets(exportObject.Id);

                exportResult = exportObject;
            }
            else if (template.TemplateType == TemplateType.ObjectSkill)
            {
                SkillJsonExportObject exportObject = new SkillJsonExportObject((EvneSkill)objectData.ExportData[ExportConstants.ExportDataObject]);
                exportObject.ExportSnippets = await _objectExportSnippetDbAccess.GetExportSnippets(exportObject.Id);

                exportResult = exportObject;
            }
            else
            {
                exportResult = objectData.ExportData[ExportConstants.ExportDataObject];
            }

            JsonSerializerOptions options = new JsonSerializerOptions
            {
                WriteIndented = true,
                Encoder       = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };

            result.Code = JsonSerializer.Serialize(exportResult, options);
            return(result);
        }