Ejemplo n.º 1
0
        public object GetPropertyValueByDataSource(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return(text);
            }

            if (text.Trim().StartsWith("{"))
            {
                DataSourceVariable variable = null;
                try
                {
                    variable = JsonConvert.DeserializeObject <DataSourceVariable>(text, new JsonSerializerSettings()
                    {
                        MissingMemberHandling = MissingMemberHandling.Error
                    });
                }
                catch
                {
                    return(text);
                }

                if (variable != null)
                {
                    return(GetPropertyValueByDataSource(variable));
                }
            }

            return(text);
        }
Ejemplo n.º 2
0
        public object GetPropertyValueByDataSource(DataSourceVariable variable)
        {
            if (variable == null)
            {
                throw new NullReferenceException(nameof(variable));
            }

            try
            {
                object result = null;
                switch (variable.Type)
                {
                case DataSourceVariableType.DATASOURCE:
                    result = GetProperty(variable.String);
                    break;

                case DataSourceVariableType.CODE:
                    if (SafeCodeDataVariable)
                    {
                        try { result = CodeEvalService.Evaluate(variable.String, erpPageModel); } catch { result = null; }
                    }
                    else
                    {
                        result = CodeEvalService.Evaluate(variable.String, erpPageModel);
                    }
                    break;

                case DataSourceVariableType.HTML:
                    result = variable.String;
                    break;

                default:
                    throw new NotSupportedException(variable.Type.ToString());
                }
                if (result is string)
                {
                    if (string.IsNullOrWhiteSpace(result as string))
                    {
                        return(variable.Default);
                    }
                }
                else
                {
                    if (result is null)
                    {
                        return(variable.Default);
                    }
                }

                return(result);
            }
            catch (PropertyDoesNotExistException)
            {
                return(variable.Default);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public object GetPropertyValueByDataSource(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return(text);
            }

            if (text.Trim().StartsWith("{"))
            {
                DataSourceVariable variable = null;
                try
                {
                    variable = JsonConvert.DeserializeObject <DataSourceVariable>(text);
                }
                catch
                {
                    return(text);
                }

                if (variable != null)
                {
                    return(GetPropertyValueByDataSource(variable));
                }
            }

            return(text);
        }
Ejemplo n.º 4
0
        public object GetPropertyValueByDataSource(DataSourceVariable variable)
        {
            if (variable == null)
            {
                throw new NullReferenceException(nameof(variable));
            }

            try
            {
                object result = null;
                switch (variable.Type)
                {
                case DataSourceVariableType.DATASOURCE:
                    result = GetProperty(variable.String);
                    break;

                case DataSourceVariableType.CODE:
                    if (SafeCodeDataVariable)
                    {
                        try { result = CodeEvalService.Evaluate(variable.String, erpPageModel); } catch { result = null; }
                    }
                    else
                    {
                        result = CodeEvalService.Evaluate(variable.String, erpPageModel);
                    }
                    break;

                case DataSourceVariableType.HTML:
                    result = variable.String;
                    break;

                case DataSourceVariableType.SNIPPET:
                    if (SafeCodeDataVariable)
                    {
                        var snippet = SnippetService.GetSnippet(variable.String);
                        if (snippet == null)
                        {
                            result = $"Snippet '{variable.String}' is not found.";
                        }
                        else
                        {
                            if (snippet.Name.ToLowerInvariant().EndsWith(".cs"))
                            {
                                string csCode = snippet.GetText();
                                try { result = CodeEvalService.Evaluate(csCode, erpPageModel); } catch { result = null; }
                            }
                            else
                            {
                                result = snippet.GetText();
                            }
                        }
                    }
                    else
                    {
                        var snippet = SnippetService.GetSnippet(variable.String);
                        if (snippet == null)
                        {
                            result = $"Snippet '{variable.String}' is not found.";
                        }
                        else
                        {
                            if (snippet.Name.ToLowerInvariant().EndsWith(".cs"))
                            {
                                string csCode = snippet.GetText();
                                result = CodeEvalService.Evaluate(csCode, erpPageModel);
                            }
                            else
                            {
                                result = snippet.GetText();
                            }
                        }
                    }
                    break;

                default:
                    throw new NotSupportedException(variable.Type.ToString());
                }
                if (result is string)
                {
                    if (string.IsNullOrWhiteSpace(result as string))
                    {
                        return(variable.Default);
                    }
                }
                else
                {
                    if (result is null)
                    {
                        return(variable.Default);
                    }
                }

                return(result);
            }
            catch (PropertyDoesNotExistException)
            {
                return(variable.Default);
            }
            catch (Exception)
            {
                throw;
            }
        }