Ejemplo n.º 1
0
        public bool Connect()
        {
            try
            {
                WellKnownClientTypeEntry CoRemote =
                    new WellKnownClientTypeEntry(typeof(RpcConnector), "tcp://" + _Ip + ":" + _Port + "/" + typeof(RpcConnector).Name + _Key);

                if (_Channel == null)
                {
                    _Channel = new TcpChannel();
                    ChannelServices.RegisterChannel(_Channel, false);
                    RemotingConfiguration.RegisterWellKnownClientType(CoRemote);
                }

                Log.Info("Connect", "Registering connector : " + CoRemote.ObjectUrl);

                Connector = (RpcConnector)Activator.GetObject(CoRemote.ObjectType, CoRemote.ObjectUrl);
                _Id       = Connector.Connect(_Name);

                Log.Success("RpcClient", "Connected to : " + _Ip + ":" + _Port);
                Load();
            }
            catch (Exception e)
            {
                Log.Error("RcpClient", "Can not connect to : " + _Ip + ":" + _Port);
                Log.Error("RpcClient", "Erreur = " + e.ToString());
                try
                {
                    ChannelServices.UnregisterChannel(_Channel);
                }
                catch (Exception) { }

                _Channel = null;
                return(false);
            }

            try
            {
                _Ping          = new Timer();
                _Ping.Interval = 1000;
                _Ping.Elapsed += Ping;
                _Ping.Start();
            }
            catch (Exception e)
            {
                Log.Error("RpcClient", "Erreur :" + e.ToString());
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void Load()
        {
            Log.Info("Load", "Registering RpcConnector : " + typeof(RpcConnector).Name + _Key);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RpcConnector), typeof(RpcConnector).Name + _Key, WellKnownObjectMode.SingleCall);
            Connector            = (RpcConnector)Activator.CreateInstance(typeof(RpcConnector), this);
            RpcConnector._Server = this;

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (!type.IsClass)
                    {
                        continue;
                    }

                    if (type.IsSubclassOf(typeof(ARpc)))
                    {
                        object[] attrib = type.GetCustomAttributes(typeof(RpcAttributes), true);
                        if (attrib.Length <= 0)
                        {
                            continue;
                        }

                        RpcAttributes[] packethandlerattribs =
                            (RpcAttributes[])type.GetCustomAttributes(typeof(RpcAttributes), true);

                        if (packethandlerattribs.Length <= 0)
                        {
                            continue;
                        }

                        foreach (string auth in packethandlerattribs[0].Authorised)
                        {
                            if (auth.StartsWith(_Name))
                            {
                                Log.Info("RpcServer", "Registering Rpc : " + type.Name);

                                RemotingConfiguration.RegisterWellKnownServiceType(type, type.Name + _Key, WellKnownObjectMode.Singleton);

                                ARpc Rpc = (ARpc)Activator.CreateInstance(type);
                                _Rpcs.Add(Rpc);
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Load()
        {
            Log.Info("Load", "Registering RpcConnector : " + typeof(RpcConnector).Name + _Key);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RpcConnector), typeof(RpcConnector).Name + _Key, WellKnownObjectMode.SingleCall);
            Connector = (RpcConnector)Activator.CreateInstance(typeof(RpcConnector), this);
            RpcConnector._Server = this;

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (!type.IsClass)
                        continue;

                    if (type.IsSubclassOf(typeof(ARpc)))
                    {
                        object[] attrib = type.GetCustomAttributes(typeof(RpcAttributes), true);
                        if (attrib.Length <= 0)
                            continue;

                        RpcAttributes[] packethandlerattribs =
                            (RpcAttributes[])type.GetCustomAttributes(typeof(RpcAttributes), true);

                        if (packethandlerattribs.Length <= 0)
                            continue;

                        foreach (string auth in packethandlerattribs[0].Authorised)
                        {
                            if (auth.StartsWith(_Name))
                            {
                                Log.Info("RpcServer", "Registering Rpc : " + type.Name);

                                RemotingConfiguration.RegisterWellKnownServiceType(type, type.Name + _Key, WellKnownObjectMode.Singleton);

                                ARpc Rpc = (ARpc)Activator.CreateInstance(type);
                                _Rpcs.Add(Rpc);
                                break;
                            }
                        }
                    }

                }
            }
        }
Ejemplo n.º 4
0
        public bool Connect()
        {
            try
            {
                WellKnownClientTypeEntry CoRemote =
                new WellKnownClientTypeEntry(typeof(RpcConnector), "tcp://" + _Ip + ":" + _Port + "/" + typeof(RpcConnector).Name + _Key);

                if (_Channel == null)
                {
                    _Channel = new TcpChannel();
                    ChannelServices.RegisterChannel(_Channel, false);
                    RemotingConfiguration.RegisterWellKnownClientType(CoRemote);
                }

                Log.Info("Connect", "Registering connector : " + CoRemote.ObjectUrl);

                Connector = (RpcConnector)Activator.GetObject(CoRemote.ObjectType, CoRemote.ObjectUrl);
                _Id = Connector.Connect(_Name);

                Log.Success("RpcClient", "Connected to : " + _Ip + ":" + _Port);
                Load();
            }
            catch (Exception e)
            {
                Log.Error("RcpClient", "Can not connect to : " + _Ip + ":" + _Port);
                Log.Error("RpcClient", "Erreur = " + e.ToString());
                try
                {
                    ChannelServices.UnregisterChannel(_Channel);
                }
                catch (Exception) { }

                _Channel = null;
                return false;
            }

            try
            {
                _Ping = new Timer();
                _Ping.Interval = 1000;
                _Ping.Elapsed += Ping;
                _Ping.Start();
            }
            catch (Exception e)
            {
                Log.Error("RpcClient", "Erreur :" + e.ToString());
            }

            return true;
        }