// Syntax

        /// <summary>
        /// Gets the Sql string corresponding to the specified value.
        /// </summary>
        /// <param name="value">The value to consider.</param>
        /// <param name="valueType">The value type to consider.</param>
        /// <returns>Returns the Sql string.</returns>
        protected virtual string GetSqlText_Value(object value, DataValueTypes valueType = DataValueTypes.Text)
        {
            if (value == null)
            {
                return(GetSqlText_Null());
            }

            switch (valueType)
            {
            case DataValueTypes.Text:
                return(value == null?GetSqlText_Null() : GetSqlText_Text(value as string));

            case DataValueTypes.ByteArray:
            case DataValueTypes.Date:
                return(value == null?GetSqlText_Null() : GetSqlText_Text(value.ToString(valueType)));

            case DataValueTypes.Number:
            case DataValueTypes.Integer:
            case DataValueTypes.Long:
            case DataValueTypes.ULong:
                return(value == null?GetSqlText_Null() : value.ToString(valueType));

            default:
                return(value == null?GetSqlText_Null() : value.ToString());
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new instance of the DataElement class.
 /// </summary>
 /// <param name="name">The name to consider.</param>
 /// <param name="valueType">The data value type to consider.</param>
 /// <param name="value">The data table to consider.</param>
 public static IScalarElement Parameter(
     string name,
     DataValueTypes valueType,
     object value)
 {
     return(ElementFactory.CreateScalar(name, valueType, value));
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new instance of the ScalarElement class.
 /// </summary>
 /// <param name="name">The name to consider.</param>
 /// <param name="valueType">The value type to consider.</param>
 /// <param name="items">The items to consider.</param>
 public static ScalarElement CreateScalar(
     string name,
     DataValueTypes valueType,
     params object[] items)
 {
     return(CreateScalar(name, null as string, valueType, null, items));
 }
Beispiel #4
0
 /// <summary>
 /// Adds a new option specification.
 /// </summary>
 /// <param name="dataValueType">The value type to consider.</param>
 /// <param name="nameKind">The name kind to consider.</param>
 /// <param name="aliases">Aliases of the option to add.</param>
 public IOptionSpecSet AddOption(
     DataValueTypes dataValueType,
     OptionNameKind nameKind,
     params string[] aliases)
 {
     return(AddOption(dataValueType, RequirementLevels.Required, OptionNameKind.OnlyValue, aliases));
 }
Beispiel #5
0
 /// <summary>
 /// Creates a new instance of the DbField class.
 /// </summary>
 /// <param name="name">The name to consider.</param>
 /// <param name="value">The value to consider.</param>
 /// <param name="valueType">The value type to consider.</param>
 public static DbField FieldAsLiteral(
     string name,
     object value,
     DataValueTypes valueType = DataValueTypes.Any)
 {
     return(DbFluent.FieldAsLiteral(name, null, value, valueType));
 }
Beispiel #6
0
        /// <summary>
        /// Sets the constraint parameter value.
        /// </summary>
        /// <param name="constraintName">The name of the constraint to return.</param>
        /// <param name="definitionUniqueId">The name of the definition to return.</param>
        /// <param name="parameterName">The name of the parameter to return.</param>
        /// <param name="dataValueType">The name of the parameter to return.</param>
        /// <returns>Returns the specified constrainst parameter.</returns>
        public IDataElement AddConstraintParameter(
            string constraintName,
            string definitionUniqueId    = null,
            string parameterName         = null,
            DataValueTypes dataValueType = DataValueTypes.Any)
        {
            IDataElement dataElement = null;

            IBdoRoutineConfiguration routine = GetConstraint(constraintName);

            if ((routine == null) || (!routine.DefinitionUniqueId.KeyEquals(definitionUniqueId)))
            {
                routine = AddConstraint(constraintName, definitionUniqueId);
            }

            if (routine != null)
            {
                if (parameterName == null && routine.Count > 0)
                {
                    dataElement = routine[0];
                }
                else
                {
                    dataElement = routine[parameterName];
                }
                if (dataElement == null)
                {
                    routine.Add(dataElement = ElementFactory.CreateScalar(
                                    parameterName,
                                    dataValueType == DataValueTypes.Any ? dataValueType.GetValueType() : dataValueType));
                }
            }

            return(dataElement);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new instance of the ScalarElement class.
        /// </summary>
        /// <param name="name">The name to consider.</param>
        /// <param name="id">The ID to consider.</param>
        /// <param name="valueType">The value type to consider.</param>
        /// <param name="specification">The specification to consider.</param>
        /// <param name="items">The items to consider.</param>
        public static ScalarElement CreateScalar(
            string name,
            string id,
            DataValueTypes valueType,
            IScalarElementSpec specification,
            params object[] items)
        {
            if (valueType == DataValueTypes.Any)
            {
                if (items == null)
                {
                    valueType = DataValueTypes.None;
                }
                else
                {
                    valueType = items.GetValueType();
                }
            }

            ScalarElement element = new ScalarElement(name, id)
            {
                ValueType     = valueType,
                Specification = specification as ScalarElementSpec
            };

            if (items != null)
            {
                element.Add(items);
            }

            return(element);
        }
Beispiel #8
0
 /// <summary>
 /// Creates a new instance of the DbField class.
 /// </summary>
 /// <param name="name">The name to consider.</param>
 /// <param name="table">The data table to consider.</param>
 /// <param name="value">The value to consider.</param>
 /// <param name="valueType">The value type to consider.</param>
 public static DbField FieldAsLiteral(
     string name,
     DbTable table,
     object value,
     DataValueTypes valueType = DataValueTypes.Any)
 {
     return(DbFluent.Field(name, table).AsLiteral(value, valueType));
 }
Beispiel #9
0
 /// <summary>
 /// Instantiates a new instance of the DbFieldAttribute class.
 /// </summary>
 /// <param name="name">The name to consider.</param>
 /// <param name="valueType">The value type to consider.</param>
 /// <param name="constraintStatement">The constraint statement to consider.</param>
 public BdoDbFieldAttribute(string name,
                            DataValueTypes valueType = DataValueTypes.Any,
                            DataConstraintStatement constraintStatement = null) : base()
 {
     Name                = name;
     ValueType           = valueType;
     ConstraintStatement = constraintStatement;
 }
Beispiel #10
0
 /// <summary>
 /// Adds a new option specification.
 /// </summary>
 /// <param name="dataValueType">The value type to consider.</param>
 /// <param name="requirementLevel">The requirement level of the entry to consider.</param>
 /// <param name="nameKind">The name kind to consider.</param>
 /// <param name="aliases">Aliases of the option to add.</param>
 public IOptionSpecSet AddOption(
     DataValueTypes dataValueType,
     RequirementLevels requirementLevel,
     OptionNameKind nameKind,
     params string[] aliases)
 {
     Add(new OptionSpec(dataValueType, requirementLevel, nameKind, aliases));
     return(this);
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the ScalarElementSpec class.
 /// </summary>
 /// <param name="name">The name to consider.</param>
 /// <param name="dataValueType">The value type to consider.</param>
 /// <param name="accessibilityLevel">The accessibilty level of this instance.</param>
 /// <param name="specificationLevels">The specification levels of this instance.</param>
 public ScalarElementSpec(
     string name,
     DataValueTypes dataValueType              = DataValueTypes.Text,
     AccessibilityLevels accessibilityLevel    = AccessibilityLevels.Public,
     SpecificationLevels[] specificationLevels = null)
     : base(accessibilityLevel, specificationLevels)
 {
     Name      = name;
     ValueType = dataValueType;
 }
Beispiel #12
0
 /// <summary>
 /// Instantiates a new instance of the OptionSpec class.
 /// </summary>
 /// <param name="dataValueType">The value type to consider.</param>
 /// <param name="requirementLevel">The requirement level of the entry to consider.</param>
 /// <param name="nameKind">The name kind to consider.</param>
 /// <param name="aliases">Aliases of the option to add.</param>
 public OptionSpec(
     DataValueTypes dataValueType,
     RequirementLevels requirementLevel,
     OptionNameKind nameKind,
     params string[] aliases) : base()
 {
     Aliases           = (aliases ?? new string[1] {
         "{{*}}"
     }).ToList();
     MinimumItemNumber = nameKind.HasValue() ? 1 : 0;
     MaximumItemNumber = nameKind.HasName() ? 0 : 1;
     RequirementLevel  = requirementLevel;
 }
Beispiel #13
0
        // As literal -----

        /// <summary>
        /// Updates the specified field as literal.
        /// </summary>
        /// <param name="field">The field to consider.</param>
        /// <param name="value">The value to consider.</param>
        /// <param name="valueType">The value type to consider.</param>
        public static DbField AsLiteral(
            this DbField field,
            object value,
            DataValueTypes valueType = DataValueTypes.Any)
        {
            if (field != null)
            {
                field.ValueType = valueType;
                if (value != null)
                {
                    field.Expression = value.ToString(field.ValueType).CreateExpAsLiteral();
                }
            }

            return(field);
        }
Beispiel #14
0
        /// <summary>
        /// Creates a data element with specified items.
        /// </summary>
        /// <param name="name">The name to consider.</param>
        /// <param name="items">The items to consider.</param>
        public static DataElement Create(string name, DataValueTypes valueType, params object[] items)
        {
            DataElement element = null;

            if (valueType == DataValueTypes.Any || valueType == DataValueTypes.None)
            {
                valueType = items.GetValueType();
            }

            if (valueType.IsScalar())
            {
                element = CreateScalar(name, valueType, items);
            }
            else
            {
                string definitionUniqueId;
                switch (valueType)
                {
                case DataValueTypes.Carrier:
                    definitionUniqueId = ((items.Length > 0 ? items[0] : null) as IBdoCarrierConfiguration)?.DefinitionUniqueId;
                    element            = CreateCarrier(name, null, definitionUniqueId);
                    break;

                case DataValueTypes.Datasource:
                    definitionUniqueId = ((items.Length > 0 ? items[0] : null) as IBdoConnectorConfiguration)?.DefinitionUniqueId;
                    element            = CreateSource(name, null, definitionUniqueId);
                    break;

                case DataValueTypes.Document:
                    element = CreateDocument(name, null);
                    break;

                case DataValueTypes.Object:
                    element = CreateObject(name, items);
                    break;
                }

                if (items != null)
                {
                    element?.WithItems(items);
                }
            }

            return(element);
        }
Beispiel #15
0
        /// <summary>
        /// Indicates whether the specified value type corresponds to a scalar.
        /// </summary>
        /// <param name="valueType">The object to consider.</param>
        /// <returns>The result object.</returns>
        public static bool IsScalar(this DataValueTypes valueType)
        {
            switch (valueType)
            {
            case DataValueTypes.Boolean:
            case DataValueTypes.Date:
            case DataValueTypes.Integer:
            case DataValueTypes.Number:
            case DataValueTypes.Text:
            case DataValueTypes.ByteArray:
            case DataValueTypes.Time:
            case DataValueTypes.Long:
            case DataValueTypes.ULong:
                return(true);
            }

            return(false);
        }
Beispiel #16
0
 /// <summary>
 /// Returns the object type of the specified data value type.
 /// </summary>
 /// <param name="dataValueType">The value type to consider.</param>
 /// <returns>The result object.</returns>
 public static Type GetObjectType(this DataValueTypes dataValueType)
 {
     return(dataValueType switch
     {
         DataValueTypes.Boolean => typeof(Boolean),
         DataValueTypes.Carrier => typeof(BdoCarrierConfiguration),
         DataValueTypes.Datasource => typeof(Datasource),
         DataValueTypes.Date => typeof(DateTime),
         DataValueTypes.Document => typeof(Document),
         DataValueTypes.Integer => typeof(int),
         DataValueTypes.Number => typeof(float),
         DataValueTypes.Schema => typeof(String),
         DataValueTypes.Text => typeof(String),
         DataValueTypes.Time => typeof(TimeSpan),
         DataValueTypes.Long => typeof(long),
         DataValueTypes.ULong => typeof(ulong),
         DataValueTypes.ByteArray => typeof(byte[]),
         _ => typeof(Object),
     });
Beispiel #17
0
        /// <summary>
        /// Sets the constraint parameter value.
        /// </summary>
        /// <param name="constraintName">The name of the constraint to return.</param>
        /// <param name="definitionUniqueId">The name of the definition to return.</param>
        /// <param name="parameterName">The name of the parameter to return.</param>
        /// <param name="value">The value to consider.</param>
        /// <param name="dataValueType">The name of the parameter to return.</param>
        /// <returns>Returns the specified constrainst parameter.</returns>
        public bool SetConstraintParameterValue(
            string constraintName,
            string definitionUniqueId = null,
            string parameterName      = null,
            object value = null,
            DataValueTypes dataValueType = DataValueTypes.Any)
        {
            IBdoRoutineConfiguration routine = GetConstraint(constraintName);

            if (routine?.DefinitionUniqueId.KeyEquals(definitionUniqueId) != true)
            {
                routine = AddConstraint(constraintName, definitionUniqueId);
            }

            IDataElement dataElement;

            if (parameterName == null && routine.Count > 0)
            {
                dataElement = routine[0];
            }
            else
            {
                dataElement = routine[parameterName];
            }
            if (dataElement == null)
            {
                routine.Add(
                    ElementFactory.CreateScalar(
                        parameterName,
                        dataValueType == DataValueTypes.Any ? value.GetValueType() : dataValueType,
                        value));
            }
            else
            {
                dataElement.WithItems(value);
            }

            return(true);
        }
Beispiel #18
0
        // Element specification -------------------------

        /// <summary>
        /// Creates a data element of the specified kind.
        /// </summary>
        /// <param name="name">The name to consider.</param>
        /// <param name="valueType">The value type to consider.</param>
        public static DataElementSpec Create(string name, DataValueTypes valueType)
        {
            if (valueType.IsScalar())
            {
                return(new ScalarElementSpec(name, valueType));
            }
            else
            {
                switch (valueType)
                {
                case DataValueTypes.Carrier:
                    return(new CarrierElementSpec()
                    {
                        Name = name
                    });

                case DataValueTypes.Document:
                    return(new DocumentElementSpec()
                    {
                        Name = name
                    });

                case DataValueTypes.Object:
                    return(new ObjectElementSpec()
                    {
                        Name = name
                    });

                case DataValueTypes.Datasource:
                    return(new SourceElementSpec()
                    {
                        Name = name
                    });
                }
            }

            return(null);
        }
Beispiel #19
0
        /// <summary>
        /// Adds the specified parameter to this instance.
        /// </summary>
        /// <param name="name">The name to consider.</param>
        /// <param name="valueType">The data value type to consider.</param>
        /// <param name="value">The data table to consider.</param>
        /// <returns>Return this added parameter.</returns>
        public ScalarElement UseParameter(
            string name,
            DataValueTypes valueType,
            object value = null)
        {
            if (ParameterSet == null)
            {
                ParameterSet = new DataElementSet();
            }

            if (ParameterSet[name] is ScalarElement parameter)
            {
                parameter.WithItems(value);
            }
            else
            {
                parameter = ElementFactory.CreateScalar(name, valueType, value);
                parameter.Index = ParameterSet.Count + 1;
                ParameterSet.Add(parameter);
            }

            return parameter;
        }
Beispiel #20
0
 /// <summary>
 /// Instantiates a new instance of the OptionSpec class.
 /// </summary>
 /// <param name="dataValueType">The value type to consider.</param>
 /// <param name="nameKind">The name kind to consider.</param>
 /// <param name="aliases">Aliases of the option to add.</param>
 public OptionSpec(
     DataValueTypes dataValueType,
     OptionNameKind nameKind,
     params string[] aliases) : this(dataValueType, RequirementLevels.Required, OptionNameKind.OnlyName, aliases)
 {
 }
Beispiel #21
0
 /// <summary>
 /// Creates a new instance of the ScalarElement class.
 /// </summary>
 /// <param name="valueType">The value type to consider.</param>
 /// <param name="items">The items to consider.</param>
 public static ScalarElement CreateScalar(
     DataValueTypes valueType,
     params object[] items)
 {
     return(CreateScalar(null, null, valueType, null, items));
 }
Beispiel #22
0
 /// <summary>
 /// Specifies the value type of this instance.
 /// </summary>
 /// <param name="valueType">The value type to consider.</param>
 /// <returns>Returns this instance.</returns>
 public DbField WithValueType(DataValueTypes valueType)
 {
     ValueType = valueType;
     return(this);
 }
Beispiel #23
0
        // ------------------------------------------
        // CONSTRUCTORS
        // ------------------------------------------

        #region Constructors

        /// <summary>
        /// Instantiates a new instance of the DbFieldAttribute class.
        /// </summary>
        /// <param name="valueType">The value type to consider.</param>
        /// <param name="constraintStatement">The constraint statement to consider.</param>
        public BdoDbFieldAttribute(DataValueTypes valueType,
                                   DataConstraintStatement constraintStatement = null) : base()
        {
            ValueType           = valueType;
            ConstraintStatement = constraintStatement;
        }
Beispiel #24
0
 /// <summary>
 /// Creates a new instance of the ScalarElement class.
 /// </summary>
 /// <param name="dataValueType">The value type to consider.</param>
 public static ScalarElement CreateScalar(DataValueTypes dataValueType)
 {
     return(CreateScalar(null, null, dataValueType, null));
 }
Beispiel #25
0
        /// <summary>
        /// Returns the string value from an object based on this instance's specification.
        /// </summary>
        /// <param name="object1">The object value to convert.</param>
        /// <param name="valueType">The value type to consider.</param>
        /// <param name="isScriptMode">Indicates whether the script mode is activated.</param>
        /// <returns>The result string.</returns>
        public static string ToString(
            this object object1,
            DataValueTypes valueType,
            bool isScriptMode = false)
        {
            string stringValue = null;

            if (valueType == DataValueTypes.Any)
            {
                valueType = object1.GetValueType();
            }

            if (object1 != null)
            {
                switch (valueType)
                {
                case DataValueTypes.Boolean:
                    stringValue = (object1 as bool?) == true ? "true" : "false";

                    if (isScriptMode)
                    {
                        stringValue = stringValue.ToQuoted();
                    }
                    break;

                case DataValueTypes.Date:
                    if (object1 is DateTime dateTime)
                    {
                        stringValue = (dateTime).ToString(StringHelper.__DateFormat);

                        if (isScriptMode)
                        {
                            stringValue = stringValue.ToQuoted();
                        }
                    }
                    break;

                case DataValueTypes.Number:
                    stringValue = object1.ToString().Replace(",", ".");

                    if (isScriptMode)
                    {
                        stringValue = stringValue.ToQuoted();
                    }
                    break;

                case DataValueTypes.Time:
                    if (object1 is TimeSpan timeSpan)
                    {
                        stringValue = (timeSpan).ToString(StringHelper.__TimeFormat);

                        if (isScriptMode)
                        {
                            stringValue = stringValue.ToQuoted();
                        }
                    }
                    break;

                case DataValueTypes.ByteArray:
                    if (object1 is byte[] byteArray)
                    {
                        stringValue = Convert.ToBase64String(byteArray);

                        if (isScriptMode)
                        {
                            stringValue = stringValue.ToQuoted();
                        }
                    }
                    break;

                case DataValueTypes.Carrier:
                case DataValueTypes.Connector:
                case DataValueTypes.Datasource:
                case DataValueTypes.Document:
                case DataValueTypes.Element:
                case DataValueTypes.Entity:
                case DataValueTypes.Object:
                case DataValueTypes.Schema:
                case DataValueTypes.SchemaZone:
                    if (object1 is BdoScriptword scriptword)
                    {
                        stringValue = scriptword.ToString();
                    }
                    else if (object1 is DataExpression expression)
                    {
                        stringValue = expression.ToString();
                    }
                    else
                    {
                        stringValue = object1.ToString();

                        if (isScriptMode)
                        {
                            stringValue = stringValue.ToQuoted();
                        }
                    }
                    break;

                default:
                    stringValue = object1.ToString();

                    if (isScriptMode)
                    {
                        stringValue = stringValue.ToQuoted();
                    }
                    break;
                }
            }

            return(stringValue);
        }