Ejemplo n.º 1
0
        public override void Run()
        {
            Trace.TraceInformation("WorkerRole1 is running");
            Storage.Clear();
            Storage.Initiate();
            //Storage.linkQueue.AddMessage(new CloudQueueMessage("http://www.cnn.com/sitemaps/sitemap-profile-2018-02.xml"));
            //Storage.commandQueue.AddMessage(new CloudQueueMessage("Load"));
            // TODO: Replace the following with your own logic.
            while (true)
            {
                Thread.Sleep(100);
                Trace.TraceInformation("Working");
                CloudQueueMessage commandQueueMessage = Storage.commandQueue.GetMessage(TimeSpan.FromMinutes(5));
                //string commandQueueMessage = crawler.GetState();
                if (commandQueueMessage != null)
                {
                    if (commandQueueMessage.AsString == "Load")
                    //commandQueueMessage.AsString == "Load")
                    {
                        crawler.Load();
                        crawler.Crawling();
                        crawler.ReadHtml();
                    }
                    else if (commandQueueMessage.AsString == "Crawl")
                    {
                        crawler.Crawl();
                        crawler.Crawling();
                        crawler.ReadHtml();
                    }
                    else if (commandQueueMessage.AsString == "Idle")
                    {
                        crawler.Idle();
                    }
                    try
                    {
                        Storage.commandQueue.DeleteMessage(commandQueueMessage);
                    } catch (Exception e)
                    {
                    }
                }
                commandQueueMessage = Storage.commandQueue.GetMessage();
            }

            try
            {
                this.RunAsync(this.cancellationTokenSource.Token).Wait();
            }
            finally
            {
                this.runCompleteEvent.Set();
            }
        }