Esempio n. 1
0
        //https://msdn.microsoft.com/en-us/library/hh205277(v=vs.110).aspx
        //netsh http add urlacl url=http://+:1001/Elysium user="******"
        protected override void OnAddService()
        {
            base.OnAddService();

            //BasicHttpBinding hBasicHttpBinding  = new BasicHttpBinding(BasicHttpSecurityMode.None); //SOAP 1.1  => poor security, compatible
            //WSHttpBinding    hWsHttpBinding     = new WSHttpBinding(SecurityMode.None);             //SOAP      => full features

            if (LocalWebEndPoint != null)
            {
                WebHttpBinding hWebHttpBinding = new WebHttpBinding(WebHttpSecurityMode.None);                        //Rest      => XML
                hWebHttpBinding.ReceiveTimeout = TimeSpan.MaxValue;
                hWebHttpBinding.SendTimeout    = TimeSpan.MaxValue;
                ServiceEndpoint hEndpoint  = m_hHost.AddServiceEndpoint(typeof(IElysiumNodeWebService), hWebHttpBinding, $"http://localhost:{LocalWebEndPoint.Port}/Elysium/");
                WebHttpBehavior hBehaviour = new WebHttpBehavior();

                hEndpoint.EndpointBehaviors.Add(hBehaviour);
            }

            if (MasaterServerEndPoint != null)
            {
                NetTcpBinding hBinding = new NetTcpBinding();
                hBinding.ReceiveTimeout = TimeSpan.MaxValue;
                hBinding.SendTimeout    = TimeSpan.MaxValue;
                hBinding.Security.Mode  = SecurityMode.None;
                DuplexChannelFactory <IMasterServer> hFactory = new DuplexChannelFactory <IMasterServer>(this.GetType(), hBinding);

                IMasterServer hNewNode = hFactory.CreateChannel(new InstanceContext(this), new EndpointAddress($"net.tcp://{MasaterServerEndPoint.Address}:{MasaterServerEndPoint.Port}/ElysiumMasterServer"));
                (hNewNode as ICommunicationObject).Faulted += OnMasterServerChannelClosed;
                (hNewNode as ICommunicationObject).Closed  += OnMasterServerChannelClosed;
            }
        }
Esempio n. 2
0
        public static bool Init()
        {
            try {
                txId = -1;
                // Port 0 -> To request that an available port be dynamically assigned
                channel = new TcpChannel(0);
                ChannelServices.RegisterChannel(channel, false);
                try {
                    masterServer = (IMasterServer)Activator.GetObject(typeof(IMasterServer), urlMaster);
                } catch (RemotingException re) {
                    Console.WriteLine("[Init]:\n" + re);
                    return(false);
                    //throw new TxException(txId, "TxCommit transaction with id " + txId + "failed. canCommit voting failed.");
                }
                ChannelDataStore data = (ChannelDataStore)channel.ChannelData;
                clientUrl = (String)data.ChannelUris[0];
                //try {
                masterServer.registerClient(clientUrl);
                //} catch (RemotingException re) {

                //}
                return(true);
            } catch (Exception e) {
                Console.WriteLine("Init Exception:" + e);
                return(false);
            }
        }
Esempio n. 3
0
        public void Start(int iNetPort, int iWebPort, string sMsAddr, int iMsPort)
        {
            MasaterServerEndPoint = new IPEndPoint(IPAddress.Parse(sMsAddr), iMsPort);

            IMasterServer hNewNode = m_hMSChannelFactory.CreateChannel(new EndpointAddress($"net.tcp://{MasaterServerEndPoint.Address}:{MasaterServerEndPoint.Port}/ElysiumMasterServer"));

            (hNewNode as ICommunicationObject).Faulted += OnMasterServerChannelClosed;
            (hNewNode as ICommunicationObject).Closed  += OnMasterServerChannelClosed;


            this.Start(iNetPort, iWebPort);

            hNewNode.Register(iNetPort);
            hNewNode.GetNodes(int.MaxValue).ToList().ForEach(x => this.Connect(x.Address.ToString(), x.Port));
        }
Esempio n. 4
0
 public Server(TcpChannel channel, String name, String url, int primaryPort)
 {
     try {
         _channel      = channel;
         _name         = name;
         _url          = url;
         _masterServer = (IMasterServer)Activator.GetObject(typeof(IMasterServer), urlMaster);
         _state        = State.Normal;
         _stateLockObj = new Object();
         _isPrimary    = true;
         _slavePort    = 0;
         _lockManager  = new LockManager();
     } catch (RemotingException re) {
         Console.WriteLine("[Server]:\n" + re);
         throw new OperationException("Server " + name + "cannot start: MasterServer is not avaiable.");
     }
 }
Esempio n. 5
0
        public static bool Init()
        {
            /*Console.WriteLine("What is the master port?");
            masterPort = Console.ReadLine();

            Console.WriteLine("What is the master hostname?");
            masterHostname = Console.ReadLine();*/

            masterServer = (IMasterServer)Activator.GetObject(
                typeof(IMasterServer),
                "tcp://" + masterHostname + ":" + masterPort + "/RemoteMasterServer");

            return true;
        }