static void PrepareChild(ConfigurationManager configurationManager, ChildConfigurationManager childConfigurationManager, string fullFilename, ChildInfo child) { if (childConfigurationManager.InstanceType == InstanceType.Static) { if (child.TrySpawn()) { Logger.Write(LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName(fullFilename)); Thread.Sleep(500); // TODO: improve this (it's used to wait for the child to be ready) } else { Logger.Write(LogLevel.Error, "Couldn't start child with config file {0}", fullFilename); } } else { Socket socket; if (FastCgi.Server.TryCreateSocket(childConfigurationManager, out socket)) { var server = new GenericServer <Connection> (socket, child); server.Start(configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } }
private async Task <GenericServer> RunLocalServer(AvroProtocol protocol, LocalTranceiver tranceiver, CancellationToken token) { var server = new GenericServer(protocol, tranceiver); await RunGenericServer(server, token); return(server); }
public async Task RunGenericServer(GenericServer server, CancellationToken token) { var rpcContext = await server.ReceiveAsync(token); var response = new GenericRecord(server.Protocol.Types.First(r => r.Name == "Greeting") as RecordSchema); response[0] = "World!"; rpcContext.Response = response; await server.RespondAsync(rpcContext, token); }
private async Task <GenericServer> RunHttpServer(AvroProtocol protocol, CancellationToken token) { var urls = protocol.Messages.Select(r => $"http://localhost:8080/{protocol.Name}/{r.Name}/"); var tranceiver = HttpServer.Create(urls.ToArray()); var server = new GenericServer(protocol, tranceiver); await RunGenericServer(server, token); return(server); }
static void PrepareAutomaticChild(ConfigurationManager configurationManager, string frontSocket, ChildInfo child, uint backlog) { Socket socket; if (FastCgi.Server.TryCreateUnixSocket(frontSocket, out socket, "660")) { var server = new GenericServer <Connection> (socket, child); server.Start(configurationManager.Stoppable, (int)backlog); } }
private async Task <GenericServer> RunTcpServer(AvroProtocol protocol, CancellationToken token) { var listener = new SocketListener("127.0.0.1", 3456); listener.Start(); var tranceiver = await listener.ListenAsync(); var server = new GenericServer(protocol, tranceiver); await RunGenericServer(server, token); listener.Stop(); return(server); }
private static GenericServer GetDBConnection() { GenericServer genServer = null; switch (AppConfig.Instance.DBType) { case GlobalConstants.DB_MYSQL: genServer = new MySqlSrvr(); break; case GlobalConstants.DB_SQLSVR: genServer = new SqlSrvr(); break; default: throw new MyAppOperationNotAllowed(String.Format("Database Server: {0} not supported", AppConfig.Instance.DBType)); } GetDBSettings(); return(genServer); }
/// <summary> /// Loads an Assembly ang gets its Name /// </summary> /// <param name="a">Assembly to load</param> /// <returns>Generic Server component</returns> private static GenericServer LoadServerAssembly(Assembly a) { GenericServer retValue = null; foreach (Type type in a.GetTypes()) { if (type.IsPublic) // Ruft einen Wert ab, der angibt, ob der Type als öffentlich deklariert ist. { if (!type.IsAbstract) //nur Assemblys verwenden die nicht Abstrakt sind { // Sucht die Schnittstelle mit dem angegebenen Namen. Type typeInterface = type.GetInterface(Type.GetType("GenericHandler.GenericServer").ToString(), true); //Make sure the interface we want to use actually exists if (typeInterface != null) { object activedInstance = Activator.CreateInstance(type); if (activedInstance != null) { GenericServer script = (GenericServer)activedInstance; retValue = script; if (Servers == null) { Servers = new List <GenericServer>(); } Servers.Add(retValue); Console.WriteLine("Loaded Server: {0}", retValue); } } typeInterface = null; } } } a = null; return(retValue); }
//TODO: Create a "ConfigurationManager" so that process and server info can be queried and provided seperately. //This will remove the need to pass references to Process and Server configs to each object. /// <summary> /// Creates a server based on the supplied configuration data, and adds /// it to the Server Manager. /// </summary> public static void RegisterServer(ProcessConfigurationData processConfig, ServerConfigurationData serverConfig) { //TODO: Decide how best to determine which type of server to create. //For now, we will use the if/then approach. if (serverConfig.ServerType == ServerType.Game) { if (serverConfig.SubType == "HaloCombatEvolved") { try { Server s = new GenericServer(processConfig, serverConfig); servers.Add(s); } catch (Exception ex) { throw new Exception("Unable to create server object: " + ex.Message); } } else { throw new Exception("Unable to create server object: " + serverConfig.SubType + " is not a supported game server type."); } } }
public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager) { if (configFiles == null) throw new ArgumentNullException ("configFiles"); if (configurationManager == null) throw new ArgumentNullException ("configurationManager"); foreach (FileInfo fileInfo in configFiles) { if (fileInfo == null) continue; Logger.Write (LogLevel.Debug, "Loading {0}", fileInfo.Name); var childConfigurationManager = new ChildConfigurationManager (); string configFile = fileInfo.FullName; if (!childConfigurationManager.TryLoadXmlConfig (configFile)) continue; string user = childConfigurationManager.User; string fastCgiCommand = configurationManager.FastCgiCommand; Func<bool, Process> spawner; if (Platform.IsUnix) { if (String.IsNullOrEmpty (user)) { Logger.Write (LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", fileInfo.Name); user = UnixFileSystemInfo.GetFileSystemEntry (configFile).OwnerUser.UserName; } spawner = onDemand => Spawner.RunAs (user, Spawner.SpawnChild, configFile, fastCgiCommand, onDemand); } else { Logger.Write (LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", fileInfo.Name); spawner = onDemand => Spawner.SpawnChild (configFile, fastCgiCommand, onDemand); } var child = new ChildInfo { Spawner = spawner, ConfigurationManager = childConfigurationManager, Name = configFile, OnDemand = childConfigurationManager.InstanceType == InstanceType.Dynamic }; children.Add (child); if (child.OnDemand){ Socket socket; if (FastCgi.Server.TryCreateSocket (childConfigurationManager, out socket)) { var server = new GenericServer<Connection> (socket, child); server.Start (configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } else { if (child.TrySpawn ()) { Logger.Write (LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName (configFile)); } else { Logger.Write (LogLevel.Error, "Couldn't start child with config file {0}", configFile); } } } }
static void PrepareChild (ConfigurationManager configurationManager, ChildConfigurationManager childConfigurationManager, string fullFilename, ChildInfo child) { if (childConfigurationManager.InstanceType == InstanceType.Static) { if (child.TrySpawn ()) { Logger.Write (LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName (fullFilename)); Thread.Sleep (500); // TODO: improve this (it's used to wait for the child to be ready) } else Logger.Write (LogLevel.Error, "Couldn't start child with config file {0}", fullFilename); } else { Socket socket; if (FastCgi.Server.TryCreateSocket (childConfigurationManager, out socket)) { var server = new GenericServer<Connection> (socket, child); server.Start (configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } }
static void PrepareAutomaticChild (ConfigurationManager configurationManager, string frontSocket, ChildInfo child, uint backlog) { Socket socket; if (FastCgi.Server.TryCreateUnixSocket (frontSocket, out socket, "660")) { var server = new GenericServer<Connection> (socket, child); server.Start (configurationManager.Stoppable, (int)backlog); } }
public static void StartChildren(FileInfo[] configFiles, ConfigurationManager configurationManager) { if (configFiles == null) { throw new ArgumentNullException("configFiles"); } if (configurationManager == null) { throw new ArgumentNullException("configurationManager"); } foreach (FileInfo fileInfo in configFiles) { if (fileInfo == null) { continue; } Logger.Write(LogLevel.Debug, "Loading {0}", fileInfo.Name); var childConfigurationManager = new ChildConfigurationManager(); string configFile = fileInfo.FullName; if (!childConfigurationManager.TryLoadXmlConfig(configFile)) { continue; } string user = childConfigurationManager.User; string fastCgiCommand = configurationManager.FastCgiCommand; Func <bool, Process> spawner; if (Platform.IsUnix) { if (String.IsNullOrEmpty(user)) { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to file owner", fileInfo.Name); user = UnixFileSystemInfo.GetFileSystemEntry(configFile).OwnerUser.UserName; } spawner = onDemand => Spawner.RunAs(user, Spawner.SpawnChild, configFile, fastCgiCommand, onDemand); } else { Logger.Write(LogLevel.Warning, "Configuration file {0} didn't specify username, defaulting to the current one", fileInfo.Name); spawner = onDemand => Spawner.SpawnChild(configFile, fastCgiCommand, onDemand); } var child = new ChildInfo { Spawner = spawner, ConfigurationManager = childConfigurationManager, Name = configFile, OnDemand = childConfigurationManager.InstanceType == InstanceType.Dynamic }; children.Add(child); if (child.OnDemand) { Socket socket; if (FastCgi.Server.TryCreateSocket(childConfigurationManager, out socket)) { var server = new GenericServer <Connection> (socket, child); server.Start(configurationManager.Stoppable, (int)childConfigurationManager.Backlog); } } else { if (child.TrySpawn()) { Logger.Write(LogLevel.Notice, "Started fastcgi daemon [static] with pid {0} and config file {1}", child.Process.Id, Path.GetFileName(configFile)); } else { Logger.Write(LogLevel.Error, "Couldn't start child with config file {0}", configFile); } } } }
/// <summary> /// Creates an empty Message /// </summary> public GenericMessage() { Sender = Receiver = Command = RawContent = null; Tag = null; Server = null; }
protected override void GetData() { m_Name = GenericServer.GetStringFromDataReader(m_dataReader, MyAppDBConstants.STUDENT_NAME); m_Age = GenericServer.GetInt32FromDataReader(m_dataReader, MyAppDBConstants.STUDENT_AGE); m_Standard = GenericServer.GetStringFromDataReader(m_dataReader, MyAppDBConstants.STUDENT_STD); }
/// <inheritdoc /> public void Configure(GenericServer server, int port, string virtualPath, string physicalPath, bool disableDirectoryListing) { }