Example #1
0
        public static void SaveConfig()
        {
            /// Create xml config
            XElement root = new XElement("FileManagerConfig");

            /// Records
            XElement record = new XElement("record");
            /// History list
            XElement history_list = new XElement("history");

            foreach (ConnectionRecord c in Histories)
            {
                XElement item = new XElement("item");
                item.SetElementValue("ip", c.Info);
                item.SetElementValue("star", c.IsStarred ? "1" : "0");
                history_list.Add(item);
            }
            record.Add(history_list);
            root.Add(record);

            /// Settings
            XElement settings = new XElement("settings");

            settings.SetElementValue("ClickCloseToMinimize", ClickCloseToMinimize.ToString());
            settings.SetElementValue("UpdateLengthThreshold", UpdateLengthThreshold.ToString());
            settings.SetElementValue("UpdateTimeThreshold", UpdateTimeThreshold.ToString());
            settings.SetElementValue("SaveRecordInterval", SaveRecordInterval.ToString());
            settings.SetElementValue("ConnectionMonitorRecordCount", ConnectionMonitorRecordCount.ToString());
            settings.SetElementValue("ConnectionMonitorRecordInterval", ConnectionMonitorRecordInterval.ToString());
            settings.SetElementValue("DefaultPort", DefaultServerPort.ToString());
            settings.SetElementValue("ThreadLimit", ThreadLimit.ToString());
            settings.SetElementValue("SmallFileLimit", SmallFileThreshold.ToString());
            settings.SetElementValue("SocketSendTimeout", SocketSendTimeout.ToString());
            settings.SetElementValue("SocketReceiveTimeout", SocketReceiveTimeout.ToString());

            root.Add(settings);
            root.Save(ConfigPath);
        }
Example #2
0
        public async Task TestCommandsWithCustomSessionMultipleServerHost()
        {
            using (var server = MultipleServerHostBuilder.Create()
                                .ConfigureAppConfiguration((hostCtx, configApp) =>
            {
                configApp.Sources.Clear();
                configApp.AddInMemoryCollection(new Dictionary <string, string>
                {
                    { "serverOptions:name", "TestServer" },
                    { "serverOptions:listeners:0:ip", "Any" },
                    { "serverOptions:listeners:0:port", DefaultServerPort.ToString() }
                });
            })
                                .AddServer <StringPackageInfo, CommandLinePipelineFilter>(builder =>
            {
                builder
                .UseCommand()
                .UseSession <MySession>()
                .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                .ConfigureContainer <ContainerBuilder>(builder =>
                {
                    builder.RegisterType <ADD>().As <IAsyncCommand <IAppSession, StringPackageInfo> >();
                    builder.RegisterType <MULT>().As <IAsyncCommand <IAppSession, StringPackageInfo> >();
                    builder.RegisterType <SUB>().As <IAsyncCommand <IAppSession, StringPackageInfo> >();
                    builder.RegisterType <DIV>().As <IAsyncCommand <MySession, StringPackageInfo> >();
                });
            }).BuildAsServer())
            {
                Assert.Equal("TestServer", server.Name);

                Assert.True(await server.StartAsync());
                OutputHelper.WriteLine("Server started.");

                var client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                await client.ConnectAsync(GetDefaultServerEndPoint());

                OutputHelper.WriteLine("Connected.");

                using (var stream = new NetworkStream(client))
                    using (var streamReader = new StreamReader(stream, Utf8Encoding, true))
                        using (var streamWriter = new StreamWriter(stream, Utf8Encoding, 1024 * 1024 * 4))
                        {
                            await streamWriter.WriteAsync("ADD 1 2 3\r\n");

                            await streamWriter.FlushAsync();

                            var line = await streamReader.ReadLineAsync();

                            Assert.Equal("6", line);

                            await streamWriter.WriteAsync("MULT 2 5\r\n");

                            await streamWriter.FlushAsync();

                            line = await streamReader.ReadLineAsync();

                            Assert.Equal("10", line);

                            await streamWriter.WriteAsync("SUB 8 2\r\n");

                            await streamWriter.FlushAsync();

                            line = await streamReader.ReadLineAsync();

                            Assert.Equal("6", line);

                            await streamWriter.WriteAsync("DIV 8 2\r\n");

                            await streamWriter.FlushAsync();

                            line = await streamReader.ReadLineAsync();

                            Assert.Equal("4", line);
                        }

                await server.StopAsync();
            }
        }