Exemple #1
0
        public RssService(MongoDbService mongoDbService)
        {
            _mongoDbRss = new MongoDbUtil <Rss>(mongoDbService.Database);

            _mongoDbRss.Collection.Indexes.CreateOne(new CreateIndexModel <Rss>(
                                                         Builders <Rss> .IndexKeys.Ascending(x => x.Url)));
        }
        public void StoreDataWeatherTest()
        {
            MongoDbUtil.Instance().Drop();
            WeatherSevice sevice = new WeatherSevice();

            sevice.StoreDataWeather("9000", "BE");
            Assert.IsTrue(sevice.GetWeatherDatas().Count() == 1);
        }
        public void GetWeatherStaticsTest()
        {
            MongoService service = new MongoService();

            MongoDbUtil.Instance().Drop();
            service.AddBulk(GetDatas().ToArray());
            Assert.IsTrue(service.GetWeatherStatics().AllWeatherDatas().Count > 1);
        }
        public void GetListOfWeatherkTest()
        {
            MongoService service = new MongoService();

            MongoDbUtil.Instance().Drop();
            service.AddBulk(GetDatas().ToArray());
            Assert.IsTrue(service.GetWeatherDatas().Count() == 8);
        }
        public void StoreDataWeatherStaticsTest()
        {
            MongoDbUtil.Instance().Drop();
            WeatherSevice sevice = new WeatherSevice();

            sevice.StoreDataWeather(CityRepo.Cities().Take(5).ToList(), "BE");
            sevice.GetWeatherStatics();
            Assert.IsTrue(sevice.GetWeatherStatics().AllWeatherDatas().Count() == 4);
        }
        public NotificationService(MongoDbService mongoDbService,
                                   IHttpClientFactory httpClientFactory)
        {
            _mongoDbNotification = new MongoDbUtil <Notification>(mongoDbService.Database);
            _httpClientFactory   = httpClientFactory;

            _mongoDbNotification.Collection.Indexes.CreateOne(new CreateIndexModel <Notification>(
                                                                  Builders <Notification> .IndexKeys.Ascending(x => x.Region)));
        }
Exemple #7
0
        public RiotCrawler(IMongoDatabase mongoDatabase, HttpClient httpClient)
        {
            MongoDbSummoner    = new MongoDbUtil <Summoner>(mongoDatabase);
            MongoDbCurrentGame = new MongoDbUtil <CurrentGame>(mongoDatabase);
            MongoDbMatch       = new MongoDbUtil <Match>(mongoDatabase);
            MongoDbChampion    = new MongoDbUtil <Models.Champion>(mongoDatabase);
            MongoDbLeagueEntry = new MongoDbUtil <LeagueEntry>(mongoDatabase);

            HttpClient = httpClient;
        }
        public SourceService(MongoDbService mongoDbService)
        {
            _mongoDbSource = new MongoDbUtil <Source>(mongoDbService.Database);

            _mongoDbSource.Collection.Indexes.CreateOne(new CreateIndexModel <Source>(
                                                            Builders <Source> .IndexKeys.Ascending(x => x.Type)));

            _mongoDbSource.Collection.Indexes.CreateOne(new CreateIndexModel <Source>(
                                                            Builders <Source> .IndexKeys.Ascending(x => x.Type).Ascending(x => x.BoardId)));
        }
Exemple #9
0
        public RssCrawler(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, Rss rss)
        {
            if (mongoDb != null)
            {
                MongoDbFeedData = new MongoDbUtil <FeedData>(mongoDb);
            }

            OnCrawlDataDelegate = onCrawlDataDelegate;
            Rss = rss;
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var         builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
            var         config  = builder.Build();
            MongoDbUtil mongo   = new MongoDbUtil(config["mongo"], config["collection_name"], config["database_name"]);

            _etlWorker      = new Workers.EtlWorker(mongo, config["mysql_connection_string"]);
            _messageAPiHost = config["message_api_host"];
            _bus            = RabbitHutch.CreateBus(config["mq_url"]);
            _bus.Subscribe <ETLTaskMessage>("shell.etl.worker", ETLTaskHandler, x => x.WithTopic(config["mq_etl_topic"]));
        }
Exemple #11
0
        public CrawlerBase(CrawlDataDelegate onCrawlDataDelegate, IMongoDatabase mongoDb, string urlBase, Source source)
        {
            if (mongoDb != null)
            {
                MongoDbCrawlingData = new MongoDbUtil <CrawlingData>(mongoDb);
            }

            OnCrawlDataDelegate = onCrawlDataDelegate;
            UrlBase             = urlBase;
            Source = source;
        }
Exemple #12
0
        public void TestClient(string ip, int?port)
        {
            var st = new StackTrace(new StackFrame(true));

            TraceUtil.TraceWrapper(() =>
            {
                var mgUtil = new MongoDbUtil(ip, port);
                TraceUtil.WriteLine(string.Format("mgUtil.MgClient is null:{0}", mgUtil.MgClient == null), st);
                TraceUtil.WriteLine(string.Format("mgUtil.MgConnectString is:{0}", mgUtil.MgConnectString), st);
            }, st);
        }
Exemple #13
0
        static CheckLoginStatusService()
        {
            Task.Factory.StartNew(() => {
                try
                {
                    var redisSubHelp = new RedisSubHelp((a, b) =>
                    {
                        if (b.StartsWith(CacheKeyString.UserLoginAllKeyPre))
                        {
                            LogWrite.Write("redisLog.txt", "redis key:" + b);
                            try
                            {
                                string[] strArray = b.Split("#");
                                string ID         = strArray[3];
                                int companyID     = Convert.ToInt32(strArray[2]);
                                string userID     = strArray[1].ToString();
                                LoginLog loginLog = MongoDbUtil.GetDoc <LoginLog>(p => p.LoginID == ID, null).FirstOrDefault();

                                DateTime now       = DateTime.Now;
                                TimeSpan spendSpan = now.Subtract(loginLog.LoginTime);
                                if (loginLog != null)
                                {
                                    UpdateDefinition <LoginLog> update = Builders <LoginLog> .
                                                                         Update.Set(y => y.Seconds, spendSpan.TotalSeconds).Set(y => y.TimeSpan, DateUtil.parseTimeSeconds(spendSpan.TotalSeconds, 0))
                                                                         .Set(y => y.Status, LoginStatusEum.LogOut);
                                    MongoDbUtil.UpdateOne <LoginLog>(p => p.LoginID == ID, update);
                                }

                                var redis       = CacheFactory.Instance(CacheType.Redis) as RedisCache;
                                string thisWeek = DateUtil.GetThisWeekString();
                                string strV     = string.Format(CacheKeyString.StaOnlineUser, companyID, thisWeek);

                                string strTimeV = string.Format(CacheKeyString.StaOnlineTimes, companyID, thisWeek);

                                //累加登陆时长
                                redis.IncrementItemInSortedSet(strV, userID, spendSpan.TotalSeconds);
                                redis.Client.ExpireAt(strV, DateUtil.ToUnixEpochDate(DateTime.Now.AddDays(15)));

                                redis.IncrementItemInSortedSet(strTimeV, userID, 1);
                                redis.Client.ExpireAt(strV, DateUtil.ToUnixEpochDate(DateTime.Now.AddDays(15)));
                            }
                            catch (Exception ex) {
                                LogWrite.Write("redisLog", "错误:" + ex.Message);
                            }
                        }
                    });
                    redisSubHelp.SubscribeToChannels("__keyevent@0__:expired");
                }
                catch (Exception ex) {
                    LogWrite.Write("redisLog.txt", "最外层线程:" + ex.Message);
                }
            });
        }
        public List <LoginLog> managoDB()
        {
            LoginLog loginLog = new LoginLog();

            loginLog.LoginID     = Guid.NewGuid().ToString();
            loginLog.Account     = "123";
            loginLog.CompanyID   = 1;
            loginLog.Description = LoginTypeEum.LoginSuccess;

            MongoDbUtil.AddDoc(loginLog);

            return(MongoDbUtil.GetDoc <LoginLog>((x) => true));
        }
Exemple #15
0
        public NotificationService(MongoDbService mongoDbService,
                                   IHttpClientFactory httpClientFactory,
                                   SourceService sourceService)
        {
            _mongoDbNotification = new MongoDbUtil <Notification>(mongoDbService.Database);
            _httpClientFactory   = httpClientFactory;

            _sourceService = sourceService;

            _mongoDbNotification.Collection.Indexes.CreateOne(new CreateIndexModel <Notification>(
                                                                  Builders <Notification> .IndexKeys.Ascending(x => x.SourceId)
                                                                  .Ascending(x => x.CrawlingType)
                                                                  .Ascending(x => x.Type)));
        }
        public FeedCrawlingService(MongoDbService mongoDbService,
                                   RssService rssService,
                                   NotificationService notificationService)
        {
            _mongoDbService      = mongoDbService;
            _rssService          = rssService;
            _notificationService = notificationService;
            _mongoFeedData       = new MongoDbUtil <FeedData>(mongoDbService.Database);

            _mongoFeedData.Collection.Indexes.CreateOne(new CreateIndexModel <FeedData>(
                                                            Builders <FeedData> .IndexKeys.Ascending(x => x.DateTime)));

            _mongoFeedData.Collection.Indexes.CreateOne(new CreateIndexModel <FeedData>(
                                                            Builders <FeedData> .IndexKeys.Ascending(x => x.ItemTitle)));

            _mongoFeedData.Collection.Indexes.CreateOne(new CreateIndexModel <FeedData>(
                                                            Builders <FeedData> .IndexKeys.Ascending(x => x.FeedTitle)));
        }
Exemple #17
0
        public async Task <bool> PostAsync(List <OperateLog> operateLog)
        {
            bool result = true;

            result = await Task.Factory.StartNew(() => {
                bool tempResult = true;
                try
                {
                    MongoDbUtil.AddDoc(operateLog);
                }
                catch {
                    tempResult = false;
                }
                return(tempResult);
            });

            return(result);
        }
Exemple #18
0
        private void PushNotice(int UserId, int CompanyID, TSMUserAccountDbModel userAccount)
        {
            var permissUser = _db.Instance.Queryable <TSMUserAccountDbModel, TSMRoleUserRelationDbModel, TSMRolePermissionsDbModel, TSMRolesDbModel, TPMMenusDbModel>(
                (x, x1, x2, x3, x4) => new object[]
            {
                JoinType.Inner, x.ID == x1.UserId,
                JoinType.Inner, x1.RoleId == x2.RoleId,
                JoinType.Inner, x2.RoleId == x3.Id,
                JoinType.Inner, x2.MenuId == x4.Id
            }).Where((x, x1, x2, x3, x4) => x.CompanyId == CompanyID && x.Status == 1 && x4.MenuPath == "/views/SysSettings/UserAuth/index.vue")
                              .Select((x, x1, x2, x3, x4) => x).ToList();

            var adminUser = _db.Instance.Queryable <TSMUserAccountDbModel, TSMCompanyDbModel>((x, x1) => new object[] {
                JoinType.Inner, x.ID == x1.AdminId
            }).Where((x, x1) => x1.ID == CompanyID).Select((x, x1) => x).First();

            if (!permissUser.Any(p => p.ID == adminUser.ID))
            {
                permissUser.Add(adminUser);
            }


            var redis = CacheFactory.Instance(CacheType.Redis);

            List <ToDoMgModel> toDoMgModelList = new List <ToDoMgModel>();

            foreach (var userTtem in permissUser)
            {
                ToDoMgModel toDoModel = new ToDoMgModel();
                toDoModel.Title       = "申请加入公司";
                toDoModel.Content     = $"姓名:{userAccount.AccountName} 电话:{userAccount.TelAccount},申请加入公司";
                toDoModel.CreateBy    = UserId;
                toDoModel.CreateDate  = DateTime.Now;
                toDoModel.IsRead      = false;
                toDoModel.MessageType = MessageTypeMgEnum.ToApplytoComplany;
                toDoModel.To          = userTtem.ID;
                toDoModel.ToDoId      = Guid.NewGuid().ToString();
                toDoModel.CompanyID   = CompanyID;
                toDoMgModelList.Add(toDoModel);
            }

            MongoDbUtil.AddDoc(toDoMgModelList);
        }
        public void AddTest()
        {
            MongoService service = new MongoService();

            MongoDbUtil.Instance().Drop();
            service.Add(new WeatherData()
            {
                Country       = "BE",
                Temperature   = 12.5,
                Speed         = 10.2,
                City          = "Ghent",
                Pressure      = 12,
                WindSpeed     = 5,
                Id            = Guid.NewGuid(),
                Humidty       = 5,
                WindDirection = "NE",
                UpdateWeather = DateTime.Now
            });
            Assert.IsTrue(service.GetWeatherDatas().Count() == 1);
        }
Exemple #20
0
        public ResponseObject <bool> Read(string Id, CurrentUser currentUser)
        {
            try
            {
                ToDoMgModel loginLog = MongoDbUtil.GetDoc <ToDoMgModel>(p => p.ToDoId == Id, null).FirstOrDefault();

                if (loginLog != null)
                {
                    UpdateDefinition <ToDoMgModel> update = Builders <ToDoMgModel> .
                                                            Update.Set(y => y.IsRead, true);

                    MongoDbUtil.UpdateOne <ToDoMgModel>(p => p.ToDoId == Id && p.CompanyID == currentUser.CompanyID, update);
                }

                return(ResponseUtil <bool> .SuccessResult(true));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <bool> .FailResult(false, $"{ex.Message}"));
            }
        }
Exemple #21
0
        public WebCrawlingService(MongoDbService mongoDbService,
                                  SourceService sourceService,
                                  NotificationService notificationService)
        {
            _mongoDbService      = mongoDbService;
            _sourceService       = sourceService;
            _notificationService = notificationService;
            _mongoCrawlingData   = new MongoDbUtil <CrawlingData>(mongoDbService.Database);

            _mongoCrawlingData.Collection.Indexes.CreateOne(new CreateIndexModel <CrawlingData>(
                                                                Builders <CrawlingData> .IndexKeys.Ascending(x => x.DateTime)));

            _mongoCrawlingData.Collection.Indexes.CreateOne(new CreateIndexModel <CrawlingData>(
                                                                Builders <CrawlingData> .IndexKeys.Ascending(x => x.Title)));

            _mongoCrawlingData.Collection.Indexes.CreateOne(new CreateIndexModel <CrawlingData>(
                                                                Builders <CrawlingData> .IndexKeys.Ascending(x => x.Type)));

            _mongoCrawlingData.Collection.Indexes.CreateOne(new CreateIndexModel <CrawlingData>(
                                                                Builders <CrawlingData> .IndexKeys.Ascending(x => x.Type).Ascending(x => x.BoardId)));
        }
        public async Task <ResponseObject <TSMUserLoginResult> > LoginPost(RequestPost <TSMUserAccountAddModel> requestObject)
        {
            ResponseObject <TSMUserLoginResult> result;

            result = await _service.LoginAsync(requestObject);



            var task = Task.Factory.StartNew(() =>
            {
                try
                {
                    bool isSucess = string.IsNullOrEmpty(result.Data.Token) ? false : true;

                    if (isSucess == true)
                    {
                        string token  = result.Data.Token.Split('.')[1];
                        var payLoad   = JsonConvert.DeserializeObject <Dictionary <string, object> >(Base64UrlEncoder.Decode(token));
                        int userID    = Convert.ToInt32(payLoad["UserID"]);
                        string ID     = payLoad["ID"].ToString();
                        int CompanyID = Convert.ToInt32(payLoad["CompanyID"]);
                        if (CompanyID == 0)   //没有加入公司的员工不保存登陆日志
                        {
                            return;
                        }


                        //写 登陆状态到redis
                        var redis             = CacheFactory.Instance(CacheType.Redis);
                        UserStatus userStatus = new UserStatus()
                        {
                            ID = ID, LastRefreshTime = DateTime.Now
                        };
                        string redisKey = string.Format(CacheKeyString.UserLoginAllKey, userID, CompanyID, ID);
                        redis.AddOrUpdateKey <UserStatus>(redisKey, userStatus, 90);


                        //写登陆日志到 MangoDB
                        SMUserInfo sMUserInfo = SMCurentUserManager.GetCurentUserID(userID, _db.Instance);
                        string ipAddress      = Request.HttpContext.Connection.RemoteIpAddress.ToString();

                        LoginLog loginLog    = new LoginLog();
                        loginLog.LoginID     = ID;
                        loginLog.Account     = sMUserInfo.AccountName;
                        loginLog.CompanyID   = sMUserInfo.CompanyId.Value;
                        loginLog.Description = isSucess ? LoginTypeEum.LoginSuccess : LoginTypeEum.LoginFail;
                        loginLog.IpAddress   = ipAddress;
                        loginLog.LoginTime   = DateTime.Now;
                        loginLog.RealName    = sMUserInfo == null ? "" : sMUserInfo.RealName;
                        loginLog.RoleName    = sMUserInfo == null ? "" : sMUserInfo.RoleName;
                        loginLog.Status      = isSucess ? LoginStatusEum.Logining : LoginStatusEum.LogOut;

                        MongoDbUtil.AddDoc(loginLog);
                    }
                    else
                    {
                        //LoginLog loginLog = new LoginLog();
                        //loginLog.ID = Guid.NewGuid().ToString();
                        //loginLog.Account = sMUserInfo.AccountName;
                        //loginLog.CompanyID = sMUserInfo.CompanyId.Value;
                        //loginLog.Description = isSucess ? LoginTypeEum.LoginSuccess : LoginTypeEum.LoginFail;
                        //loginLog.IpAddress = ipAddress;
                        //loginLog.LoginTime = DateTime.Now;
                        //loginLog.RealName = sMUserInfo?.RealName;
                        //loginLog.RoleName = sMUserInfo?.RoleName;
                        //loginLog.Status = isSucess ? LoginStatusEum.Logining : LoginStatusEum.LogOut;

                        //MongoDbUtil.AddDoc(loginLog);
                    }
                }
                catch (Exception EX)
                {
                }
            });

            return(result);
        }
 /// <summary>
 /// Initializes a new instance of the MongoRepository class.
 /// </summary>
 /// <param name="url">Url to use for connecting to MongoDB.</param>
 public MongoRepository(MongoUrl url)
 {
     _collection = MongoDbUtil <TKey> .GetCollectionFromUrl <T>(url);
 }
 /// <summary>
 /// Initializes a new instance of the MongoRepository class.
 /// </summary>
 /// <param name="url">Url to use for connecting to MongoDB.</param>
 /// <param name="collectionName">The name of the collection to use.</param>
 public MongoRepository(MongoUrl url, string collectionName)
 {
     _collection = MongoDbUtil <TKey> .GetCollectionFromUrl <T>(url, collectionName);
 }
Exemple #25
0
        public ResponseObject <List <ToDoMgModel> > GetToDoModel(RequestGet requestObject, CurrentUser currentUser)
        {
            ResponseObject <List <ToDoMgModel> > responseObject = new ResponseObject <List <ToDoMgModel> >();

            responseObject.Code = 0;

            try
            {
                List <ToDoMgModel> result = new List <ToDoMgModel>();

                Expression <Func <ToDoMgModel, bool> > queryConditionLam = (x) => x.To == currentUser.UserID && x.CompanyID == currentUser.CompanyID;

                if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalFull(requestObject.QueryConditions).Where(p => !string.IsNullOrWhiteSpace(p.FieldValue)).ToList();

                    var whereConditional = ConditionalModelToExpression.BuildExpression <ToDoMgModel>(conditionals);
                    queryConditionLam = queryConditionLam.And(whereConditional);
                }

                SortDefinition <ToDoMgModel> sort = null;

                //排序条件
                if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0)
                {
                    foreach (var item in requestObject.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetExpression <ToDoMgModel>(item.Column);

                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() == "asc")
                        {
                            if (sort == null)
                            {
                                sort = Builders <ToDoMgModel> .Sort.Ascending(exp);
                            }
                            else
                            {
                                sort = sort.Ascending(exp);
                            }
                        }
                        else if (item.Condition.ToLower() == "desc")
                        {
                            if (sort == null)
                            {
                                sort = Builders <ToDoMgModel> .Sort.Descending(exp);
                            }
                            else
                            {
                                sort = sort.Descending(exp);
                            }
                        }
                    }
                }



                long totalNum = 0;

                if (requestObject.IsPaging == true)
                {
                    result = MongoDbUtil.GetDoc <ToDoMgModel>(queryConditionLam, requestObject.PageIndex, requestObject.PageSize, sort, ref totalNum);
                }
                else
                {
                    result = MongoDbUtil.GetDoc <ToDoMgModel>(queryConditionLam, sort).ToList();
                }

                return(ResponseUtil <List <ToDoMgModel> > .SuccessResult(result, totalNum));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <List <ToDoMgModel> > .FailResult(null, ex.Message));
            }
        }
 /// <summary>
 /// Initializes a new instance of the MongoRepository class.
 /// </summary>
 // <param name="options">options.Value.Conectionstring to use for connection to MongoDB</param>
 /// <param name="collectionName">The name of the collection to use.</param>
 public MongoRepository(IMongoDbSettings options, string collectionName)
 {
     _collection = MongoDbUtil <TKey> .GetCollectionFromConnectionString <T>(options, collectionName);
 }
Exemple #27
0
        /// <summary>
        /// 查询日志
        /// </summary>
        /// <param name="requestObject"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public ResponseObject <LogQueryModel, List <OperateLog> > Get(RequestObject <LogQueryModel> requestObject, int UserId)
        {
            try
            {
                long       totalNum   = -1;
                SMUserInfo sMUserInfo = SMCurentUserManager.GetCurentUserID(UserId, _db.Instance);

                List <OperateLog> result = new List <OperateLog>();

                Expression <Func <OperateLog, bool> > pression = p => p.CompanyID == sMUserInfo.CompanyId.Value;

                var queryEntiy = requestObject.PostData;
                if (queryEntiy != null)
                {
                    if (!string.IsNullOrEmpty(queryEntiy.Account))
                    {
                        pression = pression.And(p => p.Account.Contains(queryEntiy.Account));
                    }
                    if (!string.IsNullOrEmpty(queryEntiy.Path))
                    {
                        pression = pression.And(p => p.Path.Contains(queryEntiy.Path));
                    }

                    if (!string.IsNullOrEmpty(queryEntiy.RealName))
                    {
                        pression = pression.And(p => p.RealName.Contains(queryEntiy.RealName));
                    }

                    if (!string.IsNullOrEmpty(queryEntiy.IpAddress))
                    {
                        pression = pression.And(p => p.IpAddress == queryEntiy.IpAddress);
                    }

                    if (queryEntiy.CreateTimeBg != null)
                    {
                        pression = pression.And(p => p.CreateTime >= queryEntiy.CreateTimeBg.Value);
                    }

                    if (queryEntiy.CreateTimeEd != null)
                    {
                        DateTime eg = queryEntiy.CreateTimeEd.Value.AddDays(1);
                        pression = pression.And(p => p.CreateTime < eg);
                    }
                }
                var sort = Builders <OperateLog> .Sort.Descending(y => y.CreateTime);

                if (requestObject.IsPaging == true)
                {
                    result = MongoDbUtil.GetDoc <OperateLog>(pression, requestObject.PageIndex, requestObject.PageSize, sort, ref totalNum);
                }
                else
                {
                    result = MongoDbUtil.GetDoc <OperateLog>(pression, sort).ToList();
                }


                return(ResponseUtil <LogQueryModel, List <OperateLog> > .SuccessResult(requestObject, result, totalNum));
            }
            catch (Exception ex)
            {
                //返回查询异常结果
                return(ResponseUtil <LogQueryModel, List <OperateLog> > .FailResult(requestObject, null, ex.Message));
            }
        }
Exemple #28
0
 public EtlWorker(MongoDbUtil mongoDbUtil, string mysqlConStr)
 {
     _mongoDbUtil      = mongoDbUtil;
     this._mysqlConStr = mysqlConStr;
 }