ExistsBlob() public static method

public static ExistsBlob ( Uri uri ) : bool
uri System.Uri
return bool
Beispiel #1
0
        public void ExistsExistingBlobIsTrue()
        {
            var blobname = CreateBlob();

            blobmeta = new Hashtable();
            bs.PutBlob(containername, blobname, blobmeta, blobcontent, "");
            HttpUtils.Wait(delay);
            Assert.That(BlobStorage.ExistsBlob(containername, blobname) == true);
            bs.DeleteBlob(containername, blobname);
        }
Beispiel #2
0
        private static JsonCompareResult NewJsonMatchesExistingJson(JsonSnapshotType type, Object new_obj, Uri existing_obj_uri)
        {
            var result = JsonCompareResult.different;

            try
            {
                if (BlobStorage.ExistsBlob(existing_obj_uri))
                {
                    if (type == JsonSnapshotType.DictStr)
                    {
                        var new_dict_str = (Dictionary <string, string>)new_obj;
                        if (new_dict_str.Keys.Count == 0)
                        {
                            return(JsonCompareResult.invalid);
                        }
                        var existing_dict_str = ObjectUtils.GetDictStrFromJsonUri(existing_obj_uri);
                        if (existing_dict_str.Keys.Count == 0)                         // this shouldn't happen, but...
                        {
                            return(JsonCompareResult.invalid);
                        }
                        var equal = ObjectUtils.DictStrEqualsDictStr((Dictionary <string, string>)existing_dict_str, new_dict_str);
                        result = equal ? JsonCompareResult.same : JsonCompareResult.different;
                    }
                    else                     // JsonSnapshotType.ListDictStr
                    {
                        var new_list_dict_str = (List <Dictionary <string, string> >)new_obj;
                        if (AllDictsHaveKeys(new_list_dict_str) == false)
                        {
                            return(JsonCompareResult.invalid);
                        }
                        var existing_list_dict_str = ObjectUtils.GetListDictStrFromJsonUri(existing_obj_uri);
                        if (AllDictsHaveKeys(existing_list_dict_str) == false)
                        {
                            return(JsonCompareResult.invalid);
                        }
                        var equal = ObjectUtils.ListDictStrEqualsListDictStr((List <Dictionary <string, string> >)existing_list_dict_str, new_list_dict_str);
                        result = equal ? JsonCompareResult.same : JsonCompareResult.different;
                    }
                }
            }
            catch (Exception e)
            {
                GenUtils.LogMsg("exception", "NewJsonMatchesExistingJson", e.Message + e.StackTrace);
            }

            return(result);
        }
Beispiel #3
0
        public static bool SavedJsonSnapshot(string id, JsonSnapshotType type, string name, Object new_obj)
        {
            try
            {
                var json_blob_name           = id + "." + name + ".json";
                var existing_obj_uri         = BlobStorage.MakeAzureBlobUri(id, json_blob_name, false);
                var exists                   = BlobStorage.ExistsBlob(existing_obj_uri);
                JsonCompareResult comparison = NewJsonMatchesExistingJson(type, new_obj, existing_obj_uri);
                if (!exists || comparison == JsonCompareResult.different)
                {
                    var    bs = BlobStorage.MakeDefaultBlobStorage();
                    var    timestamped_json_blob_name = string.Format(id + "." + string.Format("{0:yyyy.MM.dd.HH.mm}" + "." + name + ".json", DateTime.UtcNow));
                    var    timestamped_dict_uri       = BlobStorage.MakeAzureBlobUri(id, timestamped_json_blob_name, false);
                    string new_obj_as_json;
                    if (type == JsonSnapshotType.DictStr)
                    {
                        new_obj_as_json = ObjectUtils.DictStrToJson((Dictionary <string, string>)new_obj);
                    }
                    else                     // JsonSnapshotType.ListDictStr
                    {
                        new_obj_as_json = ObjectUtils.ListDictStrToJson((List <Dictionary <string, string> >)new_obj);
                    }
                    //bs.PutBlob(id, json_blob_name, new_obj_as_json, "application/json");
                    bs.PutBlob(id, timestamped_json_blob_name, new_obj_as_json, "application/json");
                }

                if (comparison == JsonCompareResult.same || comparison == JsonCompareResult.invalid)
                {
                    return(false);                    // either the objects matched, or the comparison failed, either way a json snapshot was not saved
                }
                else
                {
                    return(true);                     // the objects did not match, a json snapshot was saved
                }
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "SavedJsonSnapshot", e.Message + e.StackTrace);
                return(false);
            }
        }
Beispiel #4
0
        public BlobStorageResponse PutBlobWithLease(string container, string blobname, Hashtable headers, byte[] data, string content_type)
        {
            try
            {
                if (BlobStorage.ExistsBlob(container, blobname))
                {
                    var r = this.RetryAcquireLease(container, blobname);
                    if (r.status == HttpStatusCode.Created)
                    {
                        headers.Add("x-ms-lease-id", r.headers["x-ms-lease-id"]);
                    }
                    else
                    {
                        GenUtils.PriorityLogMsg("warning", "PutBlobWithLease: Did not acquire lease for: ", container + ", " + blobname);
                    }
                }
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "PutBlobWithLease", e.Message + e.StackTrace);
            }

            return(this.PutBlob(container, blobname, headers, data, content_type));
        }