本文整理汇总了C#中Collection.Except方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.Except方法的具体用法?C# Collection.Except怎么用?C# Collection.Except使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.Except方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(HttpContext context)
{
//get the JSON string which
//from the UI
String jsonString = context.Request.Form[0];
//get only the deliverable for the application
Collection<String> appDeliverablesCol = client.GetApplication(jsonString).Deliverables;
//all deliverables collection
Collection<String> allDeliverablesCol = new Collection<String>();
allDeliverablesCol.Add("WEB");
allDeliverablesCol.Add("WS");
allDeliverablesCol.Add("K2WS");
allDeliverablesCol.Add("DB");
allDeliverablesCol.Add("K2PROCESS");
allDeliverablesCol.Add("REPORT");
allDeliverablesCol.Add("BATCH");
//get all deliverables that the application
//is not conserned with
Collection<String> notDeliverablesCol = allDeliverablesCol.Except(appDeliverablesCol).ToCollection();
//set the response type to be JSON
context.Response.ContentType = "application/json; charset=utf-8";
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
//write the output back
context.Response.Write(jsSerializer.Serialize(notDeliverablesCol));
}
示例2: UpdateIssueLabelsAsync
private async Task UpdateIssueLabelsAsync(PortingInfo ruleToPort, Issue existingIssue)
{
var existingLabelNames = new Collection<string>(existingIssue.Labels.Select(label => label.Name).ToList());
var labelNamesToAdd = new Collection<string>();
var labelNamesToRemove = new Collection<string>();
AddLabel(FxCopPortLabel, labelNamesToAdd, existingLabelNames);
if (ruleToPort.Soon)
{
AddLabel(UrgencySoonLabel, labelNamesToAdd, existingLabelNames);
}
else
{
RemoveLabel(UrgencySoonLabel, labelNamesToRemove, existingLabelNames);
}
switch (ruleToPort.Disposition)
{
case Disposition.NeedsReview:
AddLabel(NeedsReviewLabel, labelNamesToAdd, existingLabelNames);
RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
break;
case Disposition.Port:
RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
break;
case Disposition.Cut:
AddLabel(CutLabel, labelNamesToAdd, existingLabelNames);
RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
break;
case Disposition.Ported:
AddLabel(PortedLabel, labelNamesToAdd, existingLabelNames);
RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
break;
}
RemoveAreaLabels(existingLabelNames, labelNamesToRemove);
AddAreaLabel(ruleToPort, labelNamesToAdd);
if (_options.DryRun)
{
_log.Info(Resources.InfoDryRunLabelsNotUpdated);
}
else
{
if (labelNamesToAdd.Any())
{
await _issuesLabelsClient.AddToIssue(
_options.RepoOwner,
_options.RepoName,
existingIssue.Number,
labelNamesToAdd.ToArray());
}
// Take care not to remove any labels we've just added.
//
// For some reason the "Remove" API doesn't take an array.
foreach (string labelName in labelNamesToRemove.Except(labelNamesToAdd))
{
await _issuesLabelsClient.RemoveFromIssue(
_options.RepoOwner,
_options.RepoName,
existingIssue.Number,
labelName);
}
}
}
示例3: Get
public Collection<Item> Get(Collection<int> ids)
{
var notInCache = ids.Except(_cache.Keys);
// if some items don't exist in cache
if (notInCache.Count() > 0)
{
_requestedIdsLock.EnterUpgradeableReadLock();
try
{
var needToGet = notInCache.Except(_requestedIds);
// if any items have not yet been requested by other threads
if (needToGet.Count() > 0)
{
_requestedIdsLock.EnterWriteLock();
try
{
// record the current request
foreach (var id in ids)
_requestedIds.Add(id);
_requestedIdsLock.ExitWriteLock();
_requestedIdsLock.ExitUpgradeableReadLock();
// get the data from the external resource
#region fake implementation - replace with real code
var data = new Collection<Item>();
foreach (var id in needToGet)
{
var item = _externalDataStoreProxy[id];
data.Add(item);
}
Thread.Sleep(10000);
#endregion
lock (_cache)
{
foreach (var item in data)
_cache.Add(item.ID, item);
Monitor.PulseAll(_cache);
}
}
finally
{
// let go of any held locks
if (_requestedIdsLock.IsWriteLockHeld)
_requestedIdsLock.ExitWriteLock();
}
}
if (_requestedIdsLock.IsUpgradeableReadLockHeld)
_requestedIdsLock.ExitUpgradeableReadLock();
var waitingFor = notInCache.Except(needToGet);
// if any remaining items were already requested by other threads
if (waitingFor.Count() > 0)
{
lock (_cache)
{
while (waitingFor.Count() > 0)
{
Monitor.Wait(_cache);
waitingFor = waitingFor.Except(_cache.Keys);
}
// once we get here, _cache has all our items
}
}
}
finally
{
// let go of any held locks
if (_requestedIdsLock.IsUpgradeableReadLockHeld)
_requestedIdsLock.ExitReadLock();
}
}
return new Collection<Item>(ids.Select(id => _cache[id]).ToList());
}