Service.cs 2.0 KB
Newer Older
cdy816's avatar
cdy816 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
using Cdy.Tag;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DBDevelopService
{
    public class Service
    {

        #region ... Variables  ...
        
        private GrpcDBService grpcDBService = new GrpcDBService();
cdy816's avatar
cdy816 已提交
15
        private WebAPIDBService webDBService = new WebAPIDBService();
cdy816's avatar
cdy816 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

        /// <summary>
        /// 
        /// </summary>
        public static Service Instanse = new Service();

        #endregion ...Variables...

        #region ... Events     ...

        #endregion ...Events...

        #region ... Constructor...

        public Service()
        {
            DBDevelopService.SecurityManager.Manager.Init();
            //驱动初始化
            Cdy.Tag.DriverManager.Manager.Init();
cdy816's avatar
cdy816 已提交
35 36 37

            ////注册日志
            //ServiceLocator.Locator.Registor<ILog>(new ConsoleLogger());
cdy816's avatar
cdy816 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50
        }

        #endregion ...Constructor...

        #region ... Properties ...

        #endregion ...Properties...

        #region ... Methods    ...

        /// <summary>
        /// 
        /// </summary>
cdy816's avatar
cdy816 已提交
51
        public void Start(int grpcPort = 5001, int webSocketPort = 8000, bool isEnableGrpc = true, bool isEnableWebApi = true)
cdy816's avatar
cdy816 已提交
52
        {
cdy816's avatar
cdy816 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66
            try
            {
                LoggerService.Service.Info("Service", "Ready to start....");
                DbManager.Instance.Load();
                if (isEnableGrpc)
                    grpcDBService.Start(grpcPort);

                if (isEnableWebApi)
                    webDBService.Start(webSocketPort);
            }
            catch(Exception ex)
            {
                LoggerService.Service.Erro("Service","start "+ ex.Message);
            }
cdy816's avatar
cdy816 已提交
67 68 69 70 71 72 73 74
        }

        /// <summary>
        /// 
        /// </summary>
        public void Stop()
        {
            grpcDBService.StopAsync();
cdy816's avatar
cdy816 已提交
75
            webDBService.StopAsync();
cdy816's avatar
cdy816 已提交
76 77 78 79 80 81 82 83 84
        }

        #endregion ...Methods...

        #region ... Interfaces ...

        #endregion ...Interfaces...
    }
}