本文整理汇总了C#中IContent.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.SetValue方法的具体用法?C# IContent.SetValue怎么用?C# IContent.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContent
的用法示例。
在下文中一共展示了IContent.SetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PublishErrorPage
private static void PublishErrorPage(CancellableEventArgs e, IContent content)
{
var helper = new UmbracoHelper(UmbracoContext.Current);
var published = helper.TypedContent(content.Id);
if (published != null)
{
var publisher = NinjectWebCommon.Kernel.GetService<IPublishingService>();
if (publisher.PublishWebFormsPage(published.UrlWithDomain(), content.ContentType.Alias))
{
e.Messages.Add(new EventMessage("Success", "Static error page updated", EventMessageType.Info));
content.SetValue(PropertyAliases.StaticPage, string.Format("/{0}.aspx", content.ContentType.Alias));
}
else
{
e.Messages.Add(new EventMessage("Error", "Failure updating static error page", EventMessageType.Error));
}
}
else
{
e.Messages.Add(new EventMessage("Warning", "Publish again to update static error page", EventMessageType.Warning));
}
}
示例2: FormBulkUpdate
private IContent FormBulkUpdate(IContent form, BulkUpdateModel model)
{
if (model.Tags != null)
{
form.SetTags("formTags", model.Tags, true, TAG_GROUP_GLEANER_FORM);
}
if (model.Groups != null)
{
form.SetValue("associatedGroups", string.Join(",", model.Groups));
}
if (model.IsPublic.HasValue)
{
form.SetValue("isPublic", model.IsPublic.Value);
}
if (model.IsRequired.HasValue)
{
form.SetValue("isRequired", model.IsRequired.Value);
}
if (model.StartDate.HasValue)
{
form.SetValue("startDate", model.StartDate.Value);
}
if (model.EndDate.HasValue)
{
form.SetValue("endDate", model.EndDate.Value);
}
return form;
}
示例3: FormBulkRemove
private IContent FormBulkRemove(IContent form, BulkUpdateModel model)
{
if (model.Tags != null)
{
form.RemoveTags("formTags", model.Tags, TAG_GROUP_GLEANER_FORM);
}
if (model.Groups != null)
{
var currentValue = form.GetValue<string>("associatedGroups").ToDelimitedList().Select(Int32.Parse);
form.SetValue("associatedGroups", string.Join(",", currentValue.Except(model.Groups)));
}
return form;
}
示例4: FormBulkArchive
private IContent FormBulkArchive(IContent form)
{
form.SetValue("isArchived", true);
return form;
}
示例5: SetDescription
private IContent SetDescription(IContent content, bool hasLowKarma, ref bool hasAnchors)
{
content.SetValue("description", tb_desc.Text);
// Filter out links when karma is low, probably a spammer
if (hasLowKarma)
{
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(tb_desc.Text);
var anchorNodes = doc.DocumentNode.SelectNodes("//a");
if (anchorNodes != null)
{
hasAnchors = true;
foreach (var anchor in anchorNodes)
anchor.ParentNode.RemoveChild(anchor, true);
}
content.SetValue("description", doc.DocumentNode.OuterHtml);
}
return content;
}
示例6: SetModelToContent
private static void SetModelToContent(ref IContent content, ArborEventModel model)
{
DateTime startDate;
DateTime.TryParse(model.StartDate + " " + model.StartTime, out startDate);
DateTime endDate;
DateTime.TryParse(model.EndDate + " " + model.EndTime, out endDate);
content.SetValue("title", model.Title);
content.SetValue("description", model.Description);
content.SetValue("startDate", startDate);
content.SetValue("endDate", endDate);
content.SetValue("location", JsonConvert.SerializeObject(new List<Address>
{
new Address()
{
Street = model.Street,
City = model.City,
State = model.State,
ZipCode = model.ZipCode
}
}));
content.SetValue("links", JsonConvert.SerializeObject(new List<SocialLinks>
{
new SocialLinks()
{
Facebook = model.Facebook,
Twitter = model.Twitter,
Instagram = model.Instagram,
Blog = model.Blog
}
}));
content.SetValue("images", model.Images);
}
示例7: SaveContent
private void SaveContent(XElement node, IContent content, Content newContent, ZipFile zip)
{
var dataTypes = new Config().GetSpecialDataTypes();
content.ParentId = GetContentParentId(newContent);
content.SortOrder = newContent.SortOrder;
content.Name = newContent.Name;
content.CreatorId = User.GetCurrent().Id;
content.WriterId = User.GetCurrent().Id;
if (content.Template != null)
{
content.Template.Id = newContent.TemplateId;
}
if (newContent.ReleaseDate != DateTime.MinValue)
{
content.ReleaseDate = newContent.ReleaseDate;
}
if (newContent.ExpireDate != DateTime.MinValue)
{
content.ExpireDate = newContent.ExpireDate;
}
foreach (var propertyTag in node.Elements())
{
var dataTypeGuid = new Guid(propertyTag.Attribute("dataTypeGuid").Value);
var value = propertyTag.Value;
// The null check here is necessary. Blank content exports into the xml, which is fine, since on
// import the blank value gets mapped across. However, for upload datatypes, this blank value
// causes an exception here - unless we perform the null check.
if (dataTypeGuid == new Guid(Constants.UploadDataTypeGuid) && propertyTag.Attribute("fileName") != null)
{
var fileName = propertyTag.Attribute("fileName").Value;
var umbracoFile = propertyTag.Attribute("umbracoFile").Value;
if (!string.IsNullOrWhiteSpace(umbracoFile))
{
content.SetValue(propertyTag.Name.ToString(), fileName, GetFileStream(umbracoFile, zip));
}
else
{
content.SetValue(propertyTag.Name.ToString(), string.Empty);
}
}
else if (!dataTypes.ContainsKey(dataTypeGuid))
{
content.SetValue(propertyTag.Name.ToString(), value);
}
}
SaveContent(content, bool.Parse(node.Attribute("published").Value));
}
示例8: AddOrUpdateContent
private void AddOrUpdateContent(IContent content, MetaWeblogPost post, IUser user, bool publish)
{
content.Name = post.Title;
content.SetValue("author", user.Name);
if (content.HasProperty("richText"))
{
content.SetValue("richText", post.Content);
}
if (!post.Slug.IsNullOrWhiteSpace())
{
content.SetValue("umbracoUrlName", post.Slug);
}
if (!post.Excerpt.IsNullOrWhiteSpace())
{
content.SetValue("excerpt", post.Excerpt);
}
if (post.AllowComments == 1)
{
content.SetValue("enableComments", 1);
}
else if (post.AllowComments == 2)
{
content.SetValue("enableComments", 0);
}
content.SetTags("categories", post.Categories, true, "ArticulateCategories");
var tags = post.Tags.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();
content.SetTags("tags", tags, true, "ArticulateTags");
if (publish)
{
if (post.CreateDate != DateTime.MinValue)
{
content.SetValue("publishedDate", post.CreateDate);
}
_applicationContext.Services.ContentService.SaveAndPublishWithStatus(content, user.Id);
}
else
{
_applicationContext.Services.ContentService.Save(content, user.Id);
}
}
示例9: SetPropertyOnIContent
private void SetPropertyOnIContent(IContent content, UmbracoPropertyAttribute umbracoPropertyAttribute, object propertyValue, string alias = null)
{
object convertedValue;
if (umbracoPropertyAttribute.ConverterType != null)
{
TypeConverter converter = (TypeConverter)Activator.CreateInstance(umbracoPropertyAttribute.ConverterType);
convertedValue = converter.ConvertTo(null, CultureInfo.InvariantCulture, propertyValue, typeof(string));
}
else
{
//No converter is given so basically we push the string back into umbraco
convertedValue = propertyValue.ToString();
}
if (alias == null) alias = umbracoPropertyAttribute.Alias;
content.SetValue(alias, convertedValue);
}
示例10: AddOrUpdateContent
private void AddOrUpdateContent(IContent content, MetaWeblogPost post, IUser user, bool publish, bool extractFirstImageAsProperty)
{
content.Name = post.Title;
content.SetValue("author", user.Name);
if (content.HasProperty("richText"))
{
var firstImage = "";
//we need to replace all absolute image paths with relative ones
var contentToSave = _mediaSrc.Replace(post.Content, match =>
{
if (match.Groups.Count == 2)
{
var imageSrc = match.Groups[1].Value.EnsureStartsWith('/');
if (firstImage.IsNullOrWhiteSpace())
{
firstImage = imageSrc;
}
return " src=\"" + imageSrc + "\"";
}
return null;
});
var imagesProcessed = 0;
//now replace all absolute anchor paths with relative ones
contentToSave = _mediaHref.Replace(contentToSave, match =>
{
if (match.Groups.Count == 2)
{
var href = " href=\"" +
match.Groups[1].Value.EnsureStartsWith('/') +
"\" class=\"a-image-" + imagesProcessed + "\" ";
imagesProcessed++;
return href;
}
return null;
});
content.SetValue("richText", contentToSave);
if (extractFirstImageAsProperty
&& content.HasProperty("postImage")
&& !firstImage.IsNullOrWhiteSpace())
{
content.SetValue("postImage", firstImage);
//content.SetValue("postImage", JsonConvert.SerializeObject(JObject.FromObject(new
//{
// src = firstImage
//})));
}
}
if (!post.Slug.IsNullOrWhiteSpace())
{
content.SetValue("umbracoUrlName", post.Slug);
}
if (!post.Excerpt.IsNullOrWhiteSpace())
{
content.SetValue("excerpt", post.Excerpt);
}
if (post.AllowComments == 1)
{
content.SetValue("enableComments", 1);
}
else if (post.AllowComments == 2)
{
content.SetValue("enableComments", 0);
}
content.SetTags("categories", post.Categories, true, "ArticulateCategories");
var tags = post.Tags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();
content.SetTags("tags", tags, true, "ArticulateTags");
if (publish)
{
if (post.CreateDate != DateTime.MinValue)
{
content.SetValue("publishedDate", post.CreateDate);
}
_applicationContext.Services.ContentService.SaveAndPublishWithStatus(content, user.Id);
}
else
{
_applicationContext.Services.ContentService.Save(content, user.Id);
}
}
示例11: SetPropertyDefaults
private void SetPropertyDefaults(DefinedContentItem item, IContent contentItem)
{
foreach (PropertyDefault property in item.PropertyDefaults)
{
if (!string.IsNullOrEmpty(property.PropertyAlias) && !string.IsNullOrEmpty(property.Value))
{
string propertyValue = "";
switch (property.ValueType)
{
case PropertyDefaultValueType.Key:
propertyValue = GetId(property.Value).ToString();
break;
case PropertyDefaultValueType.StaticValue:
propertyValue = property.Value;
break;
default:
throw new Exception("Unknown property default value type for property " + property.PropertyAlias + " on key " + item.Key);
}
contentItem.SetValue(property.PropertyAlias, propertyValue);
}
}
}
示例12: UpdateFormVersion
private void UpdateFormVersion(IContent savingContent)
{
if (!savingContent.IsDirty())
{
return;
}
var glVersion = savingContent.GetValue<string>("glVersion");
var version = "1";
if (!string.IsNullOrEmpty(glVersion))
{
var parts = glVersion.ToDelimitedList(".");
var major = Int32.Parse(parts[0]);
var minor = parts.Count > 1 ? Int32.Parse(parts[1]) : 0;
var isNewVersion = savingContent.IsPropertyDirty("formUpload");
version = isNewVersion
? (major + 1).ToString()
: string.Join(".", major, minor + 1);
}
savingContent.SetValue("glVersion", version);
}
示例13: SetProperty
private static void SetProperty(IContent orderedProductDoc, string propertyAlias, object value)
{
if (orderedProductDoc.HasProperty(propertyAlias))
orderedProductDoc.SetValue(propertyAlias, value);
}
示例14: EnsureNavigationTitle
/// <summary>
/// Ensures that the node name is the same as the post title
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
public IContent EnsureNavigationTitle(IContent doc)
{
var navTitle = doc.GetValue<string>("uBlogsyNavigationTitle");
var title = doc.GetValue<string>("uBlogsyContentTitle");
if (string.IsNullOrEmpty(navTitle) && !string.IsNullOrEmpty(title))
{
navTitle = title;
// ensure node name is same as title
doc.SetValue("uBlogsyNavigationTitle", navTitle);
ApplicationContext.Current.Services.ContentService.Save(doc, 0, false);
}
return doc;
}
示例15: EnsureCorrectPostTitle
/// <summary>
/// Ensures that the node name is the same as the post title
/// </summary>
/// <param name="doc"></param>
/// <returns></returns>
public IContent EnsureCorrectPostTitle(IContent doc)
{
var title = doc.GetValue<string>("uBlogsyContentTitle");
if (string.IsNullOrEmpty(title))
{
// ensure node name is same as title
doc.SetValue("uBlogsyContentTitle", doc.Name);
ApplicationContext.Current.Services.ContentService.Save(doc, 0, false);
}
return doc;
}