本文整理汇总了C#中Package.TryGetParameter方法的典型用法代码示例。如果您正苦于以下问题:C# Package.TryGetParameter方法的具体用法?C# Package.TryGetParameter怎么用?C# Package.TryGetParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.TryGetParameter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
package.TryGetParameter("retrofitMode", out _retrofitMode, Logger);
// The input Component is used to relate all the generated Binaries to (so they get unpublished if the Component is unpublished).
Component inputComponent = GetComponent();
StructureGroup mappingsStructureGroup = GetSystemStructureGroup("mappings");
List<Binary> binaries = new List<Binary>
{
PublishSemanticVocabularies(mappingsStructureGroup, inputComponent),
PublishSemanticSchemas(mappingsStructureGroup, inputComponent),
PublishXpmRegionConfiguration(mappingsStructureGroup, inputComponent),
PublishPageIncludes(mappingsStructureGroup, inputComponent)
};
AddBootstrapJsonBinary(binaries, inputComponent, mappingsStructureGroup, "mapping");
OutputSummary("Publish Mappings", binaries.Select(b => b.Url));
}
示例2: Transform
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
bool cleanup;
package.TryGetParameter("cleanup", out cleanup, Logger);
string drive;
package.TryGetParameter("drive", out drive, Logger);
List<Binary> binaries = new List<Binary>();
// Read values from HTML Design Configuration Component (which should be the Component used for this Component Presentation)
Component inputComponent = GetComponent();
if (inputComponent.Schema.NamespaceUri != HtmlDesignConfigNamespace || inputComponent.Schema.RootElementName != HtmlDesignConfigRootElementName)
{
throw new DxaException(
string.Format("Unexpected input Component {0} ('{1}'). Expecting HTML Design Configuration Component.", inputComponent.Id, inputComponent.Title)
);
}
ItemFields htmlDesignConfigFields = new ItemFields(inputComponent.Content, inputComponent.Schema);
Component favIconComponent = htmlDesignConfigFields.GetMultimediaLink("favicon");
string htmlDesignVersion = htmlDesignConfigFields.GetTextValue("version");
// Publish version.json file
IDictionary<string, string> versionData = new Dictionary<string, string> { { "version", htmlDesignVersion } };
Binary versionJsonBinary = AddJsonBinary(versionData, inputComponent, Publication.RootStructureGroup, "version", variantId: "version");
binaries.Add(versionJsonBinary);
string tempFolder = GetTempFolder(drive);
Directory.CreateDirectory(tempFolder);
Logger.Debug("Created temp folder: " + tempFolder);
try
{
// Unzip and merge files
ProcessModules(tempFolder);
string distFolder = BuildHtmlDesign(tempFolder);
// Save favicon to disk (if available)
if (favIconComponent != null)
{
string favIconFilePath = Path.Combine(distFolder, "favicon.ico");
File.WriteAllBytes(favIconFilePath, favIconComponent.BinaryContent.GetByteArray());
Logger.Debug("Saved " + favIconFilePath);
}
// Publish all files from dist folder
Publication pub = (Publication) inputComponent.ContextRepository;
string rootStructureGroupWebDavUrl = pub.RootStructureGroup.WebDavUrl;
RenderedItem renderedItem = engine.PublishingContext.RenderedItem;
string[] distFiles = Directory.GetFiles(distFolder, "*.*", SearchOption.AllDirectories);
foreach (string file in distFiles)
{
Logger.Debug("Found " + file);
// Map the file path to a Structure Group
string relativeFolderPath = file.Substring(distFolder.Length, file.LastIndexOf('\\') - distFolder.Length);
Logger.Debug(string.Format("Relative folder path: '{0}'",relativeFolderPath));
string sgWebDavUrl = rootStructureGroupWebDavUrl + relativeFolderPath.Replace("system", SystemSgName).Replace('\\', '/');
StructureGroup structureGroup = engine.GetObject(sgWebDavUrl) as StructureGroup;
if (structureGroup == null)
{
throw new DxaException(string.Format("Cannot publish '{0}' because Structure Group '{1}' does not exist.", file, sgWebDavUrl));
}
// Add binary to package and publish
using (FileStream fs = File.OpenRead(file))
{
string filename = Path.GetFileName(file);
string extension = Path.GetExtension(file);
string variantId = string.Format("dist-{0}-{1}", structureGroup.Id.ItemId, filename);
Item binaryItem = Package.CreateStreamItem(GetContentType(extension), fs);
Binary binary = renderedItem.AddBinary(
binaryItem.GetAsStream(),
filename,
structureGroup,
variantId,
inputComponent,
GetMimeType(extension)
);
binaryItem.Properties[Item.ItemPropertyPublishedPath] = binary.Url;
package.PushItem(filename, binaryItem);
binaries.Add(binary);
Logger.Info(string.Format("Added Binary '{0}' related to Component '{1}' ({2}) with variant ID '{3}'",
binary.Url, inputComponent.Title, inputComponent.Id, variantId));
}
}
}
finally
{
if (cleanup)
{
Directory.Delete(tempFolder, true);
Logger.Debug("Removed temp folder " + tempFolder);
}
else
//.........这里部分代码省略.........