Пример #1
0
        protected override async Task <DatasourceResult <List <T> > > RunAsync()
        {
            string        assemblyPath        = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
            Configuration cfg                 = ConfigurationManager.OpenExeConfiguration(assemblyPath);
            string        isQueyMongo         = cfg.AppSettings.Settings["AlwaysQueryMongo"].Value;
            int           switchTimeDurations = int.Parse(cfg.AppSettings.Settings["SwitchTimeDuration"].Value);

            if (isQueyMongo != "true")
            {
                if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - QueryConstant.PreviousSwitchTime >=
                    switchTimeDurations * 60 * 1000 && QueryConstant.IsSwitch && switchTimeDurations > 0)
                {
                    QueryConstant.IsSwitch = false;
                }
                if (QueryConstant.IsSwitch)
                {
                    var mongoQuery  = new MongoDbQuery <T>(_query.Collection, _query.BoolQuery, _query.EsSort, _query.Aggregations, _query.From, _query.Size);
                    var resultMongo = await mongoQuery.GetResult();

                    return(resultMongo);
                }
                var elasticsearchQuery = new ElasticsearchQuery <T>(_query.EsClient, _query.BoolQuery, _query.EsSort, _query.Aggregations, _query.From, _query.Size);
                var result             = await elasticsearchQuery.GetResult();

                return(result);
            }
            else
            {
                var mongoQuery = new MongoDbQuery <T>(_query.Collection, _query.BoolQuery, _query.EsSort, _query.Aggregations, _query.From, _query.Size);
                var result     = await mongoQuery.GetResult();

                return(result);
            }
        }
Пример #2
0
        protected override async Task <DatasourceResult <List <T> > > RunFallbackAsync()
        {
            string        assemblyPath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
            Configuration cfg          = ConfigurationManager.OpenExeConfiguration(assemblyPath);
            string        isQueyMongo  = cfg.AppSettings.Settings["AlwaysQueryMongo"].Value;

            if (isQueyMongo != "true")
            {
                QueryConstant.IsSwitch           = true;
                QueryConstant.PreviousSwitchTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                var mongoQuery = new MongoDbQuery <T>(_query.Collection, _query.BoolQuery, _query.EsSort, _query.Aggregations, _query.From, _query.Size);
                var result     = await mongoQuery.GetResult();

                return(result);
            }
            return(new DatasourceResult <List <T> >());
        }