Exemplo n.º 1
0
        public ClientAgentServer(ClientAgentConfiguration configuration, TdlFile file, LoggerCategory category)
            : base(configuration, category)
        {
            Configuration = configuration;
            NetworkFile   = file;

            // Create the internal connection
            InternalClient = new ToffeeInternalClient(configuration.Internal, "ClientAgent", category);
        }
Exemplo n.º 2
0
        public bool Configure(object config, Logger logger = null)
        {
            try
            {
                // Get the configuration
                JObject jConfig = (JObject)config;
                ClientAgentConfiguration configuration = jConfig.ToObject <ClientAgentConfiguration>();

                // Load the network files
                TdlFile networkFile = new TdlFile(configuration.Network.Namespace, false);
                foreach (string file in configuration.Network.Files)
                {
                    if (!networkFile.ParseFile(file))
                    {
                        Console.WriteLine("Could not find: {0}", file);
                        return(false);
                    }
                }

                // Create the logger category
                LoggerCategory category =
                    logger?.MakeCategory(string.Format("ClientAgent-{0}", UniqueClientAgentIndex)) ?? null;

                // Sanity checks
                if (configuration.Internal.ChannelCount != 0)
                {
                    category.Warning("Internal channel count should not be set manually. Resetting value to maximum connections.");
                    configuration.Internal.ChannelCount = configuration.MaximumConnections;
                }

                // Create the server
                Server = new ClientAgentServer(configuration, networkFile, category);
                return(true);
            }
            catch (JsonException e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }