コード例 #1
0
        protected void SignButton_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                InitializeStorage( );

                //Subo la imagen al Blob Storage
                CloudBlobContainer container      = blobStorage.GetContainerReference("fotogolpics");
                string             uniqueBlobName = string.Format("image_{0}.jpg", Guid.NewGuid( ).ToString( ));
                CloudBlockBlob     blob           = container.GetBlockBlobReference(uniqueBlobName);
                blob.Properties.ContentType = FileUpload1.PostedFile.ContentType;
                blob.UploadFromStream(FileUpload1.FileContent);
                System.Diagnostics.Trace.TraceInformation("Uploaded image '{0}' to blob storage as '{1}'", FileUpload1.FileName, uniqueBlobName);

                //Creo un nuevo registro en la tabla
                FotoGolEntry entry = new FotoGolEntry( )
                {
                    GuestName = NameTextBox.Text, Message = MessageTextBox.Text, PhotoUrl = blob.Uri.ToString( ), ThumbnailUrl = blob.Uri.ToString( )
                };
                FotoGolEntryDataSource ds = new FotoGolEntryDataSource( );
                ds.AddGuestBookEntry(entry);
                System.Diagnostics.Trace.TraceInformation("Added entry {0}-{1} in table storage for guest '{2}'", entry.PartitionKey, entry.RowKey, entry.GuestName);

                //Pongo un mensaje en cola para que se procese
                var queue   = queueStorage.GetQueueReference("fotogolthumbs");
                var message = new CloudQueueMessage(String.Format("{0},{1},{2}", uniqueBlobName, entry.PartitionKey, entry.RowKey));
                queue.AddMessage(message);
                System.Diagnostics.Trace.TraceInformation("Queued message to process blob '{0}'", uniqueBlobName);
            }

            NameTextBox.Text    = "";
            MessageTextBox.Text = "";

            DataList1.DataBind( );
        }
コード例 #2
0
        public override void Run( )
        {
            Trace.TraceInformation("Listening for queue messages...");
            while (true)
            {
                try
                {
                    CloudQueueMessage msg = queue.GetMessage( );
                    if (msg != null)
                    {
                        string[] messageParts = msg.AsString.Split(new char[] { ',' });
                        string   uri          = messageParts[0];
                        string   partitionKey = messageParts[1];
                        string   rowkey       = messageParts[2];
                        Trace.TraceInformation("Processing image in blob '{0}'.", new object[] { uri });

                        CloudBlockBlob imageBlob = container.GetBlockBlobReference(uri);
                        MemoryStream   image     = new MemoryStream( );
                        imageBlob.DownloadToStream(image);
                        image.Seek(0L, SeekOrigin.Begin);

                        string         thumbnailUri  = Path.GetFileNameWithoutExtension(uri) + "_thumb.jpg";
                        CloudBlockBlob thumbnailBlob = container.GetBlockBlobReference(thumbnailUri);
                        thumbnailBlob.UploadFromStream(CreateThumbnail(image));

                        var dataSource = new FotoGolEntryDataSource( );
                        dataSource.UpdateImageThumbnail(partitionKey, rowkey, thumbnailBlob.Uri.AbsoluteUri);

                        queue.DeleteMessage(msg);

                        Trace.TraceInformation("Generated thumbnail in blob '{0}'.", new object[] { thumbnailBlob.Uri });
                    }
                    else
                    {
                        Thread.Sleep(0x3e8);
                    }
                }
                catch (StorageClientException e)
                {
                    Trace.TraceError("Exception when processing queue item. Message: '{0}'", e.Message);
                    System.Threading.Thread.Sleep(5000);
                }
            }
        }
コード例 #3
0
        public override void Run()
        {
            Trace.WriteLine("FotoGol_Email entry point called", "Information");

            InitializeStorage();

            while (true)
            {
                Thread.Sleep(10000);
                Trace.WriteLine("Working", "Information");

                var list = MailGetter.GetPhotoData(true);

                foreach (var item in list)
                {
                    //Subo la imagen al Blob Storage
                    CloudBlobContainer container      = blobStorage.GetContainerReference("fotogolpics");
                    string             uniqueBlobName = string.Format("image_{0}.jpg", Guid.NewGuid().ToString());
                    CloudBlockBlob     blob           = container.GetBlockBlobReference(uniqueBlobName);

                    //blob.Properties.ContentType = item.ImageType;
                    blob.UploadFromStream(new MemoryStream(item.Data));
                    System.Diagnostics.Trace.TraceInformation("Uploaded image '{0}' to blob storage as '{1}'", item.FileName, uniqueBlobName);

                    //Creo un registro en la tabla
                    FotoGolEntry entry = new FotoGolEntry()
                    {
                        GuestName = item.From, Message = item.Title, PhotoUrl = blob.Uri.ToString(), ThumbnailUrl = blob.Uri.ToString()
                    };
                    FotoGolEntryDataSource ds = new FotoGolEntryDataSource();
                    ds.AddGuestBookEntry(entry);
                    System.Diagnostics.Trace.TraceInformation("Added entry {0}-{1} in table storage for guest '{2}'", entry.PartitionKey, entry.RowKey, entry.GuestName);

                    //Pongo un mensaje para procesar
                    var queue   = queueStorage.GetQueueReference("fotogolthumbs");
                    var message = new CloudQueueMessage(String.Format("{0},{1},{2}", uniqueBlobName, entry.PartitionKey, entry.RowKey));
                    queue.AddMessage(message);
                    System.Diagnostics.Trace.TraceInformation("Queued message to process blob '{0}'", uniqueBlobName);
                }
            }
        }