Inheritance: IChannelDataStore
Ejemplo n.º 1
0
		public void Bug81653 ()
		{
			IpcClientChannel c = new IpcClientChannel ();
			ChannelDataStore cd = new ChannelDataStore (new string[] { "foo" });
			string objectUri;
			c.CreateMessageSink (null, cd, out objectUri);
		}
Ejemplo n.º 2
0
    void Init (IServerChannelSinkProvider provider) {
      if (!_e.Incoming)
        throw new InvalidOperationException("Non-listening Endpoint passed to IceServerChannel");

      if (!(_e is TcpEndpoint))
        throw new NotSupportedException("Only TcpEndpoints are supported as servers (for now)");

      if (provider == null) {
        provider = new IceServerFormatterSinkProvider();
      }

      IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain (provider, this);

      TcpEndpoint te = _e as TcpEndpoint;

      string[] uris = null;
      if (te.port != 0) {
        uris = new string[1];
        uris[0] = "ice://" + te.host + ":" + te.port;
      }

      _channelData = new ChannelDataStore (uris);
      _channelData["__iceEndpoint"] = _e;

      _sink = new IceServerTransportSink (nextSink);
      //      _listener = new TcpListener (te.IPAddress, te.port);
      _listener = new TcpListener (IPAddress.Any, te.port);
      _listenerThread = null;

      StartListening (null);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Замена имени хоста или IP-адреса
        /// </summary>
        /// <param name="dataStore">Данные канала</param>
        /// <param name="serverHostNameOrIp">Имя или адрес хоста, переданное с клиента</param>
        private void ReplaceHostNameOrIp(ChannelDataStore dataStore, String serverHostNameOrIp)
        {
            for (Int32 i = 0; i < dataStore.ChannelUris.Length; i++)
            {
                if (_eventLink != null)
                {
                    _eventLink.Post(EventSource, String.Format(
                        "Исходный URI в данных канала связи: {0}", dataStore.ChannelUris[i]));
                }

                UriBuilder ub = new UriBuilder(dataStore.ChannelUris[i]);
                
                // сравниваем имя хоста в URI канала и то же, переданное с клиента
                if (String.Compare(ub.Host, serverHostNameOrIp, true) != 0)
                {
                    // меняем на значение, переданное с клиента
                    ub.Host = serverHostNameOrIp;
                    dataStore.ChannelUris[i] = ub.ToString();

                    if (_eventLink != null)
                    {
                        _eventLink.Post(EventSource, String.Format(
                            "Хост изменен. Новый URI: {0}", dataStore.ChannelUris[i]));
                    }
                }
            }
        }
Ejemplo n.º 4
0
    public static void Main(string[] args)
    {
        // Krijo server channel
        IpcChannel serverChannel =
            new IpcChannel("localhost:9090");

        // Regjistro channelin e serverit dhe percakto sigurine
        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(serverChannel, false);

        // Trego emrin e channel
        Console.WriteLine("Emri i channel eshte {0}.",
                          serverChannel.ChannelName);

        // Trego prioritetin e channel
        Console.WriteLine("Prioriteti i channel eshte {0}.",
                          serverChannel.ChannelPriority);

        // Trego URIte e asociuara me kete channel
        System.Runtime.Remoting.Channels.ChannelDataStore channelData =
            (System.Runtime.Remoting.Channels.ChannelDataStore)
            serverChannel.ChannelData;
        foreach (string uri in channelData.ChannelUris)
        {
            Console.WriteLine("URI e channel eshte {0}.", uri);
        }

        // Lejo qasjen ne nje object per remote call
        System.Runtime.Remoting.RemotingConfiguration.
        RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            System.Runtime.Remoting.WellKnownObjectMode.Singleton);

        // Parso URLne e channel
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0], objectUri,
                   channelUri = serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("URI e objektit eshte {0}.", objectUri);
            Console.WriteLine("URI e channel eshte {0}.", channelUri);
            Console.WriteLine("URL e objektit eshte {0}.", objectUrl);
        }
        Console.WriteLine("Per t'e ndalur serverin, shtyp 0 dhe ENTER.");
        // Prit per ndalim
        // Serveri ndalet momentin kur perdoruesi shtyp ndonje send
        String uInput = "";

        while (!uInput.Equals("exit"))
        {
            try{ uInput = Console.ReadLine(); }
            catch { uInput = ""; }
        }
        if (uInput.Equals("exit"))
        {
            serverChannel.StopListening(null);
            Console.WriteLine("Serveri eshte ndalur.");
            Console.ReadLine();
        }
    }
Ejemplo n.º 5
0
 internal static void CollectChannelDataFromServerSinkProviders(ChannelDataStore channelData, IServerChannelSinkProvider provider)
 {
     while (provider != null)
     {
         provider.GetChannelData(channelData);
         provider = provider.Next;
     }
 }
 internal static void CollectChannelDataFromServerSinkProviders(ChannelDataStore channelData, IServerChannelSinkProvider provider)
 {
     while (provider != null)
     {
         provider.GetChannelData(channelData);
         provider = provider.Next;
     }
 }
Ejemplo n.º 7
0
    public static void Main(string[] args)
    {
        // Create the server channel.
        IpcServerChannel serverChannel =
            new IpcServerChannel("localhost:9090");

        // Register the server channel.
        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(
            serverChannel);

        //<snippet12>
        // Show the name of the channel.
        Console.WriteLine("The name of the channel is {0}.",
                          serverChannel.ChannelName);
        //</snippet12>

        //<snippet13>
        // Show the priority of the channel.
        Console.WriteLine("The priority of the channel is {0}.",
                          serverChannel.ChannelPriority);
        //</snippet13>

        //<snippet15>
        // Show the URIs associated with the channel.
        System.Runtime.Remoting.Channels.ChannelDataStore channelData =
            (System.Runtime.Remoting.Channels.ChannelDataStore)
            serverChannel.ChannelData;
        foreach (string uri in channelData.ChannelUris)
        {
            Console.WriteLine("The channel URI is {0}.", uri);
        }
        //</snippet15>

        // Expose an object for remote calls.
        System.Runtime.Remoting.RemotingConfiguration.
        RegisterWellKnownServiceType(
            typeof(RemoteObject), "RemoteObject.rem",
            System.Runtime.Remoting.WellKnownObjectMode.Singleton);

        //<snippet19>
        // Parse the channel's URI.
        string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
        if (urls.Length > 0)
        {
            string objectUrl = urls[0];
            string objectUri;
            string channelUri = serverChannel.Parse(objectUrl, out objectUri);
            Console.WriteLine("The object URI is {0}.", objectUri);
            Console.WriteLine("The channel URI is {0}.", channelUri);
            Console.WriteLine("The object URL is {0}.", objectUrl);
        }
        //</snippet19>

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
        Console.WriteLine("The server is exiting.");
    }
Ejemplo n.º 8
0
        } // AppendProviderToClientProviderChain

        internal static void CollectChannelDataFromServerSinkProviders(
            ChannelDataStore channelData,
            IServerChannelSinkProvider provider)
        {
            // walk chain and ask each provider for channel data
            while (provider != null)
            {
                provider.GetChannelData(channelData);

                provider = provider.Next;
            }
        } // CollectChannelDataFromServerSinkProviders
        static TcpChannel tcpChannel; //Tcp通道

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            Console.Title = "远程过程调用服务端";

            tcpChannel = new TcpChannel(8888);                      //创建Tcp通道
            ChannelServices.RegisterChannel(tcpChannel, false);     //注意通道服务
            data = (ChannelDataStore)tcpChannel.ChannelData;        //获取通道信息
            ChannelUris = data.ChannelUris[0];                      //获取通道地址
            Remote.HelloCallback += new EventHandler<EventArgsHello>(Remote_HelloCallback);
            RemotingConfiguration.RegisterWellKnownServiceType(     //注册Remote类型
            typeof(Remote), "HelloServer", WellKnownObjectMode.Singleton);

            Console.Read();
        }
Ejemplo n.º 10
0
        public BidirTcpServerChannel(IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
        {
            _name = (String) properties["name"];
            if (_name == null)
            {
                _name = "BidirTcpServer";
            }
            _port = int.Parse((String) properties["port"]);

            String[] urls = { this.GetURLBase() };

            // needed for CAOs!
            _channelData = new ChannelDataStore(urls);

            String IPAddress = Helper.GetIPAddress();

            if (serverSinkProvider == null)
            {
                serverSinkProvider = new BinaryServerFormatterSinkProvider();
            }

            if (_clientProvider == null)
            {
                _clientProvider = new BinaryClientFormatterSinkProvider();
            }

            _sinkProvider = serverSinkProvider;

            // collect channel data from all providers
            IServerChannelSinkProvider provider = _sinkProvider;
            while (provider != null)
            {
                provider.GetChannelData(_channelData);
                provider = provider.Next;
            }

            // create the sink chain
            IServerChannelSink snk =
                ChannelServices.CreateServerChannelSinkChain(_sinkProvider,this);

            // add the BidirTcpServerTransportSink as a first element to the chain
            _transportSink = new BidirTcpServerTransportSink(snk, _port ,IPAddress);
            MessageHandler.RegisterServer(_transportSink,Helper.GetIPAddress() + ":" + _port);
            MessageHandler.RegisterServer(_transportSink,Helper.GetMyGUID().ToString());

            // start to listen
            this.StartListening(null);
        }
Ejemplo n.º 11
0
        static void SetupRPCListener(MainForm mainForm)
        {
            // connect to the scanner controller
            var serverProvider = new BinaryServerFormatterSinkProvider();
            var clientProvider = new BinaryClientFormatterSinkProvider();

            serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            var props = new Hashtable();

            props["name"]     = "ipc";
            props["portName"] = APP_NAME;

            IpcChannel serverChannel = new IpcChannel(props, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(serverChannel);
            RemotingConfiguration.ApplicationName = APP_NAME;

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(ScanWorker), SERVICE_NAME, WellKnownObjectMode.Singleton);

            ScanWorker myScanWorker = new ScanWorker(mainForm);

            wellKnown = RemotingServices.Marshal(myScanWorker, SERVICE_NAME, typeof(ScanWorker));
            Console.WriteLine("object published at: " + wellKnown.URI);

            // Parse the channel's URI.
            string[] urls = serverChannel.GetUrlsForUri(SERVICE_NAME);
            if (urls != null && urls.Length > 0)
            {
                string objectUrl = urls[0];
                string objectUri;
                string channelUri = serverChannel.Parse(objectUrl, out objectUri);
                Console.WriteLine("The URL is {0}.", String.Join(" : ", urls));
                Console.WriteLine("The object URI is {0}.", objectUri);
                Console.WriteLine("The channel URI is {0}.", channelUri);
            }

            // Show the URIs associated with the channel.
            System.Runtime.Remoting.Channels.ChannelDataStore channelData =
                (System.Runtime.Remoting.Channels.ChannelDataStore)
                serverChannel.ChannelData;
            foreach (string uri in channelData.ChannelUris)
            {
                Console.WriteLine("The channel URI is {0}.", uri);
            }
        }
Ejemplo n.º 12
0
        public static ChannelDataStore ServerChannelCreateDataStore(
			string channelUri,
			IServerChannelSinkProvider sinkProviderChain)
        {
            var uris = new[] { channelUri };
            var channelData = new ChannelDataStore(uris);

            // walk throw the chain of sink providers and collect their data
            IServerChannelSinkProvider sinkProvider = sinkProviderChain;
            while (sinkProvider != null)
            {
                sinkProvider.GetChannelData(channelData);
                sinkProvider = sinkProvider.Next;
            }

            return channelData;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Ininitializes a new instance of the <see cref="NullChannel"/> class.
        /// </summary>
        /// <param name="channelName">Channel name.</param>
        /// <param name="clientSinkProvider">The client sink provider.</param>
        /// <param name="serverSinkProvider">The server sink provider.</param>
        public NullChannel(string channelName = "NullChannel", IClientChannelSinkProvider clientSinkProvider = null, IServerChannelSinkProvider serverSinkProvider = null)
        {
            ChannelName = channelName;
            ChannelDataStore = new ChannelDataStore(new[] { "null://" + channelName });

            // standard mode: message serialization must be enabled
            if (clientSinkProvider != null || serverSinkProvider != null)
            {
                InitializeWithFormatters(clientSinkProvider, serverSinkProvider);
            }
            else
            {
                // fast mode (no additional sinks specified) — bypass serialization
                ClientSinkProvider = new NullClientChannelSink.Provider();
                ServerSink = new NullServerChannelSink(null);
            }

            // start listening for messages
            StartListening(null);
        }
Ejemplo n.º 14
0
 public void MarshaledObject(object obj, ObjRef or)
 {
     object data = CallContext.GetData("ClientIp");
     if ((data != null) && (or.ChannelInfo != null))
     {
         string ip = "";
         string port = "";
         this.SplitClientAddress(data.ToString(), out ip, out port);
         for (int i = or.ChannelInfo.ChannelData.GetLowerBound(0); i <= or.ChannelInfo.ChannelData.GetUpperBound(0); i++)
         {
             if (or.ChannelInfo.ChannelData[i] is ChannelDataStore)
             {
                 foreach (string str3 in ((ChannelDataStore) or.ChannelInfo.ChannelData[i]).ChannelUris)
                 {
                     ChannelDataStore store = new ChannelDataStore(this.GetClientAddressFromUri(str3, ip, port));
                     or.ChannelInfo.ChannelData[i] = store;
                 }
             }
         }
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Initilaize the queue remoting.
        /// </summary>
        public void Start()
        {
            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(RemoteQueueServer),
                "RemoteQueueServer.rem", WellKnownObjectMode.Singleton);

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(RemoteQueueManager),
                "RemoteQueueManager.rem", WellKnownObjectMode.Singleton);

            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(ImplementationClass<int>), "IntRemoteObject.rem", WellKnownObjectMode.SingleCall);

            Dictionary <string, string> props = new Dictionary <string, string>();

            props.Add("authorizedGroup", "Everyone");
            props.Add("portName", "portMQueue");
            props.Add("exclusiveAddressUse", "false");
            //        prop["name"] = "RemoteServer";
            //        prop["tokenImpersonationLevel"] = System.Security.Principal.TokenImpersonationLevel.Delegation;
            //        prop["includeVersions"] = false;
            //        prop["strictBinding"] = false;
            //        prop["secure"] = true;

            IpcChannel channel = new IpcChannel(props, null, null);// ("test");

            ChannelServices.RegisterChannel(channel, false /*ensureSecurity*/);

            //// Show the URIs associated with the channel.
            System.Runtime.Remoting.Channels.ChannelDataStore channelData =
                (System.Runtime.Remoting.Channels.ChannelDataStore)
                channel.ChannelData;
            foreach (string uri in channelData.ChannelUris)
            {
                Console.WriteLine("The channel URI is {0}.", uri);
            }



            Console.WriteLine("Channel:{0} Waiting for connections...", channel.ChannelName);
        }
Ejemplo n.º 16
0
		void Init (IServerChannelSinkProvider serverSinkProvider)
		{
			if (serverSinkProvider == null) 
			{
				serverSinkProvider = new BinaryServerFormatterSinkProvider ();
			}

			if (host == null)
			{
				if (useIpAddress) {
					if (!bindAddress.Equals(IPAddress.Any)) host = bindAddress.ToString ();
					else {
						IPHostEntry he = Dns.Resolve (Dns.GetHostName());
						if (he.AddressList.Length == 0) throw new RemotingException ("IP address could not be determined for this host");
						host = he.AddressList [0].ToString ();
					}
				}
				else
					host = Dns.GetHostByName(Dns.GetHostName()).HostName;
			}
			
			// Gets channel data from the chain of channel providers

			channel_data = new ChannelDataStore (null);
			IServerChannelSinkProvider provider = serverSinkProvider;
			while (provider != null)
			{
				provider.GetChannelData(channel_data);
				provider = provider.Next;
			}

			// Creates the sink chain that will process all incoming messages

			IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain (serverSinkProvider, this);
			sink = new TcpServerTransportSink (next_sink);

			StartListening (null);
		}
Ejemplo n.º 17
0
        public BidirTcpClientChannel(IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
        {
            _properties = properties;
            _provider = clientSinkProvider;
            _name = (String) _properties["name"];

            String[] urls = { this.GetURLBase() };
            // needed for CAOs!
            _channelData = new ChannelDataStore(urls);

            if (_provider == null)
            {
                _provider = new BinaryClientFormatterSinkProvider();
            }

            if (serverSinkProvider == null)
            {
                serverSinkProvider = new BinaryServerFormatterSinkProvider();
            }

            // collect additional channel data from all providers
            IServerChannelSinkProvider prov = serverSinkProvider;
            while (prov != null)
            {
                prov.GetChannelData(_channelData);
                prov = prov.Next;
            }

            // create the sink chain
            IServerChannelSink snk =
                ChannelServices.CreateServerChannelSinkChain(serverSinkProvider,this);

            // add the BidirTcpServerTransportSink as a first element to the chain
            _serverSink = new BidirTcpServerTransportSink(snk);
            MessageHandler.RegisterServer(_serverSink,Helper.GetMyGUID().ToString());
        }
        void Init (IServerChannelSinkProvider serverSinkProvider) 
        {
            if (serverSinkProvider == null) 
            {
                serverSinkProvider = new UnixBinaryServerFormatterSinkProvider ();
            }
            
            // Gets channel data from the chain of channel providers

            channel_data = new ChannelDataStore (null);
            IServerChannelSinkProvider provider = serverSinkProvider;
            while (provider != null)
            {
                provider.GetChannelData(channel_data);
                provider = provider.Next;
            }

            // Creates the sink chain that will process all incoming messages

            IServerChannelSink next_sink = ChannelServices.CreateServerChannelSinkChain (serverSinkProvider, this);
            sink = new UnixServerTransportSink (next_sink);
            
            StartListening (null);
        }
        private void SetupChannel()
        {
            // set channel data 
            // (These get changed inside of StartListening(), in the case where the listen
            //   port is 0, because we can't determine the port number until after the 
            //   IpcListener starts.) 

            if (authSet && !_secure) 
                throw new RemotingException(CoreChannel.GetResourceString(
                                                "Remoting_Ipc_AuthenticationConfig"));

            _channelData = new ChannelDataStore(null); 
            _channelData.ChannelUris = new String[1];
                _channelData.ChannelUris[0] = GetChannelUri(); 
 
            // set default provider (soap formatter) if no provider has been set
            if (_sinkProvider == null) 
                _sinkProvider = CreateDefaultServerProviderChain();

            CoreChannel.CollectChannelDataFromServerSinkProviders(_channelData, _sinkProvider);
 
            // construct sink chain
            IServerChannelSink sink = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this); 
            _transportSink = new IpcServerTransportSink(sink, _secure, _impersonate); 

            // Start a thread to listen for incoming requests 
            ThreadStart t = new ThreadStart(this.Listen);
            _listenerThread = new Thread(t);
            _listenerThread.IsBackground = true;
 
            // Wait for thread to spin up
            StartListening(null); 
        } // SetupChannel 
Ejemplo n.º 20
0
 void PopulateChannelData( ChannelDataStore channelData,
     IServerChannelSinkProvider provider)
 {
     while (provider != null)
     {
         provider.GetChannelData(channelData);
         provider = provider.Next;
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a server channel.
        /// </summary>
        /// <param name="properties">The channel properties.</param>
        /// <param name="provider">The sink provider.</param>
        public IpcServerChannel(IDictionary properties, IServerChannelSinkProvider provider)
        {
            bool impersonate = false;

            if (properties != null) 
            {
                foreach (DictionaryEntry e in properties) 
                {
                    switch ((string)e.Key) 
                    {
                        case "name":
                            channelName = (string)e.Value;
                            break;

                        case "priority":
                            channelPriority = Convert.ToInt32(e.Value);
                            break;

                        case "portName":
                            portName = (string)e.Value;
                            if (!IpcChannelHelper.IsValidPipeName(portName))
                                throw new ArgumentException("Invalid pipe name.", "portName");
                            break;

                        case "impersonate":
                            impersonate = Boolean.Parse((string)e.Value);
                            break;
                    }
                }
            }

            if (portName == null) 
            {
                portName = Guid.NewGuid().ToString("N");
            }

            serverProvider = provider;

            if (serverProvider == null) 
            {
                serverProvider = new BinaryServerFormatterSinkProvider();
            }

            dataStore = new ChannelDataStore(
                new string[] {IpcChannelHelper.SchemeStart + portName}
                );
            PopulateChannelData(dataStore, serverProvider);

            sink = new IpcServerChannelSink(
                ChannelServices.CreateServerChannelSinkChain(serverProvider, this),
                portName,
                impersonate
                );

            StartListening(null);
        }
Ejemplo n.º 22
0
        } // SetupMachineName



        private void SetupChannel()
        {   
            // set channel data
            // (These get changed inside of StartListening(), in the case where the listen
            //   port is 0, because we can't determine the port number until after the
            //   TcpListener starts.)
            
            _channelData = new ChannelDataStore(null);
            if (_port > 0)
            {
                _channelData.ChannelUris = new String[1];
                _channelData.ChannelUris[0] = GetChannelUri();
            }

            // set default provider (soap formatter) if no provider has been set
            if (_sinkProvider == null)
                _sinkProvider = CreateDefaultServerProviderChain();

            CoreChannel.CollectChannelDataFromServerSinkProviders(_channelData, _sinkProvider);

            // construct sink chain
            IServerChannelSink sink = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this);
            _transportSink = new TcpServerTransportSink(sink);
            
            if (_port >= 0)
            {
                // Open a TCP port and create a thread to start listening
                _tcpListener = new TcpListener(_bindToAddr, _port);
                ThreadStart t = new ThreadStart(this.Listen);
                _listenerThread = new Thread(t);
                _listenerThread.IsBackground = true;

                // Wait for thread to spin up
                StartListening(null);
            }
        } // SetupChannel
Ejemplo n.º 23
0
		private void Initialize(IDictionary properties, IServerChannelSinkProvider sinkProvider)
		{
			if (properties != null)
			{
				// read property values
				foreach (DictionaryEntry property in properties)
				{
					switch ((string)property.Key)
					{
						case "name": _channelName = Convert.ToString(property.Value); break;
						case "priority": _channelPriority = Convert.ToInt32(property.Value); break;
						case "pipe": _pipe = Convert.ToString(property.Value); break;
						case "securityDescriptor": _securityDescriptor = (property.Value as SecurityDescriptor); break;
					}
				}
			}

			// setup pipe name
			_pipeName = new PipeName(@"\\.\pipe\" + _pipe);

			// create the chain of the sink providers that will process all messages
			_sinkProvider = ChannelHelper.ServerChannelCreateSinkProviderChain(sinkProvider);
			_channelData = ChannelHelper.ServerChannelCreateDataStore(ChannelUri, _sinkProvider);

			// create transport sink
			IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this);
			_transportSink = new ServerTransportSink(nextSink);

			// create listener thread
			_transportListener = new TransportListener(ChannelUri, typeof(PipeTransport));
			_listenerThread = new Thread(new ThreadStart(ListenerStart));
			_listenerThread.IsBackground = true;

			_requestHandler = new ProcessRequestCallback(_transportSink.ProcessRequest);

			// start listening on the channel
			StartListening(null);
		}
Ejemplo n.º 24
0
        internal void InitProviders(IServerChannelSinkProvider serverProviderChain)
        {
            _listener = null;
            _event = new AutoResetEvent(false);

            _data = new ChannelDataStore(null);
            _data.ChannelUris = new String[1];
            _data.ChannelUris[0] = ChannelScheme + "://" + m_pipeName;

            _serverSinkProvider = serverProviderChain;

            // Create the default sink chain if one was not passed in
            if (_serverSinkProvider == null)
                _serverSinkProvider = CreateDefaultServerProviderChain();;

            // Collect the rest of the channel data:
            IServerChannelSinkProvider provider = _serverSinkProvider;
            while(provider != null)
            {
                provider.GetChannelData(_data);
                provider = provider.Next;
            }

            IServerChannelSink next = ChannelServices.CreateServerChannelSinkChain(_serverSinkProvider, this);
            _transportSink = new PipeServerTransportSink(next);

            StartListening(null);
        }
Ejemplo n.º 25
0
		private void Initialize(IDictionary properties, IServerChannelSinkProvider sinkProvider)
		{
			if (properties != null)
			{
				// read property values
				foreach (DictionaryEntry property in properties)
				{
					switch ((string)property.Key)
					{
						case "name": _channelName = Convert.ToString(property.Value); break;
						case "priority": _channelPriority = Convert.ToInt32(property.Value); break;
						case "port": _port = Convert.ToInt32(property.Value); break;
						case "bindTo": _bindToAddr = IPAddress.Parse(Convert.ToString(property.Value)); break;
						case "machineName": _machineName = Convert.ToString(property.Value); break;
						case "useIpAddress": _useIpAddress = Convert.ToBoolean(property.Value); break;
						case "rejectRemoteRequests": if (Convert.ToBoolean(property.Value)) _bindToAddr = IPAddress.Loopback; break;
					}
				}
			}

			if (_machineName == null)
			{
				// setup machine name
				if (_useIpAddress)
				{
					if (_bindToAddr == IPAddress.Any)
						_machineName = NetHelper.GetMachineIp();
					else
						_machineName = _bindToAddr.ToString();
				}
				else
				{
					_machineName = NetHelper.GetMachineName();
				}
			}

			// create the chain of the sink providers that will process all messages
			_sinkProvider = ChannelHelper.ServerChannelCreateSinkProviderChain(sinkProvider);
			_channelData = ChannelHelper.ServerChannelCreateDataStore(ChannelUri, _sinkProvider);

			// create transport sink
			IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this);
			_transportSink = new ServerTransportSink(nextSink);

			// create listener thread
			_transportListener = new TransportListener(ListenerUri, typeof(TcpTransport));
			_listenerThread = new Thread(new ThreadStart(ListenerStart));
			_listenerThread.IsBackground = true;

			_requestHandler = new ProcessRequestCallback(_transportSink.ProcessRequest);

			// start listening on the channel
			StartListening(null);
		}
        } // SetupMachineName

 

        private void SetupChannel() 
        { 
            // set channel data
            // (These get changed inside of StartListening(), in the case where the listen 
            //   port is 0, because we can't determine the port number until after the
            //   TcpListener starts.)

            if (authSet && !_secure) 
                throw new RemotingException(CoreChannel.GetResourceString(
                                                "Remoting_Tcp_AuthenticationConfigServer")); 
 
            _channelData = new ChannelDataStore(null);
            if (_port > 0) 
            {
                _channelData.ChannelUris = new String[1];
                _channelData.ChannelUris[0] = GetChannelUri();
            } 

            // set default provider (soap formatter) if no provider has been set 
            if (_sinkProvider == null) 
                _sinkProvider = CreateDefaultServerProviderChain();
 
            CoreChannel.CollectChannelDataFromServerSinkProviders(_channelData, _sinkProvider);

            // construct sink chain
            IServerChannelSink sink = ChannelServices.CreateServerChannelSinkChain(_sinkProvider, this); 
            _transportSink = new TcpServerTransportSink(sink, _impersonate);
            // Initialize the accept socket callback 
            _acceptSocketCallback = new AsyncCallback(AcceptSocketCallbackHelper); 
            if (_port >= 0)
            { 
                // Open a TCP port and create a thread to start listening
                _tcpListener = new ExclusiveTcpListener(_bindToAddr, _port);
                // Wait for thread to spin up
                StartListening(null); 
            }
        } // SetupChannel 
 private void SetupChannel()
 {
     if (this.authSet && !this._secure)
     {
         throw new RemotingException(CoreChannel.GetResourceString("Remoting_Tcp_AuthenticationConfigServer"));
     }
     this._channelData = new ChannelDataStore(null);
     if (this._port > 0)
     {
         this._channelData.ChannelUris = new string[] { this.GetChannelUri() };
     }
     if (this._sinkProvider == null)
     {
         this._sinkProvider = this.CreateDefaultServerProviderChain();
     }
     CoreChannel.CollectChannelDataFromServerSinkProviders(this._channelData, this._sinkProvider);
     IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain(this._sinkProvider, this);
     this._transportSink = new TcpServerTransportSink(nextSink, this._impersonate);
     this._acceptSocketCallback = new AsyncCallback(this.AcceptSocketCallbackHelper);
     if (this._port >= 0)
     {
         this._tcpListener = new ExclusiveTcpListener(this._bindToAddr, this._port);
         this.StartListening(null);
     }
 }
		void SetupChannel (IServerChannelSinkProvider sinkProvider, IDictionary properties)
		{
			if (properties == null) properties = new Hashtable ();
			
			SetupMachineName();
			
			_sinkProvider = sinkProvider;
			
			String[] urls = { this.GetChannelUri() };

			// needed for CAOs
			_channelData = new ChannelDataStore(urls);
			
			if(_sinkProvider == null)
			{
				_sinkProvider = new SdlChannelSinkProvider();
				_sinkProvider.Next = new SoapServerFormatterSinkProvider();
			}

			// collect channel data from all providers
			IServerChannelSinkProvider provider = _sinkProvider;
			while (provider != null) 
			{
				provider.GetChannelData(_channelData);
				provider = provider.Next;
			}			

			// create the sink chain
			IServerChannelSink snk = 
				ChannelServices.CreateServerChannelSinkChain(_sinkProvider,this);

			_transportSink = new HttpServerTransportSink (snk, properties);
			SinksWithProperties = _transportSink;
		}
Ejemplo n.º 29
0
        /// <summary>
        /// <see cref="yukkuri_lib"/> のコンストラクタ
        /// </summary>
        /// <param name="dll_path">使うAquestalkのDLLパス</param>
        /// <param name="application_id"> 独自のid。競合防止のため。</param>
        public yukkuri_lib(string dll_path, string application_id)
        {
            if (!File.Exists(dll_path))
            {
                throw new System.IO.FileNotFoundException("DLL Load failed! " + dll_path + " is not found!");
            }
            string           dll_name = Path.GetFileName(Path.GetDirectoryName(dll_path));                                    //dllのフォルダ名を取得。
            ProcessStartInfo psinfo   = new ProcessStartInfo();                                                               //子プロセス用。

            psinfo.FileName        = System.AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\yukkuri_86_wrapper.exe"; //子プロセスのファイル名。
            psinfo.UseShellExecute = false;                                                                                   //シェルは使わん。
            psinfo.CreateNoWindow  = true;                                                                                    //ウィンドウも作らん。
            string dtnow = DateTime.Now.ToString("ddHHmmssfff");                                                              //現在時刻を取得

            psinfo.Arguments = dll_name + '|' + application_id + dtnow;                                                       //現在時刻をもとに作り、競合を回避。。
            System.Collections.IDictionary properties =
                new System.Collections.Hashtable();                                                                           //ハッシュテーブルを作成。
            properties["portName"]            = application_id + dtnow + "_yukkuri_lib_kokkiemouse_" + dll_name;              //ポートネーム生成。
            properties["exclusiveAddressUse"] = false;
            properties["name"] = dll_name;

            IpcChannel serverChannel = new IpcChannel(properties, null,
                                                      new BinaryServerFormatterSinkProvider
            {
                TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full,
            });                                                   //チャンネル生成。

            ChannelServices.RegisterChannel(serverChannel, true); //チャンネル登録

            /*yukkui = (yukkuri_lib_interface.yukkuri_lib_interface)Activator.GetObject(typeof(yukkuri_lib_interface.yukkuri_lib_interface),
             *  "ipc://yukkuri_lib_kokkiemouse/" + dll_name);
             */
            CountdownEvent inited_ev = new CountdownEvent(1);                   //待機用。

            yukkui         = new yukkuri_lib_interface.yukkuri_lib_interface(); //インターフェースを生成。
            yukkui.Oninit += new yukkuri_lib_interface.init_delegate(() =>      //初期化後に実行される
            {
                inited_ev.Signal();                                             //処理を再開。
            }
                                                                     );
            CountdownEvent loaded_dll_ev = new CountdownEvent(1); //dllを読み込むまでの待機用。

            yukkui.OnDllLoaded += new dll_loaded_delegate(() =>   //dllが読み込まれると実行
            {
                loaded_dll_ev.Signal();                           //処理を再開。
            });
            yukkui.Ondiscardloop += new Discard_loop(() =>
            {
                //そりゃ酢豚だからなんもしないさ。
#if DEBUG
                Debug.WriteLine("Stub Timer");
            #endif
            });
            RemotingServices.Marshal(yukkui, dll_name, typeof(yukkuri_lib_interface.yukkuri_lib_interface));    //定義したオブジェクトを登録。
            System.Runtime.Remoting.Channels.ChannelDataStore channelData =
                (System.Runtime.Remoting.Channels.ChannelDataStore)
                serverChannel.ChannelData;
            foreach (string uri in channelData.ChannelUris)
            {
                Debug.WriteLine("The channel URI is {0}.", uri); //デバッグ用。
            }
            Process.Start(psinfo);                               //子プロセス起動。
            inited_ev.Wait();                                    //初期化が完了するまで待機。
            try
            {
                yukkui.DllLoad_to_client(dll_path); //dllを読み込み。
            }catch (Exception)
            {
                throw;
            }
        }
 private void SetupChannel()
 {
     if (this.authSet && !this._secure)
     {
         throw new RemotingException(CoreChannel.GetResourceString("Remoting_Ipc_AuthenticationConfig"));
     }
     this._channelData = new ChannelDataStore(null);
     this._channelData.ChannelUris = new string[] { this.GetChannelUri() };
     if (this._sinkProvider == null)
     {
         this._sinkProvider = this.CreateDefaultServerProviderChain();
     }
     CoreChannel.CollectChannelDataFromServerSinkProviders(this._channelData, this._sinkProvider);
     IServerChannelSink nextSink = ChannelServices.CreateServerChannelSinkChain(this._sinkProvider, this);
     this._transportSink = new IpcServerTransportSink(nextSink, this._secure, this._impersonate);
     ThreadStart start = new ThreadStart(this.Listen);
     this._listenerThread = new Thread(start);
     this._listenerThread.IsBackground = true;
     this.StartListening(null);
 }
Ejemplo n.º 31
0
        } // AppendProviderToClientProviderChain

        internal static void CollectChannelDataFromServerSinkProviders(
            ChannelDataStore channelData,
            IServerChannelSinkProvider provider)
        {
            // walk chain and ask each provider for channel data
            while (provider != null)
            {
                provider.GetChannelData(channelData);
            
                provider = provider.Next;
            }
        } // CollectChannelDataFromServerSinkProviders
Ejemplo n.º 32
0
    public static void Main(string[] args)
    {
        // 引数が2つ必要。1番目のIPで、2番目がnodeに引き渡す.jsのファイル名
        if (args.Length < 3)
        {
            return;
        }

        // 常駐秀丸以外が何も起動していなければ、何もしない。(hideの秀丸も起動しているものとする)
        if (!HidemaruWindowInfo.IsFindWindow())
        {
            return;
        }

        try
        {
            // 1番めの引数にはIPが入っている50000~65535の範囲あたりを想定
            int IP = int.Parse(args[0]);

            bool bShowWindow = int.Parse(args[2]) > 0; // 1ならtrue, 0ならfalse

            // IPCサーバーチャンネルの生成.
            serverChannel = new IpcChannel("localhost:" + IP);

            // リモート用として、サーバーチャンネルを登録
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(serverChannel, false);

            // チャンネル名の表示.
            Console.WriteLine("チャンネルの名前は {0}.",
                              serverChannel.ChannelName);

            // チャンネルの優先度.
            Console.WriteLine("チャンネルの優先度は {0}.", serverChannel.ChannelPriority);

            // 該当のチャンネルデータの取得.
            System.Runtime.Remoting.Channels.ChannelDataStore channelData = (System.Runtime.Remoting.Channels.ChannelDataStore)serverChannel.ChannelData;
            // チャンネルの場所表示
            foreach (string uri in channelData.ChannelUris)
            {
                Console.WriteLine("チャンネルのURIは {0}.", uri);
            }

            // リモート呼び出しのため、オブジェクトを登録し、公開。サーバータイプ。シングルトン。
            System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(HmNodeRemoteObject), HmNodeRemoteObject.Name + IP + ".rem",
                System.Runtime.Remoting.WellKnownObjectMode.Singleton
                );

            // チャンネルの URI を分析.
            string[] urls = serverChannel.GetUrlsForUri(HmNodeRemoteObject.Name + IP + ".rem");
            if (urls.Length > 0)
            {
                string objectUrl = urls[0];
                string objectUri;
                string channelUri = serverChannel.Parse(objectUrl, out objectUri);
                Console.WriteLine("オブジェクトの URI は {0}.", objectUri);
                Console.WriteLine("チェンネルの URI は {0}.", channelUri);
                Console.WriteLine("オブジェクトの URL は {0}.", objectUrl);
            }

            // ユーザーの入力待ち
            // Console.WriteLine("サーバー終了には、リターンキーを入力");


            // Node.JSを、ファイル名やIPを指定して起動
            ProcessNodeJS.Start(args[1], IP, bShowWindow);

            // ShowDialogにすることで、一種モーダルとする。(常駐秀丸以外の)秀丸が無ければ、Close()してくる。
            // 外アプリからClose()した時に、正当な処理が行われるように(nodeもCloseできるように)、Formにしている。
            var f = new HmNodeProxyForm(IP, bShowWindow);
            f.ShowDialog();

            // Node.JSの終了
            ProcessNodeJS.Close();

            // チャンネルの解除
            System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(serverChannel);

            HmNodeIPCServerListManager.UpdateProcessMap();

            // Console.WriteLine("サーバーを終了します。");
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message + "ううう");
        }
    }