From 08065f7478c97b86cd9f5a329d87bcfe162966c4 Mon Sep 17 00:00:00 2001 From: prashelke Date: Wed, 17 Jul 2024 18:53:25 +0530 Subject: [PATCH 1/5] Mock Data By reflection all dataset,locale and methods are shown --- .../ValueExpression/ValueExpressionEditor.cs | 14 + .../ValueExpressionMockDataEditorPage.xaml | 24 ++ .../ValueExpressionMockDataEditorPage.xaml.cs | 325 ++++++++++++++++++ .../GingerCoreNET/RosLynLib/CodeProcessor.cs | 11 +- .../ValueExpressionLib/ValueExpression.cs | 45 ++- 5 files changed, 416 insertions(+), 3 deletions(-) create mode 100644 Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml create mode 100644 Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs index 971b4bf31a..0fd73c84e3 100644 --- a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs @@ -21,6 +21,7 @@ limitations under the License. using Amdocs.Ginger.Plugin.Core; using Ginger.Actions; using Ginger.UserControlsLib.TextEditor.Common; +using GingerCore; using GingerCore.Variables; using ICSharpCode.AvalonEdit.CodeCompletion; using ICSharpCode.AvalonEdit.Highlighting; @@ -193,6 +194,15 @@ private Page GetPageFor(SelectedContentArgs SelectedContentArgs) } } + if(txt.StartsWith("{MockDataExp Fun=")) + { + Mockdata expParams = GingerCore.ValueExpression.GetMockDataDatasetsFunction(txt); + if (expParams != null) + { + p = new ValueExpressionMockDataEditorPage(mContext, SelectedContentArgs,expParams.MockDataDatasets, expParams.Function, expParams.Locale, expParams.MockExpression); + } + } + if (txt.StartsWith("{EnvURL App=")) { //TODO: impl get page for Env @@ -233,6 +243,10 @@ public override void UpdateSelectedContent() { ((ValueExpressionFlowDetailsEditorPage)p).UpdateContent(); } + else if(p.GetType() == typeof(ValueExpressionMockDataEditorPage)) + { + ((ValueExpressionMockDataEditorPage)p).UpdateContent(); + } } // if we want to add tool bar item and handler this is the place diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml new file mode 100644 index 0000000000..88e4e659a0 --- /dev/null +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs new file mode 100644 index 0000000000..11f56d6733 --- /dev/null +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs @@ -0,0 +1,325 @@ +#region License +/* +Copyright © 2014-2024 European Support Limited + +Licensed under the Apache License, Version 2.0 (the "License") +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#endregion + +using Amdocs.Ginger.Common; +using Bogus; +using Ginger.UserControlsLib.TextEditor.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Windows.Controls; + +namespace Ginger.UserControlsLib.TextEditor.ValueExpression +{ + /// + /// Interaction logic for ValueExpressionMockDataEditorPage.xaml + /// + public partial class ValueExpressionMockDataEditorPage : Page + { + SelectedContentArgs mSelectedContentArgs; + Context mContext; + string mObj; + public ValueExpressionMockDataEditorPage(Context context, SelectedContentArgs SelectedContentArgs, string obj, string function, string Locale, string MockExpression) + { + InitializeComponent(); + mContext = context; + mSelectedContentArgs = SelectedContentArgs; + mObj = obj; + int datasetStartindex = MockExpression.IndexOf('='); + int datasetendindex = MockExpression.IndexOf('('); + int localestartindex = MockExpression.IndexOf('"'); + int localeendindex = MockExpression.IndexOf(')'); + int functionstartindex = MockExpression.IndexOf('.'); + + List Localelst = GetLocales(); + Type objType; + List objClasses = new List(); + List methodList = new List(); + + Assembly assembly = Assembly.Load("Bogus"); // or load your target assembly + + string namespaceName = "Bogus.DataSets"; + + objClasses = GetObjectClasses(assembly, namespaceName); + + + // Example of fetching locales (replace with actual implementation) + Localelst = GetLocales(); + + string objTypeName = mObj.Equals("Randomizer") ? $"Bogus.{mObj}" : $"Bogus.DataSets.{mObj}"; + objType = assembly.GetType(objTypeName); + + methodList = GetMethodsOfType(objType); + int CaretPossition = SelectedContentArgs.GetCaretPosition(); + if ((datasetStartindex < CaretPossition) && (CaretPossition < datasetendindex)) + { + FunctionsList.ItemsSource = objClasses.OrderBy(x => x).ToList(); + } + else if ((localestartindex < CaretPossition) && (CaretPossition < localeendindex) && (!mObj.Equals("Randomizer") || !mObj.Equals("Finance"))) + { + FunctionsList.ItemsSource = Localelst.OrderBy(x => x).ToList(); + } + else + { + FunctionsList.ItemsSource = methodList.OrderBy(x => x).ToList(); + } + } + + + private static List GetLocales() + { + // Replace with actual implementation to fetch locales + return Bogus.Database.GetAllLocales().ToList(); + } + + private static List GetObjectClasses(Assembly assembly, string namespaceName) + { + Type[] types = assembly.GetTypes(); + List objclass = types.Where(t => t.Namespace == namespaceName && typeof(DataSet).IsAssignableFrom(t) && t != typeof(DataSet) && t.FullName.Contains(namespaceName)) + .Select(x => x.Name) + .ToList(); + objclass.Add("Randomizer"); + return objclass; + } + + private static List GetMethodsOfType(Type objType) + { + List methodList = new List(); + + if (objType != null) + { + MethodInfo[] methods = objType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); + + if (methods != null) + { + var excludedMethods = GetExcludedMethods(objType.ToString()); + var groupedMethods = methods.GroupBy(m => m.Name); + foreach (var methodGroup in groupedMethods) + { + foreach (MethodInfo method in methodGroup) + { + if (excludedMethods.Contains(method.Name)) + { + continue; + } + string parameters = string.Join(", ", method.GetParameters().Select(p => FormatParameter(p))); + + string functionString = $"{method.Name}({parameters})"; + methodList.Add(functionString); + } + } + } + } + + return methodList; + } + + private static HashSet GetExcludedMethods(string objType) + { + return objType switch + { + "Bogus.Randomizer" => new HashSet { "EnumValues", "WeightedRandom", "ArrayElement", "ArrayElements", "ListItem", "ListItems", "ReplaceSymbols" }, + "Bogus.DataSets.Date" => new HashSet { "BetweenTimeOnly" }, + _ => new HashSet() + }; + } + + private static string FormatParameter(ParameterInfo parameter) + { + string paramType = parameter.ParameterType.Name; + string paramName = parameter.Name; + bool hasDefaultValue = parameter.HasDefaultValue; + object defaultValue = hasDefaultValue ? $"{FormatDefaultValue(parameter.DefaultValue)}" : SetDefaultValue(parameter); + return $"{defaultValue}"; + + } + + private static object SetDefaultValue(ParameterInfo parameter) + { + Type parameterType = parameter.ParameterType; + TimeOnly defaultSartTime = TimeOnly.MaxValue; + if (parameterType == typeof(DateTime) && parameter.Name.Equals("start")) + { + return "Past(1)"; + } + else if (parameterType == typeof(DateTime) && parameter.Name.Equals("end")) + { + return "Future(1)"; + } + + if (parameterType == typeof(DateOnly) && parameter.Name.Equals("start")) + { + return "PastDateOnly(1)"; + } + else if (parameterType == typeof(DateOnly) && parameter.Name.Equals("end")) + { + return "FutureDateOnly(1)"; + } + + if (parameterType == typeof(DateTimeOffset) && parameter.Name.Equals("start")) + { + return "PastOffset(1)"; + } + else if (parameterType == typeof(DateTimeOffset) && parameter.Name.Equals("end")) + { + return "FutureOffset(1)"; + } + + if(parameterType == typeof(Array)) + { + return "[1,2,3,4]"; + } + + if (parameterType == typeof(List)) + { + return "[1,2,3,4,5]"; + } + + if (parameterType == typeof(string)) + { + if(parameter.Name.Equals("format")) + { + return "'12#34'"; + } + else if (parameter.Name.Equals("symbol")) + { + return "'#'"; + } + else + { + return "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"; + } + + } + //DateTimeOffset + return GetDefaultForType(parameterType); + } + + public static T[] CreateArrayWithDefaultValues(int length, T defaultValue) + { + T[] array = new T[length]; + for (int i = 0; i < length; i++) + { + array[i] = defaultValue; + } + return array; + } + + private static object GetDefaultForType(Type type) + { + return type.IsValueType ? Activator.CreateInstance(type) : null; + } + + private static string FormatDefaultValue(object defaultValue) + { + if (defaultValue == null) + return "null"; + + if (defaultValue is string) + return $"\"{defaultValue}\""; + + if (defaultValue is char) + return $"'{defaultValue}'"; + + if (defaultValue is bool) + return defaultValue.ToString().ToLower(); + + return defaultValue.ToString(); + } + public void UpdateContent() + { + + string selectedItem = (string)FunctionsList.SelectedItem; + string initialText = mSelectedContentArgs.TextEditor.Text.Substring(0, mSelectedContentArgs.StartPos); + + // Parsing the text editor content + string editorText = mSelectedContentArgs.TextEditor.Text; + int datasetStartIndex = editorText.IndexOf('='); + int datasetEndIndex = editorText.IndexOf('('); + int localeStartIndex = editorText.IndexOf('"'); + int localeEndIndex = editorText.IndexOf(')'); + int functionStartIndex = editorText.IndexOf('.'); + + string functionSubstring = editorText.Substring(functionStartIndex + 1); + int functionEndIndex = functionSubstring.IndexOf('('); + + string datasetObject = ExtractSubstring(editorText, datasetStartIndex + 1, datasetEndIndex - datasetStartIndex - 1); + string locale = ExtractSubstring(editorText, localeStartIndex + 1, localeEndIndex - localeStartIndex - 2); + string objStr = ExtractSubstring(editorText, datasetStartIndex + 1, datasetEndIndex - datasetStartIndex - 1); + string functions = functionSubstring.Substring(0, functionEndIndex).Replace("\"", "").Trim(); + + int caretPosition = mSelectedContentArgs.GetCaretPosition(); + string resultText = BuildResultText(selectedItem, objStr, locale, functions, caretPosition, datasetStartIndex, datasetEndIndex, localeStartIndex, localeEndIndex); + + // Append the remaining text and update the text editor content + resultText += editorText.Substring(mSelectedContentArgs.EndPos + 1); + mSelectedContentArgs.TextEditor.Text = resultText; + } + + static string ExtractSubstring(string text, int startIndex, int length) + { + return text.Substring(startIndex, length); + } + + static string BuildResultText(string selectedItem, string objStr, string locale, string functions, int caretPosition, int datasetStartIndex, int datasetEndIndex, int localeStartIndex, int localeEndIndex) + { + string resultText = string.Empty; + + if(objStr.Equals("Randomizer") || objStr.Equals("Finance")) + { + if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) + { + Assembly assembly = Assembly.Load("Bogus"); + string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; + Type objType = assembly.GetType(objTypeName); + + List methodList = GetMethodsOfType(objType); + resultText += "{MockDataExp Fun=" + selectedItem + "()." + methodList.FirstOrDefault() + ";}"; + } + else + { + resultText += "{MockDataExp Fun=" + objStr + "()." + selectedItem + ";}"; + } + } + else + { + if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) + { + Assembly assembly = Assembly.Load("Bogus"); + string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; + Type objType = assembly.GetType(objTypeName); + + List methodList = GetMethodsOfType(objType); + resultText += "{MockDataExp Fun=" + selectedItem + "(@\"" + locale + "\")." + methodList.FirstOrDefault() + ";}"; + } + else if (localeStartIndex < caretPosition && caretPosition < localeEndIndex) + { + resultText += "{MockDataExp Fun=" + objStr + "(@\"" + selectedItem + "\")." + functions + "();}"; + } + else + { + resultText += "{MockDataExp Fun=" + objStr + "(@\"" + locale + "\")." + selectedItem + ";}"; + } + } + + + return resultText; + } + } +} diff --git a/Ginger/GingerCoreNET/RosLynLib/CodeProcessor.cs b/Ginger/GingerCoreNET/RosLynLib/CodeProcessor.cs index 78bc229c8f..71c514aa7c 100644 --- a/Ginger/GingerCoreNET/RosLynLib/CodeProcessor.cs +++ b/Ginger/GingerCoreNET/RosLynLib/CodeProcessor.cs @@ -343,7 +343,14 @@ public static string GetBogusExpressionEvaluteResult(string expression, out stri /// Handles scenarios with special case like Between function have inbuilt function as parameter and constructs expressions accordingly if (expressionlist[1].Contains("Past") && expressionlist[1].Contains("Future")) { - expressionlist[1] = expressionlist[1].Replace(Parameter[0], $"Result.{Parameter[0]}").Replace(Parameter[1], $"Result.{Parameter[1]}"); + if (expressionlist[1].Contains("BetweenTimeOnly")) + { + expressionlist[1] = expressionlist[1].Replace(Parameter[0], $"TimeOnly.FromDateTime(Result.{Parameter[0]})").Replace(Parameter[1], $"TimeOnly.FromDateTime(Result.{Parameter[1]})"); + } + else + { + expressionlist[1] = expressionlist[1].Replace(Parameter[0], $"Result.{Parameter[0]}").Replace(Parameter[1], $"Result.{Parameter[1]}"); + } } expression = $"var Result = new Bogus.DataSets.{expressionlist[0]}; return Result.{expressionlist[1]}"; } @@ -381,7 +388,7 @@ public static string GetBogusExpressionEvaluteResult(string expression, out stri } catch (Exception e) { - Reporter.ToLog(eLogLevel.DEBUG, expression + System.Environment.NewLine + " not a valid Bogus data generate expression to evaluate", e); + Reporter.ToLog(eLogLevel.ERROR, expression + System.Environment.NewLine + " not a valid Bogus data generate expression to evaluate", e); } return evalresult; } diff --git a/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs b/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs index 38d59706b4..d5d3224def 100644 --- a/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs +++ b/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs @@ -347,7 +347,6 @@ public enum eFlowDetailsObjects { Environment, Runset, Runner, BusinessFlow, ActivitiesGroup, Activity, Action, PreviousBusinessFlow, PreviousActivity, PreviousAction, LastFailedAction, ErrorHandlerOriginActivitiesGroup, ErrorHandlerOriginActivity, ErrorHandlerOriginAction, LastFailedBusinessFlow, LastFailedActivity, Solution } - public static Tuple GetFlowDetailsParams(string flowDetailsExpression) { try @@ -375,6 +374,39 @@ public static Tuple GetFlowDetailsParams(string flo } } + public static Mockdata GetMockDataDatasetsFunction(string MockDataExpression) + { + try + { + string objStr = string.Empty; + string functions = string.Empty; + string Datasetobject = string.Empty; + string Locale = string.Empty; + int datasetStartindex = MockDataExpression.IndexOf('='); + int datasetendindex = MockDataExpression.IndexOf('('); + int localestartindex = MockDataExpression.IndexOf('"'); + int localeendindex = MockDataExpression.IndexOf(')'); + int functionstartindex = MockDataExpression.IndexOf('.'); + string funsubstring = MockDataExpression.Substring(functionstartindex + 1, MockDataExpression.Length - functionstartindex - 1); + int functionendindex = funsubstring.IndexOf('('); + Datasetobject = MockDataExpression.Substring(datasetStartindex + 1, datasetendindex - 1 - datasetStartindex); + Locale = MockDataExpression.Substring(localestartindex + 1, localeendindex - 2 - localestartindex); + objStr = MockDataExpression.Substring(datasetStartindex + 1, datasetendindex - 1 - datasetStartindex); + functions = funsubstring.Substring(0, functionendindex).Replace("\"", "").Trim(); + Mockdata mockdata = new (); + mockdata.MockDataDatasets = objStr; + mockdata.Locale = Locale; + mockdata.Function = functions; + mockdata.MockExpression = MockDataExpression; + return mockdata; + } + catch (Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to evaluate flow details expression '{0}' due to wrong format", MockDataExpression)); + return null; + } + } + private void ReplaceFlowDetails(string flowDetailsExpression) { eFlowDetailsObjects obj; @@ -1804,4 +1836,15 @@ public static string Calculate(ProjEnvironment ProjEnvironment, BusinessFlow Bus return VE.ValueCalculated; } } + + public class Mockdata + { + public string MockDataDatasets { get; set; } + + public string Locale { get; set; } + + public string Function { get; set; } + + public string MockExpression { get; set; } + } } From ffd47ea2d616f8acf9c57bdca4e39b53eccbf4f2 Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 18 Jul 2024 14:28:56 +0530 Subject: [PATCH 2/5] Mock Data Review Comment changes --- .../ValueExpression/ValueExpressionEditor.cs | 31 +- .../ValueExpressionMockDataEditorPage.xaml.cs | 305 ++++++++++-------- .../ValueExpressionLib/ValueExpression.cs | 66 +++- 3 files changed, 233 insertions(+), 169 deletions(-) diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs index 0fd73c84e3..294f2d8f9c 100644 --- a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionEditor.cs @@ -231,21 +231,28 @@ private Page GetPageFor(SelectedContentArgs SelectedContentArgs) public override void UpdateSelectedContent() { - if (p.GetType() == typeof(ValueExpressionVariableEditorPage)) + try { - ((ValueExpressionVariableEditorPage)p).UpdateContent(); - } - else if (p.GetType() == typeof(ActDataSourcePage)) - { - ((ActDataSourcePage)p).UpdateContent(); - } - else if (p.GetType() == typeof(ValueExpressionFlowDetailsEditorPage)) - { - ((ValueExpressionFlowDetailsEditorPage)p).UpdateContent(); + if (p.GetType() == typeof(ValueExpressionVariableEditorPage)) + { + ((ValueExpressionVariableEditorPage)p).UpdateContent(); + } + else if (p.GetType() == typeof(ActDataSourcePage)) + { + ((ActDataSourcePage)p).UpdateContent(); + } + else if (p.GetType() == typeof(ValueExpressionFlowDetailsEditorPage)) + { + ((ValueExpressionFlowDetailsEditorPage)p).UpdateContent(); + } + else if (p.GetType() == typeof(ValueExpressionMockDataEditorPage)) + { + ((ValueExpressionMockDataEditorPage)p).UpdateContent(); + } } - else if(p.GetType() == typeof(ValueExpressionMockDataEditorPage)) + catch (Exception ex) { - ((ValueExpressionMockDataEditorPage)p).UpdateContent(); + Reporter.ToLog(eLogLevel.ERROR, "Failed to update the selected content", ex); } } diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs index 11f56d6733..8cf85f0fb5 100644 --- a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs @@ -24,6 +24,8 @@ limitations under the License. using System.Linq; using System.Reflection; using System.Windows.Controls; +using GingerCore; +using Org.BouncyCastle.Asn1.Pkcs; namespace Ginger.UserControlsLib.TextEditor.ValueExpression { @@ -35,49 +37,55 @@ public partial class ValueExpressionMockDataEditorPage : Page SelectedContentArgs mSelectedContentArgs; Context mContext; string mObj; + static List Localelst; + static List objClasses; public ValueExpressionMockDataEditorPage(Context context, SelectedContentArgs SelectedContentArgs, string obj, string function, string Locale, string MockExpression) { - InitializeComponent(); - mContext = context; - mSelectedContentArgs = SelectedContentArgs; - mObj = obj; - int datasetStartindex = MockExpression.IndexOf('='); - int datasetendindex = MockExpression.IndexOf('('); - int localestartindex = MockExpression.IndexOf('"'); - int localeendindex = MockExpression.IndexOf(')'); - int functionstartindex = MockExpression.IndexOf('.'); - - List Localelst = GetLocales(); - Type objType; - List objClasses = new List(); - List methodList = new List(); + try + { - Assembly assembly = Assembly.Load("Bogus"); // or load your target assembly - string namespaceName = "Bogus.DataSets"; + InitializeComponent(); + mContext = context; + mSelectedContentArgs = SelectedContentArgs; + mObj = obj; + int datasetStartindex = MockExpression.IndexOf('='); + int datasetendindex = MockExpression.IndexOf('('); + int localestartindex = MockExpression.IndexOf('"'); + int localeendindex = MockExpression.IndexOf(')'); + int functionstartindex = MockExpression.IndexOf('.'); - objClasses = GetObjectClasses(assembly, namespaceName); - + Localelst = Localelst == null ? GetLocales() : Localelst; + Type objType; + List methodList = new List(); - // Example of fetching locales (replace with actual implementation) - Localelst = GetLocales(); + Assembly assembly = Assembly.Load("Bogus"); // or load your target assembly - string objTypeName = mObj.Equals("Randomizer") ? $"Bogus.{mObj}" : $"Bogus.DataSets.{mObj}"; - objType = assembly.GetType(objTypeName); + string namespaceName = "Bogus.DataSets"; - methodList = GetMethodsOfType(objType); - int CaretPossition = SelectedContentArgs.GetCaretPosition(); - if ((datasetStartindex < CaretPossition) && (CaretPossition < datasetendindex)) - { - FunctionsList.ItemsSource = objClasses.OrderBy(x => x).ToList(); - } - else if ((localestartindex < CaretPossition) && (CaretPossition < localeendindex) && (!mObj.Equals("Randomizer") || !mObj.Equals("Finance"))) - { - FunctionsList.ItemsSource = Localelst.OrderBy(x => x).ToList(); + objClasses = objClasses == null ? GetObjectClasses(assembly, namespaceName) : objClasses; + + string objTypeName = mObj.Equals("Randomizer") ? $"Bogus.{mObj}" : $"Bogus.DataSets.{mObj}"; + objType = assembly.GetType(objTypeName); + + methodList = GetMethodsOfType(objType); + int CaretPossition = SelectedContentArgs.GetCaretPosition(); + if ((datasetStartindex < CaretPossition) && (CaretPossition < datasetendindex)) + { + FunctionsList.ItemsSource = objClasses.OrderBy(x => x).ToList(); + } + else if ((localestartindex < CaretPossition) && (CaretPossition < localeendindex) && (!mObj.Equals("Randomizer") || !mObj.Equals("Finance"))) + { + FunctionsList.ItemsSource = Localelst.OrderBy(x => x).ToList(); + } + else + { + FunctionsList.ItemsSource = methodList.OrderBy(x => x).ToList(); + } } - else + catch (Exception ex) { - FunctionsList.ItemsSource = methodList.OrderBy(x => x).ToList(); + Reporter.ToLog(eLogLevel.ERROR, "Failed to load ValueExpressionMockDataEditorPage", ex); } } @@ -153,62 +161,31 @@ private static string FormatParameter(ParameterInfo parameter) private static object SetDefaultValue(ParameterInfo parameter) { Type parameterType = parameter.ParameterType; - TimeOnly defaultSartTime = TimeOnly.MaxValue; - if (parameterType == typeof(DateTime) && parameter.Name.Equals("start")) - { - return "Past(1)"; - } - else if (parameterType == typeof(DateTime) && parameter.Name.Equals("end")) - { - return "Future(1)"; - } - if (parameterType == typeof(DateOnly) && parameter.Name.Equals("start")) - { - return "PastDateOnly(1)"; - } - else if (parameterType == typeof(DateOnly) && parameter.Name.Equals("end")) + return parameterType switch { - return "FutureDateOnly(1)"; - } + Type type when type == typeof(DateTime) && parameter.Name.Equals("start") => "Past(1)", + Type type when type == typeof(DateTime) && parameter.Name.Equals("end") => "Future(1)", - if (parameterType == typeof(DateTimeOffset) && parameter.Name.Equals("start")) - { - return "PastOffset(1)"; - } - else if (parameterType == typeof(DateTimeOffset) && parameter.Name.Equals("end")) - { - return "FutureOffset(1)"; - } + Type type when type == typeof(DateOnly) && parameter.Name.Equals("start") => "PastDateOnly(1)", + Type type when type == typeof(DateOnly) && parameter.Name.Equals("end") => "FutureDateOnly(1)", - if(parameterType == typeof(Array)) - { - return "[1,2,3,4]"; - } + Type type when type == typeof(DateTimeOffset) && parameter.Name.Equals("start") => "PastOffset(1)", + Type type when type == typeof(DateTimeOffset) && parameter.Name.Equals("end") => "FutureOffset(1)", - if (parameterType == typeof(List)) - { - return "[1,2,3,4,5]"; - } + Type type when type == typeof(Array) => "[1,2,3,4]", - if (parameterType == typeof(string)) - { - if(parameter.Name.Equals("format")) - { - return "'12#34'"; - } - else if (parameter.Name.Equals("symbol")) - { - return "'#'"; - } - else + Type type when type == typeof(List) => "[1,2,3,4,5]", + + Type type when type == typeof(string) => parameter.Name switch { - return "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"; - } - - } - //DateTimeOffset - return GetDefaultForType(parameterType); + "format" => "'12#34'", + "symbol" => "'#'", + _ => "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" + }, + + _ => GetDefaultForType(parameterType) + }; } public static T[] CreateArrayWithDefaultValues(int length, T defaultValue) @@ -228,48 +205,44 @@ private static object GetDefaultForType(Type type) private static string FormatDefaultValue(object defaultValue) { - if (defaultValue == null) - return "null"; - - if (defaultValue is string) - return $"\"{defaultValue}\""; - - if (defaultValue is char) - return $"'{defaultValue}'"; - - if (defaultValue is bool) - return defaultValue.ToString().ToLower(); - - return defaultValue.ToString(); + switch (defaultValue) + { + case null: + return "null"; + case string s: + return $"\"{s}\""; + case char c: + return $"'{c}'"; + case bool b: + return b.ToString().ToLower(); + default: + return defaultValue.ToString(); + } } public void UpdateContent() { + try + { + string selectedItem = (string)FunctionsList.SelectedItem; + string initialText = mSelectedContentArgs.TextEditor.Text.Substring(0, mSelectedContentArgs.StartPos); - string selectedItem = (string)FunctionsList.SelectedItem; - string initialText = mSelectedContentArgs.TextEditor.Text.Substring(0, mSelectedContentArgs.StartPos); - - // Parsing the text editor content - string editorText = mSelectedContentArgs.TextEditor.Text; - int datasetStartIndex = editorText.IndexOf('='); - int datasetEndIndex = editorText.IndexOf('('); - int localeStartIndex = editorText.IndexOf('"'); - int localeEndIndex = editorText.IndexOf(')'); - int functionStartIndex = editorText.IndexOf('.'); - - string functionSubstring = editorText.Substring(functionStartIndex + 1); - int functionEndIndex = functionSubstring.IndexOf('('); + // Parsing the text editor content + string objStr, functions, Locale; + Mockdata expParams = GingerCore.ValueExpression.GetMockDataDatasetsFunction(mSelectedContentArgs.TextEditor.Text); - string datasetObject = ExtractSubstring(editorText, datasetStartIndex + 1, datasetEndIndex - datasetStartIndex - 1); - string locale = ExtractSubstring(editorText, localeStartIndex + 1, localeEndIndex - localeStartIndex - 2); - string objStr = ExtractSubstring(editorText, datasetStartIndex + 1, datasetEndIndex - datasetStartIndex - 1); - string functions = functionSubstring.Substring(0, functionEndIndex).Replace("\"", "").Trim(); + string editorText = mSelectedContentArgs.TextEditor.Text; - int caretPosition = mSelectedContentArgs.GetCaretPosition(); - string resultText = BuildResultText(selectedItem, objStr, locale, functions, caretPosition, datasetStartIndex, datasetEndIndex, localeStartIndex, localeEndIndex); + int caretPosition = mSelectedContentArgs.GetCaretPosition(); + string resultText = BuildResultText(selectedItem, expParams.MockDataDatasets, expParams.Locale, expParams.Function, caretPosition, expParams.DatasetStartIndex, expParams.DatasetEndIndex, expParams.LocaleStartIndex, expParams.LocaleEndIndex); - // Append the remaining text and update the text editor content - resultText += editorText.Substring(mSelectedContentArgs.EndPos + 1); - mSelectedContentArgs.TextEditor.Text = resultText; + // Append the remaining text and update the text editor content + resultText += editorText.Substring(mSelectedContentArgs.EndPos + 1); + mSelectedContentArgs.TextEditor.Text = resultText; + } + catch(Exception ex) + { + Reporter.ToLog(eLogLevel.ERROR, "Failed to update content in ValueExpressionMockDataEditorPage", ex); + } } static string ExtractSubstring(string text, int startIndex, int length) @@ -277,38 +250,70 @@ static string ExtractSubstring(string text, int startIndex, int length) return text.Substring(startIndex, length); } + //static string BuildResultText(string selectedItem, string objStr, string locale, string functions, int caretPosition, int datasetStartIndex, int datasetEndIndex, int localeStartIndex, int localeEndIndex) + //{ + // string resultText = string.Empty; + + // if(objStr.Equals("Randomizer") || objStr.Equals("Finance")) + // { + // if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) + // { + // Assembly assembly = Assembly.Load("Bogus"); + // string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; + // Type objType = assembly.GetType(objTypeName); + + // List methodList = GetMethodsOfType(objType); + // resultText += "{MockDataExp Fun=" + selectedItem + "()." + methodList.FirstOrDefault() + ";}"; + // } + // else + // { + // resultText += "{MockDataExp Fun=" + objStr + "()." + selectedItem + ";}"; + // } + // } + // else + // { + // if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) + // { + // Assembly assembly = Assembly.Load("Bogus"); + // string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; + // Type objType = assembly.GetType(objTypeName); + + // List methodList = GetMethodsOfType(objType); + // resultText += "{MockDataExp Fun=" + selectedItem + "(@\"" + locale + "\")." + methodList.FirstOrDefault() + ";}"; + // } + // else if (localeStartIndex < caretPosition && caretPosition < localeEndIndex) + // { + // resultText += "{MockDataExp Fun=" + objStr + "(@\"" + selectedItem + "\")." + functions + "();}"; + // } + // else + // { + // resultText += "{MockDataExp Fun=" + objStr + "(@\"" + locale + "\")." + selectedItem + ";}"; + // } + // } + + + // return resultText; + //} + static string BuildResultText(string selectedItem, string objStr, string locale, string functions, int caretPosition, int datasetStartIndex, int datasetEndIndex, int localeStartIndex, int localeEndIndex) { string resultText = string.Empty; - - if(objStr.Equals("Randomizer") || objStr.Equals("Finance")) - { - if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) - { - Assembly assembly = Assembly.Load("Bogus"); - string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; - Type objType = assembly.GetType(objTypeName); + bool isWithinDataset = datasetStartIndex < caretPosition && caretPosition < datasetEndIndex; + bool isWithinLocale = localeStartIndex < caretPosition && caretPosition < localeEndIndex; - List methodList = GetMethodsOfType(objType); - resultText += "{MockDataExp Fun=" + selectedItem + "()." + methodList.FirstOrDefault() + ";}"; - } - else - { - resultText += "{MockDataExp Fun=" + objStr + "()." + selectedItem + ";}"; - } + if (objStr.Equals("Randomizer") || objStr.Equals("Finance")) + { + resultText += isWithinDataset + ? GenerateResultText(selectedItem, "Bogus", isWithinDataset) + : "{MockDataExp Fun=" + objStr + "()." + selectedItem + ";}"; } else { - if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) + if (isWithinDataset) { - Assembly assembly = Assembly.Load("Bogus"); - string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; - Type objType = assembly.GetType(objTypeName); - - List methodList = GetMethodsOfType(objType); - resultText += "{MockDataExp Fun=" + selectedItem + "(@\"" + locale + "\")." + methodList.FirstOrDefault() + ";}"; + resultText += GenerateResultText(selectedItem, "Bogus", isWithinDataset, locale); } - else if (localeStartIndex < caretPosition && caretPosition < localeEndIndex) + else if (isWithinLocale) { resultText += "{MockDataExp Fun=" + objStr + "(@\"" + selectedItem + "\")." + functions + "();}"; } @@ -317,9 +322,27 @@ static string BuildResultText(string selectedItem, string objStr, string locale, resultText += "{MockDataExp Fun=" + objStr + "(@\"" + locale + "\")." + selectedItem + ";}"; } } - return resultText; } + + private static string GenerateResultText(string selectedItem, string baseNamespace, bool isWithinDataset, string locale = null) + { + Assembly assembly = Assembly.Load("Bogus"); + string objTypeName = selectedItem.Equals("Randomizer") ? $"{baseNamespace}.{selectedItem}" : $"{baseNamespace}.DataSets.{selectedItem}"; + Type objType = assembly.GetType(objTypeName); + + List methodList = GetMethodsOfType(objType); + string methodCall = methodList.FirstOrDefault(); + + if (locale == null) + { + return "{MockDataExp Fun=" + selectedItem + "()." + methodCall + ";}"; + } + else + { + return "{MockDataExp Fun=" + selectedItem + "(@\"" + locale + "\")." + methodCall + ";}"; + } + } } } diff --git a/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs b/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs index d5d3224def..95049b0371 100644 --- a/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs +++ b/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs @@ -378,26 +378,18 @@ public static Mockdata GetMockDataDatasetsFunction(string MockDataExpression) { try { - string objStr = string.Empty; - string functions = string.Empty; - string Datasetobject = string.Empty; - string Locale = string.Empty; - int datasetStartindex = MockDataExpression.IndexOf('='); - int datasetendindex = MockDataExpression.IndexOf('('); - int localestartindex = MockDataExpression.IndexOf('"'); - int localeendindex = MockDataExpression.IndexOf(')'); - int functionstartindex = MockDataExpression.IndexOf('.'); - string funsubstring = MockDataExpression.Substring(functionstartindex + 1, MockDataExpression.Length - functionstartindex - 1); - int functionendindex = funsubstring.IndexOf('('); - Datasetobject = MockDataExpression.Substring(datasetStartindex + 1, datasetendindex - 1 - datasetStartindex); - Locale = MockDataExpression.Substring(localestartindex + 1, localeendindex - 2 - localestartindex); - objStr = MockDataExpression.Substring(datasetStartindex + 1, datasetendindex - 1 - datasetStartindex); - functions = funsubstring.Substring(0, functionendindex).Replace("\"", "").Trim(); - Mockdata mockdata = new (); + string objStr, functions, Locale; + int DatasetStartIndex, DatasetEndIndex, LocaleStartIndex, LocaleEndIndex; + MockdataExpressionExtract(MockDataExpression, out objStr, out functions, out Locale,out DatasetStartIndex,out DatasetEndIndex,out LocaleStartIndex,out LocaleEndIndex); + Mockdata mockdata = new(); mockdata.MockDataDatasets = objStr; mockdata.Locale = Locale; mockdata.Function = functions; mockdata.MockExpression = MockDataExpression; + mockdata.DatasetStartIndex = DatasetStartIndex; + mockdata.DatasetEndIndex = DatasetEndIndex; + mockdata.LocaleStartIndex = LocaleStartIndex; + mockdata.LocaleEndIndex = LocaleEndIndex; return mockdata; } catch (Exception ex) @@ -406,6 +398,37 @@ public static Mockdata GetMockDataDatasetsFunction(string MockDataExpression) return null; } } + /// + /// This method extracts specific parts from the MockDataExpression string. + /// It initializes several string variables and then uses indices to parse substrings, + /// assigning these substrings to the initialized variables. + /// + /// + /// + /// + /// + /// Index of '=' in MockDataExpression. + /// Index of '(' in MockDataExpression. + /// Index of '"' in MockDataExpression. + /// Index of ')' in MockDataExpression. + private static void MockdataExpressionExtract(string MockDataExpression, out string objStr, out string functions, out string Locale, out int DatasetStartIndex, out int DatasetEndIndex, out int LocaleStartIndex, out int LocaleEndIndex) + { + objStr = string.Empty; + functions = string.Empty; + string Datasetobject = string.Empty; + Locale = string.Empty; + DatasetStartIndex = MockDataExpression.IndexOf('='); + DatasetEndIndex = MockDataExpression.IndexOf('('); + LocaleStartIndex = MockDataExpression.IndexOf('"'); + LocaleEndIndex = MockDataExpression.IndexOf(')'); + int functionstartindex = MockDataExpression.IndexOf('.'); + string funsubstring = MockDataExpression.Substring(functionstartindex + 1); ; + int functionendindex = funsubstring.IndexOf('('); + Datasetobject = MockDataExpression.Substring(DatasetStartIndex + 1, DatasetEndIndex - 1 - DatasetStartIndex); + Locale = MockDataExpression.Substring(LocaleStartIndex + 1, LocaleEndIndex - 2 - LocaleStartIndex); + objStr = MockDataExpression.Substring(DatasetStartIndex + 1, DatasetEndIndex - 1 - DatasetStartIndex); + functions = funsubstring.Substring(0, functionendindex).Replace("\"", "").Trim(); + } private void ReplaceFlowDetails(string flowDetailsExpression) { @@ -1846,5 +1869,16 @@ public class Mockdata public string Function { get; set; } public string MockExpression { get; set; } + + public int DatasetStartIndex { get; set; } + + public int DatasetEndIndex { get; set; } + + public int LocaleStartIndex { get; set; } + + public int LocaleEndIndex { get; set; } + + public int FunctionStartIndex { get; set; } + } } From c00829aec631e6d0b0f85f0aa630fe08ba6144e4 Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 18 Jul 2024 14:38:18 +0530 Subject: [PATCH 3/5] Remove commented Code --- .../ValueExpressionMockDataEditorPage.xaml.cs | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs index 8cf85f0fb5..fa1eb938ee 100644 --- a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs @@ -250,51 +250,6 @@ static string ExtractSubstring(string text, int startIndex, int length) return text.Substring(startIndex, length); } - //static string BuildResultText(string selectedItem, string objStr, string locale, string functions, int caretPosition, int datasetStartIndex, int datasetEndIndex, int localeStartIndex, int localeEndIndex) - //{ - // string resultText = string.Empty; - - // if(objStr.Equals("Randomizer") || objStr.Equals("Finance")) - // { - // if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) - // { - // Assembly assembly = Assembly.Load("Bogus"); - // string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; - // Type objType = assembly.GetType(objTypeName); - - // List methodList = GetMethodsOfType(objType); - // resultText += "{MockDataExp Fun=" + selectedItem + "()." + methodList.FirstOrDefault() + ";}"; - // } - // else - // { - // resultText += "{MockDataExp Fun=" + objStr + "()." + selectedItem + ";}"; - // } - // } - // else - // { - // if (datasetStartIndex < caretPosition && caretPosition < datasetEndIndex) - // { - // Assembly assembly = Assembly.Load("Bogus"); - // string objTypeName = selectedItem.Equals("Randomizer") ? $"Bogus.{selectedItem}" : $"Bogus.DataSets.{selectedItem}"; - // Type objType = assembly.GetType(objTypeName); - - // List methodList = GetMethodsOfType(objType); - // resultText += "{MockDataExp Fun=" + selectedItem + "(@\"" + locale + "\")." + methodList.FirstOrDefault() + ";}"; - // } - // else if (localeStartIndex < caretPosition && caretPosition < localeEndIndex) - // { - // resultText += "{MockDataExp Fun=" + objStr + "(@\"" + selectedItem + "\")." + functions + "();}"; - // } - // else - // { - // resultText += "{MockDataExp Fun=" + objStr + "(@\"" + locale + "\")." + selectedItem + ";}"; - // } - // } - - - // return resultText; - //} - static string BuildResultText(string selectedItem, string objStr, string locale, string functions, int caretPosition, int datasetStartIndex, int datasetEndIndex, int localeStartIndex, int localeEndIndex) { string resultText = string.Empty; From afefd7f97d48daa29fdc8877ca9eb96381224d77 Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 18 Jul 2024 15:58:18 +0530 Subject: [PATCH 4/5] Codacy Issue Resolved --- .../ValueExpressionMockDataEditorPage.xaml.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs index fa1eb938ee..171aaf019e 100644 --- a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs @@ -43,8 +43,6 @@ public ValueExpressionMockDataEditorPage(Context context, SelectedContentArgs Se { try { - - InitializeComponent(); mContext = context; mSelectedContentArgs = SelectedContentArgs; @@ -55,15 +53,15 @@ public ValueExpressionMockDataEditorPage(Context context, SelectedContentArgs Se int localeendindex = MockExpression.IndexOf(')'); int functionstartindex = MockExpression.IndexOf('.'); - Localelst = Localelst == null ? GetLocales() : Localelst; + Localelst = Localelst ?? GetLocales(); Type objType; - List methodList = new List(); + List methodList = new(); Assembly assembly = Assembly.Load("Bogus"); // or load your target assembly string namespaceName = "Bogus.DataSets"; - objClasses = objClasses == null ? GetObjectClasses(assembly, namespaceName) : objClasses; + objClasses = objClasses ?? GetObjectClasses(assembly, namespaceName); string objTypeName = mObj.Equals("Randomizer") ? $"Bogus.{mObj}" : $"Bogus.DataSets.{mObj}"; objType = assembly.GetType(objTypeName); From dbb81437de1b11ff376ee0388043046ff1ae7cda Mon Sep 17 00:00:00 2001 From: prashelke Date: Thu, 18 Jul 2024 16:27:14 +0530 Subject: [PATCH 5/5] Updated --- .../ValueExpressionMockDataEditorPage.xaml.cs | 7 +++---- Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs | 4 +--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs index 171aaf019e..abff7f2d6e 100644 --- a/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs +++ b/Ginger/Ginger/UserControlsLib/TextEditor/ValueExpression/ValueExpressionMockDataEditorPage.xaml.cs @@ -37,8 +37,8 @@ public partial class ValueExpressionMockDataEditorPage : Page SelectedContentArgs mSelectedContentArgs; Context mContext; string mObj; - static List Localelst; - static List objClasses; + List Localelst; + List objClasses; public ValueExpressionMockDataEditorPage(Context context, SelectedContentArgs SelectedContentArgs, string obj, string function, string Locale, string MockExpression) { try @@ -55,7 +55,7 @@ public ValueExpressionMockDataEditorPage(Context context, SelectedContentArgs Se Localelst = Localelst ?? GetLocales(); Type objType; - List methodList = new(); + List methodList; Assembly assembly = Assembly.Load("Bogus"); // or load your target assembly @@ -90,7 +90,6 @@ public ValueExpressionMockDataEditorPage(Context context, SelectedContentArgs Se private static List GetLocales() { - // Replace with actual implementation to fetch locales return Bogus.Database.GetAllLocales().ToList(); } diff --git a/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs b/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs index 95049b0371..e285e7aaa9 100644 --- a/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs +++ b/Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs @@ -415,16 +415,14 @@ private static void MockdataExpressionExtract(string MockDataExpression, out str { objStr = string.Empty; functions = string.Empty; - string Datasetobject = string.Empty; Locale = string.Empty; DatasetStartIndex = MockDataExpression.IndexOf('='); DatasetEndIndex = MockDataExpression.IndexOf('('); LocaleStartIndex = MockDataExpression.IndexOf('"'); LocaleEndIndex = MockDataExpression.IndexOf(')'); int functionstartindex = MockDataExpression.IndexOf('.'); - string funsubstring = MockDataExpression.Substring(functionstartindex + 1); ; + string funsubstring = MockDataExpression.Substring(functionstartindex + 1); int functionendindex = funsubstring.IndexOf('('); - Datasetobject = MockDataExpression.Substring(DatasetStartIndex + 1, DatasetEndIndex - 1 - DatasetStartIndex); Locale = MockDataExpression.Substring(LocaleStartIndex + 1, LocaleEndIndex - 2 - LocaleStartIndex); objStr = MockDataExpression.Substring(DatasetStartIndex + 1, DatasetEndIndex - 1 - DatasetStartIndex); functions = funsubstring.Substring(0, functionendindex).Replace("\"", "").Trim();