public static void WriteToOutputFile(Slideshow slideShow, string outputFile) { if (slideShow.slides == null) { return; } var fileStream = new FileStream(outputFile, FileMode.CreateNew, FileAccess.Write); if (fileStream == null) { throw new Exception("Cannot open the output file."); } using (var streamWriter = new StreamWriter(fileStream)) { streamWriter.WriteLine(slideShow.slideCount); foreach (var slide in slideShow.slides) { streamWriter.WriteLine(String.Join(" ", slide)); } } }
public Slideshow MakeSlideshow() { Slideshow slideshow = new Slideshow(); slideshow.slides = new List <long[]>(); for (int i = 0; i < Photos.Count; i++) { if (Photos[i].addedInSlideshow && Photos[i].type != PhotoType.Vertical) { continue; } if (Photos[i].type == PhotoType.Horizontal || (Photos[i].type == PhotoType.Vertical && !Photos[i].addedInSlideshow)) { Photos[i].addedInSlideshow = true; Photo neighbor; FindHorizontalNeighboringSlide(Photos[i], out neighbor); if (neighbor != null) { if (Photos[i].type == PhotoType.Vertical) { slideshow.slides.Add(new long[] { i, Photos.IndexOf(neighbor) }); } else { slideshow.slides.Add(new long[] { Photos.IndexOf(neighbor) }); } Photos[Photos.IndexOf(neighbor)].addedInSlideshow = true; } else { Photos[i].addedInSlideshow = false; } } else { Photos[i].addedInSlideshow = true; Photo neighbor; FindVerticalNeighboringSlide(Photos[0], out neighbor); if (neighbor != null) { if (neighbor.type == PhotoType.Horizontal) { slideshow.slides.Add(new long[] { Photos.IndexOf(neighbor) }); } else { slideshow.slides.Add(new long[] { i, Photos.IndexOf(neighbor) }); } Photos[Photos.IndexOf(neighbor)].addedInSlideshow = true; } else { Photos[i].addedInSlideshow = false; } } } slideshow.slideCount = slideshow.slides.Count; return(slideshow); }