public override void Emit(IEmitContext context, IProject project) { base.Emit(context, project); var fileName = PathHelper.Combine(project.ProjectDirectory, Configuration.GetString(Constants.Configuration.Output.Directory) + "\\content.xml"); using (var stream = new FileStream(fileName, FileMode.Create)) { var settings = new XmlWriterSettings { Encoding = new UTF8Encoding(false), Indent = true }; using (var writer = XmlWriter.Create(stream, settings)) { writer.WriteStartElement("content"); EmitReset(writer); EmitTemplates(writer); EmitItems(context, writer); EmitPublish(writer); writer.WriteEndElement(); } } EmitNugetPackage(context); }
protected override void EmitProjectItems(IEmitContext context, IEnumerable <IProjectItem> projectItems, List <IEmitter> emitters, ICollection <Tuple <IProjectItem, Exception> > retries) { var unemittedItems = new List <IProjectItem>(projectItems); foreach (var projectItem in projectItems) { if (projectItem is MediaFile mediaFile) { EmitMediaFile(context, mediaFile); unemittedItems.Remove(projectItem); } else if (projectItem is Projects.Files.File file) { EmitFile(context, file); unemittedItems.Remove(projectItem); } else if (projectItem is Item item) { var sourcePropertyBag = (ISourcePropertyBag)item; if (item.IsEmittable || sourcePropertyBag.GetValue <string>("__origin_reason") == nameof(CreateItemsFromTemplates)) { EmitItem(context, item); } unemittedItems.Remove(projectItem); } else if (projectItem is Template) { unemittedItems.Remove(projectItem); } } base.EmitProjectItems(context, unemittedItems, emitters, retries); }
protected override void EmitProjectItems(IEmitContext context, IEnumerable <IProjectItem> projectItems, List <IEmitter> emitters, ICollection <Tuple <IProjectItem, Exception> > retries) { var unemittedItems = new List <IProjectItem>(projectItems); foreach (var projectItem in projectItems) { if (projectItem is MediaFile mediaFile) { unemittedItems.Remove(projectItem); EmitMediaFile(context, mediaFile); } else if (projectItem is File file) { unemittedItems.Remove(projectItem); EmitFile(context, file); } else if (projectItem is Item item) { unemittedItems.Remove(projectItem); EmitItem(context, item); } else if (projectItem is Template template) { unemittedItems.Remove(projectItem); EmitTemplate(context, template); } } base.EmitProjectItems(context, unemittedItems, emitters, retries); }
protected virtual void EmitProjectItem([NotNull] IEmitContext context, [NotNull] IEmitter emitter, [NotNull] IProjectItem projectItem, [NotNull, ItemNotNull] ICollection <Tuple <IProjectItem, Exception> > retries) { try { emitter.Emit(context, projectItem); } catch (RetryableEmitException ex) { lock (_syncObject) { retries.Add(new Tuple <IProjectItem, Exception>(projectItem, ex)); } } catch (EmitException ex) { Trace.TraceError(ex.Msg, ex.Text, ex.FileName, ex.Span, ex.Details); } catch (Exception ex) { lock (_syncObject) { retries.Add(new Tuple <IProjectItem, Exception>(projectItem, ex)); } } }
public override void Emit(IEmitContext context, IProject project) { var packageFileName = Configuration.GetString(Constants.Configuration.Output.Package.FileName, "package"); if (!packageFileName.EndsWith(".zip")) { packageFileName += ".zip"; } var outputDirectory = PathHelper.Combine(project.ProjectDirectory, Configuration.GetString(Constants.Configuration.Output.Directory)); var fileName = Path.Combine(outputDirectory, packageFileName); FileSystem.CreateDirectoryFromFileName(fileName); using (Zip = new ZipWriter(fileName)) { base.Emit(context, project); EmitProject(); EmitVersion(); EmitMetaData(); } context.OutputFiles.Add(Factory.OutputFile(fileName)); }
protected virtual void EmitImportedItems([NotNull] IEmitContext context, [NotNull] IProject project) { // Unicorn requires item files for the entire path, so fill in the gaps foreach (var item in project.Items) { var parentItem = item.GetParent(); if (parentItem != null && parentItem.IsEmittable) { continue; } var itemPath = PathHelper.GetItemParentPath(item.ItemIdOrPath); while (!string.IsNullOrEmpty(itemPath)) { var fileName = GetItemFileName(item.DatabaseName, itemPath); if (!FileSystem.FileExists(fileName)) { var i = item.Database.GetItem(itemPath); if (i == null) { Trace.TraceError(Msg.E1045, "Required item not found for Unicorn serialization", itemPath); break; } EmitItem(context, i); } itemPath = PathHelper.GetItemParentPath(itemPath); } } }
public virtual void EmitFile([NotNull] IEmitContext context, [NotNull] Projects.Files.File file) { var sourceFileAbsoluteFileName = file.Snapshot.SourceFile.AbsoluteFileName; var fileName = PathHelper.NormalizeFilePath(file.FilePath); if (fileName.StartsWith("~\\")) { fileName = fileName.Mid(2); } _files.Add('/' + fileName); Trace.TraceInformation(Msg.I1011, "Publishing", "~\\" + fileName); Zip.AddEntry("files/" + NormalizeZipPath(fileName), sourceFileAbsoluteFileName); using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { writer.WriteLine("type=file"); } Zip.AddEntry("properties/files/" + NormalizeZipPath(fileName), stream.ToArray()); } }
protected override void EmitMediaFile(IEmitContext context, MediaFile mediaFile) { if (!mediaFile.IsEmittable) { return; } var item = context.Project.Indexes.FindQualifiedItem <Item>(mediaFile.MediaItemUri); if (item == null) { Trace.TraceInformation(Msg.E1047, "No media item - skipping", mediaFile.Snapshot.SourceFile); return; } Trace.TraceInformation(Msg.I1011, "Publishing", item.ItemIdOrPath); var destinationFileName = GetItemFileName(item.DatabaseName, item.ItemIdOrPath); FileSystem.CreateDirectoryFromFileName(destinationFileName); using (var stream = new FileStream(destinationFileName, FileMode.Create)) { using (var writer = new StreamWriter(stream)) { item.WriteAsUnicornYaml(writer); } } }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var unicornFile = projectItem as UnicornFile; Assert.Cast(unicornFile, nameof(unicornFile)); var snapshot = unicornFile.Snapshots.First(); // todo: use real Unicorn configuration instead of hacking it var log = new TraceLogger(context.Trace); var logger = new DefaultDeserializerLogger(log); var fieldFilter = new AllFieldFilter(); var defaultDeserializer = new DefaultDeserializer(logger, fieldFilter); // todo: file has already been read and parsed - do not read it again var formatter = new YamlSerializationFormatter(null, null); using (var stream = new FileStream(snapshot.SourceFile.AbsoluteFileName, FileMode.Open)) { var serializedItem = formatter.ReadSerializedItem(stream, unicornFile.ShortName); if (string.IsNullOrEmpty(serializedItem.DatabaseName)) { serializedItem.DatabaseName = unicornFile.DatabaseName; } try { defaultDeserializer.Deserialize(serializedItem); } catch (Exception ex) { throw new RetryableEmitException(Texts.Failed_to_deserialize_item, unicornFile.Snapshots.First(), ex.Message); } } }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var item = projectItem as Item; Assert.Cast(item, nameof(item)); if (!item.IsEmittable || item.IsImport) { return; } var templateIdOrPath = ResolveTemplateIdOrPath(item); if (string.IsNullOrEmpty(templateIdOrPath)) { throw new RetryableEmitException(Texts.Template_missing, TraceHelper.GetTextNode(item.TemplateIdOrPathProperty, item.ItemNameProperty), item.TemplateIdOrPath); } var database = Factory.GetDatabase(item.DatabaseName); var templateItem = database.GetItem(templateIdOrPath); if (string.IsNullOrEmpty(templateIdOrPath)) { throw new RetryableEmitException(Texts.Template_missing, TraceHelper.GetTextNode(item.TemplateIdOrPathProperty), item.TemplateIdOrPath); } var template = TemplateManager.GetTemplate(templateItem.ID, templateItem.Database); if (template == null) { throw new RetryableEmitException(Texts.Template_missing, TraceHelper.GetTextNode(item.TemplateIdOrPathProperty), item.TemplateIdOrPath); } // todo: convert to pipeline ValidateFields(database, template, item); var itemWriter = new ItemWriter { Snapshot = item.Snapshots.First(), DatabaseName = item.DatabaseName, Guid = projectItem.Uri.Guid, ItemName = item.ItemName, ItemIdOrPath = item.ItemIdOrPath, TemplateIdOrPath = templateIdOrPath }; foreach (var field in item.Fields) { var templateField = template.GetField(field.FieldName); if (templateField == null) { throw new RetryableEmitException(Texts.Template_field_missing, TraceHelper.GetTextNode(field.FieldNameProperty, item.ItemNameProperty), field.FieldName); } var fieldWriter = new FieldWriter(field.FieldIdProperty, field.FieldNameProperty, field.Language, field.Version, field.CompiledValue); itemWriter.Fields.Add(fieldWriter); } var dataItem = itemWriter.Write(context); Check(context, item, dataItem); }
protected virtual void EmitItems([NotNull] IEmitContext context, [NotNull] XmlWriter writer) { writer.WriteStartElement("items"); foreach (var item in _items.OrderBy(t => t.ItemPathLevel).ThenBy(t => t.ItemName)) { writer.WriteStartElement("item"); writer.WriteAttributeString("id", item.Uri.Guid.Format()); writer.WriteAttributeString("database", item.DatabaseName); writer.WriteAttributeString("name", item.ItemName); writer.WriteAttributeString("path", item.ItemIdOrPath); writer.WriteAttributeString("template", item.Template.Uri.Guid.Format()); writer.WriteAttributeStringIf("icon", item.Icon); writer.WriteAttributeStringIf("sortorder", item.Sortorder.ToString()); foreach (var field in item.Fields) { writer.WriteStartElement("field"); writer.WriteAttributeString("id", field.FieldId.Format()); writer.WriteAttributeString("name", field.FieldName); if (!field.TemplateField.Shared) { writer.WriteAttributeString("language", field.Language.LanguageName); } if (!field.TemplateField.Shared && !field.TemplateField.Unversioned) { writer.WriteAttributeString("version", field.Version.Number.ToString()); } if (string.Equals(field.TemplateField.Type, "attachment", StringComparison.OrdinalIgnoreCase)) { var mediaFile = context.Project.Indexes.FindQualifiedItem <MediaFile>(field.Value); if (mediaFile == null) { Trace.TraceInformation(Msg.E1047, "No media item", item.SourceTextNode); } else { var bytes = File.ReadAllBytes(mediaFile.Snapshot.SourceFile.AbsoluteFileName); var blob = Convert.ToBase64String(bytes); writer.WriteAttributeString("blob", blob); writer.WriteAttributeString("blobExtension", Path.GetExtension(mediaFile.Snapshot.SourceFile.AbsoluteFileName).TrimStart('.')); } } writer.WriteValue(field.CompiledValue); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var configFile = (ConfigFile)projectItem; var destinationFileName = FileUtil.MapPath(configFile.FilePath); context.FileSystem.CreateDirectoryFromFileName(destinationFileName); context.FileSystem.Copy(projectItem.Snapshots.First().SourceFile.AbsoluteFileName, destinationFileName, context.ForceUpdate); }
public override void Emit(IEmitContext context, IProject project) { base.Emit(context, project); if (Configuration.GetBool(Constants.Configuration.Output.Unicorn.EmitMissingItems)) { EmitImportedItems(context, project); } MirrorItems(context); }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var template = (Template)projectItem; if (!template.IsEmittable || template.IsImport) { return; } var templateWriter = new TemplateWriter(template); templateWriter.Write(context); }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var binFile = (BinFile)projectItem; var destinationFileName = FileUtil.MapPath(binFile.FilePath); if (!CanCopyBinFile(context, binFile, destinationFileName)) { return; } context.FileSystem.CreateDirectory(Path.GetDirectoryName(destinationFileName) ?? string.Empty); context.FileSystem.Copy(projectItem.Snapshots.First().SourceFile.AbsoluteFileName, destinationFileName, context.ForceUpdate); }
public virtual void EmitFile([NotNull] IEmitContext context, [NotNull] File file) { var sourceFileAbsoluteFileName = file.Snapshot.SourceFile.AbsoluteFileName; var fileName = PathHelper.NormalizeFilePath(file.FilePath); if (fileName.StartsWith("~\\")) { fileName = fileName.Mid(2); } _files.Add('/' + fileName); Trace.TraceInformation(Msg.I1011, "Publishing", "~\\" + fileName); Zip.AddEntry("addedfiles/" + NormalizeZipPath(fileName), sourceFileAbsoluteFileName); using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream, Encoding.UTF8)) { var sb = new StringBuilder(); var settings = new XmlWriterSettings { OmitXmlDeclaration = false, Encoding = Encoding.UTF8 }; using (var output = XmlWriter.Create(sb, settings)) { output.WriteProcessingInstruction("xml", "version=\"1.0\""); output.WriteStartElement("addFile"); output.WriteFullElementString("collisionbehavior", string.Empty); output.WriteFullElementString("path", PathHelper.NormalizeFilePath("\\" + fileName)); output.WriteFullElementString("id", PathHelper.NormalizeFilePath("\\" + fileName)); output.WriteFullElementString("parent", string.Empty); output.WriteFullElementString("file", string.Empty); output.WriteFullElementString("hashCode", string.Empty); output.WriteEndElement(); } writer.WriteLine("version=2.0"); writer.WriteLine("xml=" + sb); } Zip.AddEntry("properties/addedfiles/" + NormalizeZipPath(fileName), stream.ToArray()); } }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var itemModel = (SerializationFile)projectItem; try { var item = DoLoadItem(itemModel.Snapshots.First().SourceFile.AbsoluteFileName, LoadOptions); if (item == null) { throw new RetryableEmitException(Texts.Failed_to_deserialize_item, itemModel.Snapshots.First(), "Item not created"); } } catch (Exception ex) { throw new RetryableEmitException(Texts.Failed_to_deserialize_item, itemModel.Snapshots.First(), ex.Message); } }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var template = (Template)projectItem; if (!template.IsEmittable || template.IsImport) { return; } var templateWriter = new TemplateWriter(template); var dataItem = templateWriter.Write(context); if (dataItem != null) { Check(context, template, dataItem); } }
public virtual void EmitFile([NotNull] IEmitContext context, [NotNull] Projects.Files.File file) { var fileName = PathHelper.NormalizeFilePath(file.FilePath); if (fileName.StartsWith("~\\")) { fileName = fileName.Mid(2); } Trace.TraceInformation(Msg.I1011, "Publishing", "~\\" + fileName); var forceUpdate = Configuration.GetBool(Constants.Configuration.BuildProject.ForceUpdate, true); var destinationFileName = PathHelper.Combine(OutputDirectory, fileName); FileSystem.CreateDirectoryFromFileName(destinationFileName); FileSystem.Copy(file.Snapshot.SourceFile.AbsoluteFileName, destinationFileName, forceUpdate); }
public virtual void Emit(IEmitContext context, IProject project) { if (Configuration.GetBool(Constants.Configuration.InstallPackage.ShowDiagnostics)) { var treatWarningsAsErrors = Configuration.GetBool(Constants.Configuration.CheckProject.TreatWarningsAsErrors); Trace.TraceDiagnostics(project.Diagnostics, treatWarningsAsErrors); } project.Lock(Locking.ReadOnly); var emitters = Emitters.OrderBy(e => e.Sortorder).ToList(); var retries = new List <Tuple <IProjectItem, Exception> >(); Emit(context, project, emitters, retries); EmitRetry(context, emitters, retries); project.Lock(Locking.ReadWrite); }
public virtual void EmitItem([NotNull] IEmitContext context, [NotNull] Item item) { _items.Add(item); Trace.TraceInformation(Msg.I1011, "Publishing", item.ItemIdOrPath); var fileName = item.DatabaseName + PathHelper.NormalizeFilePath(item.ItemIdOrPath) + "_" + item.Uri.Guid.ToString("B"); using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { item.WriteAsUpdatePackageXml(writer); } Zip.AddEntry("addeditems/" + NormalizeZipPath(fileName), stream.ToArray()); } }
protected virtual void MirrorItems([NotNull] IEmitContext context) { if (!Configuration.GetBool(Constants.Configuration.Output.Unicorn.MirrorItems)) { return; } var sourceDirectory = PathHelper.Combine(OutputDirectory, Configuration.GetString(Constants.Configuration.Output.Unicorn.ItemsDirectory)); sourceDirectory = PathHelper.Combine(sourceDirectory, PathHelper.NormalizeFilePath(Configuration.GetString(Constants.Configuration.Output.Unicorn.MirrorItemsSourceDirectory)).TrimStart('\\')); var destinationDirectory = Configuration.GetString(Constants.Configuration.Output.Unicorn.UnicornRootPath); Trace.TraceInformation(Msg.E1046, "Mirroring item files", sourceDirectory + " => " + destinationDirectory); FileSystem.CreateDirectory(destinationDirectory); FileSystem.Mirror(sourceDirectory, destinationDirectory); }
public override void Emit(IEmitContext context, IProjectItem projectItem) { var mediaFile = (MediaFile)projectItem; var mediaItem = context.Project.FindQualifiedItem(mediaFile.MediaItemUri) as Projects.Items.Item; if (mediaItem == null) { context.Trace.TraceError(Msg.E1004, Texts.Media_item_not_found, new SnapshotTextNode(mediaFile.Snapshots.First()), mediaFile.MediaItemUri.Guid.Format()); return; } if (mediaFile.UploadMedia) { UploadFile(context, mediaItem, mediaFile); return; } CopyFile(context, mediaFile); }
protected virtual void EmitMediaFile([NotNull] IEmitContext context, [NotNull] MediaFile mediaFile) { if (!mediaFile.UploadMedia) { EmitFile(context, mediaFile); return; } var item = context.Project.Indexes.FindQualifiedItem <Item>(mediaFile.MediaItemUri); if (item == null) { Trace.TraceInformation(Msg.E1047, "No media item - skipping", mediaFile.Snapshot.SourceFile); return; } EmitFile(context, mediaFile); EmitItem(context, item); }
public override void EmitItem(IEmitContext context, Item item) { var sourceBag = item as ISourcePropertyBag; if (!item.IsEmittable && sourceBag.GetValue <string>("__origin_reason") != nameof(CreateItemsFromTemplates)) { return; } Trace.TraceInformation(Msg.I1011, "Publishing", item.ItemIdOrPath); foreach (var language in item.Versions.GetLanguages()) { foreach (var version in item.Versions.GetVersions(language)) { var versionedItem = item.Versions.GetVersionedItem(language, version); PackageWriter.WriteItem(versionedItem); } } }
protected virtual void EmitMediaFile([NotNull] IEmitContext context, [NotNull] MediaFile mediaFile) { if (!mediaFile.UploadMedia) { EmitFile(context, mediaFile); return; } var item = context.Project.Indexes.FindQualifiedItem <Item>(mediaFile.MediaItemUri); if (item == null) { Trace.TraceInformation(Msg.E1047, "No media item - skipping", mediaFile.Snapshot.SourceFile); return; } EmitItem(context, item); Zip.AddEntry("blob/" + mediaFile.Database.DatabaseName + "/" + mediaFile.Uri.Guid.ToString("D"), mediaFile.Snapshot.SourceFile.AbsoluteFileName); }
protected virtual void EmitRetry([NotNull] IEmitContext context, [NotNull, ItemNotNull] List <IEmitter> emitters, [NotNull, ItemNotNull] ICollection <Tuple <IProjectItem, Exception> > retries) { while (true) { var retryAgain = new List <Tuple <IProjectItem, Exception> >(); var projectItems = retries.Reverse().Select(retry => retry.Item1).ToArray(); EmitProjectItems(context, projectItems, emitters, retryAgain); if (retryAgain.Count >= retries.Count) { // did not succeed to install any items retries = retryAgain; break; } retries = retryAgain; } foreach (var retry in retries) { var projectItem = retry.Item1; var exception = retry.Item2; var buildException = exception as EmitException; if (buildException != null) { Trace.TraceError(buildException.Msg, buildException.Text, buildException.FileName, buildException.Span, buildException.Details); } else if (exception != null) { Trace.TraceError(Msg.E1002, exception.Message, projectItem.Snapshot.SourceFile.AbsoluteFileName, TextSpan.Empty); Trace.WriteLine(exception.StackTrace); } else { Trace.TraceError(Msg.E1003, Texts.An_error_occured, projectItem.Snapshot.SourceFile.AbsoluteFileName, TextSpan.Empty); } } }
public virtual void EmitMediaFile([NotNull] IEmitContext context, [NotNull] MediaFile mediaFile) { var fileName = PathHelper.NormalizeFilePath(mediaFile.FilePath); if (fileName.StartsWith("~\\")) { fileName = fileName.Mid(2); } Trace.TraceInformation(Msg.I1011, "Publishing", "~\\" + fileName); var item = context.Project.Indexes.FindQualifiedItem <Item>(mediaFile.MediaItemUri); if (item == null) { Trace.TraceInformation(Msg.E1047, "No media item - skipping", mediaFile.Snapshot.SourceFile); return; } EmitItem(context, item); }
protected virtual void EmitProjectItems([NotNull] IEmitContext context, [NotNull, ItemNotNull] IEnumerable <IProjectItem> projectItems, [NotNull, ItemNotNull] List <IEmitter> emitters, [NotNull, ItemNotNull] ICollection <Tuple <IProjectItem, Exception> > retries) { var unemitted = new List <IProjectItem>(projectItems); foreach (var emitter in emitters.OrderBy(e => e.Sortorder)) { foreach (var projectItem in projectItems) { if (!emitter.CanEmit(context, projectItem)) { continue; } EmitProjectItem(context, emitter, projectItem, retries); unemitted.Remove(projectItem); } } foreach (var projectItem in unemitted) { Trace.TraceWarning(Msg.E1039, "No emitter found", projectItem.Snapshot.SourceFile, projectItem.QualifiedName); } /* * var isMultiThreaded = context.Configuration.GetBool(Constants.Configuration.System.MultiThreaded); * if (isMultiThreaded) * { * Parallel.ForEach(nonTemplates, projectItem => EmitProjectItem(context, projectItem, emitters, retries)); * } * else * { * foreach (var projectItem in nonTemplates) * { * EmitProjectItem(context, projectItem, emitters, retries); * } * } */ }
public override void EmitItem(IEmitContext context, Item item) { if (!item.IsEmittable) { return; } Trace.TraceInformation(Msg.I1011, "Publishing", item.ItemIdOrPath); var destinationFileName = PathHelper.Combine(OutputDirectory, PathHelper.NormalizeFilePath(item.ItemIdOrPath).TrimStart('\\')); destinationFileName += ".content.xml"; FileSystem.CreateDirectoryFromFileName(destinationFileName); using (var stream = new FileStream(destinationFileName, FileMode.Create)) { using (var writer = new StreamWriter(stream)) { item.WriteAsXml(writer); } } }
public override void EmitItem(IEmitContext context, Item item) { var sourceBag = item as ISourcePropertyBag; if (!item.IsEmittable && sourceBag.GetValue <string>("__origin_reason") != nameof(CreateItemsFromTemplates)) { return; } Trace.TraceInformation(Msg.I1011, "Publishing", item.ItemIdOrPath); var destinationFileName = GetItemFileName(item.DatabaseName, item.ItemIdOrPath); FileSystem.CreateDirectoryFromFileName(destinationFileName); using (var stream = new FileStream(destinationFileName, FileMode.Create)) { using (var writer = new StreamWriter(stream)) { item.WriteAsUnicornYaml(writer); } } }
public abstract void Emit(IEmitContext context, IProjectItem projectItem);
public abstract bool CanEmit(IEmitContext context, IProjectItem projectItem);
protected virtual void EmitNugetPackage([NotNull] IEmitContext context) { var packageFileName = Configuration.GetString(Constants.Configuration.Output.Nuget.FileName, "package"); if (!packageFileName.EndsWith(".nupkg")) { packageFileName += ".nupkg"; } var outputDirectory = PathHelper.Combine(context.Project.ProjectDirectory, Configuration.GetString(Constants.Configuration.Output.Directory)); var fileName = Path.Combine(outputDirectory, packageFileName); var packageId = Path.GetFileNameWithoutExtension(fileName); var description = Configuration.GetString(Constants.Configuration.Description); if (string.IsNullOrEmpty(description)) { description = "Generated by Sitecore Pathfinder"; } var manifest = string.Empty; var nuspecFileName = Configuration.GetString(Constants.Configuration.Output.Nuget.NuspecFileName); if (!string.IsNullOrEmpty(nuspecFileName)) { nuspecFileName = PathHelper.Combine(context.Project.ProjectDirectory, nuspecFileName); if (!FileSystem.FileExists(nuspecFileName)) { Trace.TraceError(Msg.E1044, "NuSpec file not found", nuspecFileName); return; } manifest = FileSystem.ReadAllText(nuspecFileName); } if (string.IsNullOrEmpty(manifest)) { var sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\"?>"); sb.AppendLine("<package xmlns=\"http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd\">"); sb.AppendLine(" <metadata>"); sb.AppendLine(" <id>" + packageId + "</id>"); sb.AppendLine(" <title>" + Configuration.GetString(Constants.Configuration.Name, packageId) + "</title>"); sb.AppendLine(" <version>" + Configuration.GetString(Constants.Configuration.Version, string.Empty) + "</version>"); sb.AppendLine(" <authors>" + Configuration.GetString(Constants.Configuration.Author, string.Empty) + "</authors>"); sb.AppendLine(" <owners>" + Configuration.GetString(Constants.Configuration.Publisher, string.Empty) + "</owners>"); sb.AppendLine(" <requireLicenseAcceptance>false</requireLicenseAcceptance>"); sb.AppendLine(" <description>" + description + "</description>"); sb.AppendLine(" </metadata>"); sb.AppendLine("</package>"); manifest = sb.ToString(); } using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(manifest))) { var packageBuilder = new PackageBuilder(stream, outputDirectory); using (var nupkg = FileSystem.OpenWrite(fileName)) { packageBuilder.Save(nupkg); } } context.OutputFiles.Add(Factory.OutputFile(fileName)); }
public override bool CanEmit(IEmitContext context, IProjectItem projectItem) { return projectItem is SerializationFile; }
protected virtual void Emit([NotNull] IEmitContext context, [NotNull] IProjectBase project, [NotNull, ItemNotNull] List <IEmitter> emitters, [NotNull, ItemNotNull] ICollection <Tuple <IProjectItem, Exception> > retries) { EmitProjectItems(context, project.ProjectItems, emitters, retries); }
public override bool CanEmit(IEmitContext context, IProjectItem projectItem) { return projectItem is MediaFile; }
protected virtual void EmitTemplate([NotNull] IEmitContext context, [NotNull] Template template) { }
public virtual void EmitTemplate([NotNull] IEmitContext context, [NotNull] Template item) { Trace.TraceInformation(Msg.I1011, "Publishing", item.ItemIdOrPath); _templates.Add(item); }
public virtual void EmitItem([NotNull] IEmitContext context, [NotNull] Item item) { _items.Add(item); Trace.TraceInformation(Msg.I1011, "Publishing", item.ItemIdOrPath); var hasVersions = item.Fields.Any(f => !f.TemplateField.Shared && !f.TemplateField.Unversioned); var languages = item.Versions.GetLanguages().ToList(); if (!languages.Any()) { var language = item.Database.Languages.FirstOrDefault(); if (language == null) { Trace.TraceError(Msg.E1000, "No languages defined"); return; } languages = new List <Language> { language }; } foreach (var language in languages) { var versions = item.Versions.GetVersions(language).ToList(); if (!versions.Any()) { versions = new List <Projects.Items.Version> { Factory.Version(1) }; } foreach (var version in versions) { var fileName = item.DatabaseName + PathHelper.NormalizeFilePath(item.ItemIdOrPath) + "\\" + item.Uri.Guid.Format() + "\\" + language.LanguageName + "\\" + version.Number + "\\xml"; using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream, Encoding.UTF8)) { using (var output = Factory.XmlWriter(writer)) { var parent = item.GetParent(); var parentId = parent != null?parent.Uri.Guid.Format() : string.Empty; output.WriteStartElement("item"); output.WriteAttributeString("name", item.ItemName); output.WriteAttributeString("key", item.ItemName.ToLowerInvariant()); output.WriteAttributeString("id", item.Uri.Guid.Format()); output.WriteAttributeString("tid", item.Template.Uri.Guid.Format()); output.WriteAttributeString("mid", "{00000000-0000-0000-0000-000000000000}"); output.WriteAttributeString("sortorder", item.Sortorder.ToString()); output.WriteAttributeString("language", language.LanguageName); output.WriteAttributeString("version", version.ToString()); output.WriteAttributeString("template", item.TemplateName.ToLowerInvariant()); output.WriteAttributeString("parentid", parentId); output.WriteStartElement("fields"); foreach (var field in item.Fields[language, version]) { output.WriteStartElement("field"); output.WriteAttributeString("tfid", field.FieldId.Format()); output.WriteAttributeString("key", field.FieldName.ToLowerInvariant()); output.WriteAttributeString("type", field.TemplateField.Type); output.WriteStartElement("content"); output.WriteValue(field.CompiledValue); output.WriteEndElement(); output.WriteEndElement(); } if (!hasVersions) { // make sure there is a version output.WriteStartElement("field"); output.WriteAttributeString("tfid", Constants.Fields.CreatedBy.Format()); output.WriteAttributeString("key", "__created by"); output.WriteAttributeString("type", "text"); output.WriteStartElement("content"); output.WriteValue("sitecore\\admin"); output.WriteEndElement(); output.WriteEndElement(); } output.WriteEndElement(); output.WriteEndElement(); } Zip.AddEntry("items/" + NormalizeZipPath(fileName), stream.ToArray()); } } using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream, Encoding.UTF8)) { writer.WriteLine("database=" + item.DatabaseName); writer.WriteLine("id=" + item.Uri.Guid.Format()); writer.WriteLine("language=" + language.LanguageName); writer.WriteLine("version=" + version.Number); writer.WriteLine("revision=" + Guid.NewGuid().ToString("D")); writer.WriteLine("fieldproperties=" + string.Join("|", item.Fields[language, version].Select(f => f.FieldId.Format() + ":" + (f.TemplateField.Shared ? "Shared" : f.TemplateField.Unversioned ? "Unversioned" : "Versioned")))); } Zip.AddEntry("properties/items/" + NormalizeZipPath(fileName), stream.ToArray()); } } } }
public override bool CanEmit(IEmitContext context, IProjectItem projectItem) { return projectItem is Template; }