private void _processContentConfig(BridgeContentConfig contentConfig, Stream stream) { var serializer = new SerializerBuilder().ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull).Build(); var watch = new Stopwatch(); string serializationFolder = BridgeConfiguration.GetConfig().SerializationFolder; _clearTempFolder(); watch.Start(); //have this driven by config var serializationPath = $"{serializationFolder}/content/{contentConfig.Name}"; var tempGUID = DateTime.Now.Ticks.ToString(); var tempSerializationPath = $"{serializationFolder}/temp/{tempGUID}/{contentConfig.Name}"; var pageTypes = contentConfig.GetPageTypes(); var fieldsToIgnore = contentConfig.GetIgnoreFields(); var path = contentConfig.Query; //TODO: Query to see if page types exist, if DOESNT, display that... MultiDocumentQuery docs = DocumentHelper.GetDocuments().Path(path).Types(pageTypes.ToArray()).AllCultures().FilterDuplicates(); var treeNodes = docs.ToList <TreeNode>(); foreach (var treeNode in treeNodes) { watch.Reset(); watch.Start(); var mappedItem = treeNode.Adapt <BridgeTreeNode>(); mappedItem.FieldValues = new Dictionary <string, object>(); foreach (string columnName in treeNode.ColumnNames) { if (!fieldsToIgnore.Contains(columnName)) { var columnValue = treeNode.GetValue(columnName); if (columnValue != null) { mappedItem.FieldValues.Add(columnName, columnValue); } } } mappedItem.ParentNodeGUID = treeNode?.Parent?.NodeGUID; var stringBuilder = new StringBuilder(); var res = serializer.Serialize(mappedItem); stringBuilder.AppendLine(res); var pathToWriteTo = $"{tempSerializationPath}/{mappedItem.NodeAliasPath}#{mappedItem.DocumentCulture}.yaml"; var concretePath = this.GetRootPath(pathToWriteTo); FileInfo file = new FileInfo(concretePath); file.Directory.Create(); // If the directory already exists, this method does nothing. File.WriteAllText(concretePath, res); } watch.Stop(); _outputToStream(stream, $"Generating temp {contentConfig.Name} - {watch.ElapsedMilliseconds}ms"); _processDifferences(stream, watch, serializationPath, tempSerializationPath); }
private void _processContentConfig(BridgeContentConfig contentConfig, Stream stream) { var serializer = new SerializerBuilder().ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull).Build(); var watch = new Stopwatch(); string serializationFolder = BridgeConfiguration.GetConfig().SerializationFolder; //have this driven by config var serializationPath = $"{serializationFolder}/content/{contentConfig.Name}"; var pageTypes = contentConfig.GetPageTypes(); var fieldsToIgnore = contentConfig.GetIgnoreFields(); var path = contentConfig.Query; MultiDocumentQuery docs = DocumentHelper.GetDocuments().Path(path).Types(pageTypes.ToArray()).AllCultures().FilterDuplicates(); var treeNodes = docs.ToList <TreeNode>(); foreach (var treeNode in treeNodes) { watch.Reset(); watch.Start(); var mappedItem = treeNode.Adapt <BridgeTreeNode>(); mappedItem.FieldValues = new Dictionary <string, object>(); foreach (string columnName in treeNode.ColumnNames) { if (!fieldsToIgnore.Contains(columnName)) { var columnValue = treeNode.GetValue(columnName); if (columnValue != null) { mappedItem.FieldValues.Add(columnName, columnValue); } } } mappedItem.ParentNodeGUID = treeNode?.Parent?.NodeGUID; var stringBuilder = new StringBuilder(); var res = serializer.Serialize(mappedItem); stringBuilder.AppendLine(res); var pathToWriteTo = $"{serializationPath}/{mappedItem.NodeAliasPath}#{mappedItem.DocumentCulture}.yaml"; var concretePath = this.GetRootPath(pathToWriteTo); FileInfo file = new FileInfo(concretePath); file.Directory.Create(); // If the directory already exists, this method does nothing. File.WriteAllText(concretePath, res); watch.Stop(); byte[] bytes = Encoding.UTF8.GetBytes($"Serialized {contentConfig.Name}: {mappedItem.NodeAliasPath}#{mappedItem.DocumentCulture}.yaml ({mappedItem.NodeGUID}) - {watch.ElapsedMilliseconds}ms"); stream.Write(bytes, 0, bytes.Length); stream.WriteByte(10); stream.Flush(); } }