Azure Storage Queue novost: potrdilo ob dodanem sporočilu

by Rok Bermež 5. January 2017 08:35
Azure Storage je dobil v zadnjem času kar nekaj dolgo pričakovanih novosti. Poleg konkretnega povečanja velikosti blobov je ena izmed njih potrdilo ob dodanem sporočilu v vrsto, ki nam omogoča spremembe sporočila (dokler se vidnost sporočila ne izteče samo tistemu klientu, ki je sporočilo dodal) brez tega, da bi ga morali prvo iz vrste vzeti in ga nato spremenjenega dodati nazaj. Ta funkcionalnost je odlično orodje za enostavnejšo identifikacijo sporočil v vrsti za dodatno procesiranje. Spodaj je kratek primer uporabe te funkcionalnosti z pomočjo paketa 'Client Library 8.0 for .NET'. // naredimo sporočilo CloudQueueMessage message = new CloudQueueMessage(""); // ga dodamo v vrsto a vseeno skrijemo pred ostalimi za 3 minute queue.AddMessage(message, null, TimeSpan.FromSeconds(180)); //message.PopReceipt je napolnjen in samo is ta klient lahko nad njim izvaja spremembe dokler se vidnost ne izteče . // spremenimo vsebino sporočila message.SetMessageContent(""); queue.UpdateMessage(message, TimeSpan.FromSeconds(180), MessageUpdateFields.Content | MessageUpdateFields.Visibility); // po uspešni obdelavi ga umaknemo iz vrste preden ga vidijo drugi klienti await queue.DeleteMessageAsync(message.Id, message.PopReceipt); Spološni oblačni problem je koordinacija sprememb nad ne transakcijskimi viri. Aplikacija, ki obdeluje videe ali fotografije lahko: 1. obdela video/sliko 2. jo naloži v blob 3. shrani metapodatke v table entity. Tem korakom lahko sledi s pomočjo sporočila v vrsti z naslednjim potekom: 1. poda stanje kot sporočilo v vrsto 2. obdela video/sliko 3. spremeni stanje 4. shrani metapodatke 5. pobriše sporočilo iz vrste Vsa sporočila ki tako ostanejo v vrsti tako predstavljajo tiste naloge, ki so bile iz kakršnega koli razloga neuspešno obdelane in jih lahko prevzame 'cleanup' delavec ter poizkusi še enkrat ali pa obvesti skrbnika procesa. Kot vidimo je s pomočjo te nove funkcionalnosti implementacija takšnega procesa precej lažja.

Tags:

ASP.NET | .Net | Adobe

Manualy Submiting Unobtrusive MVC 3 Ajax Form

by Rok Bermež 21. April 2011 14:21
If you want to submit Ajax.BeginForm created ajax form a simple this.form.submit() wont work. Well to be exact it will, but not as it was intended. In order to make it work like expected, we can do it like this:   Html.DropDownList("selPredavanja",ViewBag.Lectures as SelectList,new { onchange = "Sys.Mvc.AsyncForm.handleSubmit( this.form, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'lectureData' });"})

Tags:

ASP.NET | mvc | Web

Windows Azure Cache Dependency

by Rok Bermež 10. April 2011 23:07
We are supposed to get Windows AppFabric Cache real soon, but till than form time to time we need to synchronize content cached inside our Web roles. SqlDependency is one way, but it cannot solve all problems (especialy those that are not based on SQL data). So to help with the matter I wrote AzureStorageCacheDependency that uses Azure storage to know when data is outdated and cache shloul be cleared. If anyone is in need of something similar, here it goes: public class AzureStorageCacheDependency : System.Web.Caching.CacheDependency { private System.Threading.Timer _timer; private int _poolTime; private CloudBlob _blob; private string _key; public AzureStorageCacheDependency(string connectionString, string conteinerAddress, string blobAddress, int poolTime = 5000) { _poolTime = poolTime; using (AzureContext azureContext = new AzureContext(true)) { var storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobStorage.GetContainerReference(conteinerAddress.ToLower()); container.CreateIfNotExist(); _blob = container.GetBlockBlobReference(blobAddress.ToLower()); if (!Exists(_blob)) { Reset(); } else { _key = _blob.DownloadText(); } } _timer = new Timer(new System.Threading.TimerCallback(CheckDependencyCallback), this, 0, _poolTime); } public void Reset() { _key = Guid.NewGuid().ToString(); _blob.UploadText(_key); } private void CheckDependencyCallback(object sender) { if (!Exists(_blob) || _key != _blob.DownloadText()) { NotifyDependencyChanged(this, EventArgs.Empty); _timer.Dispose(); } } public static bool Exists(CloudBlob blob) { try { blob.FetchAttributes(); return true; } catch (StorageClientException e) { if (e.ErrorCode == StorageErrorCode.ResourceNotFound) { return false; } else { throw; } } } } public class AzureContext : IDisposable { HttpContext _oldHttpContext; bool _restoreOldHttpContext = false; public AzureContext(bool forceSettingContextToNull = false) { if (forceSettingContextToNull) { _oldHttpContext = HttpContext.Current; HttpContext.Current = null; _restoreOldHttpContext = true; } else { try { HttpResponse response = HttpContext.Current.Response; } catch (HttpException) { _oldHttpContext = HttpContext.Current; HttpContext.Current = null; _restoreOldHttpContext = true; } } } public void Dispose(bool disposing) { if (disposing) { if (_restoreOldHttpContext) { HttpContext.Current = _oldHttpContext; } } } public void Dispose() { Dispose(true); } ~AzureContext() { Dispose(false); } }

Tags:

.Net | c# | ASP.NET | Azure | Web

ASP.NET MVC 3 AJAX REDIRECT RESULT

by Rok Bermež 5. April 2011 14:31
From time to time, we need to selectively redirect the browser to another location as a result of an AJAX action. Just returning RedirectResult won’t do the trick (even if we are used to similar functionality in ASP.NET AJAX in combination with WebForms ). Here is a very simple RedirectResult thet will be appropriate in those scenarios: public class AjaxRedirectResult : RedirectResult { public AjaxRedirectResult(string url): base(url){} public override void ExecuteResult(ControllerContext context) { if (context.RequestContext.HttpContext.Request.IsAjaxRequest()) { JavaScriptResult result = new JavaScriptResult() { Script = String.Format("window.location='{0}';", UrlHelper.GenerateContentUrl(Url, context.HttpContext)) }; result.ExecuteResult(context); } else base.ExecuteResult(context); } }

Tags:

.Net | c# | ASP.NET | mvc | Web

MVC3 Windows Azure Deployment

by Rok Bermež 14. January 2011 12:12
For RTM version of MVC 3 make sure the deployment contains following dlls: Microsoft.Web.Infrastructure System.Web.Helpers System.Web.Mvc System.Web.Razor System.Web.WebPages System.Web.WebPages.Deployment System.Web.WebPages.Razor  

Tags:

ASP.NET | Azure | mvc

Calendar

<<  May 2017  >>
MonTueWedThuFriSatSun
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Page List

Month List