本文整理汇总了C#中TcmUri.GetVersionlessUri方法的典型用法代码示例。如果您正苦于以下问题:C# TcmUri.GetVersionlessUri方法的具体用法?C# TcmUri.GetVersionlessUri怎么用?C# TcmUri.GetVersionlessUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcmUri
的用法示例。
在下文中一共展示了TcmUri.GetVersionlessUri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
if (package.GetByName(Package.OutputName) == null)
{
log.Error("Could not find \"Output\" item in Package. This template building block should be the last TBB in your template.");
return;
}
Item output = package.GetByName(Package.OutputName);
string outputText = output.GetAsString();
bool outputchanged = false;
foreach (Match m in TcmUriRegEx.Matches(outputText))
{
log.Debug("Found " + m.Value);
TcmUri uri = new TcmUri(m.Value);
if(uri.GetVersionlessUri().ToString().Equals(m.Value)) continue;
log.Debug("Found version information on uri " + m.Value + ". Removing.");
outputText = outputText.Replace(m.Value, uri.GetVersionlessUri().ToString());
outputchanged = true;
}
if (outputchanged)
{
output.SetAsString(outputText);
package.Remove(output);
package.PushItem(Package.OutputName, output);
}
}
示例2: GetImportTemplateContent
/// <summary>
/// Gets an imported template's content. Works with tcm uri's, web dav urls, or physical file paths.
/// </summary>
/// <param name="path">The path to check.</param>
/// <param name="engine"></param>
/// <returns></returns>
private string GetImportTemplateContent(string path)
{
TcmUri templateID = new TcmUri(_templateID);
if (path.ToLower().StartsWith("tcm:") || path.ToLower().StartsWith("/webdav/") || !path.Contains("\\"))
{
if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/"))
{
path = GetRelativeImportPath(path);
}
TemplateBuildingBlock template;
try
{
template = Session.GetObject(path) as TemplateBuildingBlock;
}
catch (Exception ex)
{
_logger.Warning("Error import of '" + path + "'. " + ex.ToString());
return String.Empty;
}
if (template == null)
{
_logger.Warning("Import of '" + path + "' not found.");
return String.Empty;
}
_logger.Debug("Comaring import template " + template.Id + " to razor tbb ID " + templateID);
// Get local copy of the imported template if possible.
int publicationID = templateID.PublicationId;
if (TcmUri.IsNullOrUriNull(templateID))
{
// Is new item, so templateID is tcm:0-0-0. We need to grab the pub id manually.
string[] webDav = _webDavUrl.Split('/');
string pubWebDav = "/webdav/" + webDav[2];
publicationID = Session.GetObject(pubWebDav).Id.ItemId;
}
if (template.Id.PublicationId != publicationID)
{
// If import is from diff publication, try to grab local copy.
try
{
template = (TemplateBuildingBlock)Session.GetObject(TemplateUtilities.CreateTcmUriForPublication(publicationID, template.Id));
}
catch
{
_logger.Warning("Error trying to get local copy of template '" + template.Id + "' for Publication ID '" + publicationID + "'");
}
}
// Don't import itself
if (template.Id.GetVersionlessUri().Equals(templateID.GetVersionlessUri()))
{
return String.Empty;
}
return template.Content;
}
else
{
// If its a file path, get the contents of the file and return.
return File.ReadAllText(path);
}
}