Example #1
0
        // Add the images in the folder to the slide show.
        // Return the number of images found.
        public int PopulateFromFolder()
        {
            string mainPath        = Path.GetDirectoryName(iFilePath);
            string subDirectory    = Path.GetFileNameWithoutExtension(iFilePath);
            string slideShowFolder = Path.Combine(mainPath, subDirectory);

            int dayOfPrevSlide = -1;

            foreach (FileInfo file in new DirectoryInfo(slideShowFolder).GetFiles())
            {
                if (IsPhoto(file))
                {
                    string   relativePath = Path.Combine(subDirectory, file.ToString());
                    Caption  caption      = null;
                    DateTime dateTime;
                    if (ParseDateName(file.ToString(), out dateTime))
                    {
                        string day  = dateTime.DayOfWeek.ToString();
                        string date = dateTime.ToLongDateString();
                        caption = new Caption();

                        int thisDay = dateTime.DayOfYear;
                        if (thisDay == dayOfPrevSlide)
                        {
                            // Same day: abbreviated date in caption
                            caption.AddLine(string.Format("{0}, {1:HH}:{1:mm}", day, dateTime));
                        }
                        else
                        {
                            // New day: include full date in caption
                            caption.AddLine(string.Format("{0} {1}", day, date));
                            caption.AddLine(string.Format("{0:HH}:{0:mm}", dateTime));
                            dayOfPrevSlide = thisDay;
                        }
                    }

                    // Add images provided they are not already in the slideshow.
                    // This enables new images to be added to an existing slideshow.
                    if (!IsInShow(file.ToString()))
                    {
                        Add(relativePath, caption);
                    }
                }
            }

            // In case we are adding new slides to an existing show, sort the final set
            // to ensure that the new slides appear in the correct order
            iShow.Sort();

            return(iShow.Count);
        }
Example #2
0
        // Read one HTML page and return a slide show
        public SlideShow ReadSlideShow(string aSlideFile, out string aDiagnostic)
        {
            aDiagnostic = null;

            // Determine the name of the future XML slide show file
            string    xmlFilePath = aSlideFile.Replace(".htm", ".xml");
            SlideShow slideShow   = new SlideShow(xmlFilePath);

            //Console.WriteLine("     HtmlReader ReadSlideShow: parsing " + aSlideFile);
            string html = ReadFile(aSlideFile);

            if (html == null)
            {
                aDiagnostic = "ReadSlideShow: bad HTML slideshow file " + aSlideFile;
                return(null);
            }
            else
            {
                ParseHTML parse = new ParseHTML();
                parse.Source = html;

                HtmlPreprocess htmlPreprocess = new HtmlPreprocess();

                // Default overall title for the slide show, hopefully replaced with something better
                string title           = "A most peculiar day";
                bool   collectingTitle = false;

                bool    collectingCaption = false;
                Caption caption           = new Caption();
                string  link = "";
                while (!parse.Eof())
                {
                    char ch = parse.Parse();
                    if (ch == 0)
                    {
                        AttributeList tag = parse.GetTag();
                        if (tag.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
                        {
                            collectingTitle = true;       // Start collecting title
                            title           = string.Empty;
                        }
                        else if (tag.Name.Equals("/title", StringComparison.CurrentCultureIgnoreCase))
                        {
                            collectingTitle = false;      // Title now complete
                            slideShow.Title = title.Trim();
                        }
                        if (tag.Name.Equals("td", StringComparison.CurrentCultureIgnoreCase))
                        {
                            collectingCaption = true;       // Start collecting new caption
                            caption           = new Caption();
                        }
                        else if (tag.Name.Equals("/td", StringComparison.CurrentCultureIgnoreCase))
                        {
                            collectingCaption = false;      // Any caption is now complete
                            if (!link.Equals(""))
                            {
                                // Got a link to go with the caption
                                slideShow.Add(link, caption);
                                link = "";
                            }
                        }
                        else if (collectingCaption &&
                                 tag.Name.Equals("p", StringComparison.CurrentCultureIgnoreCase))
                        {
                            // HTML paragraph tag within caption
                            caption.NewLine();
                        }
                        else if (tag["href"] != null)
                        {
                            string href = tag["href"].Value.Replace('/', '\\');
                            if (IsPhoto(href))
                            {
                                //Console.WriteLine("     + HtmlReader ReadSlideShow: add " + href +
                                //                  " from tag " + tag.Name);
                                link = href;
                            }
                        }

                        // Preprocessing of regular character stream starts with clean sheet after tag
                        htmlPreprocess.Reset();
                    }
                    else
                    {
                        // Got a character
                        ch = htmlPreprocess.Add(ch);
                        if (ch != HtmlPreprocess.NullChar)
                        {
                            if (collectingTitle)
                            {
                                title += ch;
                            }
                            else if (collectingCaption)
                            {
                                caption.AddChar(ch);
                            }
                        }
                    }
                }

                return(slideShow);
            }
        }
Example #3
0
 // Parameterless constructor needed for serialisation
 public Slide()
 {
     Path     = null;
     iCaption = null;
 }
Example #4
0
 // Add a new slide to the sequence
 public void Add(string aPhotoPath, Caption aCaption)
 {
     iShow.Add(new Slide(aPhotoPath, aCaption));
 }
Example #5
0
 public Slide(string aPath, Caption aCaption)
 {
     Path     = aPath;
     iCaption = aCaption;
 }