Esempio n. 1
0
 public async static void AktualizujWiadomosci()
 {
     try
     {
         BaseGETMethod.GetCardsAttachmentsNajwazniejsze();
         BaseGETMethod.GetCardsAttachmentsPopularne();
         BaseGETMethod.GetCardsAttachmentsNajnowsze();
     }
     catch (Exception ex)
     {
         BaseDB.AddToLog("Błąd pobierania wiadomosci: " + ex.ToString());
     }
 }
        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            if (DateTime.UtcNow.Hour == 15 && (DateTime.UtcNow.Minute > 0 && DateTime.UtcNow.Minute <= 3))
            {
                DataTable dtWiadomosci = Helpers.BaseDB.GetWiadomosci();
                DataTable dt           = Helpers.BaseGETMethod.GetUser();
                List <IGrouping <string, string> > hrefList = new List <IGrouping <string, string> >();
                var items = BaseGETMethod.GetCardsAttachmentsAktualnosci(ref hrefList, false, dtWiadomosci);
                if (items == null)
                {
                    Thread.Sleep(5000);
                    items = BaseGETMethod.GetCardsAttachmentsAktualnosci(ref hrefList, false, dtWiadomosci);
                }
                foreach (DataRow dr in dt.Rows)
                {
                    Task.Run(() => Controllers.ThreadClass.SendThreadMessage(dr, dtWiadomosci, items));
                }

                hrefList = new List <IGrouping <string, string> >();
                Helpers.BaseGETMethod.GetCardsAttachmentsAktualnosci(ref hrefList, false, dtWiadomosci);
                Helpers.BaseDB.AddWiadomosc(hrefList);
            }
        }
Esempio n. 3
0
        public async static void SendThreadMessage()
        {
            try
            {
                if (DateTime.UtcNow.Hour == 20 && (DateTime.UtcNow.Minute > 0 && DateTime.UtcNow.Minute <= 3))
                {
                    BaseDB.AddToLog("Wywołanie metody SendThreadMessage");

                    List <IGrouping <string, string> > hrefList  = new List <IGrouping <string, string> >();
                    List <IGrouping <string, string> > hrefList2 = new List <IGrouping <string, string> >();
                    List <IGrouping <string, string> > hreflist3 = new List <IGrouping <string, string> >();
                    List <IGrouping <string, string> > hreflist4 = new List <IGrouping <string, string> >();
                    var items = BaseGETMethod.GetCardsAttachmentsAktualnosci(ref hrefList, true);
                    hreflist3 = hrefList;


                    string    uzytkownik = "";
                    DataTable dt         = BaseGETMethod.GetUser();

                    if (items.Count > 0)
                    {
                        try
                        {
                            MicrosoftAppCredentials.TrustServiceUrl(@"https://facebook.botframework.com", DateTime.MaxValue);


                            IMessageActivity message = Activity.CreateMessageActivity();
                            message.ChannelData = JObject.FromObject(new
                            {
                                notification_type = "REGULAR",
                                quick_replies     = new dynamic[]
                                {
                                    new
                                    {
                                        content_type = "text",
                                        title        = "Najważniejsze",
                                        payload      = "DEVELOPER_DEFINED_PAYLOAD_Najwazniejsze",
                                        //     image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Green%20Ball.png"
                                        //        image_url = "http://archiwum.koluszki.pl/zdjecia/naglowki_nowe/listopad%202013/pi%C5%82ka[1].png"
                                    },
                                    new
                                    {
                                        content_type = "text",
                                        title        = "Najnowsze",
                                        payload      = "DEVELOPER_DEFINED_PAYLOAD_Najnowsze",
                                        //             image_url = "https://gim7bytom.edupage.org/global/pics/iconspro/sport/volleyball.png"
                                    }, new
                                    {
                                        content_type = "text",
                                        title        = "Popularne",
                                        payload      = "DEVELOPER_DEFINED_PAYLOAD_Popularne",
                                        //       image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Green%20Ball.png"
                                    },
                                }
                            });

                            message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                            message.Attachments      = items;
                            message.Text             = "Podsumowanie dnia";
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                try
                                {
                                    var userAccount = new ChannelAccount(name: dt.Rows[i]["UserName"].ToString(), id: dt.Rows[i]["UserId"].ToString());
                                    uzytkownik = userAccount.Name;
                                    var botAccount     = new ChannelAccount(name: dt.Rows[i]["BotName"].ToString(), id: dt.Rows[i]["BotId"].ToString());
                                    var connector      = new ConnectorClient(new Uri(dt.Rows[i]["Url"].ToString()), "31a42302-5d77-403b-8636-de8bf91274e6", "aqiePPBrh9fc0YtetVmiojB");
                                    var conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);

                                    message.From         = botAccount;
                                    message.Recipient    = userAccount;
                                    message.Conversation = new ConversationAccount(id: conversationId.Id, isGroup: false);
                                    await connector.Conversations.SendToConversationAsync((Activity)message).ConfigureAwait(false);
                                }
                                catch (Exception ex)
                                {
                                    BaseDB.AddToLog("Błąd wysyłania wiadomości do: " + uzytkownik + " " + ex.ToString());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            BaseDB.AddToLog("Błąd wysyłania wiadomości do: " + uzytkownik + " " + ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                BaseDB.AddToLog("Błąd wysłania wiadomosci: " + ex.ToString());
            }
        }
Esempio n. 4
0
        public async static void SendThreadMessage()
        {
            try
            {
                if (DateTime.UtcNow.Hour == 12 && (DateTime.UtcNow.Minute > 0 && DateTime.UtcNow.Minute <= 3))
                {
                    BaseDB.AddToLog("Wywołanie metody SendThreadMessage");

                    List <IGrouping <string, string> > hrefList  = new List <IGrouping <string, string> >();
                    List <IGrouping <string, string> > hrefList2 = new List <IGrouping <string, string> >();
                    List <IGrouping <string, string> > hreflist3 = new List <IGrouping <string, string> >();
                    List <IGrouping <string, string> > hreflist4 = new List <IGrouping <string, string> >();
                    var items = BaseGETMethod.GetCardsAttachmentsWydarzenia(ref hrefList);
                    hreflist3 = hrefList;
                    // var items2 = BaseGETMethod.GetCardsAttachmentsWydarzenia(ref hrefList2);

                    var items3 = new List <Attachment>();


                    string    uzytkownik = "";
                    DataTable dt         = BaseGETMethod.GetUser();

                    if (items.Count > 0)
                    {
                        try
                        {
                            MicrosoftAppCredentials.TrustServiceUrl(@"https://facebook.botframework.com", DateTime.MaxValue);

                            IMessageActivity message = Activity.CreateMessageActivity();
                            message.ChannelData = JObject.FromObject(new
                            {
                                notification_type = "REGULAR",

                                quick_replies = new dynamic[]
                                {
                                    new
                                    {
                                        content_type = "text",
                                        title        = "Dzisiaj",
                                        payload      = "DEVELOPER_DEFINED_PAYLOAD_WydarzeniaDzisiaj",
                                        //     image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Green%20Ball.png"
                                        //        image_url = "http://archiwum.koluszki.pl/zdjecia/naglowki_nowe/listopad%202013/pi%C5%82ka[1].png"
                                    },
                                    new
                                    {
                                        content_type = "text",
                                        title        = "W weekend",
                                        payload      = "DEVELOPER_DEFINED_PAYLOAD_WydarzeniaWeekend",
                                        //             image_url = "https://gim7bytom.edupage.org/global/pics/iconspro/sport/volleyball.png"
                                    },
                                    new
                                    {
                                        content_type = "text",
                                        title        = "Inny termin",
                                        payload      = "DEVELOPER_DEFINED_PAYLOAD_WydarzeniaPozostale",
                                        //             image_url = "https://gim7bytom.edupage.org/global/pics/iconspro/sport/volleyball.png"
                                    },
                                }
                            });

                            message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                            message.Attachments      = items;
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                try
                                {
                                    var userAccount = new ChannelAccount(name: dt.Rows[i]["UserName"].ToString(), id: dt.Rows[i]["UserId"].ToString());
                                    uzytkownik = userAccount.Name;
                                    var botAccount     = new ChannelAccount(name: dt.Rows[i]["BotName"].ToString(), id: dt.Rows[i]["BotId"].ToString());
                                    var connector      = new ConnectorClient(new Uri(dt.Rows[i]["Url"].ToString()), "7dba3148-9e01-41c6-af1a-846d99571099", "bUBfkobEieMZq54jonzMane");
                                    var conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);

                                    message.From         = botAccount;
                                    message.Recipient    = userAccount;
                                    message.Conversation = new ConversationAccount(id: conversationId.Id, isGroup: false);
                                    await connector.Conversations.SendToConversationAsync((Activity)message).ConfigureAwait(false);
                                }
                                catch (Exception ex)
                                {
                                    BaseDB.AddToLog("Błąd wysyłania wiadomości do: " + uzytkownik + " " + ex.ToString());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            BaseDB.AddToLog("Błąd wysyłania wiadomości do: " + uzytkownik + " " + ex.ToString());
                        }


                        BaseDB.AddWiadomosci(hrefList);
                        //BaseDB.AddWiadomoscSiatka(hrefList2);
                        //BaseDB.AddWiadomoscHokej(hreflist4);
                    }
                }
            }
            catch (Exception ex)
            {
                BaseDB.AddToLog("Błąd wysłania wiadomosci: " + ex.ToString());
            }
        }
Esempio n. 5
0
        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            if (DateTime.UtcNow.Hour == 16 && (DateTime.UtcNow.Minute > 0 && DateTime.UtcNow.Minute <= 3))
            {
                Helpers.BaseDB.AddToLog("Wywołanie metody SendThreadMessage");

                DataTable dt = new DataTable();

                if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                {
                    dt = BaseGETMethod.GetUser(3);
                }
                else if (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday || DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                {
                    dt = BaseGETMethod.GetUser(2);
                }
                else
                {
                    dt = BaseGETMethod.GetUser(1);
                }

                Helpers.BaseDB.AddToLog("Liczba pobranych użytkowników do wysłania: " + dt.Rows.Count);

                List <IGrouping <string, string> > hrefList  = new List <IGrouping <string, string> >();
                List <IGrouping <string, string> > hrefList2 = new List <IGrouping <string, string> >();
                List <IGrouping <string, string> > hreflist3 = new List <IGrouping <string, string> >();
                List <IGrouping <string, string> > hreflist4 = new List <IGrouping <string, string> >();
                var items = BaseGETMethod.GetCardsAttachments(ref hrefList);
                hreflist3 = hrefList;
                var items2 = BaseGETMethod.GetCardsAttachmentsOrlenLiga(ref hrefList2);
                var items4 = BaseGETMethod.GetCardsAttachmentsHokej(ref hreflist4);

                var items3 = new List <Attachment>();

                //if(items.Count>0)
                //{
                //    items3.Add(items[0]);
                //}

                if (items.Count > 0)
                {
                    items3.Add(items[0]);
                }
                if (items2.Count > 0)
                {
                    items3.Add(items2[0]);
                }
                if (items4.Count > 0)
                {
                    items3.Add(items4[0]);
                }

                if (items3.Count < 3)
                {
                    if (items.Count >= 2)
                    {
                        if (items3.Count == 2)
                        {
                            items3.Insert(1, items[1]);
                        }
                        else if (items3.Count == 1)
                        {
                            items3.Add(items[1]);
                            if (items.Count == 3)
                            {
                                items3.Add(items[2]);
                            }
                        }
                    }
                    else if (items2.Count >= 2)
                    {
                        items3.Add(items2[1]);
                    }
                }

                items = items3;

                int i = 0;
                while (i <= dt.Rows.Count)
                {
                    var listaUzytkownikow = dt.AsEnumerable().Skip(i).Take(50).ToList();
                    Controllers.ThreadClass.SendThreadMessage(listaUzytkownikow, items);
                    i += 50;
                    Thread.Sleep(1000);
                }
                BaseDB.AddToLog("Wysyłanie zostało zakończone");
                BaseDB.AddWiadomoscPilka(hreflist3);
                BaseDB.AddWiadomoscSiatka(hrefList2);
                BaseDB.AddWiadomoscHokej(hreflist4);
            }
            else
            {
            }
        }