Exemple #1
0
        /// <summary>
        ///		Resta el valor de una variable
        /// </summary>
        public void Substract(VariableModel value)
        {
            VariableModel variable = ConvertToVariable(value);

            switch (Type)
            {
            case VariableType.String:
                throw new NotImplementedException($"Cant substract a string. Variable: {Name}");

            case VariableType.Numeric:
                Value = ConvertToNumeric(this) - ConvertToNumeric(variable);
                break;

            case VariableType.Boolean:
                throw new NotImplementedException($"Cant substract a boolean. Variable: {Name}");

            case VariableType.Date:
                DateTime?date = ConvertToDate(this);

                if (date == null)
                {
                    throw new NotImplementedException($"Source date has a null value. Variable {Name}");
                }
                else
                {
                    Value = SumSubstractDate(date ?? DateTime.Now, ConvertToString(variable), false);
                }
                break;
            }
        }
Exemple #2
0
        /// <summary>
        ///		Suma el valor de una variable
        /// </summary>
        public void Sum(object value)
        {
            VariableModel variable = ConvertToVariable(value);

            switch (Type)
            {
            case VariableType.String:
                Value = Value?.ToString() + variable.Value?.ToString();
                break;

            case VariableType.Numeric:
                Value = ConvertToNumeric(this) + ConvertToNumeric(variable);
                break;

            case VariableType.Boolean:
                Value = ConvertToBoolean(this) || ConvertToBoolean(variable);
                break;

            case VariableType.Date:
                DateTime?date = ConvertToDate(this);

                if (date == null)
                {
                    throw new NotImplementedException($"Source date has a null value. Variable {Name}");
                }
                else
                {
                    Value = SumSubstractDate(date ?? DateTime.Now, ConvertToString(variable), true);
                }
                break;
            }
        }
Exemple #3
0
        /// <summary>
        ///		Obtiene una variable
        /// </summary>
        public VariableModel Get(string name, int?index = null)
        {
            VariableModel variable = GetIfExists(name, index);

            // Si no existe, crea una variable predeterminada
            if (variable == null)
            {
                variable = new VariableModel(name, null);
            }
            // Devuelve la variable
            return(variable);
        }
Exemple #4
0
        /// <summary>
        ///		Compara el valor de la variable con un valor
        /// </summary>
        public CompareResult Compare(object value)
        {
            VariableModel target = ConvertToVariable(value);

            if (target == null && Value == null)
            {
                return(CompareResult.Equals);
            }
            else if (target != null && Value == null)
            {
                return(CompareResult.LessThan);
            }
            else if (target == null && Value != null)
            {
                return(CompareResult.GreaterThan);
            }
            else
            {
                switch (Type)
                {
                case VariableType.Numeric:
                    return(CompareWithNumeric(ConvertToNumeric(target)));

                case VariableType.Date:
                    return(CompareWithDate(ConvertToDate(target)));

                case VariableType.Boolean:
                    return(CompareWithBoolean(ConvertToBoolean(target)));

                case VariableType.String:
                    return(CompareWithString(ConvertToString(target)));

                default:
                    throw new NotImplementedException($"Cant compare variable {Name} with type {Type} and the value {target}");
                }
            }
        }
Exemple #5
0
        /// <summary>
        ///		Convierte un objeto a un tipo determinado
        /// </summary>
        private string ConvertToString(VariableModel variable)
        {
            switch (variable.Value)
            {
            case DateTime date:
                return($"{date:yyyy-MM-dd HH:mm:ss}");

            case double number:
                return(number.ToString(System.Globalization.CultureInfo.InvariantCulture));

            case decimal number:
                return(number.ToString(System.Globalization.CultureInfo.InvariantCulture));

            case int number:
                return(number.ToString(System.Globalization.CultureInfo.InvariantCulture));

            case float number:
                return(number.ToString(System.Globalization.CultureInfo.InvariantCulture));

            case bool boolean:
                if (boolean)
                {
                    return("true");
                }
                else
                {
                    return("false");
                }

            case string value:
                return(value);

            default:
                return(variable.Value.ToString());
            }
        }
Exemple #6
0
 /// <summary>
 ///		Añade una variable
 /// </summary>
 public void Add(VariableModel variable)
 {
     Add(variable.Name, variable.Value);
 }
Exemple #7
0
 /// <summary>
 ///		Convierte un objeto a fecha
 /// </summary>
 private DateTime?ConvertToDate(VariableModel variable)
 {
     return(variable.Value.ToString().GetDateTime());
 }
Exemple #8
0
 /// <summary>
 ///		Convierte un objeto a boolean
 /// </summary>
 private bool ConvertToBoolean(VariableModel variable)
 {
     return(Convert.ToBoolean(variable.Value));
 }
Exemple #9
0
 /// <summary>
 ///		Convierte un objeto a numérico
 /// </summary>
 private double ConvertToNumeric(VariableModel variable)
 {
     return(Convert.ToDouble(variable.Value));
 }