示例#1
0
        public IRawViewContainer GetContainer(string containerName)
        {
            if (containerName == null)
            {
                throw new ArgumentNullException("containerName");
            }

            return(new AzureViewContainer(_directory.GetSubdirectory(containerName)));
        }
        public IStreamContainer GetContainer(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return(new BlobStreamingContainer(_directory.GetSubdirectory(name)));
        }
        public bool SaveJsonResource(string resourcetype, string containerName, string directoryPath, string resourceid, string json)
        {
            // Retrieve a reference to a container
            CloudBlobContainer container = blobClient.GetContainerReference(containerName);

            string[]           pathTokens = directoryPath.Split('/');
            CloudBlobDirectory dir        = container.GetDirectoryReference(pathTokens[0]);

            if (pathTokens.Length > 1)
            {
                for (var i = 1; i < pathTokens.Length; i++)
                {
                    dir = dir.GetSubdirectory(pathTokens[i]);
                }
            }

            // Create the container if it doesn't already exist
            container.CreateIfNotExist();
            container.SetPermissions(new BlobContainerPermissions {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            try
            {
                CloudBlob jsblob = dir.GetBlobReference(resourceid + ".js");

                string guid = ShortGuidGenerator.NewGuid();

                if (resourcetype != null)
                {
                    jsblob.UploadText("var $" + guid + " = " + json + "; $" + resourcetype + "_ready($" + guid + ",'" + containerName + "', '" + resourceid + "', '" + directoryPath + "');");
                }
                else
                {
                    jsblob.UploadText("var $" + guid + " = " + json + "; $" + resourceid.Replace("-", "") + "_ready($" + guid + ",'" + containerName + "', '" + directoryPath + "');");
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }