public static void Configure(string fileName = "", Credential[] credentials = null)
        {
            Configuration configuration =
                string.IsNullOrWhiteSpace(fileName)
                    ? ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
                    : ConfigurationManager.OpenMappedExeConfiguration(
                    fileMap: new ExeConfigurationFileMap()
            {
                ExeConfigFilename = fileName
            },
                    userLevel: ConfigurationUserLevel.None);

            var configSection = (CoreRemotingConfigSection)
                                configuration.Sections["coreRemoting"];

            foreach (ServerInstanceConfigElement serverInstanceConfig in configSection.ServerInstances)
            {
                var serverConfig = serverInstanceConfig.ToServerConfig();
                var server       = new RemotingServer(serverConfig);
                server.Start();
            }

            foreach (WellKnownServiceConfigElement serviceConfigElement in configSection.Services)
            {
                var entry = serviceConfigElement.ToWellKnownServiceTypeEntry();
                RegisterWellKnownServiceType(entry);
            }

            foreach (ClientInstanceConfigElement clientInstanceConfig in configSection.ClientInstances)
            {
                var clientConfig = clientInstanceConfig.ToClientConfig();
                clientConfig.Credentials = credentials;
                var client = new RemotingClient(clientConfig);
            }
        }
Example #2
0
 /// <summary>
 /// 清除超时用户
 /// </summary>
 private void ClearHadOutTimeRomtingServerObject()
 {
     if ((loginUserOnlineList != null) && (loginUserOnlineList.Count > 0))
     {
         object[] array = new object[loginUserOnlineList.Count];
         loginUserOnlineList.Keys.CopyTo(array, 0);
         RemotingServer server = null;
         foreach (int num in array)
         {
             server = loginUserOnlineList[num] as RemotingServer;
             if ((server == null) || (server._OnlineUserInfo == null))
             {
                 server = null;
                 loginUserOnlineList.Remove(num);
             }
             else
             {
                 if (!server._RemotingState.IsOutTime)
                 {
                     TimeSpan span = (TimeSpan)(DateTime.Now - server._OnlineUserInfo.SynDbUserTime);
                     if (span.Minutes < 5)
                     {
                         continue;
                     }
                 }
                 //清除超时或者同步时间大于5分钟的用户
                 server = null;
                 loginUserOnlineList.Remove(num);
             }
         }
     }
 }
Example #3
0
        private static void p_Server(object serverObject)
        {
            try
            {
                RemotingServer server = (RemotingServer)serverObject;

                // To this sample, I will require cryptography, and will only
                // accept RijndaelManaged and TripleDES. If I don't register a
                // valid cryptography, all cryptographies are valid.

                server.CryptographyMode = CryptographyMode.Required;
                server.RegisterAcceptedCryptography <RijndaelManaged>();
                server.RegisterAcceptedCryptography <TripleDESCryptoServiceProvider>();

                // Here I register the valid classes that the client can create
                // directly.
                //server.Register(typeof(IServer), typeof(SecureChat.Server.Server));
                server.Register(typeof(SecureChat.Common.IServer), typeof(SecureChat.Server.Server));
                // Here I start the server.
                server.Run(570);
            }
            catch (ObjectDisposedException)
            {
                // If during initialization the user press ENTER and disposes the
                // server, I will simple ignore the exception and finish the thread.
            }
        }
Example #4
0
 /// <summary>
 /// Hemera 服务器平台应用程序入口点。
 /// </summary>
 /// <param name="args">应用程序参数</param>
 static void Main(string[] args)
 {
     //启动Remoting服务
     RemotingServer.Start();
     Console.WriteLine("Press Enter to Exit.");
     Console.ReadLine();
 }
        public void GlobalSetup()
        {
#if !NO_REMOTING
            _remotingServer = new RemotingServer();
            _remotingClient = new RemotingClient();

            _remotingServer.RegisterActivatedService(typeof(Disposable));
            _remotingServer.RegisterActivatedService(typeof(Monk));

            _disposableTransparentProxy = new InstanceReference {
                Instance = _remotingClient.GetService <Disposable>()
            };
            _nonDisposableTransparentProxy = new InstanceReference {
                Instance = _remotingClient.GetService <Monk>()
            };
#endif // !NO_REMOTING

            _disposable = new InstanceReference {
                Instance = new Disposable()
            };
            _nonDisposable = new InstanceReference {
                Instance = new Monk()
            };

            _context  = new Mock <IContext>(MockBehavior.Strict).Object;
            _strategy = new DisposableStrategy();
        }
Example #6
0
        private RemotingServer CreateRemotingServer(UserInfoEntity userInfoEntity, string userId, int moduleId)
        {
            OnlineUserManager manager     = new OnlineUserManager();
            RemotingServer    remotingObj = new RemotingServer(userInfoEntity, userId, moduleId);

            manager.Add(userInfoEntity.WorkId, remotingObj);
            return(remotingObj);
        }
Example #7
0
 public void UnInit()
 {
     if (m_fResetSharedProjectValue)
     {
         Db4oServerInfo.AreProjectsShared_Internal = m_fResetSharedProjectValue;
     }
     RemotingServer.Stop();
 }
Example #8
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            FlatRedBallServices.InitializeFlatRedBall(this, graphics);

            InitializeIoc();

            this.TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0);

            mToolForm       = new ToolForm();
            mToolForm.Owner = (Form)(Form.FromHandle(FlatRedBallServices.WindowHandle));
            mToolForm.ItemCollapsedOrExpanded += HandleToolFormItemCollapsedOrExpanded;
            Plugin.PluginManager.Initialize();

            IsMouseVisible = true;

            IsFixedTimeStep = false;

            GuiData.Initialize();

            RegisterAdditionalAssemblies();

            AvailableAssetTypes.Self.Initialize(FileManager.RelativeDirectory);

            #region Set up resizing

            mFormMethods = new FormMethods(0, 0, 0, 0);

            #endregion

            SpriteManager.Camera.BackgroundColor = Color.Gray;
            FlatRedBall.Math.Geometry.Polygon.TolerateEmptyPolygons = true;
            ExposedVariableManager.Initialize();

            try
            {
                RemotingServer.SetupPort(8686);
                RemotingServer.SetupInterface <FlatRedBall.Glue.SelectionInterface>();
                RemotingServer.SetupInterface <RegisterInterface>();
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("GlueView could not start, please make sure GlueView is not already running on your computer \n \n Exception: \n" + e.ToString());
                FlatRedBall.FlatRedBallServices.Game.Exit();
            }

            mToolForm.Show();

            GluxManager.ContentManagerName = "GlueView";


            EditorLogic.Initialize();

            CommandLineManager.Self.ProcessCommandLineArgs(this.mToolForm);

            mainForm         = Form.FromHandle(FlatRedBallServices.WindowHandle) as Form;
            mainForm.Resize += HandleResize;
            base.Initialize();
        }
Example #9
0
        public void CallContext_should_flow_from_client_to_server_and_back()
        {
            var testService =
                new TestService
            {
                TestMethodFake = _ =>
                {
                    CallContext.SetData("test", "Changed");
                    return(CallContext.GetData("test"));
                }
            };

            var serverConfig =
                new ServerConfig()
            {
                NetworkPort            = 9093,
                RegisterServicesAction = container =>
                                         container.RegisterService <ITestService>(
                    factoryDelegate: () => testService,
                    lifetime: ServiceLifetime.Singleton)
            };

            using var server = new RemotingServer(serverConfig);
            server.Start();

            var clientThread =
                new Thread(() =>
            {
                CallContext.SetData("test", "CallContext");

                var client =
                    new RemotingClient(new ClientConfig()
                {
                    ServerPort        = 9093,
                    ConnectionTimeout = 0
                });

                client.Connect();

                var localCallContextValueBeforeRpc = CallContext.GetData("test");

                var proxy  = client.CreateProxy <ITestService>();
                var result = (string)proxy.TestMethod("x");

                var localCallContextValueAfterRpc = CallContext.GetData("test");

                Assert.NotEqual(localCallContextValueBeforeRpc, result);
                Assert.Equal("Changed", result);
                Assert.Equal("Changed", localCallContextValueAfterRpc);

                client.Dispose();
            });

            clientThread.Start();
            clientThread.Join();

            server.Dispose();
        }
Example #10
0
        public void StartFwRemoteDatabaseConnector()
        {
            RemotingServer.Start();

            var connectString = String.Format("tcp://{0}:{1}/FwRemoteDatabaseConnector.Db4oServerInfo",
                                              "localhost", Db4OPorts.ServerPort);

            m_db4OServerInfo = (Db4oServerInfo)Activator.GetObject(typeof(Db4oServerInfo), connectString);
        }
Example #11
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected override void Dispose(bool disposing)
 {
     if (disposing && (components != null))
     {
         RemotingServer.DeInit();
         components.Dispose();
     }
     base.Dispose(disposing);
 }
        public void StopFwRemoteDatabaseConnector()
        {
            RemotingServer.Stop();

            Directory.Delete(DirectoryFinder.ProjectsDirectory, true);
            DirectoryFinder.ProjectsDirectory = m_oldProjectDirectory;

            m_db4OServerInfo = null;
        }
Example #13
0
 public void Init()
 {
     // Allow db4o client server unit test to work without running the window service.
     RemotingServer.Start();
     if (Db4oServerInfo.AreProjectsShared_Internal)
     {
         m_fResetSharedProjectValue = true;
         Db4oServerInfo.AreProjectsShared_Internal = false;
     }
 }
Example #14
0
        public static void Initialize()
        {
            Console.WriteLine("Redirect Server Core Initialization");
            Console.WriteLine("-----------------------------------");

            #region Configuration Engine Initialization

            m_ConfigEngine = new ConfigEngine(CoreAssembly);
            Console.WriteLine();

            #endregion

            ConfigFile    ServerConfig        = m_ConfigEngine.LoadFile(Path.Combine(m_ConfigEngine.DataPath, "ServerConfiguration.xml"));
            ConfigElement ServerConfigElement = ServerConfig["config", "RedirectServer"];

            #region Script Engine Initialization

            ConfigElement[] PackageElements = ServerConfigElement.GetSubElements("packages");
            string[]        PathList        = new string[PackageElements.Length];

            for (int i = 0; i <= PackageElements.Length - 1; i++)
            {
                PathList[i] = PackageElements[i].GetString("packages_Column");
            }

            m_ScriptEngine = new ScriptEngine(m_ConfigEngine, PathList);

            Console.WriteLine();

            #endregion
            #region .NET Remoting Initialization

            Console.WriteLine("* Redirect Server .NET remoting service has been configured:\n");

            ConfigElement[] RemotingElements = ServerConfigElement.GetSubElements("remoting");
            if (RemotingElements.Length != 1)
            {
                //We must have a remoting configuration (and only one), so throw an exception here.
            }

            string RemotingName = RemotingElements[0].GetString("name");
            ushort RemotingPort = RemotingElements[0].GetUInt16("port");

            RemotingServer RemoteInterface = new RemotingServer(RemotingName, RemotingPort);
            RemoteInterface.RegisterType(RemotingName, typeof(RemoteRedirectServer));
            RemoteInterface.Enabled = true;

            Console.WriteLine("  Service Name: {0}\n  Service Port: {1}", RemotingName, RemotingPort);
            Console.WriteLine();

            #endregion

            ushort Port = ServerConfigElement.GetUInt16("port");
            m_Server = new RedirectServerListener(Port);
        }
        public void StartFwRemoteDatabaseConnector()
        {
            FdoTestHelper.SetupStaticFdoProperties();
            m_sharedProject = true;
            RemotingServer.Start(FwDirectoryFinder.RemotingTcpServerConfigFile, FwDirectoryFinder.FdoDirectories, () => m_sharedProject, v => m_sharedProject = v);

            var connectString = String.Format("tcp://{0}:{1}/FwRemoteDatabaseConnector.Db4oServerInfo",
                                              "localhost", Db4OPorts.ServerPort);

            m_db4OServerInfo = (Db4oServerInfo)Activator.GetObject(typeof(Db4oServerInfo), connectString);
        }
Example #16
0
 private void button2_Click(object sender, EventArgs e)
 {
     using (var server = new RemotingServer())
     {
         Thread thread = new Thread(p_Server);
         thread.Name = "Listener server thread";
         thread.Start(server);
         label4.Text = thread.Name + " Started";
         //textBox1.Text = myIP;
     }
 }
Example #17
0
        public static void Initialize()
        {
            #region .NET Remoting Service Setup

            RemotingServer RemoteInterface = new RemotingServer(CONST_SERVER_NAME, CONST_REMOTE_PORT);
            RemoteInterface.RegisterType("ClientHandlerServer", typeof(RemoteClientHandlerServer));

            RemoteInterface.Enabled = true;

            #endregion
        }
Example #18
0
        public void Delegate_invoked_on_server_should_callback_client()
        {
            string argumentFromServer = null;

            var testService = new TestService();

            var serverConfig =
                new ServerConfig()
            {
                NetworkPort            = 9095,
                RegisterServicesAction = container =>
                                         container.RegisterService <ITestService>(
                    factoryDelegate: () => testService,
                    lifetime: ServiceLifetime.Singleton)
            };

            int serverErrorCount = 0;

            using var server = new RemotingServer(serverConfig);
            server.Error    += (sender, e) => serverErrorCount++;
            server.Start();

            void ClientAction()
            {
                try
                {
                    using var client = new RemotingClient(
                              new ClientConfig()
                    {
                        ConnectionTimeout = 0,
                        ServerPort        = 9095,
                    });

                    client.Connect();

                    var proxy = client.CreateProxy <ITestService>();
                    proxy.TestMethodWithDelegateArg(arg => argumentFromServer = arg);
                }
                catch (Exception e)
                {
                    _testOutputHelper.WriteLine(e.ToString());
                    throw;
                }
            }

            var clientThread = new Thread(ClientAction);

            clientThread.Start();
            clientThread.Join();

            Assert.Equal("test", argumentFromServer);
            Assert.Equal(0, serverErrorCount);
        }
Example #19
0
        public static void Initialize()
        {
            #region .NET Remoting Service Setup

            RemotingServer RemoteInterface = new RemotingServer(CONST_SERVER_NAME, CONST_REMOTE_PORT);
            RemoteInterface.RegisterType("RealmListServer", typeof(RemoteRealmListServer));

            RemoteInterface.Enabled = true;

            #endregion

            m_Server = new Network.Server();
        }
        public void RemotingServer_should_register_on_construction_AND_unregister_on_Dispose()
        {
            using var server = new RemotingServer(new ServerConfig()
            {
                UniqueServerInstanceName = "TestServer"
            });

            Assert.NotNull(RemotingConfiguration.GetRegisteredServer("TestServer"));

            server.Dispose();

            Assert.Null(RemotingConfiguration.GetRegisteredServer("TestServer"));
        }
Example #21
0
        void InitRemoting()
        {
            RoutedUICommand[] commands =
            {
                GreenScanCommands.Close,
                GreenScanCommands.CloseFile,
                GreenScanCommands.Import,
                GreenScanCommands.Export,
                GreenScanCommands.Open,
                GreenScanCommands.Save,
                GreenScanCommands.Start,
                GreenScanCommands.Stop,

                TurntableCommands.Export,
                TurntableCommands.Open,
                TurntableCommands.Save,
                TurntableCommands.Scan,
                TurntableCommands.Stop,
                TurntableCommands.ToOrigin
            };

            Remote = new RemotingServer(Settings, commands, this, 5656, 101);

            Remote.RemoteConnected += (object sender, RemoteEventArgs e) =>
            {
                if (Remote.RemoteCount == 1)
                {
                    TBRemoting.Text = string.Format(GreenResources.RemotingRemotedFrom, e.RemoteEndPoint.ToString());
                }
                else
                {
                    TBRemoting.Text = string.Format(GreenResources.RemotingRemotesConnected, Remote.RemoteCount);
                }
                if (Remote.RemoteCount == 1)
                {
                    Settings.IsReadOnly = true;
                    (Resources["RemotingIn"] as Storyboard).Begin();
                }
            };
            Remote.RemoteDisconnected += (object sender, RemoteEventArgs e) =>
            {
                TBRemoting.Text = string.Format(GreenResources.RemotingRemotesConnected, Remote.RemoteCount);
                if (Remote.RemoteCount == 0)
                {
                    Settings.IsReadOnly = false;
                    (Resources["RemotingOut"] as Storyboard).Begin();
                }
            };
        }
        public void Marshal_should_register_a_service_instance()
        {
            var testService = new TestService();

            using var server = new RemotingServer();
            server.Start();

            string serviceName =
                RemotingServices.Marshal(testService, "test", typeof(ITestService), server.UniqueServerInstanceName);

            var registeredServiceInstance = server.ServiceRegistry.GetService(serviceName);

            Assert.Same(testService, registeredServiceInstance);
            Assert.True(registeredServiceInstance is ITestService);
        }
Example #23
0
        protected override void OnStart(string[] args)
        {
            try
            {
                RemotingServer.Start();
            }
            catch (Exception e)
            {
                // TODO: remove this debugging message.
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }

            m_clientListenerThread = new Thread(ThreadStartListenForClients);
            m_clientListenerThread.Start();
        }
Example #24
0
 public KinectCalibrationWindow(RemotingServer remotingServer)
 {
     InitializeComponent();
     Remote = remotingServer;
     Remote.StoreOption("Save.Directory");
     Remote.StoreOption("Save.Label");
     Remote.StoreOption("Save.NoTimestamp");
     Remote.StoreOption("Kinect.Mode");
     TBPath.Text          = PathSetting.GetAbsolutePath(Remote.GetOption("Save.CalibrationDirectory"));
     CheckBoxes           = new CheckBox[] { CBInfrared, CBColor, CBDepth };
     Modes                = new string[] { "Infrared", "Color", "Depth" };
     Commands             = new string[] { "Export", "Export", "Save" };
     Arguments            = new string[] { "PNG/raw", "PNG/raw", "" };
     Labels               = new string[] { "Infrared", "Color", "Depth" };
     SAngle.ValueChanged += SAngle_ValueChanged;
 }
        public void Server_Creating()
        {
            // Prepare
            RemotingServer server = this._Provider.GetRequiredService <RemotingServer>();

            // Pre-validate
            Assert.False(server.IsEnable());

            // Perform
            server.Start();

            // Post-validate
            Assert.True(server.IsEnable());

            server.Stop();
        }
        public void Test_Exception()
        {
            // Prepare
            RemotingServer server = this._Provider.GetRequiredService <RemotingServer>();

            server.Start();
            IMyService service = this._Provider.GetRequiredService <IMyService>();

            // Pre-validate
            Assert.True(server != null && service != null);

            // Perform
            Exception ex = Assert.Throws <Exception>(() => { service.CheckUnitNotNull(null); });

            // Post-validate
            Assert.Equal("Value cannot be null.\r\nParameter name: Argument must declared!", ex.Message);
        }
        public void Connect_should_create_a_proxy_for_a_remote_service()
        {
            var testService =
                new TestService
            {
                TestMethodFake = arg =>
                                 arg
            };

            using var server =
                      new RemotingServer(new ServerConfig
            {
                NetworkPort = 9199,
                IsDefault   = true
            });

            RemotingServices.Marshal(testService, "test", typeof(ITestService));
            server.Start();

            var clientThread = new Thread(() =>
            {
                // ReSharper disable once ObjectCreationAsStatement
                new RemotingClient(new ClientConfig {
                    ServerPort = 9199, IsDefault = true
                });

                var proxy =
                    RemotingServices.Connect(
                        typeof(ITestService),
                        "test",
                        string.Empty);

                Assert.True(RemotingServices.IsTransparentProxy(proxy));

                object result = ((ITestService)proxy).TestMethod(1);

                RemotingClient.DefaultRemotingClient.Dispose();

                Assert.Equal(1, Convert.ToInt32(result));
            });

            clientThread.Start();
            clientThread.Join();

            server.Dispose();
        }
Example #28
0
        public void Activate_TransparentProxy_NotStartable()
        {
            using (var server = new RemotingServer())
                using (var client = new RemotingClient())
                {
                    server.RegisterActivatedService(typeof(Monk));

                    var notStartable = client.GetService <Monk>();
                    var reference    = new InstanceReference {
                        Instance = notStartable
                    };

                    _strategy.Activate(_contextMock.Object, reference);

                    Assert.Same(notStartable, reference.Instance);
                }
        }
        public void RegisterWellKnownServiceType_should_register_type_resolved_at_runtime()
        {
            using var server = new RemotingServer(new ServerConfig { UniqueServerInstanceName = "Server1" });

            RemotingConfiguration.RegisterWellKnownServiceType(
                interfaceType: typeof(ITestService),
                implementationType: typeof(TestService),
                lifetime: ServiceLifetime.Singleton,
                serviceName: "Service1",
                uniqueServerInstanceName: "Server1");

            var service = server.ServiceRegistry.GetService("Service1");

            Assert.NotNull(service);
            Assert.Equal(typeof(TestService), service.GetType());

            RemotingConfiguration.ShutdownAll();
        }
        public void Activate_TransparentProxy_Disposable()
        {
            using (var server = new RemotingServer())
                using (var client = new RemotingClient())
                {
                    server.RegisterActivatedService(typeof(Disposable));

                    var initializable = client.GetService <Disposable>();
                    var reference     = new InstanceReference {
                        Instance = initializable
                    };

                    _strategy.Activate(_contextMock.Object, reference);

                    Assert.Equal(0, initializable.DisposeCount);
                    Assert.Same(initializable, reference.Instance);
                }
        }
Example #31
0
        public void Run()
        {
            _Log.Info("AccountServer is starting");

            _Log.Info("Reading configuration");
            _ConfigTree.FromConfigFile("Config/AccountServer.cfg");

            _Log.Info("Connecting to database");
            _DatabaseConnection = new MySqlConnection(BuildConnectionString());

            try
            {
                _DatabaseConnection.Open();
            }
            catch (Exception ex)
            {
                _Log.Fatal("Error connecting to database!", ex);
                return;
            }

            _RemotingServer = new RemotingServer(_ConfigTree.Get("inter.uri", "net.tcp://localhost:5401/"));
            _RemotingServer.ExposeType<CharServerService>("CharServer", typeof(ICharServerService));
            _RemotingServer.Start();
            _Log.InfoFormat("Accepting CharServer connections at {0}", _RemotingServer.BaseUri);

            IPAddress bindAddress = IPAddress.Parse(_ConfigTree.Get("network.interface.ip", "0.0.0.0"));
            int bindPort = _ConfigTree.Get("network.interface.port", 5500);
            _Log.InfoFormat("Accepting connections at {0}:{1}", bindAddress, bindPort);
            _Listener.Bind(bindAddress, bindPort);
            _Listener.Listen();

            _Running = true;
            while (_Running)
                Thread.Yield();

            _RemotingServer.Stop();
        }
 public string LoadProperty(string obj, string propertyName, string domainKey, bool useCompression)
 {
     IRemotingServer rs = new RemotingServer(factory, formatter, compressor, useCompression);
     return (string) rs.LoadProperty(obj, propertyName, domainKey);
 }
 public string LoadObjects(string query, string domainKey, bool useCompression)
 {
     IRemotingServer rs = new RemotingServer(factory, formatter, compressor, useCompression);
     return (string) rs.LoadObjects(query, domainKey);
 }
 public string LoadObject(string type, string identity, string domainKey, bool useCompression)
 {
     IRemotingServer rs = new RemotingServer(factory, formatter, compressor, useCompression);
     return (string) rs.LoadObject(type, identity, domainKey);
 }
 public string GetMap(string domainKey, bool useCompression)
 {
     IRemotingServer rs = new RemotingServer(factory, formatter, compressor, useCompression);
     return rs.GetMap(domainKey);
 }
 public string CommitUnitOfWork(string obj, string domainKey, bool useCompression)
 {
     IRemotingServer rs = new RemotingServer(factory, formatter, compressor, useCompression);
     return (string) rs.CommitUnitOfWork(obj, domainKey);
 }