本文整理汇总了C#中IEntity.GetBestValue方法的典型用法代码示例。如果您正苦于以下问题:C# IEntity.GetBestValue方法的具体用法?C# IEntity.GetBestValue怎么用?C# IEntity.GetBestValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntity
的用法示例。
在下文中一共展示了IEntity.GetBestValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseContentBlockDefinition
private void ParseContentBlockDefinition(IEntity cbDefinition)
{
ContentBlockEntity = cbDefinition;
_appName = ContentBlockEntity.GetBestValue(CbPropertyApp)?.ToString() ?? "";
string temp = ContentBlockEntity.GetBestValue(CbPropertyContentGroup)?.ToString() ?? "";
Guid.TryParse(temp, out _contentGroupGuid);
temp = ContentBlockEntity.GetBestValue(CbPropertyTemplate)?.ToString() ?? "";
Guid.TryParse(temp, out _previewTemplateGuid);
temp = ContentBlockEntity.GetBestValue(CbPropertyShowChooser)?.ToString() ?? "";
bool show;
if (bool.TryParse(temp, out show))
ShowTemplateChooser = show;
}
示例2: GetDictionaryFromEntity
/// <summary>
/// Convert an entity into a lightweight dictionary, ready to serialize
/// </summary>
/// <param name="entity"></param>
/// <param name="language"></param>
/// <returns></returns>
public virtual Dictionary<string, object> GetDictionaryFromEntity(IEntity entity, string language)
{
var lngs = new[] {language};
// Convert Entity to dictionary
// If the value is a relationship, then give those too, but only Title and Id
var entityValues = (from d in entity.Attributes select d.Value).ToDictionary(k => k.Name, v =>
{
var value = entity.GetBestValue(v.Name, lngs, true);
if (v.Type == "Entity" && value is Data.EntityRelationship)
return ((Data.EntityRelationship) value).Select(p => new
{
Id = p?.EntityId,
Title = p?.GetBestValue("EntityTitle", lngs)?.ToString()
}).ToList();
return value;
}, StringComparer.OrdinalIgnoreCase);
// Add Id and Title
// ...only if these are not already existing with this name in the entity itself as an internal value
if (entityValues.ContainsKey("Id")) entityValues.Remove("Id");
entityValues.Add("Id", entity.EntityId);
if (IncludeGuid)
{
if (entityValues.ContainsKey("Guid")) entityValues.Remove("Guid");
entityValues.Add("Guid", entity.EntityGuid);
}
if (IncludePublishingInfo)
{
entityValues.Add("RepositoryId", entity.RepositoryId);
entityValues.Add("IsPublished", entity.IsPublished);
if (entity.IsPublished && entity.GetDraft() != null)
{
// do a check if there was a field called Published, which we must remove for this to work
if (entityValues.ContainsKey(Constants.DraftEntityField))
entityValues.Remove(Constants.DraftEntityField);
entityValues.Add(Constants.DraftEntityField, new
{
entity.GetDraft().RepositoryId,
});
}
if (!entity.IsPublished & entity.GetPublished() != null)
{
// do a check if there was a field called Published, which we must remove for this to work
if (entityValues.ContainsKey(Constants.PublishedEntityField))
entityValues.Remove(Constants.PublishedEntityField);
entityValues.Add(Constants.PublishedEntityField, new
{
entity.GetPublished().RepositoryId,
});
}
}
if (IncludeMetadata)
{
if(entity.Metadata.HasMetadata)
entityValues.Add("Metadata", entity.Metadata);
}
if (!entityValues.ContainsKey("Title"))
try // there are strange cases where the title is missing, then just ignore this
{
entityValues.Add("Title", entity.GetBestValue("EntityTitle", lngs, true));
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
}
return entityValues;
}
示例3: DoesPermissionAllow
/// <summary>
/// Check if a specific permission entity allows for the desired permission
/// </summary>
/// <param name="permissionEntity">The entity describing a permission</param>
/// <param name="desiredActionCode">A key like r (for read), u (for update) etc. which is the level you want to check</param>
/// <returns></returns>
private bool DoesPermissionAllow(IEntity permissionEntity, char desiredActionCode)
{
// Check if it's a grant-read permission - otherwise stop here
var grnt = permissionEntity.GetBestValue(Grant).ToString();
if (grnt.IndexOf(desiredActionCode) == -1) // Grant doesn't contain read, so stop here
return false;
// Check if the current user fits the reason for this grant
try
{
// check general permissions
var condition = permissionEntity.GetBestValue(Condition).ToString();
if (condition.ToLower().StartsWith(_salPrefix))
{
var salWord = condition.Substring(_salPrefix.Length);
var sal = (SecurityAccessLevel)Enum.Parse(typeof(SecurityAccessLevel), salWord);
// check anonymous - this is always valid, even if not in a module context
if (sal == SecurityAccessLevel.Anonymous)
return true;
// check within module context
return DotNetNuke.Security.Permissions.ModulePermissionController
.HasModuleAccess(sal, CustomPermissionKey, Module);
}
// check owner conditions
if (condition == _keyOwner)
// if it's an entity, possibly also check owner-permissions
if (TargetItem != null && TargetItem.Owner == Environment.Dnn7.UserIdentity.CurrentUserIdentityToken)
return true;
}
catch
{
// something happened, in this case we assume that this rule cannot described a "is allowed"
return false;
}
// If the code gets here, we apparently don't know what the rule is about - return false
return false;
}
示例4: DoesPermissionAllow
/// <summary>
/// Check if a specific permission entity allows for the desired permission
/// </summary>
/// <param name="permissionEntity">The entity describing a permission</param>
/// <param name="desiredActionCode">A key like r (for read), u (for update) etc. which is the level you want to check</param>
/// <returns></returns>
private bool DoesPermissionAllow(IEntity permissionEntity, char desiredActionCode)
{
// Check if it's a grant-read permission - otherwise stop here
var grnt = permissionEntity.GetBestValue(Grant).ToString();
if (grnt.IndexOf(desiredActionCode) == -1) // Grant doesn't contain read, so stop here
return false;
// Check if the current user fits the reason for this grant
try
{
var rsn = permissionEntity.GetBestValue(Condition).ToString();
if (rsn.ToLower().StartsWith(_salPrefix))
{
var salWord = rsn.Substring(_salPrefix.Length);
var sal = (SecurityAccessLevel)Enum.Parse(typeof(SecurityAccessLevel), salWord);
return DotNetNuke.Security.Permissions.ModulePermissionController
.HasModuleAccess(sal, CustomPermissionKey, Module);
}
}
catch
{
// something happened, assume that this rule cannot describe a "is allowed"
return false;
}
// If the code gets here, we apparently don't know what the rule is about - return false
return false;
}