本文整理汇总了C#中Package.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Package.GetValue方法的具体用法?C# Package.GetValue怎么用?C# Package.GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public void Transform(Engine engine, Package package)
{
this.package = package;
this.engine = engine;
if (engine.PublishingContext.RenderContext != null && engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery))
{
if (engine.PublishingContext.RenderContext.ContextVariables[BasePageTemplate.VariableNameCalledFromDynamicDelivery].Equals(BasePageTemplate.VariableValueCalledFromDynamicDelivery))
{
log.Debug("template is rendered by a DynamicDelivery page template, will not convert from XML to java");
return;
}
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (inputValue == null || inputValue.Length == 0)
{
log.Warning("Could not find 'Output' in the package, nothing to transform");
return;
}
String minimizeSettings = package.GetValue("MinimizeSettings");
string outputValue = XmlMinimizer.Convert(inputValue, minimizeSettings);
// replace the Output item in the package
package.Remove(outputItem);
outputItem.SetAsString(outputValue);
package.PushItem("Output", outputItem);
}
示例2: Transform
public void Transform(Engine engine, Package package) {
this.package = package;
this.engine = engine;
if (engine.PublishingContext.RenderContext != null && engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery))
{
if (engine.PublishingContext.RenderContext.ContextVariables[BasePageTemplate.VariableNameCalledFromDynamicDelivery].Equals(BasePageTemplate.VariableValueCalledFromDynamicDelivery))
{
log.Debug("template is rendered by a DynamicDelivery page template, will not convert to lower case");
return;
}
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (inputValue == null || inputValue.Length == 0) {
log.Error("Could not find 'Output' in the package. Exiting template.");
return;
}
string convertedValue = LowerCaseConverter.Convert(inputValue);
package.Remove(outputItem);
outputItem.SetAsString(convertedValue);
package.PushItem("Output", outputItem);
}
示例3: Transform
public void Transform(Engine engine, Package package)
{
// do NOT execute this logic when we are actually publishing! (similair for fast track publishing)
if (engine.RenderMode == RenderMode.Publish || (engine.PublishingContext.PublicationTarget != null && !Tcm.TcmUri.IsNullOrUriNull(engine.PublishingContext.PublicationTarget.Id)))
{
return;
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (string.IsNullOrEmpty(inputValue))
{
log.Warning("Could not find 'Output' in the package, nothing to preview");
return;
}
// read staging url from configuration
string stagingUrl = TridionConfigurationManager.GetInstance(engine, package).AppSettings["StagingUrl"];
string outputValue = HttpPost(stagingUrl, inputValue);
if (string.IsNullOrEmpty(outputValue))
{
outputValue = "<h2>There was an error while generating the preview.</h2>";
}
// replace the Output item in the package
package.Remove(outputItem);
package.PushItem("Output", package.CreateStringItem(ContentType.Html, outputValue));
}
示例4: Transform
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
Component comp = GetComponent();
if (IsPageTemplate() || comp == null)
{
Logger.Error("No Component found (is this a Page Template?)");
return;
}
Item outputItem = package.GetByName(Package.OutputName);
if (outputItem == null)
{
Logger.Error("No Output package item found (is this TBB placed at the end?)");
return;
}
_metaFieldNames = (package.GetValue("multimediaLinkAttributes") ?? String.Empty).Split(',').Select(s => s.Trim()).ToList();
// resolve rich text fields
XmlDocument doc = new XmlDocument();
string output = outputItem.GetAsString();
doc.LoadXml(output);
var fields = doc.SelectNodes("//Field[@FieldType='Xhtml']/Values/string");
foreach (XmlElement field in fields)
{
field.InnerXml = ResolveXhtml(field.InnerXml);
}
package.Remove(outputItem);
package.PushItem(Package.OutputName, package.CreateXmlDocumentItem(ContentType.Xml, doc));
}
示例5: Transform
public void Transform(Engine engine, Package package)
{
this.package = package;
this.engine = engine;
if (engine.PublishingContext.RenderContext != null && engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery))
{
if (engine.PublishingContext.RenderContext.ContextVariables[BasePageTemplate.VariableNameCalledFromDynamicDelivery].Equals(BasePageTemplate.VariableValueCalledFromDynamicDelivery))
{
log.Debug("template is rendered by a DynamicDelivery page template, will not convert from XML to java");
return;
}
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (inputValue == null || inputValue.Length == 0)
{
log.Warning("Could not find 'Output' in the package, nothing to transform");
return;
}
// Combine the 'to lower' and 'to java' functions, since there is no reason to have one without the other.
// Note: it is still possible (for backwards compatibility) to have a separate ToLower TBB in your templates.
// In that case, the first letter of each element will be converted into lower case twice, which doesn't do any harm.
string outputValue = LowerCaseConverter.Convert(inputValue);
outputValue = XmlToJavaConverter.Convert(outputValue);
// outputValue = XmlMinimizer.Convert(outputValue);
// replace the Output item in the package
package.Remove(outputItem);
outputItem.SetAsString(outputValue);
package.PushItem("Output", outputItem);
}
示例6: Transform
public void Transform(Engine engine, Package package)
{
if (package.GetByName(Package.PageName) == null) return;
comm.Page page = (comm.Page)engine.GetObject(package.GetByName(Package.PageName));
Dictionary<string, List<ComponentPresentation>> lists = new Dictionary<string, List<ComponentPresentation>>();
string matchTokens = package.GetValue("ComponentTemplateTitleMatchTokens");
if (!String.IsNullOrEmpty(matchTokens))
{
foreach (string token in matchTokens.Split(','))
{
_matchTokens.Add(token.Trim());
}
}
foreach (comm.ComponentPresentation cp in page.ComponentPresentations)
{
string ct = GetPresentationType(cp.ComponentTemplate.Title);
if (!lists.ContainsKey(ct))
lists.Add(ct, new List<ComponentPresentation>());
lists[ct].Add(new ComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id));
}
foreach (string token in lists.Keys)
{
Item item = package.CreateStringItem(ContentType.ComponentArray, ComponentPresentationList.ToXml(lists[token]));
package.PushItem(token + "Components", item);
}
}
示例7: Transform
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
Component comp = GetComponent();
if (IsPageTemplate() || comp == null)
{
Logger.Error("No Component found (is this a Page Template?)");
return;
}
Item outputItem = package.GetByName(Package.OutputName);
if (outputItem == null)
{
Logger.Error("No Output package item found (is this TBB placed at the end?)");
return;
}
_metaFieldNames = (package.GetValue("multimediaLinkAttributes") ?? String.Empty).Split(',').Select(s => s.Trim()).ToList();
// resolve rich text fields
string output = outputItem.GetAsString();
package.Remove(outputItem);
if (output.StartsWith("<"))
{
Logger.Debug("Content is XML");
//XML - only for backwards compatibility
package.PushItem(Package.OutputName, package.CreateXmlDocumentItem(ContentType.Xml, ResolveXmlContent(output)));
}
else
{
Logger.Debug("Content is JSON");
//JSON
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, ResolveJsonContent(output)));
}
}
示例8: Transform
public override void Transform(Engine engine, Package package)
{
GeneralUtils.TimedLog("started Transform");
this.Package = package;
this.Engine = engine;
object component;
bool hasOutput = HasPackageValue(package, "Output");
if (hasOutput)
{
String inputValue = package.GetValue("Output");
if (ComponentPresentationRenderStyle == Base.ComponentPresentationRenderStyle.Component)
{
component = (Dynamic.Component)SerializerService.Deserialize<Dynamic.Component>(inputValue);
}
else
{
component = (Dynamic.ComponentPresentation)SerializerService.Deserialize<Dynamic.ComponentPresentation>(inputValue);
}
}
else
{
if (ComponentPresentationRenderStyle == Base.ComponentPresentationRenderStyle.Component)
{
component = GetDynamicComponent();
}
else
{
component = GetDynamicComponentPresentation();
}
}
try
{
TransformComponent(ComponentPresentationRenderStyle == Base.ComponentPresentationRenderStyle.Component ? (Dynamic.Component) component : ((Dynamic.ComponentPresentation)component).Component);
}
catch (StopChainException)
{
Log.Debug("caught stopchainexception, will not write current component back to the package");
return;
}
string outputValue = ComponentPresentationRenderStyle == Base.ComponentPresentationRenderStyle.Component ? SerializerService.Serialize<Dynamic.Component>((Dynamic.Component)component) : SerializerService.Serialize<Dynamic.ComponentPresentation>((Dynamic.ComponentPresentation)component);
if (hasOutput)
{
Item outputItem = package.GetByName("Output");
outputItem.SetAsString(outputValue);
}
else
{
package.PushItem(Package.OutputName, package.CreateStringItem(SerializerService is XmlSerializerService ? ContentType.Xml : ContentType.Text, outputValue));
}
GeneralUtils.TimedLog("finished Transform");
}
示例9: Transform
public void Transform(Engine engine, Package package)
{
//Emid the field "data" as output
package.PushItem(
Package.OutputName,
package.CreateStringItem(
ContentType.Text,
package.GetValue("Component.Fields.data")
)
);
}
示例10: Transform
public void Transform(Engine engine, Package package)
{
//Fetch package variables and template paramaters
string output = package.GetValue(Package.OutputName);
string pattern = package.GetValue("tp_find");
string regexOptions = package.GetValue("tp_regexoptions") ?? string.Empty;
string replace = package.GetValue("tp_replace") ?? string.Empty;
//Create regex options enum variable
RegexOptions options = RegexOptions.None;
if (regexOptions.Contains("i")) { options |= RegexOptions.IgnoreCase; }
if (regexOptions.Contains("s")) { options |= RegexOptions.Singleline; }
if (regexOptions.Contains("m")) { options |= RegexOptions.Multiline; }
if (regexOptions.Contains("r")) { options |= RegexOptions.RightToLeft; }
//Create regex and perform replace on output
Regex regex = new Regex(pattern, options);
output = regex.Replace(output, replace);
//Update output package variable
package.GetByName(Package.OutputName).SetAsString(output);
}
示例11: Main
static void Main(string[] args)
{
ITemplate tbb = new RegexReplace();
Session session = new Session();
Console.WriteLine(session.GetObject("tcm:4-847").Title);
using (UnittestingTemplatingRenderer engine = new UnittestingTemplatingRenderer("tcm:4-847", "tcm:4-64-32"))
{
Package package = new Package(engine);
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, "Tridion Developer Summit 2013"));
package.PushItem("tp_find", package.CreateStringItem(ContentType.Text, "2013"));
package.PushItem("tp_replace", package.CreateStringItem(ContentType.Text, "2014"));
tbb.Transform(engine, package);
string output = package.GetValue(Package.OutputName);
}
Console.ReadLine();
}
示例12: Transform
public void Transform(Engine engine, Package package)
{
this.package = package;
this.engine = engine;
Item outputItem = package.GetByName(Package.OutputName);
string inputValue = package.GetValue(Package.OutputName);
if (string.IsNullOrEmpty(inputValue))
{
log.Warning("Could not find 'Output' in the package, nothing to transform");
return;
}
string outputValue = Compressor.Compress(inputValue);
// replace the Output item in the package
outputItem.SetAsString(outputValue);
}
示例13: DxaBuildManager
public DxaBuildManager(Package package, Engine engine)
: base(package, engine)
{
// Minimize the amount of unneeded data in the DD4T JSON:
BuildProperties.OmitFolders = true;
BuildProperties.OmitCategories = true;
BuildProperties.OmitContextPublications = true;
BuildProperties.OmitOwningPublications = true;
BuildProperties.OmitValueLists = true;
BuildProperties.ECLEnabled = true; // ECL is only used for ECL Stubs
string expandLinkDepth = package.GetValue("expandLinkDepth");
_logger.Debug(string.Format("expandLinkDepth: {0}", expandLinkDepth));
if (!string.IsNullOrEmpty(expandLinkDepth))
{
BuildProperties.LinkLevels = Convert.ToInt32(expandLinkDepth);
}
}
示例14: Transform
public override void Transform(Engine engine, Package package)
{
GeneralUtils.TimedLog("started Transform");
Package = package;
Engine = engine;
Dynamic.Page page;
bool hasOutput = HasPackageValue(package, "Output");
if (hasOutput)
{
String inputValue = package.GetValue("Output");
page = (Dynamic.Page)SerializerService.Deserialize<Dynamic.Page>(inputValue);
}
else
{
page = GetDynamicPage();
}
try
{
TransformPage(page);
}
catch (StopChainException)
{
Log.Debug("caught stopchainexception, will not write current page back to the package");
return;
}
string outputValue = SerializerService.Serialize<Dynamic.Page>(page);
if (hasOutput)
{
Item outputItem = package.GetByName("Output");
outputItem.SetAsString(outputValue);
//package.Remove(outputItem);
//package.PushItem(Package.OutputName, package.CreateStringItem(SerializerService is XmlSerializerService ? ContentType.Xml : ContentType.Text, outputValue));
}
else
{
package.PushItem(Package.OutputName, package.CreateStringItem(SerializerService is XmlSerializerService ? ContentType.Xml : ContentType.Text, outputValue));
}
GeneralUtils.TimedLog("finished Transform");
}
示例15: Transform
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
Item outputItem = package.GetByName(Package.OutputName);
if (outputItem == null)
{
Logger.Error("No Output item found in package. Ensure this TBB is executed at the end of the modular templating pipeline.");
return;
}
string multimediaLinkAttributesParam = package.GetValue("multimediaLinkAttributes") ?? string.Empty;
Logger.Debug("Using multimediaLinkAttributes: " + multimediaLinkAttributesParam);
_dataFieldNames = multimediaLinkAttributesParam.Split(',').Select(s => s.Trim()).ToList();
string output = outputItem.GetAsString();
package.Remove(outputItem);
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, PreProcessRichTextContent(output)));
}