コード例 #1
0
ファイル: util.cs プロジェクト: damccull/MyFlightbookWeb
        /// <summary>
        /// Notify the user of an event, optionally Bcc admins.
        /// </summary>
        /// <param name="szSubject">The subject to send</param>
        /// <param name="szMessage">The message to send  This will be rebranded per Branding.ReBrand().</param>
        /// <param name="maUser">The address of the recipient</param>
        /// <param name="fCcAdmins">True if you want Admins CC'd; false if not</param>
        /// <param name="fIsHTML">True if the content of the message is HTML</param>
        /// <param name="brand">The branding to use</param>
        /// <param name="RoleMask">The roles to whom this should go (if admin)</param>
        static private void NotifyUser(string szSubject, string szMessage, MailAddress maUser, bool fCcAdmins, bool fIsHTML, Brand brand, uint RoleMask)
        {
            try
            {
                if (brand == null)
                {
                    brand = Branding.CurrentBrand;
                }

                using (MailMessage msg = new MailMessage())
                {
                    msg.Subject    = szSubject;
                    msg.Body       = Branding.ReBrand(szMessage, brand);
                    msg.IsBodyHtml = fIsHTML || szMessage.Contains("<!DOCTYPE");

                    msg.From = new MailAddress(brand.EmailAddress, brand.AppName);

                    if (maUser != null)
                    {
                        msg.To.Add(maUser);
                    }

                    if (fCcAdmins)
                    {
                        AddAdminsToMessage(msg, (maUser == null), RoleMask);
                    }

                    SendMessage(msg);
                }
            }
            catch (ArgumentNullException ex)
            {
                MyFlightbookException mfbEx = new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, "Null Argument in NotifyUser: {0}", ex.ParamName), ex);
                MyFlightbookException.NotifyAdminException(mfbEx);
            }
            catch (InvalidOperationException ex)
            {
                MyFlightbookException mfbEx = new MyFlightbookException("Invalid Operation in NotifyUser", ex);
                MyFlightbookException.NotifyAdminException(mfbEx);
            }
            catch (System.Net.Mail.SmtpException)
            {
                // Don't re-throw or do anything that would cause new mail to be sent because that could loop.  Just fail silently and eat this.
            }
        }
コード例 #2
0
ファイル: util.cs プロジェクト: ericberman/MyFlightbookWeb
        /// <summary>
        /// Notify the user of an event, optionally Bcc admins.
        /// </summary>
        /// <param name="szSubject">The subject to send</param>
        /// <param name="szMessage">The message to send  This will be rebranded per Branding.ReBrand().</param>
        /// <param name="maUser">The address of the recipient</param>
        /// <param name="fCcAdmins">True if you want Admins CC'd; false if not</param>
        /// <param name="fIsHTML">True if the content of the message is HTML</param>
        /// <param name="brand">The branding to use</param>
        /// <param name="RoleMask">The roles to whom this should go (if admin)</param>
        static private void NotifyUser(string szSubject, string szMessage, MailAddress maUser, bool fCcAdmins, bool fIsHTML, Brand brand, uint RoleMask)
        {
            if (brand == null)
            {
                brand = Branding.CurrentBrand;
            }

            if (szMessage == null)
            {
                throw new ArgumentNullException(nameof(szMessage));
            }

            new System.Threading.Thread(() =>
            {
                try
                {
                    using (MailMessage msg = new MailMessage())
                    {
                        msg.Subject    = szSubject;
                        msg.Body       = Branding.ReBrand(szMessage, brand);
                        msg.IsBodyHtml = fIsHTML || szMessage.Contains("<!DOCTYPE");

                        msg.From = new MailAddress(brand.EmailAddress, brand.AppName);

                        if (maUser != null)
                        {
                            msg.To.Add(maUser);
                        }

                        if (fCcAdmins)
                        {
                            AddAdminsToMessage(msg, (maUser == null), RoleMask);
                        }

                        SendMessage(msg);
                    }
                }
                catch (ArgumentNullException) { }
                catch (InvalidOperationException) { }
                catch (Exception ex) when(ex is SmtpException)
                {
                }
            }).Start();
        }
コード例 #3
0
        protected FAQItem(MySqlDataReader dr) : this()
        {
            if (dr == null)
            {
                throw new ArgumentNullException("dr");
            }
            idFAQ    = Convert.ToInt32(dr["idFAQ"], CultureInfo.InvariantCulture);
            Category = Branding.ReBrand(dr["Category"].ToString());
            Question = Branding.ReBrand(dr["Question"].ToString());
            Answer   = Branding.ReBrand(dr["Answer"].ToString());
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(Answer);
            StringBuilder sb = new StringBuilder();

            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()"))
            {
                sb.Append(node.InnerText);
            }
            AnswerPlainText = sb.ToString();
            IsSelected      = false;
        }
コード例 #4
0
        /// <summary>
        /// Creates/returns a memory stream containing a zip of a) an HTML file of images, and b) the thumbnails of the images, linked to Amazon.
        /// THE STREAM MUST BE CLOSED BY THE CALLER!
        /// </summary>
        /// <param name="activeBrand">The brand to use - null for current brand</param>
        /// <returns>A memory stream of flight images followed by any profile images</returns>
        public MemoryStream ZipOfImagesForUser(Brand activeBrand)
        {
            if (activeBrand == null)
            {
                activeBrand = Branding.CurrentBrand;
            }

            MemoryStream ms = new MemoryStream();

            using (ZipFile zip = new ZipFile())
            {
                System.IO.StringWriter sw = new System.IO.StringWriter();
                HtmlTextWriter         tw = new HtmlTextWriter(sw);

                tw.RenderBeginTag(HtmlTextWriterTag.Html);
                tw.RenderBeginTag(HtmlTextWriterTag.Head);
                tw.AddAttribute("href", Branding.ReBrand("http://%APP_URL%%APP_ROOT%/public/stylesheet.css", activeBrand));
                tw.AddAttribute("rel", "stylesheet");
                tw.AddAttribute("type", "text/css");
                tw.RenderBeginTag(HtmlTextWriterTag.Link);
                tw.RenderEndTag();   // Link
                tw.RenderBeginTag(HtmlTextWriterTag.Title);
                tw.Write(HttpUtility.HtmlEncode(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.ImagesBackupTitle, User.UserFullName)));
                tw.RenderEndTag();   // Head
                tw.RenderBeginTag(HtmlTextWriterTag.Body);

                // Write out profile images
                tw.RenderBeginTag(HtmlTextWriterTag.H1);
                tw.Write(HttpUtility.HtmlEncode(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.ImagesBackupEndorsementsHeader, User.UserFullName)));
                tw.RenderEndTag();  // h1

                ImageList il = new ImageList(MFBImageInfo.ImageClass.Endorsement, User.UserName);
                il.Refresh(true);
                foreach (MFBImageInfo mfbii in il.ImageArray)
                {
                    zip.AddFile(System.Web.Hosting.HostingEnvironment.MapPath(mfbii.PathThumbnail), szThumbFolder);
                    mfbii.ToHtml(tw);
                    mfbii.UnCache();
                }

                // Write out any digital endorsements too
                IEnumerable <Endorsement> rgEndorsements = Endorsement.EndorsementsForUser(User.UserName, null);
                if (rgEndorsements.Count() > 0)
                {
                    Page p = new FormlessPage();
                    p.Controls.Add(new HtmlForm());
                    IEndorsementListUpdate el = (IEndorsementListUpdate)p.LoadControl("~/Controls/mfbEndorsement.ascx");
                    foreach (Endorsement en in rgEndorsements)
                    {
                        el.SetEndorsement(en);
                        try { ((UserControl)el).RenderControl(tw); }
                        catch { }  // don't write bogus or incomplete HTML
                    }
                }

                // And any BasicMed stuff
                IEnumerable <BasicMedEvent> lstBMed = BasicMedEvent.EventsForUser(User.UserName);
                foreach (BasicMedEvent bme in lstBMed)
                {
                    ImageList ilBasicMed = new ImageList(MFBImageInfo.ImageClass.BasicMed, bme.ImageKey);
                    ilBasicMed.Refresh(true);
                    foreach (MFBImageInfo mfbii in ilBasicMed.ImageArray)
                    {
                        zip.AddFile(System.Web.Hosting.HostingEnvironment.MapPath(mfbii.PathThumbnail), szThumbFolder);
                        mfbii.ToHtml(tw);
                        mfbii.UnCache();
                    }
                }

                // Write out flight images
                tw.RenderBeginTag(HtmlTextWriterTag.H1);
                tw.Write(HttpUtility.HtmlEncode(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.ImagesBackupFlightsHeader, User.UserFullName)));
                tw.RenderEndTag();  // H1

                // We'll get images from the DB rather than slamming the disk
                // this is a bit of a hack, but limits our queries
                const string szQ       = @"SELECT f.idflight, img.*
            FROM Images img INNER JOIN flights f ON f.idflight=img.ImageKey
            WHERE f.username=?user AND img.VirtPathID=0
            ORDER BY f.Date desc, f.idFlight desc";
                DBHelper     dbhImages = new DBHelper(szQ);
                Dictionary <int, List <MFBImageInfo> > dImages = new Dictionary <int, List <MFBImageInfo> >();
                dbhImages.ReadRows((comm) => { comm.Parameters.AddWithValue("user", User.UserName); },
                                   (dr) =>
                {
                    int idFlight = Convert.ToInt32(dr["idflight"], CultureInfo.InvariantCulture);
                    List <MFBImageInfo> lstMFBii;
                    if (dImages.ContainsKey(idFlight))
                    {
                        lstMFBii = dImages[idFlight];
                    }
                    else
                    {
                        dImages[idFlight] = lstMFBii = new List <MFBImageInfo>();
                    }
                    lstMFBii.Add(MFBImageInfo.ImageFromDBRow(dr));
                });

                // Get all of the user's flights, including telemetry
                const int PageSize     = 200; // get 200 flights at a time.
                int       offset       = 0;
                int       iRow         = 0;
                bool      fCouldBeMore = true;

                while (fCouldBeMore)
                {
                    FlightQuery fq         = new FlightQuery(User.UserName);
                    DBHelper    dbhFlights = new DBHelper(LogbookEntry.QueryCommand(fq, offset, PageSize, true, LogbookEntry.LoadTelemetryOption.LoadAll));
                    dbhFlights.ReadRows((comm) => { },
                                        (dr) =>
                    {
                        LogbookEntry le = new LogbookEntry(dr, User.UserName, LogbookEntry.LoadTelemetryOption.LoadAll);
                        le.FlightImages = (dImages.ContainsKey(le.FlightID)) ? dImages[le.FlightID].ToArray() : new MFBImageInfo[0];

                        // skip any flights here that don't have images, videos, or telemetry
                        if (le.FlightImages.Length > 0 || le.Videos.Count > 0 || le.HasFlightData)
                        {
                            WriteFlightInfo(tw, zip, le);
                        }
                        iRow++;
                    });
                    if (fCouldBeMore = (iRow == offset + PageSize))
                    {
                        offset += PageSize;
                    }
                }

                tw.RenderEndTag();  // Body
                tw.RenderEndTag();  // Html

                zip.AddEntry(Branding.ReBrand(String.Format(CultureInfo.InvariantCulture, "{0}.htm", Resources.LocalizedText.ImagesBackupFilename), activeBrand), sw.ToString());
                zip.Save(ms);
            }

            return(ms);
        }