Beispiel #1
0
        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");
            }
        }
Beispiel #2
0
        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);
        }