Example #1
0
 /// <summary>
 /// The name for the images file
 /// </summary>
 public static string BackupImagesFilename(Brand activeBrand, bool fDateStamp = false)
 {
     if (activeBrand == null)
     {
         throw new ArgumentNullException(nameof(activeBrand));
     }
     return(Branding.ReBrand(String.Format(CultureInfo.CurrentCulture, "%APP_NAME% Images{0}.zip", fDateStamp ? " " + DateTime.Now.YMDString() : string.Empty), activeBrand));
 }
Example #2
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());
     IsSelected = false;
 }
Example #3
0
        public void WriteZipOfImagesToStream(Stream ms, Brand activeBrand, Action <ZipArchive> finalize = null)
        {
            if (ms == null)
            {
                throw new ArgumentNullException(nameof(ms));
            }
            if (activeBrand == null)
            {
                activeBrand = Branding.CurrentBrand;
            }

            using (ZipArchive zip = new ZipArchive(ms, ZipArchiveMode.Create, true))
            {
                using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
                {
                    using (HtmlTextWriter tw = new HtmlTextWriter(sw))
                    {
                        string szUserFullName = User.UserFullName;

                        // Write header tags.  This leaves an open body tag and an open html tag.
                        WriteHtmlHeaders(tw, Branding.ReBrand("http://%APP_URL%%APP_ROOT%/public/stylesheet.css", activeBrand), szUserFullName);

                        // Write out pilot information
                        WritePilotInformation(tw, User);

                        // Write out profile images
                        WriteProfileImages(tw, szUserFullName, User.UserName, zip);

                        // Write out any digital endorsements too
                        WriteDigitalEndorsements(tw, User.UserName);

                        // And any BasicMed stuff
                        WriteBasicMedForUser(tw, User.UserName, zip);

                        // Write out flight images and Telemetry
                        WriteFlightImagesForUser(tw, szUserFullName, User.UserName, zip);

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

                    ZipArchiveEntry zipArchiveEntry = zip.CreateEntry(Branding.ReBrand(String.Format(CultureInfo.InvariantCulture, "{0}.htm", Resources.LocalizedText.ImagesBackupFilename), activeBrand));

                    using (StreamWriter swHtm = new StreamWriter(zipArchiveEntry.Open()))
                    {
                        swHtm.Write(sw.ToString());
                    }
                }

                // Allow caller to add any additional items.
                finalize?.Invoke(zip);
            }
        }
Example #4
0
        /// <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;
                }

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

                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 (Exception ex) when(ex is 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.
            }
        }
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                m_sm.ExecuteRequest(m_smr);
                switch (m_smr.Requestedrole)
                {
                case CFIStudentMapRequest.RoleType.RoleCFI:
                case CFIStudentMapRequest.RoleType.RoleStudent:
                    Response.Redirect("~/Member/Training.aspx/" + (m_smr.Requestedrole == CFIStudentMapRequest.RoleType.RoleCFI ? tabID.instStudents.ToString() : tabID.instInstructors.ToString()));
                    break;

                case CFIStudentMapRequest.RoleType.RoleInviteJoinClub:
                {
                    // Let the requestor know that the invitation has been accepted.
                    Profile pfTarget  = Profile.GetUser(m_smr.TargetUser.Contains("@") ? System.Web.Security.Membership.GetUserNameByEmail(m_smr.TargetUser) : m_smr.TargetUser);
                    string  szSubject = String.Format(CultureInfo.CurrentCulture, Resources.Club.AddMemberInvitationAccepted, m_smr.ClubToJoin.Name);
                    string  szBody    = Branding.ReBrand(Resources.Club.ClubInvitationAccepted).Replace("<% ClubName %>", m_smr.ClubToJoin.Name).Replace("<% ClubInvitee %>", pfTarget.UserFullName);
                    foreach (ClubMember cm in ClubMember.AdminsForClub(m_smr.ClubToJoin.ID))
                    {
                        util.NotifyUser(szSubject, szBody.Replace("<% FullName %>", cm.UserFullName), new MailAddress(cm.Email, cm.UserFullName), false, false);
                    }
                    Response.Redirect(String.Format(CultureInfo.InvariantCulture, "~/Member/ClubDetails.aspx/{0}", m_smr.ClubToJoin.ID));
                }
                break;

                case CFIStudentMapRequest.RoleType.RoleRequestJoinClub:
                {
                    // Let the requestor know that the request has been approved.
                    Profile pfRequestor = Profile.GetUser(m_smr.RequestingUser);
                    string  szSubject   = String.Format(CultureInfo.CurrentCulture, Resources.Club.AddMemberRequestAccepted, m_smr.ClubToJoin.Name);
                    string  szBody      = Branding.ReBrand(Resources.Club.ClubRequestAccepted).Replace("<% ClubName %>", m_smr.ClubToJoin.Name).Replace("<% FullName %>", pfRequestor.UserFullName);
                    util.NotifyUser(szSubject, szBody, new MailAddress(pfRequestor.Email, pfRequestor.UserFullName), false, false);
                    Response.Redirect(String.Format(CultureInfo.InvariantCulture, "~/Member/ClubDetails.aspx/{0}", m_smr.ClubToJoin.ID));
                }
                break;
                }
            }
            catch (MyFlightbookValidationException ex)
            {
                pnlReviewRequest.Visible = false;
                lblError.Text            = ex.Message;
                pnlConfirm.Visible       = false;
            }
        }
Example #6
0
        /// <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();
        }
Example #7
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;
        }
Example #8
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);
        }