Ejemplo n.º 1
0
        private static void WriteBasicMedForUser(HtmlTextWriter tw, string szUser, ZipArchive zip)
        {
            IEnumerable <BasicMedEvent> lstBMed = BasicMedEvent.EventsForUser(szUser);

            if (!lstBMed.Any())
            {
                return;
            }

            tw.Write(String.Format(CultureInfo.CurrentCulture, "<p>{0}</p>", Resources.Profile.BasicMedHeader));
            tw.RenderBeginTag(HtmlTextWriterTag.Ul);
            foreach (BasicMedEvent bme in lstBMed)
            {
                tw.Write(String.Format(CultureInfo.InvariantCulture, "<li>{0} - {1} {2}</li>", bme.EventDate.YMDString(), bme.EventTypeDescription, bme.Description));
            }
            tw.RenderEndTag(); // Ul

            foreach (BasicMedEvent bme in lstBMed)
            {
                string    szZipFolder = String.Format(CultureInfo.InvariantCulture, "{0}-{1}", bme.ImageKey, szThumbFolderBasicMed);
                ImageList ilBasicMed  = new ImageList(MFBImageInfo.ImageClass.BasicMed, bme.ImageKey);
                ilBasicMed.Refresh(true);
                foreach (MFBImageInfo mfbii in ilBasicMed.ImageArray)
                {
                    mfbii.ToHtml(tw, szZipFolder);
                    AddThumbnailToZip(mfbii, zip, szZipFolder);
                    mfbii.UnCache();
                }
            }
        }
Ejemplo n.º 2
0
 protected void gvBasicMedEvents_RowCommand(object sender, CommandEventArgs e)
 {
     if (e != null && String.Compare(e.CommandName, "_Delete", StringComparison.OrdinalIgnoreCase) == 0)
     {
         int           id  = Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture);
         BasicMedEvent bme = BasicMedEvent.EventsForUser(Page.User.Identity.Name).First <BasicMedEvent>(bme2 => bme2.ID == id);
         if (bme != null)
         {
             bme.Delete();
             RefreshBasicMedEvents();
         }
     }
 }
Ejemplo n.º 3
0
        private static void WriteBasicMedForUser(HtmlTextWriter tw, string szUser, ZipArchive zip)
        {
            IEnumerable <BasicMedEvent> lstBMed = BasicMedEvent.EventsForUser(szUser);

            foreach (BasicMedEvent bme in lstBMed)
            {
                string    szZipFolder = String.Format(CultureInfo.InvariantCulture, "{0}-{1}", bme.ImageKey, szThumbFolderBasicMed);
                ImageList ilBasicMed  = new ImageList(MFBImageInfo.ImageClass.BasicMed, bme.ImageKey);
                ilBasicMed.Refresh(true);
                foreach (MFBImageInfo mfbii in ilBasicMed.ImageArray)
                {
                    mfbii.ToHtml(tw, szZipFolder);
                    AddThumbnailToZip(mfbii, zip, szZipFolder);
                    mfbii.UnCache();
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 public void RefreshBasicMedEvents()
 {
     gvBasicMedEvents.DataSource = BasicMedEvent.EventsForUser(Page.User.Identity.Name);
     gvBasicMedEvents.DataBind();
 }