本文整理汇总了C#中Blob.TryUploadMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# Blob.TryUploadMetadata方法的具体用法?C# Blob.TryUploadMetadata怎么用?C# Blob.TryUploadMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blob
的用法示例。
在下文中一共展示了Blob.TryUploadMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例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;
}
}