• 使用Topshelf创建Windows服务(转)


    Calculator
    
       public class Calculator : ICalculator
        {
            public Calculator()
            {
                Logger = LogManager.GetCurrentClassLogger();
            }
    
            public ILogger Logger { get; set; }
    
            public CalculationResult Add(string n1, string n2)
            {
                Logger?.Info($"received request to Add {n1} to {n2}");
               
                return Calculate(n1, n2, _add);
            }
    
            public CalculationResult Subtract(string n1, string n2)
            {
                Logger?.Info($"received request to Subtract {n2} from {n1}");
                
                return Calculate(n1, n2, _subtract);
            }
    
            public CalculationResult Multiply(string n1, string n2)
            {
                Logger?.Info($"received request to Multiply {n1} by {n2}");
                
                return Calculate(n1, n2, _multiply);
            }
    
            public CalculationResult Divide(string n1, string n2)
            {
                Logger?.Info($"received request to Divide {n1} by {n2}");
               
                return Calculate(n1, n2, _divide);
            }
    
            private static CalculationResult Calculate(string n1, string n2, Func<double, double, double> calculate)
            {
                var value1 = n1.ToDouble();
                if (!value1.HasValue)
                {
                    return GetCouldNotConvertToDoubleResult(n1);
                }
    
                var value2 = n2.ToDouble();
                if (!value2.HasValue)
                {
                    return GetCouldNotConvertToDoubleResult(n2);
                }
    
                double result = calculate(value1.Value, value2.Value);
                return new CalculationResult
                {
                    Answer = result
                };
            }
    
            private static readonly Func<double, double, double> _add = (value1, value2) => value1 + value2;
            private static readonly Func<double, double, double> _subtract = (value1, value2) => value1 - value2;
            private static readonly Func<double, double, double> _multiply = (value1, value2) => value1 * value2;
            private static readonly Func<double, double, double> _divide = (value1, value2) => value2 == 0 ? double.NaN : value1 / value2;
            
            private static CalculationResult GetCouldNotConvertToDoubleResult(string input)
            {
                return new CalculationResult
                {
                    Message = $"Could not convert '{input}' to a double"
                };
            }
        }


    https://github.com/NotMyself/CalculatorService.git

    http://www.cnblogs.com/jys509/p/4614975.html

  • 相关阅读:
    MySQL之权限管理
    CentOS7使用firewalld打开关闭防火墙与端口
    CentOS 7.2 基于Docker实现MySQL主从架构
    Centos7下安装Docker
    nginx php-fpm安装配置 CentOS编译安装php7.2
    php7的扩展库安装方法
    Android 程序打包及签名
    Message和handler传递对象
    Android AlertDialog去除黑边白边自定义布局(转)
    用MVC做支付宝手机网页支付问题
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/7425295.html
Copyright © 2020-2023  润新知