public static Tag LoadFromRow (IList row) { var result = new Tag { Id = (int)row[0], Name = (string)row[1], }; return result; }
public void PivotizeTag (Tag tag, IEnumerable<int> postIds) { var relativeBinnedCxmlPath = tag.ComputeBinnedPath (".cxml"); var absoluteBinnedCxmlPath = Path.Combine (_settings.AbsoluteOutputFolder, relativeBinnedCxmlPath); Directory.CreateDirectory (Path.GetDirectoryName (absoluteBinnedCxmlPath)); using (var outputStream = absoluteBinnedCxmlPath.CreateWriteStream ()) { var streamReaders = postIds.Map (postId => { var relativeBinnedXmlPath = Post.ComputeBinnedPath (postId, ".xml", _settings.FileNameIdFormat); var absoluteBinnedXmlPath = Path.Combine (_settings.AbsoluteWorkingFolder, relativeBinnedXmlPath); var sr = new StreamReader (absoluteBinnedXmlPath); return sr; } ); PivotizeTag (tag, streamReaders, outputStream); } }
public void PivotizeTag (Tag tag, IEnumerable<StreamReader> streamReaders, Stream destination) { XDocument doc; XmlNamespaceManager namespaceManager; using (var stream = AssemblyExtensions.OpenScopedResourceStream<DeepZoomCollection> ("Template.cxml")) using (var reader = XmlReader.Create (stream, _settings.XmlReaderSettings)) { doc = XDocument.Load (reader); namespaceManager = new XmlNamespaceManager(reader.NameTable); namespaceManager.AddNamespace("c", Namespaces.Collection.NamespaceName); namespaceManager.AddNamespace("p", Namespaces.Pivot.NamespaceName); } var collectionNode = doc.Root; Debug.Assert(collectionNode != null); collectionNode.SetAttributeValue ("Name", "Tagged Questions: {0}".FormatInvariant (tag.Name)); // TODO: do we want to strip hyphens from tag for AdditionalSearchText? collectionNode.SetAttributeValue (Namespaces.Pivot + "AdditionalSearchText", tag.Name); var itemsNode = collectionNode.XPathSelectElement ("c:Items", namespaceManager); itemsNode.SetAttributeValue ("HrefBase", "http://{0}/questions/".FormatInvariant (_settings.SiteDomain)); itemsNode.SetAttributeValue ("ImgBase", Path.ChangeExtension (tag.Name, ".dzc")); using (var writer = new CollectionWriter (destination, _settings.XmlWriterSettings, futureCw => { futureCw.Flush (); var sw = new StreamWriter (destination); foreach (var sr in streamReaders) { foreach (var line in sr.Lines()) { #if DEBUG sw.WriteLine (line); #else sw.Write (line); #endif } sr.Close (); } sw.Flush (); }) ) { doc.Save (writer); } }
public void CreateCollectionTiles(Tag tag, List<int> postIds) { var relativePathToCollectionFolder = tag.ComputeBinnedPath (null) + "_files"; var absolutePathToCollectionFolder = Path.Combine (_settings.AbsoluteOutputFolder, relativePathToCollectionFolder); for (var level = 0; level < CollectionTilePower; level++) { var levelName = Convert.ToString (level, 10); var absolutePathToCollectionLevelFolder = Path.Combine (absolutePathToCollectionFolder, levelName); Directory.CreateDirectory (absolutePathToCollectionLevelFolder); var levelSize = (int) Math.Pow (2, level); var imageCollectionTiles = GenerateCollectionTiles (postIds, levelSize); foreach (var imageCollectionTile in imageCollectionTiles) { var relativePathToTile = Path.ChangeExtension (imageCollectionTile.TileName, _imageFormatName); var absolutePathToTile = Path.Combine (absolutePathToCollectionLevelFolder, relativePathToTile); var levelImages = OpenLevelImages (imageCollectionTile.Ids, level); using (var bitmap = CreateCollectionTile (levelImages, levelSize)) { bitmap.Save (absolutePathToTile, _settings.PostImageEncoding); } } } }
public void CreateCollectionManifest(Tag tag, List<int> postIds) { var relativePathToCollectionManifest = tag.ComputeBinnedPath (".dzc"); var absolutePathToCollectionManifest = Path.Combine (_settings.AbsoluteOutputFolder, relativePathToCollectionManifest); var relativePathToRoot = relativePathToCollectionManifest.RelativizePath (); Directory.CreateDirectory (Path.GetDirectoryName (absolutePathToCollectionManifest)); var element = GenerateImageCollection (postIds, relativePathToRoot); using (var outputStream = absolutePathToCollectionManifest.CreateWriteStream ()) { using (var writer = XmlWriter.Create (outputStream, _settings.XmlWriterSettings)) { Debug.Assert (writer != null); element.WriteTo (writer); } } }
internal static void PivotizeTag (PostRepository postRepository, Tag tag, Settings settings) { var workingPath = Path.GetFullPath (WorkingFolderName); var outputPath = Path.GetFullPath (OutputFolderName); var relativeBinnedCxmlPath = tag.ComputeBinnedPath (".cxml"); var absoluteBinnedCxmlPath = Path.Combine (outputPath, relativeBinnedCxmlPath); Directory.CreateDirectory (Path.GetDirectoryName (absoluteBinnedCxmlPath)); using (var outputStream = new FileStream (absoluteBinnedCxmlPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { var postIds = postRepository.RetrievePostIds (tag.Id); var streamReaders = postIds.Map (postId => { var relativeBinnedXmlPath = Post.ComputeBinnedPath (postId, ".xml", settings.FileNameIdFormat); var absoluteBinnedXmlPath = Path.Combine (workingPath, relativeBinnedXmlPath); var sr = new StreamReader (absoluteBinnedXmlPath); return sr; } ); PivotizeTag (tag, streamReaders, outputStream, settings.SiteDomain); } }
internal static void CreateCollectionTiles( Tag tag, string outputPath, List<int> postIds, ImageFormat imageFormat, string fileNameIdFormat, string absoluteOutputPath ) { var extension = imageFormat.ToString ().ToLower (); var relativePathToCollectionFolder = Tag.ComputeBinnedPath (tag.Name, null) + "_files"; var absolutePathToCollectionFolder = Path.Combine (outputPath, relativePathToCollectionFolder); for (var level = 0; level < DeepZoomCollection.CollectionTilePower; level++) { var levelName = Convert.ToString (level, 10); var absolutePathToCollectionLevelFolder = Path.Combine (absolutePathToCollectionFolder, levelName); Directory.CreateDirectory (absolutePathToCollectionLevelFolder); var levelSize = (int) Math.Pow (2, level); var imageCollectionTiles = DeepZoomCollection.GenerateCollectionTiles (postIds, levelSize); foreach (var imageCollectionTile in imageCollectionTiles) { var relativePathToTile = Path.ChangeExtension (imageCollectionTile.TileName, extension); var absolutePathToTile = Path.Combine (absolutePathToCollectionLevelFolder, relativePathToTile); var levelImages = OpenLevelImages (imageCollectionTile.Ids, extension, fileNameIdFormat, absoluteOutputPath, level); using (var bitmap = DeepZoomCollection.CreateCollectionTile (levelImages, levelSize)) { bitmap.Save (absolutePathToTile, imageFormat); } } } }