コード例 #1
0
        public JsonResult Entries()
        {
            // pull out the guestbook entries
            var azure   = new GuestBookService("DataConnectionString");
            var entries = azure.GetGuestBookEntries();

            // return the entries as JSON
            return(Json(entries, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public override void Run()
        {
            Trace.TraceInformation("Listening for queue messages...");

            while (true)
            {
                try
                {
                    // retrieve a new message from the queue
                    CloudQueueMessage msg = this.queue.GetMessage();
                    if (msg != null)
                    {
                        // parse message retrieved from queue
                        var json         = msg.AsString;
                        var data         = JsonConvert.DeserializeObject <GuestbookQueueMessage>(json);
                        var imageBlobUri = data.BlobUri.ToString();
                        var partitionKey = data.PartitionKey;
                        var rowKey       = data.RowKey;
                        Trace.TraceInformation("Processing image in blob '{0}'.", imageBlobUri);

                        string thumbnailBlobUri = System.Text.RegularExpressions.Regex.Replace(imageBlobUri, "([^\\.]+)(\\.[^\\.]+)?$", "$1-thumb$2");

                        CloudBlob inputBlob  = this.blobContainer.GetBlobReference(imageBlobUri);
                        CloudBlob outputBlob = this.blobContainer.GetBlobReference(thumbnailBlobUri);

                        using (BlobStream input = inputBlob.OpenRead())
                            using (BlobStream output = outputBlob.OpenWrite())
                            {
                                this.ProcessImage(input, output);

                                // commit the blob and set its properties
                                output.Commit();
                                outputBlob.Properties.ContentType = "image/jpeg";
                                outputBlob.SetProperties();

                                // update the entry in table storage to point to the thumbnail
                                GuestBookService ds = new GuestBookService("DataConnectionString");
                                ds.UpdateImageThumbnail(partitionKey, rowKey, thumbnailBlobUri);

                                // remove message from queue
                                this.queue.DeleteMessage(msg);

                                Trace.TraceInformation("Generated thumbnail in blob '{0}'.", thumbnailBlobUri);
                            }
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                catch (StorageClientException e)
                {
                    Trace.TraceError("Exception when processing queue item. Message: '{0}'", e.Message);
                    System.Threading.Thread.Sleep(5000);
                }
            }
        }
コード例 #3
0
        public ActionResult Index(string username, string message, HttpPostedFileBase inputFile)
        {
            // add the guestbook entry to Azure
            var azure = new GuestBookService("DataConnectionString");

            azure.AddGuestBookEntry(username, message, inputFile.FileName, inputFile.ContentType, inputFile.InputStream);

            // redirect back to the "GET" action
            return(RedirectToAction("Index"));
        }