本文整理汇总了C#中Blob.TrySet方法的典型用法代码示例。如果您正苦于以下问题:C# Blob.TrySet方法的具体用法?C# Blob.TrySet怎么用?C# Blob.TrySet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blob
的用法示例。
在下文中一共展示了Blob.TrySet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnionWith
public bool UnionWith(MsgSetBlobPack other)
{
DateTime progress = DateTime.MaxValue;
while (progress != DateTime.MinValue)
{
List<KeyValuePair<DateTime, CloudBlob>> blobsList = GetBlobs();
if (!blobsList.Any())
return false;
try
{
for (int i = blobsList.Count-1; i >=0 ; i--)
{
Blob<MessageSet> currentBlob = new Blob<MessageSet>(blobsList[i].Value);
DateTime upperBound = (i + 1 < blobsList.Count) ? blobsList[i + 1].Key : DateTime.MaxValue;
DateTime lowerBound = blobsList[i].Key;
if (lowerBound > progress)
continue;
MessageSet set;
do
{
set = GetMessageSet(currentBlob);
set.UnionWith(other.GetMessagesBetween(lowerBound, upperBound));
} while (!currentBlob.TrySet(set));
progress = lowerBound;
}
}
catch (VersionHasChanged) { continue; }
}
return true;
}
示例2: AddMessage
// return false to warn that the message was not added
public bool AddMessage(Message message)
{
while (true)
{
// find the blob
// TODO : find a better datasutrcture to do this faster
List<KeyValuePair<DateTime, CloudBlob>> blobsList = GetBlobs();
if (!blobsList.Any())
return false;
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.Add(message);
// split if necessary
// TODO : should we export this to a worker
if (set.Count > splitSize)
{
MessageSet set1 = new MessageSet(set.Take(set.Count / 2));
MessageSet set2 = new MessageSet(set.Skip(set.Count / 2));
Blob<MessageSet> blob2 = new Blob<MessageSet>(dir.Container, dir.Uri + set2.Min.Date.ToString(timeFormat));
// 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();
// specify new versions numbers
blob.AddMetadata("version", Guid.NewGuid().ToString());
blob2.AddMetadata("version", Guid.NewGuid().ToString());
// upload blobs
blob2.Set(set2);
blob.Set(set1);
return true;
}
} while (!blob.TrySet(set));
}
catch (VersionHasChanged) { continue; }
return true;
}
}
示例3: 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;
}
}