Beispiel #1
0
        /// <summary>
        /// Function for parsing string and calculate the equivalent value.
        /// </summary>
        /// <param name="input">String to be parse. Expression delimiter is allowed in the beginning of the value with format of [{value}].</param>
        /// <param name="operation">Supported operation is addition, subtraction, multiplication and division.</param>
        /// <param name="alternateDelimiter">Additional delimiter aside from build-in comma and new line characters.</param>
        /// <param name="allowNegative">Allow negative value. Default to false.</param>
        /// <param name="maxValue">Maximum allowed value. Defaulted to 0 means no limit.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public string Calculate(string input, Operations operation, string[] alternateDelimiter = null,
                                bool allowNegative = false, int maxValue = 0)
        {
            var stringDelimiter = Delimiter.Select(a => a.ToString())
                                  .ToArray();

            if (alternateDelimiter != null)
            {
                stringDelimiter = stringDelimiter.Concat(alternateDelimiter).ToArray();
            }

            var values = input.SplitWithDelimiterExpression(stringDelimiter)
                         .Select(a => int.TryParse(a, out var result) ? result : 0)
                         .Select(a => (maxValue > 0) && a > maxValue ? 0 : a)
                         .ToList();

            if (allowNegative == false)
            {
                var negativeValues = values
                                     .Where(a => a < 0)
                                     .ToList();

                if (negativeValues.Any())
                {
                    throw new ArgumentException(string.Join(",", negativeValues));
                }
            }


            return(_operationFactory.GetOperation(operation).GetExpression(values));
        }
        public void Create(MscMcomPool mscMcomPool)
        {
            MscMcomConfig mscMcomConfig = _iMComConfigRepository.GetMComConfig();

            mscMcomPool.IsAsynchronous = true;
            mscMcomPool.ProcessStatus  = "S";
            mscMcomPool.ResponseStatus = "INITIAL";

            if (mscMcomConfig.IsSynchronized)
            {
                mscMcomPool.IsAsynchronous = !mscMcomConfig.IsSynchronized;
            }

            if (_isBatch)
            {
                mscMcomPool.IsAsynchronous = !mscMcomConfig.IsBatchSynchronized;
            }

            if (!mscMcomPool.IsAsynchronous)
            {
                IOperation operation = _iOperationFactory.GetOperation(mscMcomPool.ActionType);
                operation.Create(mscMcomPool);
                mscMcomPool.ProcessStatus = "C";
            }
            _iTransactionRepository.CreatePoolItem(mscMcomPool);
        }
Beispiel #3
0
        public async Task <Guid> Save(OperationDTO data)
        {
            var operationService = _operationFactory.GetOperation(data.Operation);
            var result           = await operationService.Calc(data.Right, data.Left);

            var id = SaveToStorage(result);

            return(id);
        }
        public void Start()
        {
            MscMcomPool mscMcomPool = new MscMcomPool();

            mscMcomPool.ClearingRefKey = 0;
            mscMcomPool.ActionType     = ApiConstants.PoolActionType.ResponseStatusUpdate;
            IOperation operation = _iOperationFactory.GetOperation(mscMcomPool.ActionType);

            operation.Create(mscMcomPool);
        }
        public int ExecuteOperation(OperationModel requestModel)
        {
            var operation = _operationFactory.GetOperation(requestModel.Operation);

            var resultModel = new ResultModel
            {
                Result = operation.Exec(requestModel)
            };

            _resultRepository.Create(resultModel);

            return(resultModel.Id);
        }
Beispiel #6
0
 public void Start()
 {
     foreach (MscMcomPool item in _iTransactionRepository.GetPool())
     {
         try
         {
             IOperation operation = _iOperationFactory.GetOperation(item.ActionType);
             operation.Create(item);
             item.ProcessStatus = "C";
         }
         catch (Exception ex)
         {
             item.ProcessStatus      = "E";
             item.ProcessDescription = ex.Message;
         }
         _iTransactionRepository.UpdatePoolItem(item);
     }
 }
Beispiel #7
0
        public bool Operate(string symbol)
        {
            var operation = factory.GetOperation(symbol);

            if (operation != null)
            {
                AssertStack(operation.Operands);
                double top    = double.NaN;
                double second = double.NaN;
                if (operation.Operands > 0)
                {
                    top = inner.Pop();
                }
                if (operation.Operands > 1)
                {
                    second = inner.Pop();
                }
                inner.Push(operation.Execute(top, second));
                return(true);
            }
            return(false);
        }