public Operator CreateOperator(OperatorCodes operatorCode)
        {
            if (!Enum.IsDefined(operatorCodesType, operatorCode))
            {
                throw new ArgumentException(
                          FormattableString.Invariant($"The value provided is not a valid operator code: {(int)operatorCode}."),
                          nameof(operatorCode));
            }

            int    code        = (int)operatorCode;
            string name        = operatorCode.ToString();
            string description = string.Empty;
            string symbols     = string.Empty;

            MemberInfo literalMemberInfo = operatorCodesType.GetMember(name).First();

            description = this.GetDescription(literalMemberInfo);
            symbols     = this.GetSymbols(literalMemberInfo);

            return(new Operator(code, name)
            {
                Description = description,
                Symbols = symbols
            });
        }
        private async Task <IConditionNode> CreateConditionNodeRecursive(Guid tenantId, CreateConditionNodeBase createConditionNodeBase)
        {
            switch (createConditionNodeBase)
            {
            case CreateComposedConditionNode cccn:
                LogicalOperatorCodes logicalOperatorCode = (LogicalOperatorCodes)cccn.LogicalOperatorCode;

                List <IConditionNode> conditionNodes = new List <IConditionNode>();
                foreach (CreateConditionNodeBase ccnb in cccn.ChildNodes)
                {
                    IConditionNode conditionNode = await this.CreateConditionNodeRecursive(tenantId, ccnb);

                    conditionNodes.Add(conditionNode);
                }

                return(this.conditionNodeAbstractFactory.CreateComposedConditionNode(logicalOperatorCode, conditionNodes));

            case CreateValueConditionNode cvcn:
                ConditionTypeKey conditionTypeKey = ConditionTypeKey.New(tenantId, cvcn.ConditionTypeCode);
                ConditionType    conditionType    = await this.conditionTypeRepository.GetById(conditionTypeKey);

                DataTypeCodes dataTypeCode = (DataTypeCodes)cvcn.DataTypeCode;
                OperatorCodes operatorCode = (OperatorCodes)cvcn.OperatorCode;

                return(this.conditionNodeAbstractFactory.CreateValueConditionNode(conditionType, dataTypeCode, operatorCode, cvcn.RightHandOperand));

            default:
                throw new NotSupportedException("Unsupported condition node creation.");
            }
        }
Exemple #3
0
        public async Task <Operator> GetOperator(OperatorCodes operatorCode)
        {
            Operator @operator = null;

            if (Enum.IsDefined(operatorCodesType, operatorCode))
            {
                @operator = this.operatorsDictionary.GetOrAdd(operatorCode, oc => this.operatorFactory.CreateOperator(oc));
            }

            return(await Task.FromResult(@operator));
        }
Exemple #4
0
        protected override string ValidateCurrent(CreateValueConditionNode createValueConditionNode, Guid tenantId)
        {
            OperatorCodes operatorCode = (OperatorCodes)createValueConditionNode.OperatorCode;

            if (!Enum.IsDefined(typeof(OperatorCodes), operatorCode))
            {
                return(string.Format(InvariantResources.R009, createValueConditionNode.OperatorCode));
            }

            return(null);
        }
Exemple #5
0
        private void EnsureAllOperatorsInitialized()
        {
            Array operatorsArray = Enum.GetValues(typeof(OperatorCodes));

            foreach (object code in operatorsArray)
            {
                OperatorCodes operatorCode = (OperatorCodes)code;
                Operator      @operator    = this.operatorFactory.CreateOperator(operatorCode);
                this.operatorsDictionary.TryAdd(operatorCode, @operator);
            }

            this.allOperatorsInitialized = true;
        }
Exemple #6
0
        public async Task <OperatorDto> GetByCode(int code)
        {
            OperatorCodes operatorCodes = (OperatorCodes)code;

            return(await this.operatorRepository.GetOperator(operatorCodes)
                   .ContinueWith(operatorTask =>
            {
                Operator @operator = operatorTask.GetAwaiter().GetResult();

                if (@operator != null)
                {
                    return this.ConvertToDto(@operator);
                }

                return null;
            }));
        }
Exemple #7
0
        public IValueConditionNode CreateValueConditionNode(ConditionType conditionType, DataTypeCodes dataTypeCode, OperatorCodes operatorCode, object rightHandOperand)
        {
            if (conditionType == null)
            {
                throw new ArgumentNullException(nameof(conditionType));
            }

            if (!Enum.IsDefined(typeof(DataTypeCodes), dataTypeCode))
            {
                throw new ArgumentException("Specified invalid value for data type code.", nameof(dataTypeCode));
            }

            if (!Enum.IsDefined(typeof(OperatorCodes), operatorCode))
            {
                throw new ArgumentException("Specified invalid value for operator code.", nameof(operatorCode));
            }

            if (rightHandOperand == null)
            {
                throw new ArgumentNullException(nameof(rightHandOperand));
            }

            switch (dataTypeCode)
            {
            case DataTypeCodes.Integer:
                return(new IntegerConditionNode(conditionType.Key.Code, operatorCode, Convert.ToInt32(rightHandOperand)));

            case DataTypeCodes.Decimal:
                return(new DecimalConditionNode(conditionType.Key.Code, operatorCode, Convert.ToDecimal(rightHandOperand)));

            case DataTypeCodes.String:
                return(new StringConditionNode(conditionType.Key.Code, operatorCode, rightHandOperand.ToString()));

            default:
                throw new NotSupportedException("Unsupported data type.");
            }
        }
Exemple #8
0
 public StringConditionNode(int conditionTypeCode, OperatorCodes operatorCode, string rightHandOperand)
     : base(conditionTypeCode, operatorCode, rightHandOperand)
 {
 }
 protected ValueConditionNodeBase(int conditionTypeCode, OperatorCodes operatorCode, T rightHandOperand)
 {
     this.ConditionTypeCode = conditionTypeCode;
     this.OperatorCode      = operatorCode;
     this.RightHandOperand  = rightHandOperand;
 }
 public DecimalConditionNode(int conditionTypeCode, OperatorCodes operatorCode, decimal rightHandOperand)
     : base(conditionTypeCode, operatorCode, rightHandOperand)
 {
 }
Exemple #11
0
 public IntegerConditionNode(int conditionTypeCode, OperatorCodes operatorCode, int rightHandOperand)
     : base(conditionTypeCode, operatorCode, rightHandOperand)
 {
 }
 public IConditionNode CreateValueConditionNode(ConditionType conditionType, DataTypeCodes dataTypeCode, OperatorCodes operatorCode, object rightHandOperand)
 {
     return this.valueConditionNodeFactory.CreateValueConditionNode(conditionType, dataTypeCode, operatorCode, rightHandOperand);
 }