Advertisement
loonerz

service

Jan 7th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Runtime.Serialization;
  6. using System.ServiceModel;
  7. using System.Text;
  8. using Microsoft.WindowsAzure.ServiceRuntime;
  9. using SignalR.Client.Hubs;
  10. using SiteMonitR.WorkerRole;
  11. using System.Threading;
  12. using System.Net;
  13. using SiteMonitR.WorkerRole.Properties;
  14.  
  15. namespace SiteMonitR.Web
  16. {
  17.    
  18.     public class Service1 : IService1
  19.     {
  20.         Thread thread;
  21.         Server server;
  22.        
  23.         public Service1()
  24.         {
  25.             ServicePointManager.DefaultConnectionLimit = 12;
  26.  
  27.             // create the server
  28.             server = new Server(
  29.                 new TableStorageSiteUrlRepository(),
  30.                 new WorkerRoleHubConfiguration()
  31.                 );
  32.  
  33.             // run the server
  34.             thread = new Thread(new ThreadStart(() => server.Run()));
  35.             thread.Start();
  36.             Run();
  37.         }
  38.         public void Run()
  39.         {
  40.             Trace.WriteLine("SiteMonitR.WebRole entry point called", "Information");
  41.  
  42.             while (true)
  43.             {
  44.                 Thread.Sleep(Settings.Default.PingTimeout);
  45.                 server.Run();
  46.             }
  47.         }
  48.         ~Service1()
  49.         {
  50.             thread.Abort();
  51.             server.Stop();
  52.             Debug.WriteLine("Stopped service");
  53.         }
  54.         public int GetResponse()
  55.         {
  56.             // TODO: Implement this method
  57.            
  58.             var result = 0;
  59.             try
  60.             {
  61.                 server.DoSomething("mensaje de respuesta");
  62.             }
  63.             catch (Exception ex)
  64.             {
  65.                 Console.WriteLine("Error returned: " + ex.Message);
  66.             }
  67.             return result;
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement