Пример #1
0
        public static List <WatchDogProcessor> GetWatchDogBase(WatchDog wd)
        {
            var res = new List <WatchDogProcessor>();

            if (wd.dataType == WatchDog.AllDbDataType)
            {                                                     //add all datasets
                foreach (var ds in External.DataSets.DataSetDB.ProductionDataSets.Get())
                {
                    res.Add(new External.DataSets.WatchdogDataset(wd, ds));
                }
            }

            if (wd.dataType == typeof(Smlouva).Name || wd.dataType == WatchDog.AllDbDataType)
            {
                res.Add(new WatchdogSmlouva(wd));
            }
            if (wd.dataType == typeof(VZ.VerejnaZakazka).Name || wd.dataType == WatchDog.AllDbDataType)
            {
                res.Add(new WatchdogVerejnaZakazka(wd));
            }
            if (wd.dataType.StartsWith(typeof(Lib.Data.External.DataSets.DataSet).Name))
            {
                res.Add(new Lib.Data.External.DataSets.WatchdogDataset(wd));
            }
            //if (wd.dataType == typeof(Rizeni).Name || wd.dataType == WatchDog.AllDbDataType)
            //	res.Add(new WatchdogInsolvenciRizeni(wd));
            return(res);
        }
Пример #2
0
 public WatchdogVerejnaZakazka(WatchDog w)
     : base(w)
 {
     if (w.dataType != typeof(VZ.VerejnaZakazka).Name && w.dataType != WatchDog.AllDbDataType)
     {
         throw new InvalidCastException("It's not VEREJNAZAKAZKA type");
     }
 }
Пример #3
0
 public WatchdogSmlouva(WatchDog w)
     : base(w)
 {
     if (w.dataType != typeof(Smlouva).Name && w.dataType != WatchDog.AllDbDataType)
     {
         throw new InvalidCastException("It's not SMLOUVA type");
     }
 }
Пример #4
0
 public WatchDogProcessor(WatchDog wd)
     : this()
 {
     if (wd == null)
     {
         throw new NullReferenceException();
     }
     originalWD = wd;
 }
Пример #5
0
        public WatchdogInsolvence(WatchDog w)
            : base(w)
        {
            if (w.dataType != typeof(Insolvence.Rizeni).Name && w.dataType != WatchDog.AllDbDataType)
            {
                throw new InvalidCastException("It's not INSOLVENCE type");
            }

            isLimited = !(
                w.User().IsInRole("novinar")
                ||
                w.User().IsInRole("Admin")
                );
        }
Пример #6
0
        public ActionResult SubjektHlidac(string Id, FormCollection form)
        {
            bool   existing = false;
            string wd_id    = form["wd_id"];
            int    wdId;
            string subject = form["subjekt"];

            using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities())
            {
                string id = this.User.Identity.GetUserId();
                HlidacStatu.Lib.Data.WatchDog wd = null;
                if (!string.IsNullOrEmpty(wd_id) && int.TryParse(wd_id, out wdId))
                {
                    wd       = WatchDog.Load(wdId);
                    existing = wd != null;
                }
                string query = "";
                if (string.IsNullOrEmpty(form["ico"]) && wd != null)
                {
                    wd.Delete();
                    return(RedirectToAction("Watchdogs", "Manage"));
                }
                else if (string.IsNullOrEmpty(form["ico"]))
                {
                    return(Redirect("/Subjekt/" + id));
                }

                query = form["ico"].Split(',').Select(m => "ico:" + m).Aggregate((f, s) => f + " OR " + s);

                if (wd == null)
                {
                    wd = new HlidacStatu.Lib.Data.WatchDog();
                }

                wd.Created        = DateTime.Now;
                wd.UserId         = id;
                wd.StatusId       = 1;
                wd.SearchTerm     = query;
                wd.SearchRawQuery = "icoVazby:" + form["ico"];
                wd.PeriodId       = Convert.ToInt32(form["period"]);
                wd.FocusId        = Convert.ToInt32(form["focus"]);
                wd.Name           = Devmasters.TextUtil.ShortenText(form["wdname"], 50);
                wd.Save();
                return(RedirectToAction("Watchdogs", "Manage"));
            }
        }
Пример #7
0
        public ActionResult AddWd(string query, string dataType, string name, int period, int focus)
        {
            using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities())
            {
                if (string.IsNullOrEmpty(query))
                {
                    return(Json("0", JsonRequestBehavior.AllowGet));
                }
                string id = this.User.Identity.GetUserId();

                var dt = dataType;

                HlidacStatu.Lib.Data.WatchDog wd = new HlidacStatu.Lib.Data.WatchDog();
                wd.Created    = DateTime.Now;
                wd.UserId     = id;
                wd.StatusId   = 1;
                wd.SearchTerm = query;
                wd.PeriodId   = period;
                wd.FocusId    = focus;
                wd.Name       = Devmasters.TextUtil.ShortenText(name, 50);
                if (dt.ToLower() == typeof(Smlouva).Name.ToLower())
                {
                    wd.dataType = typeof(Smlouva).Name;
                }
                else if (dt.ToLower() == typeof(VerejnaZakazka).Name.ToLower())
                {
                    wd.dataType = typeof(VerejnaZakazka).Name;
                }
                else if (dt.ToLower() == typeof(Lib.Data.Insolvence.Rizeni).Name.ToLower())
                {
                    wd.dataType = typeof(Lib.Data.Insolvence.Rizeni).Name;
                }
                else if (dt.ToLower().StartsWith(typeof(HlidacStatu.Lib.Data.External.DataSets.DataSet).Name.ToLower()))
                {
                    var dataSetId = dt.Replace("DataSet.", "");
                    if (HlidacStatu.Lib.Data.External.DataSets.DataSet.ExistsDataset(dataSetId) == false)
                    {
                        HlidacStatu.Util.Consts.Logger.Error("AddWd - try to hack, wrong dataType = " + dataType + "." + dataSetId);
                        throw new ArgumentOutOfRangeException("AddWd - try to hack, wrong dataType = " + dataType + "." + dataSetId);
                    }
                    wd.dataType = typeof(HlidacStatu.Lib.Data.External.DataSets.DataSet).Name + "." + dataSetId;
                }
                else if (dt == WatchDog.AllDbDataType)
                {
                    wd.dataType = dt;
                }
                else
                {
                    HlidacStatu.Util.Consts.Logger.Error("AddWd - try to hack, wrong dataType = " + dataType);
                    throw new ArgumentOutOfRangeException("AddWd - try to hack, wrong dataType = " + dataType);
                }
                if (!db.WatchDogs
                    .Any(m => m.dataType == wd.dataType && m.UserId == id && m.SearchTerm == query))
                {
                    wd.Save();
                }


                //var lastOrder = HlidacStatu.Lib.Data.Invoices.GetCurrentOrderForUser(this.User.Identity.GetUserId());
                //if (lastOrder.HasValue == false && focus == 1)
                //    return Json("2", JsonRequestBehavior.AllowGet);

                return(Json("1", JsonRequestBehavior.AllowGet));
            }
        }
Пример #8
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);
                }
            }
        public ActionResult Watchdog(string _id, string _dataid, string dataType = "VerejnaZakazka", string query = null, string expiration = null)
        {
            string id     = _id;
            string dataid = _dataid;

            id = id.ToLower();
            var apiAuth = Framework.ApiAuth.IsApiAuth(this,
                                                      parameters: new Framework.ApiCall.CallParameter[] {
                new Framework.ApiCall.CallParameter("id", id),
                new Framework.ApiCall.CallParameter("query", query),
                new Framework.ApiCall.CallParameter("expiration", expiration)
            });

            if (!apiAuth.Authentificated)
            {
                //Response.StatusCode = 401;
                return(Json(ApiResponseStatus.ApiUnauthorizedAccess, JsonRequestBehavior.AllowGet));
            }
            else
            {
                if (apiAuth.ApiCall.User != "*****@*****.**" &&
                    apiAuth.ApiCall.User != "*****@*****.**"
                    )
                {
                    return(Json(ApiResponseStatus.ApiUnauthorizedAccess, JsonRequestBehavior.AllowGet));
                }

                var wdName = WatchDog.APIID_Prefix + dataid;
                using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities())
                {
                    switch (id.ToLower())
                    {
                    case "add":
                        var expirDate = Devmasters.DT.Util.ToDateTime(expiration, "yyyy-MM-ddTHH:mm:ss");
                        if (string.IsNullOrEmpty(query))
                        {
                            return(Json(ApiResponseStatus.Error(-99, "No query"), JsonRequestBehavior.AllowGet));
                        }

                        var wd2 = db.WatchDogs.AsNoTracking().Where(m => m.Name == wdName).FirstOrDefault();
                        if (wd2 != null)
                        {
                            wd2.SearchTerm = query;
                            wd2.Expires    = expirDate;
                            wd2.Save();
                        }
                        else
                        {
                            var dt = dataType;

                            HlidacStatu.Lib.Data.WatchDog wd = new HlidacStatu.Lib.Data.WatchDog();
                            wd.Created         = DateTime.Now;
                            wd.UserId          = apiAuth.ApiCall.UserId;
                            wd.StatusId        = 1;
                            wd.SearchTerm      = query;
                            wd.PeriodId        = 2; //daily
                            wd.FocusId         = 0;
                            wd.Name            = wdName;
                            wd.Expires         = expirDate;
                            wd.SpecificContact = "HTTPPOSTBACK";
                            if (dt.ToLower() == typeof(Smlouva).Name.ToLower())
                            {
                                wd.dataType = typeof(Smlouva).Name;
                            }
                            else if (dt.ToLower() == typeof(VerejnaZakazka).Name.ToLower())
                            {
                                wd.dataType = typeof(VerejnaZakazka).Name;
                            }
                            else if (dt.ToLower().StartsWith(typeof(HlidacStatu.Lib.Data.External.DataSets.DataSet).Name.ToLower()))
                            {
                                var dataSetId = dt.Replace("DataSet.", "");
                                if (HlidacStatu.Lib.Data.External.DataSets.DataSet.ExistsDataset(dataSetId) == false)
                                {
                                    HlidacStatu.Util.Consts.Logger.Error("AddWd - try to hack, wrong dataType = " + dataType + "." + dataSetId);
                                    throw new ArgumentOutOfRangeException("AddWd - try to hack, wrong dataType = " + dataType + "." + dataSetId);
                                }
                                wd.dataType = typeof(HlidacStatu.Lib.Data.External.DataSets.DataSet).Name + "." + dataSetId;
                            }
                            else if (dt == WatchDog.AllDbDataType)
                            {
                                wd.dataType = dt;
                            }
                            else
                            {
                                HlidacStatu.Util.Consts.Logger.Error("AddWd - try to hack, wrong dataType = " + dataType);
                                throw new ArgumentOutOfRangeException("AddWd - try to hack, wrong dataType = " + dataType);
                            }

                            wd.Save();
                        }
                        break;

                    case "delete":
                    case "disable":
                    case "get":
                    case "enable":
                        var wd1 = db.WatchDogs.AsNoTracking().Where(m => m.Name == wdName).FirstOrDefault();
                        if (wd1 == null)
                        {
                            return(Json(ApiResponseStatus.Error(-404, "Watchdog not found"), JsonRequestBehavior.AllowGet));
                        }

                        if (id == "delete")
                        {
                            wd1.Delete();
                            return(Json(new { Ok = true }, JsonRequestBehavior.AllowGet));
                        }
                        if (id == "disable")
                        {
                            wd1.StatusId = 0;
                        }
                        if (id == "delete")
                        {
                            wd1.StatusId = 1;
                        }
                        if (id == "get")
                        {
                            return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(new { id = wd1.Name.Replace("APIID:", ""), expiration = wd1.Expires, query = wd1.SearchTerm }), "text/json"));
                        }

                        wd1.Save();
                        break;

                    default:
                        break;
                    }
                }


                return(Json(new { Ok = true }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #10
0
 public WatchDogProcessor(int watchdogId)
     : this(WatchDog.Load(watchdogId))
 {
 }
 public WatchdogProcessor(WatchDog wd)
 {
     this.OrigWD = wd;
 }