private async Task RunAsync(CancellationToken cancellationToken) { // TODO: Replace the following with your own logic. while (!cancellationToken.IsCancellationRequested) { receivedMessage = cloudQueue.GetMessage(); if (receivedMessage != null) { try { string s = ""; s = blobHelper.DownloadFromBlob("blob"); s = s + "..........\n" + receivedMessage.AsString; blobHelper.UploadToBlob("blob", s); Trace.WriteLine(blobHelper.DownloadFromBlob("blob")); cloudQueue.DeleteMessage(receivedMessage); } catch { } } Trace.TraceInformation("Working"); await Task.Delay(2000); } }
private void OpenInternalService() { try { if (blobHelper.DownloadFromBlob("servicehoststatus").ToUpper().Equals("OTVORENO")) { cloudQueue.DeleteMessage(receivedMessage); Trace.WriteLine("ServiceHost was alredy opened,message deleted"); return; } else { jobServer.OpenInternalService(); blobHelper.UploadToBlob("servicehoststatus", "OTVORENO"); cloudQueue.DeleteMessage(receivedMessage); Trace.WriteLine("ServiceHost is opened,message deleted"); } } catch (Exception e) { Trace.TraceError($"ERROR: {e.Message}"); blobHelper.UploadToBlob("servicehoststatus", "ERROR"); } }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // For information on handling configuration changes // see the MSDN topic at https://go.microsoft.com/fwlink/?LinkId=166357. bool result = base.OnStart(); //Izvuci ID iz worker role id = int.Parse(RoleEnvironment.CurrentRoleInstance.Id.Split('_')[2]); blobHelper = new BlobHelper(); cloudQueue = QueueHelper.GetQueueReference("queue"); jobServer = new JobServer(); if (id == 0) { jobServer.AddInternalService(); try { if (blobHelper.DownloadFromBlob("servicehoststatus").ToUpper() == "OTVORENO") { jobServer.OpenInternalService(); } else { //POCETNO STANJE JE CLOSE } } catch (Exception e) { Trace.TraceError($"ERROR: {e.Message}"); } } else if (id == 1) { //DRUGA INSTANCA WORKER ROLE OTVARA SERVICE HOST ZA WEB I PRIMA PORUKU //KONTAKTIRA PRVU INSTANCU DA PROVERI DA LI JE ZIVA jobServer.AddExternalService(); jobServer.OpenExternalService(); } else { Trace.WriteLine("Instance is not in use."); } Trace.TraceInformation("WorkerRole has been started"); return(result); }
public ActionResult Index() { string uniqueBlobName = string.Format("poruka_{0}_{1}", DateTime.Now.ToShortDateString(), ++id); BlobHelper blobHelper = new BlobHelper(); string text = blobHelper.DownloadFromBlob(uniqueBlobName); if (text == null) { id--; return(RedirectToAction("Autobus")); } else if (text.Equals("Blue")) { return(RedirectToAction("Autobus")); } else { return(RedirectToAction("Vozac")); } }
public string Download(string uniqName) { return(blobHelper.DownloadFromBlob(uniqName)); }