Exemplo n.º 1
0
        public static BaseCalculator GetCompanyCalculator(CompanyData company)
        {
            if (_companyCalculator.TryGetValue(company.Code.Trim().ToUpper(), out BaseCalculator baseCalculator) && baseCalculator != null)
            {
                return(baseCalculator);
            }

            Type[] types = Assembly.GetExecutingAssembly().GetTypes();

            Type type = types.FirstOrDefault(x => x.Name.IsStringEqual(company.ClassName));

            if (type != null)
            {
                object providerClass = Activator.CreateInstance(type);

                if (providerClass as BaseCalculator != null)
                {
                    BaseCalculator returnItem = providerClass as BaseCalculator;

                    if (_companyCalculator.ContainsKey(company.Code.Trim().ToUpper()))
                    {
                        _companyCalculator.Remove(company.Code.Trim().ToUpper());
                    }

                    _companyCalculator.Add(company.Code.Trim().ToUpper(), returnItem);

                    return(returnItem);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        //public static MatrixField CreateParityMatrixBig(List<Block<byte>> dataBlocks, int parityBlockCount)
        //{
        //    int totalBlocks = dataBlocks.Count + parityBlockCount;
        //    if (totalBlocks > 256)
        //    {
        //        throw new InvalidOperationException("A total of more then 256 blocks is not supported");
        //    }

        //    var theMatrix = MatrixField.CreateIdentityMatrix(dataBlocks.Count + parityBlockCount);

        //    //Copy parity part of the matrix
        //    for (byte column = 0; column < dataBlocks.Count; column++)
        //    {
        //        for (byte row = 0; row < parityBlockCount; row++)
        //        {
        //            var val = Field.pow(new Field((byte)(column + Base)), row);
        //            theMatrix[row + dataBlocks.Count, column] = val;
        //        }
        //    }

        //    return theMatrix;
        //}

        public static MatrixField CreateParityOnlyMatrix(List <Block <byte> > dataBlocks, int parityBlockCount)
        {
            int totalBlocks = dataBlocks.Count + parityBlockCount;

            if (totalBlocks > 256)
            {
                throw new InvalidOperationException("A total of more then 256 blocks is not supported");
            }

            var parityMatrixArray = new Field[parityBlockCount, dataBlocks.Count];



            var baseList = BaseCalculator.CalcBase(8).ToList();

            //Copy parity part of the matrix
            for (byte column = 0; column < parityMatrixArray.GetLength(1); column++)
            {
                for (byte row = 0; row < parityBlockCount; row++)
                {
                    //var val = Field.pow(new Field((byte)(column + Base)), row);
                    var val = Field.pow(baseList[column], (byte)(row + 1));
                    parityMatrixArray[row, column] = val;
                }
            }


            return(new MatrixField(parityMatrixArray));
        }
        public FeeDiscountCalculator(BaseCalculator calculator, decimal discount) : base(calculator)
        {
            if (discount < 0 || discount > 1)
            {
                throw new ArgumentException("Discount cannot be lower than 0 or higher than 1!");
            }

            _discount = discount;
        }
    static void Main(string[] args)
    {
        // create an instance of the derived class
        DerivedCalculator calc = new DerivedCalculator();

        // upcast to the interface type
        ICalculator icalc = calc;

        // upcast to the base type
        BaseCalculator bcalc = calc;

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Exemplo n.º 5
0
        public Processor(string fileName, CompanyData company, Action <ProgressChangedEventArgs> progress, Action <RunWorkerCompletedEventArgs, string> completed)
        {
            this._fileName          = fileName;
            this._company           = company;
            this._progress          = progress;
            this._completed         = completed;
            this._companyCalculator = Factory.GetCompanyCalculator(company);
            this._companyMetaData   = Factory.GetCompanyMetaData(company);

            this._newFileName = Path.GetFileNameWithoutExtension(this._fileName) + $"_{company.Code}" + Path.GetExtension(this._fileName);
            this._newFileName = Path.Combine(Path.GetDirectoryName(this._fileName), this._newFileName);

            if (File.Exists(this._newFileName))
            {
                File.Delete(this._newFileName);
            }
        }
Exemplo n.º 6
0
        public void TestCase()
        {
            var calc = new BaseCalculator();

            Assert.AreEqual(7, calc.Calculate("3+2*2"));
            var str = new StringBuilder();
            var op  = new char[4] {
                '-', '+', '*', '/'
            };
            var r = new Random();

            for (int i = 0; i < 100000; i++)
            {
                str.Append(1 + r.Next(9));
                str.Append(op[r.Next(4)]);
            }
            var h = new Hashtable();

            str.Remove(str.Length - 1, 1);
            calc.Calculate(str.ToString());
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var baseListTest = BaseCalculator.CalcBase(8).ToList();

            var rrrrrr = string.Join($"{Environment.NewLine}", baseListTest);

            byte aa = 0;

            aa ^= 0x11D & 0xFF;
            byte ding = 0x11D & 0xFF;



            var test1 = GFTable.GFTable8;

            var result = test1.Add(5, 10);

            result = test1.Mul(10, 5);


            var res2 = test1.Add(250, 50);
        }
 public CalculatorDecorator(BaseCalculator calculator)
 {
     _calculator = calculator;
 }
Exemplo n.º 9
0
 public ValuesController(ICalculationService myCalculatioNService)
 {
     _myCalculatioNService = myCalculatioNService;
     _baseCalculator       = new CalculationServiceThree();
 }
Exemplo n.º 10
0
 public MonthlyFeeCalculator(BaseCalculator calculator) : base(calculator)
 {
 }