當前位置: 首頁>>代碼示例>>C#>>正文


C# Blob.Set方法代碼示例

本文整理匯總了C#中Blob.Set方法的典型用法代碼示例。如果您正苦於以下問題:C# Blob.Set方法的具體用法?C# Blob.Set怎麽用?C# Blob.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Blob的用法示例。


在下文中一共展示了Blob.Set方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
            }
        }
開發者ID:ismaelbelghiti,項目名稱:Tigwi,代碼行數:54,代碼來源:MsgSetBlobPack.cs

示例2: Init

 public void Init()
 {
     Blob<MessageSet> blob = new Blob<MessageSet>(dir.Container, dir.Uri + DateTime.MinValue.ToString(timeFormat));
     blob.AddMetadata("version", Guid.NewGuid().ToString());
     blob.Set(new MessageSet());
 }
開發者ID:ismaelbelghiti,項目名稱:Tigwi,代碼行數:6,代碼來源:MsgSetBlobPack.cs

示例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;
            }
        }
開發者ID:ismaelbelghiti,項目名稱:Tigwi,代碼行數:54,代碼來源:MsgSetBlobPack.cs

示例4: Init

 public void Init()
 {
     Blob<HashSet<KeyValuePair<string, string>>> rootBlob = new Blob<HashSet<KeyValuePair<string, string>>>(dir.GetBlobReference("root"));
     rootBlob.Set(new HashSet<KeyValuePair<string, string>>());
 }
開發者ID:ismaelbelghiti,項目名稱:Tigwi,代碼行數:5,代碼來源:PrefixTreeBlob.cs


注:本文中的Blob.Set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。