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);
                }
            }
        }
Beispiel #2
0
        public override void Run()
        {
            while (true)
            {
                try
                {
                    CloudQueueMessage message = _queue.GetMessage();
                    if (message != null)
                    {
                        string[] messageArray  = message.AsString.Split(new char[] { ',' });
                        string   outputBlobUri = messageArray[0];
                        string   partitionKey  = messageArray[1];
                        string   rowkey        = messageArray[2];

                        _queue.PeekMessage();

                        string inputBlobUri = Regex.Replace(outputBlobUri, "([^\\.]+)(\\.[^\\.]+)?$", "$1-myimage$2");

                        _container.CreateIfNotExist();
                        CloudBlob inputBlob  = _container.GetBlobReference(outputBlobUri);
                        CloudBlob outputBlob = _container.GetBlobReference(inputBlobUri);

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

                                output.Commit();
                                outputBlob.Properties.ContentType = "image/jpeg";
                                outputBlob.SetProperties();

                                FunnyAppRepository <Post> postRepository = new FunnyAppRepository <Post>();
                                Post post = postRepository.Find(partitionKey, rowkey);

                                post.PostImage = inputBlobUri;
                                post.State     = true;
                                postRepository.Update(post);
                                postRepository.SubmitChange();

                                _queue.DeleteMessage(message);
                            }
                    }
                }
                catch (StorageClientException e)
                {
                    Trace.Write(e);
                }
            }
        }
Beispiel #3
0
        public int CloseFile(string filename, DokanFileInfo info)
        {
            BlobStream stream = null;

            if (blobsWriting.TryRemove(filename, out stream))
            {
                Trace.WriteLine(string.Format("CloseFile {0}", filename));
                stream.Commit();
                stream.Dispose();
                this.blobCache.Remove(filename);
                stream.Blob.Container.InvalidateCache();
            }

            return(0);
        }