Esempio n. 1
0
        public LoginPG()
        {
            InitializeComponent();
            var facebookQ = db.ExecuteQuery <string>("SELECT AToken FROM dbo.Face");
            var twitQ     = db.ExecuteQuery <string>("SELECT AToken FROM dbo.Twitter");

            if (facebookQ.Count() == 0)
            {
                fbClass.Login();
            }
            isAuth = !(twitQ.Count() <= 0);
            if (isAuth)
            {
                TwitterPB.IsEnabled = false;
            }
            else
            {
                temp = new Twit();
            }
        }
Esempio n. 2
0
        private void SendMSGBTN_Click(object sender, RoutedEventArgs e)
        {
            //Finds the items checked in the combo boxes
            List <string> SendingEmailAccounts   = new List <string>();
            List <string> SendingFBAccounts      = new List <string>();
            List <string> SendingTwitterAccounts = new List <string>();

            foreach (MenuItem item in EMailAccounts.Items)
            {
                if (item.IsChecked)
                {
                    SendingEmailAccounts.Add(item.Header.ToString());
                }
            }

            foreach (MenuItem item in FacebookAccounts.Items)
            {
                if (item.IsChecked)
                {
                    SendingFBAccounts.Add(item.Header.ToString());
                }
            }

            foreach (MenuItem item in TwitterAccounts.Items)
            {
                if (item.IsChecked)
                {
                    SendingTwitterAccounts.Add(item.Header.ToString());
                }
            }

            string message        = EventText.Text;
            string twitterMessage = TwitterText.Text;

            //string postSuc = "";
            // Facebook Posting Logic --------------------------------------------------------------------------------------------------------------
            if (lblPhotoSelected.Visibility == Visibility.Visible)
            {
                photoSelected = true;
            }
            else
            {
                photoSelected = false;
            }

            bool postSuccess = true;

            //The following nested loop is supposed to check and make sure the items checked in the combo boxes match any of the accounts listed in the
            //database.
            foreach (FacebookLogic item in fbClass)
            {
                if (SendingFBAccounts.Contains(item.getUserName()))
                {
                    postSuccess = item.postClick(message, photoSelected, photoPath);
                }
                if (!postSuccess)
                {
                    MessageBox.Show("Facebook failed to post", "facebopk failure", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }


            // --------------------------------------------------------------------------------------------------------------------------------------


            //twitter posting logic------------------------------
            bool tSuc = true;

            foreach (Twit item in twitter)
            {
                if (SendingTwitterAccounts.Contains(item.getUserHandle()))
                {
                    if (photoPath == null || photoPath.Length <= 0)//no picture
                    {
                        tSuc = item.post(twitterMessage);
                    }
                    else//1 picture
                    {
                        tSuc = item.post(twitterMessage, photoPath);
                    }
                    if (!tSuc)
                    {
                        MessageBox.Show("Twitter failed to post", "twitter failure", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }

            //--------------------------------------------

            // Email Posting Logic
            Sub = "West Chest Community Foundation E-Blast";
            foreach (var item in gMail)
            {
                if (SendingEmailAccounts.Contains(item.User))
                {
                    var client = new SmtpClient("smtp.gmail.com", 587);
                    client.EnableSsl             = true;
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new NetworkCredential(item.User, item.Password);
                    try
                    {
                        // Create instance of message
                        MailMessage emailMessage      = new MailMessage();
                        var         emailSendingQuery = db.ExecuteQuery <string>("SELECT EmailAddress FROM dbo.Email");
                        foreach (var temp in emailSendingQuery)
                        {
                            emailMessage.Bcc.Add(temp);
                        }

                        //Word docs end with .Docx    Excel with .xlsx   Pdf with .pdf   Powerpoint with .pptx   images with appropiate file typ, .jpg, .png, etc.
                        //message.Attachments.Add(new Attachment(@"M:\EmailTester.Docx"));

                        // Set sender
                        emailMessage.From = new MailAddress(item.User);
                        // Set subject
                        emailMessage.Subject = Sub;
                        //// Set body of message
                        emailMessage.Body = message;
                        // Send the message
                        client.Send(emailMessage);
                    }
                    catch (Exception ex)
                    {
                        StreamWriter w = new StreamWriter("errorLog.txt");
                        w.Write(ex.Message + "\n" + "Email" + DateTime.Now + "\n\n");
                        w.Close();
                        MessageBox.Show("Email failed to send.", "Email failed", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }

            //Displays results-----------------------------------------------------------
            if (tSuc && postSuccess)
            {
                MessageBox.Show("Both Twitter and Facebook posted successfully",
                                "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }