public ProcessorStorageFilesWork(IMathBuffer maths, ICalcIO calcIO, IOperationsHistory operationsHistory, IExpressionParser mathExpressionParser, IPathReader filePathReader, ICalcInputParser inputParser)
 {
     Maths                = maths;
     CalcIO               = calcIO;
     OperationsHistory    = operationsHistory;
     MathExpressionParser = mathExpressionParser;
     FilePathReader       = filePathReader;
     InputParser          = inputParser;
 }
Exemplo n.º 2
0
        public bool Run(IProcessorStorage storage)
        {
            ICalcIO     calcIO     = storage.CalcIO;
            IMathBuffer mathBuffer = storage.Maths;

            mathBuffer.TempValue = storage.InputParser.ReadDouble();
            mathBuffer.AccValue += mathBuffer.TempValue;
            mathBuffer.SaveAccValue();

            return(true);
        }
Exemplo n.º 3
0
        public bool Run(IProcessorStorage storage)
        {
            ICalcIO     calcIO     = storage.CalcIO;
            IMathBuffer mathBuffer = storage.Maths;

            int input = storage.InputParser.ReadInt(x => (x > 0 && x <= mathBuffer.Values.Count));

            mathBuffer.TempValue = input;
            mathBuffer.AccValue  = mathBuffer.Values[input - 1];
            mathBuffer.SaveAccValue();

            return(true);
        }
Exemplo n.º 4
0
        public bool Run(IProcessorStorage storage)
        {
            IMathBuffer mathBuffer = storage.Maths;

            List <string>     history          = null;
            IPathReader       pathReader       = null;
            IExpressionParser expressionParser = null;

            if (storage is IProcessorStorageFilesWork ext)
            {
                history          = ext.OperationsHistory.Data;
                pathReader       = ext.FilePathReader;
                expressionParser = ext.MathExpressionParser;
            }
            else
            {
                throw new ArgumentException();
            }

            var     newOperBuffer = new List <string>();
            var     valBuffer     = new List <double>();
            ICalcIO calcIO        = storage.CalcIO;

            using (var file = new StreamReader(pathReader.Read(calcIO)))
            {
                string expression, rawExpression;

                while ((rawExpression = expression = file.ReadLine()) != null)
                {
                    newOperBuffer.Add(expression);

                    double result = expressionParser.Parse(ref expression, valBuffer, calcIO);

                    if (double.IsNaN(result))
                    {
                        calcIO.Write("Parse error!\n");
                        return(true);
                    }

                    calcIO.Write($"[#{ valBuffer.Count }] { rawExpression } = { (rawExpression != expression ? $"{ expression } = " : "") }{ result }\n");
                }
            }

            mathBuffer.Values   = valBuffer;
            mathBuffer.AccValue = valBuffer.Last();

            history.Clear();
            history.AddRange(newOperBuffer);

            return(true);
        }
Exemplo n.º 5
0
        public bool Run(IProcessorStorage storage)
        {
            ICalcIO     calcIO     = storage.CalcIO;
            IMathBuffer mathBuffer = storage.Maths;

            double input = storage.InputParser.ReadDouble();

            while (input == 0)
            {
                calcIO.WriteLine(new DivideByZeroException().Message);
                input = (calcIO as ICalcInputParser).ReadDouble();
            }

            mathBuffer.TempValue = input;
            mathBuffer.AccValue /= input;
            mathBuffer.SaveAccValue();

            return(true);
        }
 public ProcessorStorage(IMathBuffer maths, ICalcIO calcIO, ICalcInputParser inputParser)
 {
     Maths       = maths;
     CalcIO      = calcIO;
     InputParser = inputParser;
 }