MakeAzureBlobUri() public static method

public static MakeAzureBlobUri ( string container, string name ) : Uri
container string
name string
return System.Uri
示例#1
0
        public CacheUtilsTest()
        {
            this.blob_uri = BlobStorage.MakeAzureBlobUri(this.containername, this.blobname, false);
            this.view_uri = new Uri(this.blob_uri.ToString() + "?view=government&count=10");
            var bs_response = bs.PutBlob(containername, blobname, new Hashtable(), view_contents, null);

            Assert.That(bs_response.HttpResponse.status == System.Net.HttpStatusCode.Created);
            this.blob_etag = HttpUtils.MaybeGetHeaderFromUriHead("ETag", blob_uri);
            this.view_etag = HttpUtils.GetMd5Hash(cached_blob_contents);
        }
示例#2
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);
            }
        }
示例#3
0
        public static string GetAzureBlobAsString(string container, string name, bool use_cdn)
        {
            var uri = BlobStorage.MakeAzureBlobUri(container, name, use_cdn);

            return(HttpUtils.FetchUrl(uri).DataAsString());
        }
示例#4
0
        public static T GetTypedObj <T>(string container, string name)
        {
            var uri = BlobStorage.MakeAzureBlobUri(container, name, false);

            return((T)BlobStorage.DeserializeObjectFromUri(uri));
        }
示例#5
0
        public static string RunIronPython(string directory, string str_script_url, List <string> args)
        {
            GenUtils.LogMsg("status", "Utils.run_ironpython: " + str_script_url, args[0] + "," + args[1] + "," + args[2]);
            //var app_domain_name = "ironpython";
            string result = "";

            try
            {
                /*
                 * string domain_id = app_domain_name;
                 * var setup = new AppDomainSetup();
                 * setup.ApplicationName = app_domain_name;
                 * setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
                 * var python_domain = AppDomain.CreateDomain(domain_id, securityInfo: null, info: setup);
                 */
                var options = new Dictionary <string, object>();
                options["LightweightScopes"] = true;
                var python = Python.CreateEngine(options);
                var paths  = new List <string>();
                paths.Add(directory + "Lib");                        // standard python lib
                paths.Add(directory + "Lib\\site-packages");
                paths.Add(directory + "ElmcityLib");                 // Elmcity python lib

                GenUtils.LogMsg("status", "Utils.run_ironpython", String.Join(":", paths.ToArray()));

                python.SetSearchPaths(paths);
                var ipy_args = new IronPython.Runtime.List();
                foreach (var item in args)
                {
                    ipy_args.Add(item);
                }
                var s = HttpUtils.FetchUrl(new Uri(str_script_url)).DataAsString();

                try
                {
                    var common_script_url = BlobStorage.MakeAzureBlobUri("admin", "common.py", false);
                    var common_script     = HttpUtils.FetchUrl(common_script_url).DataAsString();
                    s = s.Replace("#include common.py", common_script);
                }
                catch (Exception e)
                {
                    GenUtils.PriorityLogMsg("exception", "RunIronPython: cannot #include common.py", e.Message);
                }

                var source = python.CreateScriptSourceFromString(s, SourceCodeKind.Statements);
                var scope  = python.CreateScope();
                var sys    = python.GetSysModule();
                //sys.SetVariable("argv", new PythonArgs() { args = ipy_args } );
                sys.SetVariable("argv", args);
                source.Execute(scope);
                try
                {
                    result = scope.GetVariable("result").ToString();
                }
                catch
                {
                    // GenUtils.LogMsg("info", "RunIronPython: " + str_script_url, "no result");
                }
                python.Runtime.Shutdown();
                //AppDomain.Unload(python_domain);
            }
            catch (Exception e)
            {
                result = e.Message.ToString() + e.StackTrace.ToString();
            }
            return(result);
        }