Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;
            id = RoleEnvironment.CurrentRoleInstance.Id.Split('_')[2];
            // For information on handling configuration changes
            // see the MSDN topic at https://go.microsoft.com/fwlink/?LinkId=166357.

            bool result = base.OnStart();

            if (id == "1")
            {
                js = new JobServer();
                js.Open();
            }
            else
            {
                ConnectToHost();
            }

            Trace.TraceInformation("WorkerRole has been started");

            return(result);
        }