Exemplo n.º 1
0
 static void InitOpConnect()
 {
     if (_opInitialized) return;
     using (var prov = DbManager.Factory.GetProvider())
     {
         var others = prov.Operators.GetAll().OrderBy(o => o.Id).ToList();
         OperatorId = 0;
         foreach (var o in others)
         {
             if (o.Id == OperatorId) OperatorId++;
             else if (o.Id > OperatorId) break;
         }
         // listen and insert myself to db
         var myconn = new ClassConnection(OperatorController.Instance);
         StreamProxy.ListenAt(ControllerPort, () => myconn);
         var me = new OperatorData
         {
             Id = OperatorId,
             ControlerAddress = Dns.GetHostName() + ":" + ControllerPort,
             PublicAddress = Dns.GetHostName()
         };
         if (others.RemoveAll(o => o.ControlerAddress == me.ControlerAddress) > 0)
         {
             // shit, someone in db has same address as me
             // and it's not possible, because I am listening
             // so I will delete him :)
             prov.Operators.RemoveByContrAddr(me.ControlerAddress);
         }
         prov.Operators.Save(me);
         foreach (var o in others)
         {
             try
             {
                 var conn = ConnectOperator(o.ControlerAddress);
                 var proxy = ProxyCreator.GetProxy<IOperatorController>(conn);
                 proxy.NewOperator(me);
                 Operators.TryAdd(o.Id, proxy);
             }
             catch(Exception)
             {
                 // can't connect to operator => remove it from db
                 prov.Operators.Remove(o.Id);
             }
         }
         Operators.TryAdd(OperatorId, OperatorController.Instance);
     }
     _opInitialized = true;
 }
Exemplo n.º 2
0
 public void NewOperator(OperatorData op)
 {
     var connection = Global.ConnectOperator(op.ControlerAddress);
     var proxy = ProxyCreator.GetProxy<IOperatorController>(connection);
     Global.Operators.TryAdd(op.Id, proxy);
 }