/// <summary> /// Builds an action from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="data">Dialog data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Action string</returns> public override async Task <string> BuildActionFromParsedData(ValueActionRenderBase.ValueFieldActionData parsedData, ExportDialogData data, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, KortistoNpc npc, ExportSettings exportSettings) { ExportTemplate actionTemplate = await GetExportTemplate(project); IFlexFieldExportable valueObject = await GetValueObject(parsedData, npc, errorCollection); if (valueObject == null) { return(string.Empty); } FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string actionCode = actionTemplate.Code; actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueName).Replace(actionCode, m => { return(DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection)); }); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Operator).Replace(actionCode, GetOperatorFromTemplate(project, parsedData.Operator, errorCollection)); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsSetTo_Start, Placeholder_OperatorIsSetTo_End, parsedData.Operator == "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotSetTo_Start, Placeholder_OperatorIsNotSetTo_End, parsedData.Operator != "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsString_Start, Placeholder_ValueIsString_End, exportField.FieldType != ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsNumber_Start, Placeholder_ValueIsNumber_End, exportField.FieldType == ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueChange).Replace(actionCode, m => { if (exportField.FieldType != ExportConstants.FlexFieldType_Number) { return(ExportUtil.EscapeCharacters(parsedData.ValueChange, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); } return(parsedData.ValueChange); }); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, GetFlexFieldExportObjectType()); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); actionCode = _flexFieldPlaceholderResolver.FillPlaceholders(actionCode, flexFieldExportData).Result; return(actionCode); }
/// <summary> /// Builds a condition element from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Condition string</returns> public override string BuildConditionElementFromParsedData(ValueConditionResolverBase.ValueFieldConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, KortistoNpc npc, ExportSettings exportSettings) { ExportTemplate conditionTemplate = GetExportTemplate(project); IFlexFieldExportable valueObject = GetValueObject(parsedData, npc, errorCollection); if (valueObject == null) { return(string.Empty); } FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string conditionCode = conditionTemplate.Code; conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_IsOperatorPrimitiveStart, Placeholder_IsOperatorPrimitiveEnd, IsOperatorPrimitiveOperator(parsedData.Operator)); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_IsOperatorNonPrimitiveStart, Placeholder_IsOperatorNonPrimitiveEnd, !IsOperatorPrimitiveOperator(parsedData.Operator)); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueName).Replace(conditionCode, m => { return(DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection)); }); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Operator).Replace(conditionCode, GetOperatorFromTemplate(project, parsedData.Operator, errorCollection)); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_ValueIsString_Start, Placeholder_ValueIsString_End, exportField.FieldType != ExportConstants.FlexFieldType_Number); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_ValueIsNumber_Start, Placeholder_ValueIsNumber_End, exportField.FieldType == ExportConstants.FlexFieldType_Number); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_CompareValue).Replace(conditionCode, m => { if (exportField.FieldType != ExportConstants.FlexFieldType_Number) { return(ExportUtil.EscapeCharacters(parsedData.CompareValue, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); } return(parsedData.CompareValue); }); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, GetFlexFieldExportObjectType()); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); conditionCode = _flexFieldPlaceholderResolver.FillPlaceholders(conditionCode, flexFieldExportData).Result; return(conditionCode); }
/// <summary> /// Builds a preview text from parsed data /// </summary> /// <param name="parsedData">Parsed data</param> /// <param name="npc">Npc to which the dialog belongs</param> /// <param name="errorCollection">Error Collection</param> /// <returns>Preview text</returns> public override async Task <string> BuildPreviewTextFromParsedData(ValueActionRenderBase.ValueFieldActionData parsedData, KortistoNpc npc, ExportPlaceholderErrorCollection errorCollection) { IFlexFieldExportable valueObject = await GetValueObject(parsedData, npc, errorCollection); if (valueObject == null) { return(string.Empty); } FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string fieldName = DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection); return(GetPreviewPrefix() + " (" + fieldName + ")"); }
/// <summary> /// Fills the placeholders /// </summary> /// <param name="template">Template to use</param> /// <param name="errorCollection">Error Collection</param> /// <param name="parsedData">Parsed config data</param> /// <param name="valueObject">Value object to use</param> /// <param name="actionOperator">Action operator to use</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="curStep">Current step that is rendered</param> /// <param name="nextStep">Next step that is being rendered</param> /// <param name="exportSettings">Export Settings</param> /// <param name="stepRenderer">Action Step renderer</param> /// <returns>Filled placeholders</returns> protected override async Task <string> FillPlaceholders(ExportTemplate template, ExportPlaceholderErrorCollection errorCollection, ValueFieldActionData parsedData, IFlexFieldExportable valueObject, string actionOperator, FlexFieldObject flexFieldObject, ExportDialogData curStep, ExportDialogData nextStep, ExportSettings exportSettings, IActionStepRenderer stepRenderer) { FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string actionCode = template.Code; actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueName).Replace(actionCode, m => { return(DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection)); }); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Operator).Replace(actionCode, actionOperator); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsSetTo_Start, Placeholder_OperatorIsSetTo_End, parsedData.Operator == "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotSetTo_Start, Placeholder_OperatorIsNotSetTo_End, parsedData.Operator != "="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsAdd_Start, Placeholder_OperatorIsAdd_End, parsedData.Operator == "+="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotAdd_Start, Placeholder_OperatorIsNotAdd_End, parsedData.Operator != "+="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsSubstract_Start, Placeholder_OperatorIsSubstract_End, parsedData.Operator == "-="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotSubstract_Start, Placeholder_OperatorIsNotSubstract_End, parsedData.Operator != "-="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsMultiply_Start, Placeholder_OperatorIsMultiply_End, parsedData.Operator == "*="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotMultiply_Start, Placeholder_OperatorIsNotMultiply_End, parsedData.Operator != "*="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsDivide_Start, Placeholder_OperatorIsDivide_End, parsedData.Operator == "/="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_OperatorIsNotDivide_Start, Placeholder_OperatorIsNotDivide_End, parsedData.Operator != "/="); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsString_Start, Placeholder_ValueIsString_End, exportField.FieldType != ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.RenderPlaceholderIfTrue(actionCode, Placeholder_ValueIsNumber_Start, Placeholder_ValueIsNumber_End, exportField.FieldType == ExportConstants.FlexFieldType_Number); actionCode = ExportUtil.RenderPlaceholderIfFuncTrue(actionCode, Placeholder_ValueNameEquals_Start, Placeholder_ValueNameEquals_End, m => { string searchedFieldName = m.Groups[1].Value; searchedFieldName = searchedFieldName.ToLowerInvariant(); string fieldName = string.Empty; if (!string.IsNullOrEmpty(exportField.Name)) { fieldName = exportField.Name.ToLowerInvariant(); } return(fieldName == searchedFieldName); }); actionCode = ExportUtil.RenderPlaceholderIfFuncTrue(actionCode, Placeholder_ValueNameNotEquals_Start, Placeholder_ValueNameNotEquals_End, m => { string searchedFieldName = m.Groups[1].Value; searchedFieldName = searchedFieldName.ToLowerInvariant(); string fieldName = string.Empty; if (!string.IsNullOrEmpty(exportField.Name)) { fieldName = exportField.Name.ToLowerInvariant(); } return(fieldName != searchedFieldName); }); actionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueChange).Replace(actionCode, m => { if (exportField.FieldType != ExportConstants.FlexFieldType_Number) { return(ExportUtil.EscapeCharacters(parsedData.ValueChange, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); } return(parsedData.ValueChange); }); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, GetFlexFieldExportObjectType()); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); actionCode = await _flexFieldPlaceholderResolver.FillPlaceholders(actionCode, flexFieldExportData); return(await stepRenderer.ReplaceBasePlaceholders(errorCollection, actionCode, curStep, nextStep, flexFieldObject)); }
/// <summary> /// Builds a condition element from parsed data /// </summary> /// <param name="template">Export template to use</param> /// <param name="parsedData">Parsed data</param> /// <param name="project">Project</param> /// <param name="errorCollection">Error Collection</param> /// <param name="flexFieldObject">Flex field object to which the dialog belongs</param> /// <param name="exportSettings">Export Settings</param> /// <returns>Condition string</returns> public override async Task <string> BuildConditionElementFromParsedData(ExportTemplate template, ValueFieldConditionData parsedData, GoNorthProject project, ExportPlaceholderErrorCollection errorCollection, FlexFieldObject flexFieldObject, ExportSettings exportSettings) { IFlexFieldExportable valueObject = await GetValueObject(parsedData, flexFieldObject, errorCollection); if (valueObject == null) { return(string.Empty); } FlexField exportField = DialogFlexFieldUtil.GetFlexField(valueObject, parsedData.FieldId); if (exportField == null) { errorCollection.AddErrorFlexField(parsedData.FieldName, valueObject.Name); return(string.Empty); } string conditionCode = template.Code; conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_IsOperatorPrimitiveStart, Placeholder_IsOperatorPrimitiveEnd, ConditionRenderingUtil.IsConditionOperatorPrimitiveOperator(parsedData.Operator)); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_IsOperatorNonPrimitiveStart, Placeholder_IsOperatorNonPrimitiveEnd, !ConditionRenderingUtil.IsConditionOperatorPrimitiveOperator(parsedData.Operator)); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_ValueName).Replace(conditionCode, m => { return(DialogFlexFieldUtil.GetFieldName(exportField, parsedData.FieldName, errorCollection)); }); string operatorCode = await ConditionRenderingUtil.GetCompareOperatorFromTemplate(_defaultTemplateProvider, project, parsedData.Operator, errorCollection); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_Operator).Replace(conditionCode, operatorCode); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_ValueIsString_Start, Placeholder_ValueIsString_End, exportField.FieldType != ExportConstants.FlexFieldType_Number); conditionCode = ExportUtil.RenderPlaceholderIfTrue(conditionCode, Placeholder_ValueIsNumber_Start, Placeholder_ValueIsNumber_End, exportField.FieldType == ExportConstants.FlexFieldType_Number); conditionCode = ExportUtil.RenderPlaceholderIfFuncTrue(conditionCode, Placeholder_ValueNameEquals_Start, Placeholder_ValueNameEquals_End, m => { string searchedFieldName = m.Groups[1].Value; searchedFieldName = searchedFieldName.ToLowerInvariant(); string fieldName = string.Empty; if (!string.IsNullOrEmpty(exportField.Name)) { fieldName = exportField.Name.ToLowerInvariant(); } return(fieldName == searchedFieldName); }); conditionCode = ExportUtil.RenderPlaceholderIfFuncTrue(conditionCode, Placeholder_ValueNameNotEquals_Start, Placeholder_ValueNameNotEquals_End, m => { string searchedFieldName = m.Groups[1].Value; searchedFieldName = searchedFieldName.ToLowerInvariant(); string fieldName = string.Empty; if (!string.IsNullOrEmpty(exportField.Name)) { fieldName = exportField.Name.ToLowerInvariant(); } return(fieldName != searchedFieldName); }); conditionCode = ExportUtil.BuildPlaceholderRegex(Placeholder_CompareValue).Replace(conditionCode, m => { if (exportField.FieldType != ExportConstants.FlexFieldType_Number) { return(ExportUtil.EscapeCharacters(parsedData.CompareValue, exportSettings.EscapeCharacter, exportSettings.CharactersNeedingEscaping, exportSettings.NewlineCharacter)); } return(parsedData.CompareValue); }); ExportObjectData flexFieldExportData = new ExportObjectData(); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObject, valueObject); flexFieldExportData.ExportData.Add(ExportConstants.ExportDataObjectType, GetFlexFieldExportObjectType()); _flexFieldPlaceholderResolver.SetErrorMessageCollection(errorCollection); conditionCode = await _flexFieldPlaceholderResolver.FillPlaceholders(conditionCode, flexFieldExportData); return(conditionCode); }