Exemplo n.º 1
0
        public HttpResponseMessage GetBlob(string container, string name)
        {
            var blob = AzureStorageUtils.GetBlob(container, name);

            if (blob.Exists())
            {
                blob.FetchAttributes();
                var contentType = blob.Properties.ContentType;
                var ms          = new System.IO.MemoryStream();
                blob.DownloadToStream(ms);
                ms.Seek(0, SeekOrigin.Begin);
                var result = new HttpResponseMessage(HttpStatusCode.OK);
                result.Content = new StreamContent(ms);
                // ctor MediaTypeHeaderValue() does not accept "text/plain; charset=utf-8" directly
                MediaTypeHeaderValue value;
                if (MediaTypeHeaderValue.TryParse(contentType, out value))
                {
                    result.Content.Headers.ContentType = value;
                }
                return(result);
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> GetPresentation(int id)
        {
            // TODO. Enable CORS on the Azure blob and download presentation directly using AJAX. +http://odetocode.com/blogs/scott/archive/2014/03/31/http-clients-and-azure-blob-storage.aspx
            // +http://blog.cynapta.com/2013/12/cynapta-azure-cors-helper-free-tool-to-manage-cors-rules-for-windows-azure-blob-storage/
            var blob = AzureStorageUtils.GetBlob(AzureStorageUtils.ContainerNames.Presentations, KeyUtils.IntToKey(id));
            var text = await blob.DownloadTextAsync();

            //var text = await AzureStorageUtils.GetBlobAsText(AzureStorageUtils.ContainerNames.Presentations, KeyUtils.IntToKey(id));
            return(new RawStringResult(this, text, RawStringResult.TextMediaType.PlainText));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Claim(string id)
        {
            var userIdKey    = KeyUtils.IntToKey(0);
            var longTimeKey  = id + this.GetExtId();
            var blobName     = ExerciseUtils.FormatBlobName(userIdKey, longTimeKey, "metadata", "json");
            var blob         = AzureStorageUtils.GetBlob(AzureStorageUtils.ContainerNames.Artifacts, blobName);
            var metadataJson = await blob.DownloadTextAsync();

            var metadata         = JObject.Parse(metadataJson);
            var serviceType      = (string)metadata["serviceType"];
            var cardId           = (Guid?)metadata["cardId"];
            var title            = (string)metadata["title"];
            var comment          = (string)metadata["comment"];
            var details          = metadata["recordingDetails"];
            var recordingDetails = details.ToObject <RecordingDetails>();

            var exerciseId = await ExerciseUtils.CreateExercise(recordingDetails.BlobName, this.GetUserId(),
                                                                serviceType, ArtifactType.Mp3, recordingDetails.TotalDuration, title, cardId, comment, details.ToString(Formatting.None));

            //~~ Redirect to the View exercise page.
            return(RedirectToAction("View", new { Id = exerciseId }));
        }