public decimal Calculate(CalculatorInputModel input) { var result = (decimal)input.MonthlyFee; //Add Sms Price result += CalculateSmsPrice(input.NumOfSentSms) * input.NumOfSentSms; //Add Mms Price result += CalculateMmsPrice(input.NumOfSentMms) * input.NumOfSentMms; result += input.NotIncludedMinutesToA1 * 0.03m; result += input.NotIncludedMinutesToTelenor * 0.09m; result += input.NotIncludedMinutesToVivacom * 0.09m; result += input.RoumingMinutes * 0.15m; result += (decimal)input.NotIncludedUsedMbInCountry * 0.02m; result += (decimal)input.NotIncludedUsedMbInEu * 0.05m; result += (decimal)input.IncludedUsedMbOutOfEu * 0.20m; result += (decimal)input.OtherTaxes; result -= (decimal)input.Discount; return(result); }
public IActionResult Calculator(CalculatorInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } return(this.View()); }
/// <summary> /// Loads the registered Calculator Types from passsed Assembly /// </summary> /// <param name="assembly"></param> /// <param name="input"></param> /// <returns></returns> private double LoadCalculator(Assembly assembly, CalculatorInputModel input) { Type type = assembly.GetType("CSharpCalculatorPlugin.Calculator"); Type loadedType = type; if (loadedType != null) { dynamic calcInstance = Activator.CreateInstance(loadedType); //Load the calculator plugin, pass the required parameters and return the result var result = calcInstance.Calculate(input.Operation, input.FirstNumber, input.SecondNumber); _logger.LogInfo("Loging calculation result for operation " + input.Operation.ToString() + " " + result); return(result); } return(0.0); }
/// <summary> /// Excecute the Calculator Plugin /// </summary> /// <param name="path">Specifies Plugin location</param> /// <param name="input"></param> /// <returns></returns> public double ExecuteCalculator(string path, CalculatorInputModel input) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException($"'{nameof(path)}' cannot be null or empty.", nameof(path)); } Assembly pluginAssembly = _pluginLoader.LoadPlugin(path); double result = 0.0; if (!String.IsNullOrEmpty(pluginAssembly.FullName)) { result = LoadCalculator(pluginAssembly, input); } return(result); }
public IActionResult CalculatorResult(CalculatorInputModel model) { if (!ModelState.IsValid) { return(BadRequest()); } // Load commands from plugins. string[] pluginPaths = new string[] { // Paths to plugins to load. @"Plugins\CSharpCalculatorPlugin\bin\Debug\net5.0\CSharpCalculatorPlugin.dll" }; var result = _calculator.ExecuteCalculator(pluginPaths[0], model); return(Ok(result)); }