Пример #1
0
        //public virtual bool SendTwitter(string credJson, WatchDogBase<T>.Result res)
        //{
        //    try
        //    {
        //        TwitterData td = Newtonsoft.Json.JsonConvert.DeserializeObject<TwitterData>(credJson);
        //        var total = res.QueryResult.Total;
        //        var zakazkyStr = Devmasters.Core.Lang.Plural.GetWithZero((int)total, "žádné nové zakázky", "jednu novou zakázku", "{0} nové zakázky", "{0} nových zakázek");
        //        var fromDate = res.FromDate.ToString("d.M.");
        //        var toDate = res.ToDate.ToString("d.M.");
        //        var queryUrl = res.SearchUrl();
        //        var tweet = string.Format(td.TweetContent, fromDate, toDate, total, zakazkyStr, queryUrl);

        //        return StaticData.TweetingManager.GetInstance(td.Credentials).Publish(tweet);
        //    }
        //    catch (Exception e)
        //    {
        //        HlidacStatu.Util.Consts.Logger.Error("WatchDog Notification error", e);
        //        return false;
        //    }
        //}

        public virtual bool SendEmailNotification(string toEmail, WatchDogProcessor.Result res)
        {
            int maxCount = 30;

            try
            {
                var email = CreateNotificationEmail(EmailNotificationTemplate(res), res, toEmail, maxCount);
                if (email == null)
                {
                    return(false);
                }

                //copy common properties to Model
                email.Model.EmailFooterHtml = email.EmailFooterHtml;
                email.Model.EmailFooterText = email.EmailFooterText;
                email.From = "*****@*****.**";
                if (email != null)
                {
                    email.SendMe();
                }
                return(true);
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Error("WatchDog Notification error", e);
                return(false);
            }
        }
Пример #2
0
            private static bool _processIndividualWD(WatchDogProcessor wd2, string date, string order,
                                                     string specificemail, bool forceSend, bool debug = false)
            {
                HlidacStatu.Util.Consts.Logger.Debug($"Processing specific watchdog ({wd2.OrigWD.dataType}) id {wd2.OrigWD.Id}, date {date?.ToString() ?? "current"}");
                WatchDogProcessor.Result res = null;
                try
                {
                    if (!string.IsNullOrWhiteSpace(date))
                    {
                        res = wd2.DoSearch(date, order);
                        if (debug)
                        {
                            System.IO.File.AppendAllText(
                                @"c:\!\wd.debug.txt",
                                $"{wd2.OrigWD.Id}\t{res.Total}\t{res.IsValid}\t{res.RawQuery}\n"
                                );
                            return(false);
                        }
                    }
                    else if (wd2.ReadyToRun() || forceSend || debug)
                    {
                        res = wd2.DoSearch(order);
                        if (debug)
                        {
                            System.IO.File.AppendAllText(
                                @"c:\!\wd.debug.txt",
                                $"{wd2.OrigWD.Id}\t{res.Total}\t{res.IsValid}\t{res.RawQuery}\n"
                                );
                            return(false);
                        }
                    }
                }
                catch (Exception e)
                {
                    //wd2.OrigWD.DisableWDBySystem(DisabledBySystemReasons.InvalidQuery);
                    HlidacStatu.Util.Consts.Logger.Warning($"Watchdog search error, watchdog ({wd2.OrigWD.dataType}) id {wd2.OrigWD.Id}, date {date?.ToString() ?? "current"}", e);
                }

                if (res != null)
                {
                    if (res.IsValid == false)
                    {
                        //log += "INVALID QUERY: " + res?.RawQuery ?? "null";
                    }
                    else if (res.Results.Count() > 0)
                    {
                        //create email
                        return(wd2.SendNotification(res, specificemail));
                    }
                    else if (res.Total == 0 && wd2.OrigWD.StatusId == 2) //send always, included no results
                    {
                        return(wd2.SendNotification(res, specificemail));
                    }
                }
                return(false);
            }
Пример #3
0
 protected override string HtmlNotificationTemplate(WatchDogProcessor.Result res)
 {
     if (res.Total == 0)
     {
         return("NotFoundZakazkyMarkdownPost");
     }
     else
     {
         return("FoundZakazkyMarkdownPost");
     }
 }
Пример #4
0
 public virtual string GetHtmlNotificationContent(WatchDogProcessor.Result res)
 {
     try
     {
         var email = CreateNotificationEmail(HtmlNotificationTemplate(res), res, null, 12);
         var s     = email.RenderHtml();
         return(s);
     }
     catch (Exception e)
     {
         HlidacStatu.Util.Consts.Logger.Error("WatchDog Notification error", e);
         return(string.Empty);
     }
 }
Пример #5
0
        public virtual bool SendPlatformaTopicAnswer(int topicId, WatchDogProcessor.Result res, int maxCount = 10)
        {
            try
            {
                var s   = this.GetHtmlNotificationContent(res);
                var dis = new Lib.Data.External.Discourse();
                var ok  = dis.PostToTopic(topicId, s);
                if (res.Total > 0)
                {
                    this.OrigWD.LastSent = this.OrigWD.LastSearched;
                }

                return(true);
            }
            catch (Exception e)
            {
                HlidacStatu.Util.Consts.Logger.Error("WatchDog Notification error", e);
                return(false);
            }
        }
Пример #6
0
 protected override string EmailNotificationTemplate(WatchDogProcessor.Result res)
 {
     return("FoundZakazky");
 }
Пример #7
0
        protected override Lib.Emails.EmailMsg CreateNotificationEmail(string template, WatchDogProcessor.Result res, string toEmail = null, int maxCount = int.MaxValue)
        {
            var email = Emails.EmailMsg.CreateEmailMsgFromPostalTemplate(template);

            email.To = toEmail ?? "*****@*****.**";

            email.Model.WDName        = this.OrigWD.Name;
            email.Model.Interval      = GetIntervalString(res);
            email.Model.Total         = res.Total;
            email.Model.TotalTxt      = HlidacStatu.Util.PluralForm.Get((int)res.Total, "přibyla {0} zakázka;přibyly {0} zakázky;přibylo {0} zakázek", HlidacStatu.Util.Consts.czCulture);
            email.Model.Query         = this.OrigWD.SearchTerm;
            email.Model.SpecificQuery = res.RawQuery;
            email.Model.AddResults    = res.Results.Count() > maxCount?res.Results.Count() - maxCount : 0;

            email.Model.Zakazky = res.Results.Cast <VZ.VerejnaZakazka>()
                                  .OrderByDescending(o => Math.Max(o.OdhadovanaHodnotaBezDPH ?? 0, o.KonecnaHodnotaBezDPH ?? 0))
                                  .Take(maxCount)
                                  .ToList();

            return(email);
        }
Пример #8
0
 protected override string HtmlNotificationTemplate(WatchDogProcessor.Result res)
 {
     return("FoundInsolvence");
 }
Пример #9
0
 protected abstract Lib.Emails.EmailMsg CreateNotificationEmail(string template, WatchDogProcessor.Result res, string toEmail = null, int maxCount = int.MaxValue);
Пример #10
0
 protected abstract string HtmlNotificationTemplate(WatchDogProcessor.Result res);
Пример #11
0
        public bool SendNotification(WatchDogProcessor.Result result, string specificContact = null)
        {
            string contact = specificContact;

            if (string.IsNullOrEmpty(contact))
            {
                if (!string.IsNullOrEmpty(this.OrigWD.SpecificContact))
                {
                    contact = this.OrigWD.SpecificContact;
                }
                else
                {
                    contact = this.OrigWD.User().Email;
                }
            }

            HlidacStatu.Util.Consts.Logger.Debug($"Processing specific watchdog id {this.OrigWD.Id} ({this.OrigWD.dataType}) SENDING to contact {contact}.");
            if (Devmasters.Core.TextUtil.IsValidEmail(contact))
            {
                return(SendEmailNotification(contact, result));
            }

            if (contact == "HTTPPOSTBACK")
            {
                // https://daxiel.solcloud.cz/api/match

                /*
                 * {
                 * “id”:” id je ID hlidace ve vasem systemu”,
                 * “found”:[{ExportedVZ}, {ExportedVZ
                 * }]
                 * }
                 * kde ExportedVZ je datova struktura zakazky(viz dale)
                 */
                if (result.dataType == typeof(VZ.VerejnaZakazka).Name.ToLower())
                {
                    var jsonResult = new
                    {
                        id    = this.OrigWD.Name.Replace(APIID_Prefix, ""),
                        found = result.Results
                                .Cast <VZ.VerejnaZakazka>()
                                .Take(400)
                                .Select(m => m.Export())
                                .ToArray()
                    };

                    try
                    {
                        using (Devmasters.Net.Web.URLContent net = new Devmasters.Net.Web.URLContent("https://daxiel.solcloud.cz/api/match"))
                        {
                            net.Tries = 5;
                            net.TimeInMsBetweenTries = 2000;
                            net.Timeout = 30000;
                            net.Method  = Devmasters.Net.Web.MethodEnum.POST;
                            net.RequestParams.RawContent = Newtonsoft.Json.JsonConvert.SerializeObject(jsonResult);
                            net.ContentType = "application/json; charset=utf-8";
                            var apires = net.GetContent();
                        }
                    }
                    catch (Exception ex)
                    {
                        HlidacStatu.Util.Consts.Logger.Error("sending data to Solidis error", ex);
                        throw;
                    }
                }
            }

            var platformaTopicId = HlidacStatu.Util.ParseTools.GetRegexGroupValue(contact, @"(platforma\((?<platforma>\d*)\))", "platforma");

            if (Devmasters.Core.TextUtil.IsNumeric(platformaTopicId))
            {
                return(SendPlatformaTopicAnswer(Convert.ToInt32(platformaTopicId), result));
            }

            var twitterCred = HlidacStatu.Util.ParseTools.GetRegexGroupValue(contact, @"^twitter\(\s*(?<json>{ .* })\s* \)", "json");

            if (!string.IsNullOrEmpty(twitterCred))
            {
                //return SendTwitter(twitterCred, result);
            }


            return(false);
        }
Пример #12
0
        protected override Lib.Emails.EmailMsg CreateNotificationEmail(string template, WatchDogProcessor.Result res, string toEmail = null, int maxCount = int.MaxValue)
        {
            Lib.Emails.EmailMsg email;
            if (this.OrigWD.Focus == WatchDog.FocusType.Search)
            {
                email = Emails.EmailMsg.CreateEmailMsgFromPostalTemplate("FoundContracts");
            }
            else
            {
                email    = Emails.EmailMsg.CreateEmailMsgFromPostalTemplate("FoundContractsIssues");
                maxCount = 999;
            }

            IEnumerable <Smlouva> smlRes = res.Results.Cast <Smlouva>();

            email.To                  = toEmail;
            email.Model.WDName        = this.OrigWD.Name;
            email.Model.Interval      = GetIntervalString(res);
            email.Model.Total         = res.Total;
            email.Model.TotalTxt      = HlidacStatu.Util.PluralForm.Get((int)res.Total, "přibyla do Registru smluv {0} smlouva;přibyly do Registru smluv {0} smlouvy;přibylo do Registru smluv {0} smluv", HlidacStatu.Util.Consts.czCulture);
            email.Model.Query         = this.OrigWD.SearchTerm;
            email.Model.SpecificQuery = res.RawQuery;
            email.Model.AddResults    = res.Results.Count() > maxCount?res.Results.Count() - maxCount : 0;

            email.Model.Smlouvy = smlRes
                                  .OrderByDescending(h => this.OrigWD.Focus == WatchDog.FocusType.Search ? h.CalculatedPriceWithVATinCZK : h.ConfidenceValue)
                                  .Take(maxCount)
                                  .Select(m => new HlidacStatu.Lib.Emails.Templates.FoundContractItem()
            {
                PlatceTxt    = m.Platce.nazev,
                PlatceHtml   = string.Format("<a href=\"{0}\">{1}</a>", "https://www.hlidacstatu.cz/subjekt/" + m.Platce.ico, m.Platce.nazev),
                PrijemceTxt  = m.Prijemce.Select(f => f.nazev).Aggregate((f, s) => f + ", " + s),
                PrijemceHtml = m.Prijemce.Select(f => string.Format("<a href=\"{0}\">{1}</a>", "https://www.hlidacstatu.cz/subjekt/" + f.ico, f.nazev)).Aggregate((f, s) => f + "<br/>" + s),
                Cena         = HlidacStatu.Lib.Data.Smlouva.NicePrice(m.CalculatedPriceWithVATinCZK, html: true),
                Predmet      = m.predmet,
                Id           = m.Id,
                Issues       = m.Issues
                               .Where(i => i.Importance > Issues.ImportanceLevel.Ok)
                               .Select(i => string.Format("{0}: {1}; {2}", i.Importance.ToNiceDisplayName(), i.Title, i.TextDescription))
                               .ToArray()
            })
                                  .ToList();

            return(email);
        }
Пример #13
0
 protected override string HtmlNotificationTemplate(WatchDogProcessor.Result res)
 {
     return("FoundContracts");
 }