public void Can_serialize_full_set_of_options() { var options = new DestinationOptions(DestinationFileFormat.Pdf) { PdfOptions = new PdfDestinationOptions { ForceOneFilePerPage = true, Ocr = new OcrOptions { Language = "russian", DefaultDpi = new DpiOptions(72, 120), }, }, JpegOptions = new JpegDestinationOptions { MaxWidth = "640px", MaxHeight = "480px", }, PngOptions = new PngDestinationOptions { MaxWidth = "800px", MaxHeight = "600px", }, }; using (var stringWriter = new StringWriter()) { PrizmDocRestApiJsonSerializer.Instance.Serialize(stringWriter, options); Assert.AreEqual("{\"format\":\"pdf\",\"jpegOptions\":{\"maxWidth\":\"640px\",\"maxHeight\":\"480px\"},\"pdfOptions\":{\"forceOneFilePerPage\":true,\"ocr\":{\"language\":\"russian\",\"defaultDpi\":{\"x\":72,\"y\":120}}},\"pngOptions\":{\"maxWidth\":\"800px\",\"maxHeight\":\"600px\"}}", stringWriter.ToString()); } }
public void Can_serialize_a_minimal_instance() { var options = new DestinationOptions(DestinationFileFormat.Pdf); using (var stringWriter = new StringWriter()) { PrizmDocRestApiJsonSerializer.Instance.Serialize(stringWriter, options); Assert.AreEqual("{\"format\":\"pdf\"}", stringWriter.ToString()); } }
public void Can_easily_construct_a_minimal_instance() { var options = new DestinationOptions(DestinationFileFormat.Pdf); Assert.AreEqual(DestinationFileFormat.Pdf, options.Format); Assert.IsNull(options.PdfOptions); Assert.IsNull(options.JpegOptions); Assert.IsNull(options.PngOptions); Assert.IsNull(options.TiffOptions); }
public void Can_serialize_custom_PDF_options() { var options = new DestinationOptions(DestinationFileFormat.Pdf) { PdfOptions = new PdfDestinationOptions { ForceOneFilePerPage = true, Ocr = new OcrOptions { DefaultDpi = new DpiOptions(72, 120), }, }, }; using (var stringWriter = new StringWriter()) { PrizmDocRestApiJsonSerializer.Instance.Serialize(stringWriter, options); Assert.AreEqual("{\"format\":\"pdf\",\"pdfOptions\":{\"forceOneFilePerPage\":true,\"ocr\":{\"language\":\"english\",\"defaultDpi\":{\"x\":72,\"y\":120}}}}", stringWriter.ToString()); } }
public void Can_easily_construct_custom_options() { var options = new DestinationOptions(DestinationFileFormat.Pdf) { PdfOptions = new PdfDestinationOptions { ForceOneFilePerPage = true, Ocr = new OcrOptions { DefaultDpi = new DpiOptions(x: 72, y: 120), }, }, Header = new HeaderFooterOptions { Lines = new List <HeaderFooterLine> { new HeaderFooterLine { Left = "Accusoft", Right = "Page 1" }, }, }, Footer = new HeaderFooterOptions { Color = "#FF0000", Lines = new List <HeaderFooterLine> { new HeaderFooterLine { Center = "Center Info" }, }, }, }; Assert.AreEqual(DestinationFileFormat.Pdf, options.Format); Assert.IsNotNull(options.PdfOptions); Assert.IsNull(options.JpegOptions); Assert.IsNull(options.PngOptions); Assert.IsNull(options.TiffOptions); Assert.IsNotNull(options.Header); Assert.IsNotNull(options.Footer); }
public IEnumerable<Trip> ComputeTrips(char startTown, char endTown, DestinationOptions destinationOptions = DestinationOptions.None, int? numberOfStops = null, int? maxDistance = null) { List<string> paths = new List<string>(); //TODO last index of toTown for each path, then distance Func<string, string> realPath = p => { if (string.IsNullOrEmpty(p)) return p; string path = ""; switch (destinationOptions) { case DestinationOptions.None: path = p; break; case DestinationOptions.FirstStop: path = p.Substring(0, p.IndexOf(endTown, 1) + 1); break; case DestinationOptions.LastStop: path = p.Substring(0, p.LastIndexOf(endTown) + 1); break; case DestinationOptions.LinkedToMaxTrip: if (p.Last() == endTown && p.Length == numberOfStops + 1) path = p; break; case DestinationOptions.LinkedToMaxDistance: { path = p; while (!(ComputeRouteDistance(path.ToCharArray(), true) <= maxDistance && path.Last() == endTown) || path.Length == 1 || string.IsNullOrEmpty(path)) { path = path.Remove(path.Length - 1, 1); } } break; } return path; }; Action<Town, int, string> crawl = null; crawl = (from, tripCount, path) => { if ((numberOfStops != null && path.Count() < numberOfStops + 1) || (maxDistance != null && (string.IsNullOrEmpty(path) ? true : ComputeRouteDistance(path.ToCharArray(), true) <= maxDistance))) //|| (destinationOptions == DestinationOptions.FirstStop && !((string.IsNullOrEmpty(path) ? '!' : path.Last()) == endTown && path.Length > 1))) { path = path + from.Name; tripCount++; foreach (var route in from.Routes) { crawl(route.ToTown, tripCount, path); } } else { paths.Add(path); tripCount = 0; path = ""; } }; crawl(_towns.Single(t => t.Name == startTown), 0, ""); Converter<string, Trip> pathToTrip = p => { return new Trip() { Start = _towns.Single(t => t.Name == startTown) , End = _towns.Single(t => t.Name == p.Last()) , Path = p , Distance = ComputeRouteDistance(p.ToCharArray(), true) }; }; var finalPaths = GraphFunction.ApplyToAll(paths.Distinct(), realPath).ToList().Distinct().ToList(); finalPaths.RemoveAll(s => s.Length <= 1); var trips = finalPaths.ConvertAll<Trip>(pathToTrip); return trips.Distinct().ToList(); }
//compute the number of different routes between two towns public int ComputeNumberOfTripsBetweenTowns(char startTown, char endTown, DestinationOptions destinationOptions = DestinationOptions.None, int? numberOfStops = null, int? maxDistance = null) { var trips = ComputeTrips(startTown, endTown, destinationOptions, numberOfStops, maxDistance); return trips.Count(); }