protected void ButtonSave_Click(object sender, EventArgs e) { if (FileUploadImage.HasFiles & Page.IsValid) { string uniqueBobName = string.Format("{0}/funnyimage_{1}{2}", Utils.CloudBlobKey, Guid.NewGuid().ToString(), Path.GetExtension(FileUploadImage.FileName)); CloudBlockBlob blob = _blobClient.GetBlockBlobReference(uniqueBobName); blob.Properties.ContentType = FileUploadImage.PostedFile.ContentType; blob.UploadFromStream(FileUploadImage.FileContent); FunnyAppRepository<Post> postRepository = new FunnyAppRepository<Post>(); FunnyAppRepository<Tag> tagRepository = new FunnyAppRepository<Tag>(); MembershipUser user = Membership.GetUser(Page.User.Identity.Name); if (user != null) { Post post = new Post { PostContent = TextBoxDescription.Text, PostTitle = TextBoxTitle.Text, State = false, UserId = user.ProviderUserKey.ToString() }; string[] tags = TextBoxTag.Text.Split(';'); foreach (string tag in tags) { if (!string.IsNullOrEmpty(tag)) { tagRepository.Create(new Tag() { PostRowKey = post.RowKey, PostPartitionKey = post.PartitionKey, TagName = tag, }); tagRepository.SubmitChange(); } } postRepository.Create(post); postRepository.SubmitChange(); CloudQueue queue = _queueClient.GetQueueReference(Utils.CloudQueueKey); CloudQueueMessage message = new CloudQueueMessage(string.Format("{0},{1},{2}", blob.Uri, post.PartitionKey, post.RowKey)); queue.AddMessage(message); LabelResult.Text = "Uploaded"; } else { LabelResult.Text = "Failed"; } } }
protected void ButtonSave_Click(object sender, EventArgs e) { if (FileUploadImage.HasFiles & Page.IsValid) { string uniqueBobName = string.Format("{0}/funnyimage_{1}{2}", Utils.CloudBlobKey, Guid.NewGuid().ToString(), Path.GetExtension(FileUploadImage.FileName)); CloudBlockBlob blob = _blobClient.GetBlockBlobReference(uniqueBobName); blob.Properties.ContentType = FileUploadImage.PostedFile.ContentType; blob.UploadFromStream(FileUploadImage.FileContent); FunnyAppRepository <Post> postRepository = new FunnyAppRepository <Post>(); FunnyAppRepository <Tag> tagRepository = new FunnyAppRepository <Tag>(); MembershipUser user = Membership.GetUser(Page.User.Identity.Name); if (user != null) { Post post = new Post { PostContent = TextBoxDescription.Text, PostTitle = TextBoxTitle.Text, State = false, UserId = user.ProviderUserKey.ToString() }; string[] tags = TextBoxTag.Text.Split(';'); foreach (string tag in tags) { if (!string.IsNullOrEmpty(tag)) { tagRepository.Create(new Tag() { PostRowKey = post.RowKey, PostPartitionKey = post.PartitionKey, TagName = tag, }); tagRepository.SubmitChange(); } } postRepository.Create(post); postRepository.SubmitChange(); CloudQueue queue = _queueClient.GetQueueReference(Utils.CloudQueueKey); CloudQueueMessage message = new CloudQueueMessage(string.Format("{0},{1},{2}", blob.Uri, post.PartitionKey, post.RowKey)); queue.AddMessage(message); LabelResult.Text = "Uploaded"; } else { LabelResult.Text = "Failed"; } } }
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); } } }
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); } } }
protected void ButtonCommentSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { _commentRepository.Create(new Comment() { Content = TextBoxCommet.Text, UserName = TextBoxUserName.Text, UserEmail = TextBoxEmail.Text, PostRowKey = HiddenFieldPost.Value }); _commentRepository.SubmitChange(); LabelResult.Text = "Comment Sended"; } else { LabelResult.Text = "Comment Failed"; } }