示例#1
0
            private static void _SendWatchDogs(string datatype, string[] ids, string userid, string date, string specificemail, bool forceSend = false, Expression <Func <WatchDog, bool> > predicate = null)
            {
                HlidacStatu.Util.Consts.Logger.Info("Starting SendWatchDogs type:" + datatype);

                IEnumerable <int> watchdogs = null;

                using (Lib.Data.DbEntities db = new DbEntities())
                {
                    var data = db.WatchDogs.AsNoTracking()
                               .Where(m => m.StatusId > 0);


                    if (!string.IsNullOrEmpty(userid))
                    {
                        data = data.Where(m => m.UserId == userid);
                    }

                    if (!string.IsNullOrEmpty(datatype))
                    {
                        data = data.Where(m => m.dataType == datatype);
                    }

                    if (predicate != null)
                    {
                        data = data.Where(predicate);
                    }

                    if (ids != null)
                    {
                        data = data.Where(m => ids.Contains(m.Id.ToString()));
                    }

                    watchdogs = data
                                .Select(m => m.Id)
                                .ToArray();
                }


                System.Collections.Concurrent.ConcurrentBag <string> alreadySendInfo = new System.Collections.Concurrent.ConcurrentBag <string>();
                try
                {
                    Devmasters.Core.Batch.Manager.DoActionForAll <int, object>(watchdogs,
                                                                               (wdid, obj) =>
                    {
                        string log       = "";
                        var mainWatchdog = WatchDog.Load(wdid);
                        var mainWDBs     = WatchDog.GetWatchDogBase(mainWatchdog);

                        var notifResult = true;


                        foreach (var wdb in mainWDBs)
                        {
                            HlidacStatu.Util.Consts.Logger.Debug($"Starting watchdog {wdb.ToString()}");


                            var mainDatatype = wdb.OrigWD.dataType;
                            var user         = wdb.OrigWD.User();
                            if (user == null) //is not confirmed
                            {
                                var uuser = wdb.OrigWD.UnconfirmedUser();
                                wdb.OrigWD.DisableWDBySystem(DisabledBySystemReasons.NoConfirmedEmail,
                                                             alreadySendInfo.Contains(uuser.Id)
                                                             );
                                alreadySendInfo.Add(uuser.Id);
                                break;                                   //exit for
                            }
                            if (user != null && wdb.OrigWD.StatusId > 0) //check again, some of them could change to disabled
                            {
                                try
                                {
                                    notifResult = notifResult | _processIndividualWD(wdb, date, null, specificemail, forceSend);
                                }
                                catch (Exception e)
                                {
                                    HlidacStatu.Util.Consts.Logger.Error("WatchDog search error", e);
                                    log += "WatchDog search error " + e.ToString();
                                    //throw;
                                }
                            }
                        }
                        if (notifResult && date == null && forceSend == false)
                        {
                            DateTime toDate = WatchDogProcessor.DefaultRoundWatchdogTime(mainWatchdog.Period, DateTime.Now);

                            if (mainWatchdog.LastSearched.HasValue == false || mainWatchdog.LastSearched < toDate)
                            {
                                mainWatchdog.LastSearched = toDate;
                            }
                            mainWatchdog.RunCount++;
                            var latestRec = toDate;
                            if (mainWatchdog.LatestRec.HasValue == false)
                            {
                                mainWatchdog.LatestRec = latestRec;
                            }
                            else if (latestRec > mainWatchdog.LatestRec)
                            {
                                mainWatchdog.LatestRec = latestRec;
                            }

                            mainWatchdog.LastSent = mainWatchdog.LastSearched;

                            mainWatchdog.Save();
                        }



                        return(new Devmasters.Core.Batch.ActionOutputData()
                        {
                            CancelRunning = false, Log = log
                        });
                    },
                                                                               null,
                                                                               HlidacStatu.Util.Consts.outputWriter.OutputWriter,
                                                                               HlidacStatu.Util.Consts.progressWriter.ProgressWriter,
                                                                               System.Diagnostics.Debugger.IsAttached ? false : true);
                }
                catch (Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Fatal($"Watchdoga DoActionForAll error", e);
                }
            }
示例#2
0
 public WatchDogProcessor(int watchdogId)
     : this(WatchDog.Load(watchdogId))
 {
 }