本文整理汇总了C#中VersionOne.SDK.APIClient.Asset.EnsureAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Asset.EnsureAttribute方法的具体用法?C# Asset.EnsureAttribute怎么用?C# Asset.EnsureAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VersionOne.SDK.APIClient.Asset
的用法示例。
在下文中一共展示了Asset.EnsureAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetAssetAttribute
private static void SetAssetAttribute(Asset asset, string attrName, object value) {
var type = asset.AssetType;
var def = type.GetAttributeDefinition(attrName);
if (value == null || (value is Oid && value.Equals(Oid.Null))) {
asset.EnsureAttribute(def);
} else {
asset.SetAttributeValue(def, value);
}
}
示例2: Validate
/// <summary>
/// Validate single Asset attribute. If attribute is not loaded, it is just considered invalid.
/// </summary>
/// <param name="asset">Asset to validate</param>
/// <param name="attributeDefinition">Attribute definition of validated attribute</param>
/// <returns>Validation result</returns>
// TODO create separate private method to avoid excessive GetRequiredFields() calls
public bool Validate(Asset asset, IAttributeDefinition attributeDefinition)
{
GetRequiredFields(asset.AssetType);
asset.EnsureAttribute(attributeDefinition);
Attribute attribute = asset.GetAttribute(attributeDefinition);
bool result = attribute != null && !(IsMultiValueAndUnfilled(attribute) || IsSingleValueAndUnfilled(attribute));
if (!result && attribute != null)
{
result = !attribute.HasChanged && !isAttributeUnfilledOnServer(asset, attributeDefinition);
}
return result;
}
示例3: ParseAttributeNode
private static void ParseAttributeNode(Asset asset, IAttributeDefinition attribdef, XmlElement element) {
var type = element.LocalName;
asset.EnsureAttribute(attribdef);
if (type == "Relation") {
if (attribdef.IsMultiValue) {
foreach (XmlElement child in element.ChildNodes) {
var add = child.HasAttribute("act") && child.GetAttribute("act") == "add";
var token = child.GetAttribute("idref");
if(add) {
asset.AddAttributeValue(attribdef, token);
} else {
asset.LoadAttributeValue(attribdef, token);
}
}
} else {
var token = Oid.Null.Token;
if(element.HasChildNodes) {
token = ((XmlElement) element.ChildNodes.Item(0)).GetAttribute("idref");
}
var force = element.HasAttribute("act") && element.GetAttribute("act") == "set";
if(force) {
asset.ForceAttributeValue(attribdef, token);
} else {
asset.LoadAttributeValue(attribdef, token);
}
}
} else {
if (attribdef.IsMultiValue) {
foreach (XmlElement child in element.ChildNodes) {
var add = child.HasAttribute("act") && child.GetAttribute("act") == "add";
if(add) {
asset.AddAttributeValue(attribdef, child.InnerText);
} else {
asset.LoadAttributeValue(attribdef, child.InnerText);
}
}
} else {
object v = null;
if(!string.IsNullOrEmpty(element.InnerText)) {
v = element.InnerText;
}
var force = element.HasAttribute("act") && element.GetAttribute("act") == "set";
if(force) {
asset.ForceAttributeValue(attribdef, v);
} else {
asset.LoadAttributeValue(attribdef, v);
}
}
}
}
示例4: SetupAssetAttributes
private void SetupAssetAttributes(Asset asset, string typeToken) {
foreach (var attrInfo in attributesToQuery.Where(attrInfo => attrInfo.Prefix == typeToken)) {
try {
var def = dataLayer.Types[attrInfo.Prefix].GetAttributeDefinition(attrInfo.Attr);
asset.EnsureAttribute(def);
} catch(MetaException ex) {
logger.Warn("Problem setting up attribute: " + ex.Message);
}
}
}