Пример #1
0
        private void RegisterServer()
        {
            _context = SynchronizationContext.Current;
            var uiThreadScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            var dataServiceProvider = new FusionDataServiceProvider(_context, _globalFunctions as IGlobalFunctions);

            CreateDataServerFromConfig(dataServiceProvider);

            _ = Task.Run(() => {
                try
                {
                    _host = DataServerHostFactory.Create(DataServer);
                }
                catch (AddressAlreadyInUseException)
                {
                    //Another Sophis has already assumed the role of server. Sink the exception.
                    CSMLog.Write("Main", "EntryPoint", CSMLog.eMVerbosity.M_error, "Another instance is already listening and acting as the RTD Server");

                    _host = null;
                }

                DataServer = _host.SingletonInstance as DataServer;

                DataServer.Start();
                DataServer.OnClientConnectionChanged += OnClientConnectionChanged;
                DataServer.OnDataUpdatedFromProvider += OnDataUpdatedFromProvider;

#if DEBUG
                DataServer.OnSubscriptionChanged += OnSubscriptionChanged;
#endif
            }).ContinueWith(t => {
                UpdateCaption();
            }, uiThreadScheduler);
        }
        public static ServiceHost Create(DataServer server)
        {
            var baseAddress = GetListeningAddress();
            var host        = new ServiceHost(server, baseAddress);

            var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.Transport)
            {
                MaxReceivedMessageSize = int.MaxValue,
            };

            binding.ReaderQuotas.MaxArrayLength        = int.MaxValue;
            binding.Security.Transport.ProtectionLevel = ProtectionLevel.EncryptAndSign;

            host.AddServiceEndpoint(typeof(IDataServiceServer), binding, ServiceName);

            // Add ServiceDiscoveryBehavior
            var discoveryBehavior = new ServiceDiscoveryBehavior();

            discoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
            host.Description.Behaviors.Add(discoveryBehavior);

            // Add a UdpDiscoveryEndpoint
            host.AddServiceEndpoint(new UdpDiscoveryEndpoint());

            host.Open();

            return(host);
        }
Пример #3
0
        private static void CreateDataServerFromConfig(FusionDataServiceProvider dataServiceProvider)
        {
            DataServer = new DataServer(dataServiceProvider);

            string defaultMessage = "";

            CSMConfigurationFile.getEntryValue("FusionLink", "DefaultMessage", ref defaultMessage, Resources.DefaultDataLoadingMessage);

            DataServer.DefaultMessage = defaultMessage;
        }
Пример #4
0
        static void Main(string[] args)
        {
            foreach (var a in args)
            {
                Console.WriteLine(a);
            }

            var testDataProvider = new TestDataServiceProvider();

            var dataServer = new DataServer(testDataProvider);

            dataServer.OnClientConnectionChanged += Ds_OnClientConnectionChanged;

            var host = DataServerHostFactory.Create(dataServer);

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();

            host.Close();
            host = null;
        }