Exemple #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());
     }
 }
Exemple #2
0
        public async static void SendThreadMessage(List <DataRow> dt, IList <Attachment> items)
        {
            string uzytkownik   = "";
            Int64  uzytkownikId = 0;

            try
            {
                List <DataRow> drDrugaProba   = new List <DataRow>();
                List <DataRow> drtrzeciaProba = new List <DataRow>();



                if (items.Count > 0)
                {
                    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        = "Piłka nożna",
                                payload      = "DEVELOPER_DEFINED_PAYLOAD_Pilka_Nozna",
                                //     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        = "Siatkówka",
                                payload      = "DEVELOPER_DEFINED_PAYLOAD_Siatkowka",
                                //             image_url = "https://gim7bytom.edupage.org/global/pics/iconspro/sport/volleyball.png"
                            }, new
                            {
                                content_type = "text",
                                title        = "Hokej",
                                payload      = "DEVELOPER_DEFINED_PAYLOAD_Hokej",
                                //       image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Green%20Ball.png"
                            },
                        }
                    });

                    message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    message.Attachments      = items;
                    foreach (DataRow dr in dt)
                    {
                        try
                        {
                            var userAccount = new ChannelAccount(name: dr["UserName"].ToString(), id: dr["UserId"].ToString());
                            uzytkownik   = userAccount.Name;
                            uzytkownikId = Convert.ToInt64(userAccount.Id);
                            var botAccount     = new ChannelAccount(name: dr["BotName"].ToString(), id: dr["BotId"].ToString());
                            var connector      = new ConnectorClient(new Uri(dr["Url"].ToString()), "73267226-823f-46b0-8303-2e866165a3b2", "k6XBDCgzL5452YDhS3PPLsL");
                            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());
                            drDrugaProba.Add(dr);
                        }
                    }
                    foreach (DataRow dr in drDrugaProba)
                    {
                        try
                        {
                            var userAccount = new ChannelAccount(name: dr["UserName"].ToString(), id: dr["UserId"].ToString());
                            uzytkownik   = userAccount.Name;
                            uzytkownikId = Convert.ToInt64(userAccount.Id);
                            var botAccount     = new ChannelAccount(name: dr["BotName"].ToString(), id: dr["BotId"].ToString());
                            var connector      = new ConnectorClient(new Uri(dr["Url"].ToString()), "73267226-823f-46b0-8303-2e866165a3b2", "k6XBDCgzL5452YDhS3PPLsL");
                            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(true);
                        }
                        catch (Exception ex)
                        {
                            //BaseDB.AddToLog("Błąd wysyłania wiadomości do: " + uzytkownik + " " + ex.ToString());
                            drtrzeciaProba.Add(dr);
                        }
                    }
                    foreach (DataRow dr in drtrzeciaProba)
                    {
                        try
                        {
                            var userAccount = new ChannelAccount(name: dr["UserName"].ToString(), id: dr["UserId"].ToString());
                            uzytkownik   = userAccount.Name;
                            uzytkownikId = Convert.ToInt64(userAccount.Id);
                            var botAccount     = new ChannelAccount(name: dr["BotName"].ToString(), id: dr["BotId"].ToString());
                            var connector      = new ConnectorClient(new Uri(dr["Url"].ToString()), "73267226-823f-46b0-8303-2e866165a3b2", "k6XBDCgzL5452YDhS3PPLsL");
                            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(true);
                        }
                        catch (Exception ex)
                        {
                            //  BaseDB.AddToLog("Błąd wysyłania wiadomości (próba trzecia) do: " + uzytkownik + " " + ex.Message.ToString());
                            BaseDB.ChangeNotification(uzytkownikId.ToString(), 5);
                        }
                    }
                    //  BaseDB.AddToLog("Zakończenie wątku ");
                }
            }
            catch (Exception ex)
            {
                BaseDB.AddToLog("Błąd wysłania wiadomosci do " + uzytkownik + " " + ex.Message.ToString());
            }
        }
        public async static void SendThreadMessage(DataRow dr, DataTable dtWiadomosci, IList <Attachment> items)
        {
            try
            {
                //   BaseDB.AddToLog("Wywołanie metody SendThreadMessage");



                string uzytkownik = "";

                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        = "Aktualności",
                                    payload      = "DEVELOPER_DEFINED_PAYLOAD_Aktualnosci",
                                    //     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 = "Galeria",
                                //     payload = "DEVELOPER_DEFINED_PAYLOAD_Galeria",
                                ////       image_url = "https://gim7bytom.edupage.org/global/pics/iconspro/sport/volleyball.png"
                                // },
                                new
                                {
                                    content_type = "text",
                                    title        = "Sklep",
                                    payload      = "DEVELOPER_DEFINED_PAYLOAD_Sklep",
                                    //       image_url = "https://gim7bytom.edupage.org/global/pics/iconspro/sport/volleyball.png"
                                },
                                new
                                {
                                    content_type = "text",
                                    title        = "Video",
                                    payload      = "DEVELOPER_DEFINED_PAYLOAD_Video",
                                    //       image_url = "https://www.samo-lepky.sk/data/11/hokej5.png"
                                },
                            }
                        });

                        message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                        message.Attachments      = items;
                        try
                        {
                            var userAccount = new ChannelAccount(name: dr["UserName"].ToString(), id: dr["UserId"].ToString());
                            uzytkownik = userAccount.Name;
                            var botAccount     = new ChannelAccount(name: dr["BotName"].ToString(), id: dr["BotId"].ToString());
                            var connector      = new ConnectorClient(new Uri(dr["Url"].ToString()), "8fa14720-e758-4cc7-82fd-fd6ad145ec90", "oExpuWnvj4oDAQnYHSpVrCJ");
                            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());
            }
        }
Exemple #4
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());
            }
        }
Exemple #5
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());
            }
        }
Exemple #6
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
            {
            }
        }