本文整理汇总了C#中Blob.GetIfExists方法的典型用法代码示例。如果您正苦于以下问题:C# Blob.GetIfExists方法的具体用法?C# Blob.GetIfExists怎么用?C# Blob.GetIfExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blob
的用法示例。
在下文中一共展示了Blob.GetIfExists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessageSet
MessageSet GetMessageSet(Blob<MessageSet> blob)
{
string guid = blob.Metadata["version"];
MessageSet set = blob.GetIfExists(new VersionHasChanged());
// if the guid = 0, then the architecture is changing
if (guid != blob.Metadata["version"] || guid == Guid.Empty.ToString())
throw new VersionHasChanged();
return set;
}
示例2: RemoveMessage
public void RemoveMessage(Message message)
{
while (true)
{
// find the blobs
List<KeyValuePair<DateTime, CloudBlob>> blobsList = GetBlobs();
if (!blobsList.Any())
return;
int blobIndex = blobsList.IndexOf(blobsList.Last(p => p.Key <= message.Date));
// inserte data
Blob<MessageSet> blob = new Blob<MessageSet>(blobsList[blobIndex].Value);
MessageSet set;
try
{
do
{
set = GetMessageSet(blob);
set.Remove(message);
// merge if necessary -- and if it is possible
// TODO : should we move this to the worker
if (set.Count < mergeSize && blobIndex < blobsList.Count-1 )
{
Blob<MessageSet> blob2 = new Blob<MessageSet>(blobsList[blobIndex + 1].Value);
MessageSet set2 = blob2.GetIfExists(new VersionHasChanged());
// set version to 0 to be sure no one insert/remove a message while we split
blob.AddMetadata("version", Guid.Empty.ToString());
if (!blob.TryUploadMetadata())
throw new VersionHasChanged();
if (!blob2.TryDelete())
{
// restore old version
blob.AddMetadata("version", Guid.NewGuid().ToString());
blob.UploadMetadata();
throw new VersionHasChanged();
}
// specify new versions numbers
blob.AddMetadata("version", Guid.NewGuid().ToString());
set.UnionWith(set2);
blob.Set(set);
return;
}
} while (!blob.TrySet(set));
}
catch (VersionHasChanged) { continue; }
return;
}
}