Example #1
0
        public IList <string> ListMongoCollection(string datasourceCode)
        {
            DmeDataSource dmeDataSource = IsMongodbAndReturn(datasourceCode);
            MongodbHost   host          = JsonConvert.DeserializeObject <MongodbHost>(dmeDataSource.Connection);

            if (string.IsNullOrEmpty(host.DataBase))
            {
                throw new BusinessException((int)EnumSystemStatusCode.DME_FAIL, "mongodb的DataBase不能为空");
            }
            return(MongodbManager <object> .ListCollections(host.ConnectionString, host.DataBase));
        }
Example #2
0
        public static void Run(StartType type)
        {
            switch (type)
            {
            case StartType.BaseService:
                mAppHost = new ServiceHost(typeof(BaseService));
                //初始化连接池,默认10分钟清理连接
                ClientLinkPoolCache.Init(true, 200, 30, 600, "wcfserver", 30);

                AppGlobal.AppRootPath = System.Windows.Forms.Application.StartupPath + "\\";
                AppGlobal.appType     = AppType.WCF;
                AppGlobal.IsSaas      = System.Configuration.ConfigurationManager.AppSettings["IsSaas"] == "true" ? true : false;
                AppGlobal.AppStart();


                ClientManage.IsHeartbeat      = HostSettingConfig.GetValue("heartbeat") == "1" ? true : false;
                ClientManage.HeartbeatTime    = Convert.ToInt32(HostSettingConfig.GetValue("heartbeattime"));
                ClientManage.IsMessage        = HostSettingConfig.GetValue("message") == "1" ? true : false;
                ClientManage.MessageTime      = Convert.ToInt32(HostSettingConfig.GetValue("messagetime"));
                ClientManage.IsCompressJson   = HostSettingConfig.GetValue("compress") == "1" ? true : false;
                ClientManage.IsEncryptionJson = HostSettingConfig.GetValue("encryption") == "1" ? true : false;
                ClientManage.IsToken          = HostSettingConfig.GetValue("token") == "1" ? true : false;
                ClientManage.serializeType    = (SerializeType)Convert.ToInt32(HostSettingConfig.GetValue("serializetype"));
                ClientManage.IsOverTime       = HostSettingConfig.GetValue("overtime") == "1" ? true : false;
                ClientManage.OverTime         = Convert.ToInt32(HostSettingConfig.GetValue("overtimetime"));

                ClientManage.StartHost();
                mAppHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "数据服务启动完成");
                break;

            case StartType.FileService:
                AppGlobal.AppRootPath = System.Windows.Forms.Application.StartupPath + "\\";

                mFileHost = new ServiceHost(typeof(FileService));
                mFileHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "文件服务启动完成");
                break;

            case StartType.RouterBaseService:
                mRouterHost = new ServiceHost(typeof(RouterBaseService));
                RouterManage.Start();
                mRouterHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "数据路由服务启动完成");
                break;

            case StartType.RouterFileService:
                mFileRouterHost = new ServiceHost(typeof(RouterFileService));
                mFileRouterHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "文件路由服务启动完成");
                break;

            case StartType.SuperClient:
                SuperClient.CreateSuperClient();
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "超级客户端启动完成");
                break;

            case StartType.MiddlewareTask:
                MiddlewareTask.StartTask();    //开启定时任务
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "定时任务启动完成");
                break;

            case StartType.PublishService:    //订阅
                PublishServiceManage.InitPublishService();
                PublishSubManager.StartPublish();
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "发布订阅服务完成");
                break;

            case StartType.MongoDB:
                MongodbManager.StartDB();    //开启MongoDB
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "MongoDB启动完成");
                break;

            case StartType.Nginx:
                NginxManager.StartWeb();    //开启Nginx
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "Nginx启动完成");
                break;

            case StartType.KillAllProcess:
                MongodbManager.StopDB();    //停止MongoDB  清理掉所有子进程,因为主进程关闭子进程不关闭的话,占用的端口号一样不会释放
                NginxManager.StopWeb();
                break;
            }
        }
Example #3
0
        public static void Quit(StartType type)
        {
            ClientLinkManage.UnAllConnection();//关闭所有连接
            switch (type)
            {
            case StartType.BaseService:
                try
                {
                    if (mAppHost != null)
                    {
                        EFWCoreLib.WcfFrame.ClientLinkPoolCache.Dispose();
                        ClientManage.StopHost();
                        mAppHost.Close();
                        MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "数据服务已关闭!");
                    }
                }
                catch
                {
                    if (mAppHost != null)
                    {
                        mAppHost.Abort();
                    }
                }
                break;

            case StartType.FileService:
                try
                {
                    if (mFileHost != null)
                    {
                        mFileHost.Close();
                        MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "文件传输服务已关闭!");
                    }
                }
                catch
                {
                    if (mFileHost != null)
                    {
                        mFileHost.Abort();
                    }
                }
                break;

            case StartType.RouterBaseService:
                try
                {
                    if (mRouterHost != null)
                    {
                        mRouterHost.Close();
                        MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "数据路由服务已关闭!");
                    }
                }
                catch
                {
                    if (mRouterHost != null)
                    {
                        mRouterHost.Abort();
                    }
                }
                break;

            case StartType.RouterFileService:
                try
                {
                    if (mFileRouterHost != null)
                    {
                        mFileRouterHost.Close();
                        MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "文件路由服务已关闭!");
                    }
                }
                catch
                {
                    if (mFileRouterHost != null)
                    {
                        mFileRouterHost.Abort();
                    }
                }
                break;

            case StartType.SuperClient:
                SuperClient.UnCreateSuperClient();
                MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Red, "超级客户端已关闭!");
                break;

            case StartType.MiddlewareTask:
                MiddlewareTask.StopTask();    //停止任务
                MiddlewareLogHelper.WriterLog(LogType.TimingTaskLog, true, System.Drawing.Color.Red, "定时任务已停止!");
                break;

            case StartType.PublishService:    //订阅
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "订阅服务已停止");
                break;

            case StartType.MongoDB:
                MongodbManager.StopDB();    //停止MongoDB
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "MongoDB已停止");
                break;

            case StartType.Nginx:
                NginxManager.StopWeb();
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "Nginx已停止");
                break;
            }
        }
Example #4
0
        public IList <string> ListMongoDataBase(string host, int port)
        {
            string connectionString = $"mongodb://{host}:{port}";

            return(MongodbManager <object> .ListDataBases(connectionString));
        }
Example #5
0
        public IList <string> ListMongoCollection(string host, int port, string dataBase)
        {
            string connectionString = $"mongodb://{host}:{port}";

            return(MongodbManager <object> .ListCollections(connectionString, dataBase));
        }
Example #6
0
        static string ExecCmd(string m, Dictionary <string, string> a)
        {
            try
            {
                //ProcessWatcher.OnStop();
                switch (m)
                {
                case "startall":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StartHttp();
                    MongodbManager.StartDB();
                    NginxManager.StartWeb();

                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();

                    ProcessWatcher.OnStart();
                    break;

                case "quitall":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    break;

                case "exit":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    Process.GetCurrentProcess().Kill();
                    break;

                case "restart":
                    ProcessWatcher.OnStop();

                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();

                    Application.Restart();
                    Process.GetCurrentProcess().Kill();
                    //MongodbManager.StartDB();
                    //NginxManager.StartWeb();

                    //efwplusBaseManager.StartBase();
                    //efwplusRouteManager.StartRoute();
                    //efwplusWebAPIManager.StartAPI();

                    break;

                case "restartbase":
                    efwplusBaseManager.StopBase();
                    efwplusBaseManager.StartBase();
                    break;

                case "restartroute":
                    efwplusRouteManager.StopRoute();
                    efwplusRouteManager.StartRoute();
                    break;

                case "restartwebapi":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartmongodb":
                    MongodbManager.StopDB();
                    MongodbManager.StartDB();
                    break;

                case "restartnginx":
                    NginxManager.StopWeb();
                    NginxManager.StartWeb();
                    break;

                case "upgradeplugin":                                                               //升级插件
                    if (EFWCoreLib.CoreFrame.Init.HostSettingConfig.GetValue("autoupdater") == "1") //是否启动自动升级程序
                    {
                        showmsg("准备升级插件...");
                        ExecCmd("quitall", null);
                        try
                        {
                            efwplusHosting.UpgradeProgram.SetUpPluginUpgrade();
                        }
                        catch (Exception err)
                        {
                            showmsg("升级插件失败!" + err.Message + err.StackTrace);
                            showmsg("程序服务未启动.");
                            //Process.GetCurrentProcess().Kill();
                            //host.RunState = HostState.NoOpen;
                        }

                        showmsg("升级插件完成,正在启动服务...");
                        ExecCmd("startall", null);
                    }
                    else
                    {
                        showmsg("自动升级插件没有开启!");
                    }
                    break;
                }
                //ProcessWatcher.OnStart();
                return("succeed");
            }
            catch (Exception e)
            {
                showmsg(e.Message + e.StackTrace);
                return(e.Message);
            }
        }
Example #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            // 设置数据源,读取appsettings.json配置文件
            GlobalSystemConfig.DBConnectionString = this.Configuration.GetConnectionString("DataSource");
            // 注册缓存对象
            services.AddMemoryCache();
            IConfigurationSection connectionStringsSection = this.Configuration.GetSection("ConnectionStrings");
            IConfigurationSection cacheProviderSection     = connectionStringsSection.GetSection("CacheProvider");

            if (cacheProviderSection != null)
            {
                try
                {
                    string type = cacheProviderSection.GetValue <string>("type");
                    if ("redis".Equals(type, StringComparison.OrdinalIgnoreCase))
                    {
                        // redis 分布式缓存
                        RedisCacheProvider provider = cacheProviderSection.GetSection("provider").Get <RedisCacheProvider>();
                        services.AddSingleton(typeof(ICacheService), new RedisCacheService(new RedisCacheOptions
                        {
                            Configuration = provider.HostName + ":" + provider.Port,
                            InstanceName  = provider.InstanceName
                        }, provider.DataBase));
                    }
                    else if ("redis.r.w".Equals(type, StringComparison.OrdinalIgnoreCase))
                    {
                        // redis读写分离
                        RedisRWConfigInfo provider     = cacheProviderSection.GetSection("provider").Get <RedisRWConfigInfo>();
                        RedisManager      redisManager = new RedisManager(provider);
                        services.AddSingleton(typeof(ICacheService), new RedisRWCacheService(redisManager.GetClient()));
                    }
                }
                catch (Exception ex)
                {
                    LOG.Error(ex, "redis连接失败,准备启用MemoryCache服务");
                    SetCacheService(services);
                }
            }
            else
            {
                SetCacheService(services);
            }
            // mongo
            IConfigurationSection mongoSection = this.Configuration.GetSection("ConnectionStrings").GetSection("Mongo");

            if (mongoSection != null)
            {
                try
                {
                    // 注册mongo连接信息
                    MongodbHost mongohost = mongoSection.Get <MongodbHost>();
                    services.AddSingleton(typeof(MongodbHost), mongohost);
                    // IMongoClient mongoClient = new MongoClient(mongohost.Connection);
                    IMongoClient mongoClient = MongodbManager <object> .GetMongodbClient(mongohost.ConnectionString);

                    services.AddSingleton(typeof(IMongoClient), mongoClient);
                    IMongoDatabase mongoDatabase = mongoClient.GetDatabase(mongohost.DataBase);
                    services.AddSingleton(typeof(IMongoDatabase), mongoDatabase);
                }
                catch (Exception ex)
                {
                    LOG.Error(ex, "mongo连接失败");
                }
            }
            // 注册知识库
            services.AddSingleton <IRepository, Repository>();
            // 注册版本服务
            services.AddSingleton <IVersionService, VersionService>();
            // 注册用户服务
            services.AddSingleton <IUserService, UserService>();
            // 注册模型服务
            services.AddSingleton <IModelService, ModelService> ();
            // 注册数据源服务
            services.AddSingleton <IDataSourceService, DataSourceService>();
            // 注册算法服务
            services.AddSingleton <IAlgorithmService, AlgorithmService>();
            // 注册业务日志服务
            services.AddSingleton <ILogService, LogService>();
            // 注册任务服务
            services.AddSingleton <ITaskService, TaskService>();
            // 设置全局
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            ServiceFactory.CacheService  = serviceProvider.GetService <ICacheService>();
            ServiceFactory.MongoHost     = serviceProvider.GetService <MongodbHost>();
            ServiceFactory.MongoClient   = serviceProvider.GetService <IMongoClient>();
            ServiceFactory.MongoDatabase = serviceProvider.GetService <IMongoDatabase>();
            // 消息相关
            IConfigurationSection messageSection = connectionStringsSection.GetSection("Message");

            if (messageSection != null)
            {
                // 消息
                IConfigurationSection mqSection = messageSection.GetSection("MQ");
                if (mqSection != null)
                {
                    KafkaSetting kafkaSetting = mqSection.Get <KafkaSetting>();
                    if (kafkaSetting.Switch)
                    {
                        KafkaConsumer.CreateConsumer(kafkaSetting.Opinion.GroupId, kafkaSetting.Opinion.Servers, kafkaSetting.Opinion.Topics);
                        KafkaConsumer.Start();
                        KafkaProducer.CreateProducer(kafkaSetting.Opinion.Servers);
                    }
                }
                // websocket
                IConfigurationSection websocketSection = messageSection.GetSection("Websocket");
                if (websocketSection != null)
                {
                    WebsocketSetting websocketSetting = websocketSection.Get <WebsocketSetting>();
                    WebsocketFleckServer.CreateWebsocketServer(websocketSetting.NodeId, websocketSetting.Port, websocketSetting.Host);
                }
            }
            // scheduler,注入参数设置
            IConfigurationSection schedulerSection = this.Configuration.GetSection("Scheduler");

            if (schedulerSection != null)
            {
                if (schedulerSection.GetValue <Boolean>("switch"))
                {
                    IConfigurationSection propertiesSection = schedulerSection.GetSection("properties");
                    var values = propertiesSection.GetChildren()
                                 .Select(item => new KeyValuePair <string, string>(item.Key,
                                                                                   item.Value.Contains("$") ? Configuration.GetValue <string>(item.Value.Replace("${", "").Replace("}", "")) : item.Value))
                                 .ToDictionary(x => x.Key, x => x.Value);

                    DmeQuartzScheduler <TaskRunnerJob> .SetSchedulerProperties(DataUtil.ToNameValueCollection(values));

                    // 调取开启。如果不开启,则不会执行。
                    DmeQuartzScheduler <TaskRunnerJob> .Start().GetAwaiter();
                }
            }

            // DemoScheduler.RunProOracle().Wait();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "Dist Model Engine接口文档",
                    Description    = "RESTful API for DME",
                    TermsOfService = "None",
                    Contact        = new Contact {
                        Name = "weifj", Email = "*****@*****.**", Url = "https://github.com/leoterry-ulrica/dme"
                    }
                });
                //Set the comments path for the swagger json and ui.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "Dist.Dme.WebApi.xml");
                c.IncludeXmlComments(xmlPath);
                //  c.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数
            });

            // 配置日志服务
            services.AddLogging();
        }
Example #8
0
        static string ExecCmd(string m, Dictionary <string, string> a)
        {
            try
            {
                switch (m)
                {
                case "startall":
                    efwplusHttpManager.StartHttp();
                    MongodbManager.StartDB();
                    NginxManager.StartWeb();
                    //先启动mongodb,因为efwplusBaseManager启动时有访问mongodb数据
                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "quitall":
                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    break;

                case "exit":
                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    Environment.Exit(0);
                    break;

                case "restart":
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();

                    MongodbManager.StartDB();
                    NginxManager.StartWeb();

                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartbase":
                    efwplusBaseManager.StopBase();
                    efwplusBaseManager.StartBase();
                    break;

                case "restartroute":
                    efwplusRouteManager.StopRoute();
                    efwplusRouteManager.StartRoute();
                    break;

                case "restartwebapi":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartmongodb":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartnginx":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;
                }

                return("succeed");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }