Ejemplo n.º 1
0
        /// <summary>
        /// Fills the dialog placeholders
        /// </summary>
        /// <param name="code">Code</param>
        /// <param name="npc">Npc</param>
        /// <returns>Filled code</returns>
        private async Task <string> FillDialogPlaceholders(string code, KortistoNpc npc)
        {
            GoNorthProject project = await _cachedDbAccess.GetDefaultProject();

            TaleDialog dialog = await _taleDbAccess.GetDialogByRelatedObjectId(npc.Id);

            try
            {
                _errorCollection.CurrentErrorContext = _localizer["DialogErrorContext"].Value;
                _dialogParser.SetErrorCollection(_errorCollection);
                _dialogRenderer.SetErrorCollection(_errorCollection);
                ExportDialogData exportDialog   = null;
                bool             hasValidDialog = HasValidDialog(dialog);
                if (hasValidDialog)
                {
                    exportDialog = _dialogParser.ParseDialog(dialog);
                    if (exportDialog == null)
                    {
                        return(string.Empty);
                    }
                    exportDialog = await _dialogFunctionGenerator.GenerateFunctions(project.Id, npc.Id, exportDialog, _errorCollection);
                }

                code = ExportUtil.RenderPlaceholderIfTrue(code, Placeholder_HasDialog_Start, Placeholder_HasDialog_End, hasValidDialog);

                code = await RenderDialog(project, code, exportDialog, dialog, npc);
            }
            finally
            {
                _errorCollection.CurrentErrorContext = "";
            }

            return(code);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes additional depencendies for a flex field object
        /// </summary>
        /// <param name="flexFieldObject">Flex field object to delete</param>
        /// <returns>Task</returns>
        protected override async Task DeleteAdditionalFlexFieldObjectDependencies(KortistoNpc flexFieldObject)
        {
            TaleDialog dialog = await _taleDbAccess.GetDialogByRelatedObjectId(flexFieldObject.Id);

            if (dialog != null)
            {
                await _taleDbAccess.DeleteDialog(dialog);
            }
            _logger.LogInformation("Dialog was deleted.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Collects the values for an export
        /// </summary>
        /// <param name="templateType">Template type</param>
        /// <param name="parsedTemplate">Parsed scriban template</param>
        /// <param name="scriptObject">Scriban script object to fill</param>
        /// <param name="data">Export Data</param>
        /// <returns>Task</returns>
        public override async Task CollectValues(TemplateType templateType, Template parsedTemplate, ScriptObject scriptObject, ExportObjectData data)
        {
            KortistoNpc inputNpc = data.ExportData[ExportConstants.ExportDataObject] as KortistoNpc;

            if (inputNpc == null)
            {
                return;
            }

            _languageKeyGenerator.SetErrorCollection(_errorCollection);

            GoNorthProject project = await _exportCachedDbAccess.GetUserProject();

            TaleDialog dialog = await _taleDbAccess.GetDialogByRelatedObjectId(inputNpc.Id);

            ExportDialogData parsedDialog = await ParseDialog(inputNpc, project, dialog);

            ScribanExportDialog exportDialog = await BuildExportDialog(parsedDialog, inputNpc);

            scriptObject.AddOrUpdate(ExportConstants.ScribanDialogKey, exportDialog);
            scriptObject.AddOrUpdate(DialogFunctionRenderer.DialogFunctionName, new DialogFunctionRenderer(_templatePlaceholderResolver, _exportCachedDbAccess, _defaultTemplateProvider, _errorCollection, data));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Exports an object
        /// </summary>
        /// <param name="exportFormat">Format to export (Script, JSON or LanguageFile)</param>
        /// <param name="id">Id of the object to export</param>
        /// <param name="templateType">Template type</param>
        /// <returns>Export result</returns>
        private async Task <ExportObjectResult> RunExportObject(string exportFormat, string id, TemplateType templateType)
        {
            // Check Access
            if ((templateType == TemplateType.ObjectNpc && !User.IsInRole(RoleNames.Kortisto)) ||
                (templateType == TemplateType.ObjectItem && !User.IsInRole(RoleNames.Styr)) ||
                (templateType == TemplateType.ObjectSkill && !User.IsInRole(RoleNames.Evne)))
            {
                throw new UnauthorizedAccessException();
            }

            // Get Exporter
            string exporterKey = exportFormat.ToLowerInvariant();

            if (!_exporters.ContainsKey(exporterKey))
            {
                throw new InvalidOperationException("Unknown Export Format");
            }
            IObjectExporter exporter = _exporters[exporterKey];

            // Get Objects
            bool             objectFound = false;
            ExportObjectData objectData  = new ExportObjectData();

            if (templateType == TemplateType.ObjectNpc)
            {
                KortistoNpc npc = await _npcDbAccess.GetFlexFieldObjectById(id);

                if (npc != null)
                {
                    objectData.ExportData.Add(ExportConstants.ExportDataObject, npc);
                    objectData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeNpc);

                    TaleDialog dialog = await _dialogDbAccess.GetDialogByRelatedObjectId(id);

                    objectData.ExportData.Add(ExportConstants.ExportDataDialog, dialog);

                    objectFound = true;
                }
            }
            else if (templateType == TemplateType.ObjectItem)
            {
                StyrItem item = await _itemDbAccess.GetFlexFieldObjectById(id);

                if (item != null)
                {
                    objectData.ExportData.Add(ExportConstants.ExportDataObject, item);
                    objectData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeItem);
                    objectFound = true;
                }
            }
            else if (templateType == TemplateType.ObjectSkill)
            {
                EvneSkill skill = await _skillDbAccess.GetFlexFieldObjectById(id);

                if (skill != null)
                {
                    objectData.ExportData.Add(ExportConstants.ExportDataObject, skill);
                    objectData.ExportData.Add(ExportConstants.ExportDataObjectType, ExportConstants.ExportObjectTypeSkill);
                    objectFound = true;
                }
            }
            else
            {
                throw new InvalidOperationException("Template Type not supported for exporting");
            }

            if (!objectFound)
            {
                throw new KeyNotFoundException();
            }

            // Get Template
            ExportTemplateByObjectIdResult template = await GetValidExportTemplateByIdAndType(id, templateType);

            // Run Export
            ExportObjectResult result = await exporter.ExportObject(template.Template, objectData);

            result.ObjectFilename = ((FlexFieldObject)objectData.ExportData[ExportConstants.ExportDataObject]).Name;
            string regexSearch      = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
            Regex  illegalCharRegex = new Regex(string.Format("[{0}]", regexSearch));

            result.ObjectFilename = illegalCharRegex.Replace(result.ObjectFilename, string.Empty);
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetDialogByRelatedObjectId(string relatedObjectId)
        {
            TaleDialog dialog = await _taleDbAccess.GetDialogByRelatedObjectId(relatedObjectId);

            return(Ok(dialog));
        }