public GemServer(string profileName, ServerConfig serverConfig, PackageConfig packageConfig) { //validate server config Guard.That(serverConfig).IsNotNull(); Guard.That(packageConfig).IsNotNull(); GemNetwork.ActiveProfile = profileName; //setup authentication if (serverConfig.RequireAuthentication) { RequireAuthentication(); } else { Profile(GemNetwork.ActiveProfile).OnIncomingConnection((srvr, netconnection, msg) => { netconnection.Approve(); GemNetworkDebugger.Append.Info(String.Format("Approved {0} {3} Sender: {1}{3} Message: {2}", netconnection, msg.Sender, msg.Message, Environment.NewLine)); }); } this.serverConfig = serverConfig; this.PackageConfig = packageConfig; server = GemNetwork.Server; messageProcessor = new ServerMessageProcessor(server); asyncMessageProcessor = new ParallelTaskStarter(TimeSpan.Zero); }
public Peer(string name) { CanAppend = true; IncomingMessages = new ConcurrentQueue <string>(); this.Name = name; protocolExample = GemClient.Profile("GemChat") .CreateNetworkProtocolEvent <Package>() .HandleIncoming((sender, package) => { QueueMessage(String.Format("Server sent {0} {1}", sender.Statistics.SentBytes, package.Name)); }) .GenerateSendEvent(); onEvent = GemClient.Profile("GemChat") .CreateNetworkEvent .AndHandleWith(this, x => new Action <string>(x.QueueMessage)); onCommandExecute = GemClient.Profile("GemChat") .CreateNetworkEvent .AndHandleWith(this, x => new Action <string>(x.ExecuteCommand)); onEvent.Send(name + " has joined"); messageAppender = new ParallelTaskStarter(TimeSpan.Zero); messageAppender.Start(DequeueIncomingMessages); }
/// <summary> /// Initializes a new instance of GemClient. /// </summary> /// <param name="profile">The profile the client's configuration is set</param> /// <param name="connectionConfig">The configuration for the connection</param> /// <param name="packageConfig">The configuration for the outgoing messages</param> public GemClient(string profile, ConnectionConfig connectionConfig, PackageConfig packageConfig) { Guard.That(connectionConfig).IsNotNull(); Guard.That(packageConfig).IsNotNull(); PackageConfig = packageConfig; connectionDetails = connectionConfig; GemNetwork.ActiveProfile = profile; //TODO: check if the client is already connected this.client = GemNetwork.Client; this.client.PackageConfig = PackageConfig; RegisterServerNotificationPackages(profile); messageProcessor = new ClientMessageProcessor(client); asyncMessageProcessor = new ParallelTaskStarter(TimeSpan.Zero); }
private void AnimateFrames(bool animate) { if (updateLoop == null && animate) { updateLoop = new ParallelTaskStarter(TimeSpan.FromMilliseconds(5)); animationPosition = () => new Vector2(animation.Settings.TileSheetWidth / 2 - animation.Settings.FrameWidth / 2, animation.Settings.TileSheetHeight / 2 - animation.Settings.FrameHeight / 2); updateLoop.Start(() => { animation.Update(updateLoop.ElapsedTime); ReDraw(); }); output.AppendLine( $"Animating frames {animation.Settings.StartFrame} - {animation.Settings.LastFrame} with {animation.Settings.FrameDelay * 1000} ms delay"); } if (updateLoop != null && !animate) { updateLoop.Stop(); updateLoop = null; } }
public void ProcessMessagesInBackground() { asyncMessageProcessor = new ParallelTaskStarter(TimeSpan.Zero); asyncMessageProcessor.Start(async() => await IncomingMessageHandler.ProcessNetworkMessages(Host)); }