本文整理汇总了C#中IUpdateContext.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# IUpdateContext.Lock方法的具体用法?C# IUpdateContext.Lock怎么用?C# IUpdateContext.Lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUpdateContext
的用法示例。
在下文中一共展示了IUpdateContext.Lock方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Import
/// <summary>
/// Import authority groups.
/// </summary>
/// <remarks>
/// Creates any authority groups that do not already exist.
/// This method performs an additive import. It will never remove an existing authority group or
/// remove authority tokens from an existing group.
/// </remarks>
/// <param name="groupDefs"></param>
/// <param name="context"></param>
public IList<AuthorityGroup> Import(IEnumerable<AuthorityGroupDefinition> groupDefs, IUpdateContext context)
{
// first load all the existing tokens into memory
// there should not be that many tokens ( < 500), so this should not be a problem
IAuthorityTokenBroker tokenBroker = context.GetBroker<IAuthorityTokenBroker>();
IList<AuthorityToken> existingTokens = tokenBroker.FindAll();
// load existing groups
IAuthorityGroupBroker groupBroker = context.GetBroker<IAuthorityGroupBroker>();
IList<AuthorityGroup> existingGroups = groupBroker.FindAll();
foreach (AuthorityGroupDefinition groupDef in groupDefs)
{
AuthorityGroup group = CollectionUtils.SelectFirst(existingGroups,
g => g.Name == groupDef.Name);
// if group does not exist, create it
if (group == null)
{
group = new AuthorityGroup
{
Name = groupDef.Name,
Description = groupDef.Description,
DataGroup = groupDef.DataGroup
};
context.Lock(group, DirtyState.New);
existingGroups.Add(group);
}
// process all token nodes contained in group
foreach (string tokenName in groupDef.Tokens)
{
AuthorityToken token = CollectionUtils.SelectFirst(existingTokens,
t => t.Name == tokenName);
// ignore non-existent tokens
if (token == null)
continue;
// add the token to the group
group.AuthorityTokens.Add(token);
}
}
return existingGroups;
}
示例2: Import
/// <summary>
/// Import external practitioner from CSV format.
/// </summary>
/// <param name="rows">
/// Each string in the list must contain 4 CSV fields, as follows:
/// 0 - Facility ID
/// 1 - Facility Name
/// 2 - Information Authority ID
/// 3 - Information Authoirty Name
/// </param>
/// <param name="context"></param>
public override void Import(List<string> rows, IUpdateContext context)
{
_enumBroker = context.GetBroker<IEnumBroker>();
_authorities = new List<InformationAuthorityEnum>(_enumBroker.Load<InformationAuthorityEnum>(true));
List<Facility> facilities = new List<Facility>();
foreach (string line in rows)
{
// expect 4 fields in the row
string[] fields = ParseCsv(line, 4);
string facilityId = fields[0];
string facilityName = fields[1];
string facilityDescription = fields[2];
string informationAuthorityId = fields[3];
string informationAuthorityName = fields[4];
// first check if we have it in memory
Facility facility = CollectionUtils.SelectFirst(facilities,
delegate(Facility f) { return f.Code == facilityId && f.Name == facilityName; });
// if not, check the database
if (facility == null)
{
FacilitySearchCriteria where = new FacilitySearchCriteria();
where.Code.EqualTo(facilityId);
where.Name.EqualTo(facilityName);
IFacilityBroker broker = context.GetBroker<IFacilityBroker>();
facility = CollectionUtils.FirstElement(broker.Find(where));
// if not, create a new instance
if (facility == null)
{
facility = new Facility(facilityId, facilityName, facilityDescription, GetAuthority(informationAuthorityId, informationAuthorityName));
context.Lock(facility, DirtyState.New);
}
facilities.Add(facility);
}
}
}
示例3: ProcessToken
private static AuthorityToken ProcessToken(AuthorityTokenDefinition tokenDef, ICollection<AuthorityToken> existingTokens, IUpdateContext context)
{
// look for an existing instance of the token, or a token that should be renamed to this token
var token = existingTokens.FirstOrDefault(t => t.Name == tokenDef.Token || tokenDef.FormerIdentities.Contains(t.Name));
if (token != null)
{
// update the name (in the case it is a rename)
token.Name = tokenDef.Token;
// update the description
token.Description = tokenDef.Description;
}
else
{
// the token does not already exist, so create it
token = new AuthorityToken(tokenDef.Token, tokenDef.Description);
context.Lock(token, DirtyState.New);
existingTokens.Add(token);
}
return token;
}