/// <summary> /// Acquires an appropriate event envelope. /// </summary> /// <returns></returns> private static MeshEvent Create(MeshEventType type) { // Get the appropriate packet switch (type) { case MeshEventType.Error: case MeshEventType.Ping: case MeshEventType.PingAck: case MeshEventType.HandshakeAck: return(MeshEvent.Acquire()); case MeshEventType.Handshake: return(MeshHandshake.Acquire()); case MeshEventType.GossipDigest: case MeshEventType.GossipSince: case MeshEventType.GossipUpdate: return(MeshGossip.Acquire()); case MeshEventType.Subscribe: case MeshEventType.Unsubscribe: case MeshEventType.Custom: return(MeshEmitterEvent.Acquire()); default: throw new InvalidOperationException("Unknown mesh packet"); } }
/// <summary> /// Sends a mesh Handshake through the specified channel. /// </summary> /// <param name="channel">The channel to send the packet to.</param> internal static void SendMeshHandshakeAck(this Connection channel) { var provider = Service.Providers.Resolve <MeshProvider>(); if (provider == null) { return; } // Send the ack channel.Send(MeshEvent.Acquire(MeshEventType.HandshakeAck, provider.BroadcastEndpoint.ToString())); }
/// <summary> /// Sends a mesh ping through the specified channel. /// </summary> /// <param name="server">The channel to send the packet to.</param> internal static void SendMeshPing(this IServer server) { server.Send(MeshEvent.Acquire(MeshEventType.Ping)); }
/// <summary> /// Sends a mesh PingAck through the specified channel. /// </summary> /// <param name="channel">The channel to send the packet to.</param> internal static void SendMeshPingAck(this Connection channel) { // Send the ack channel.Send(MeshEvent.Acquire(MeshEventType.PingAck)); }
/// <summary> /// Sends a mesh PingAck through the specified channel. /// </summary> /// <param name="channel">The channel to send the packet to.</param> /// <param name="ex">The exception to wrap.</param> internal static void SendMeshError(this Connection channel, Exception ex) { // Send the error back channel.Send(MeshEvent.Acquire(MeshEventType.Error, ex.Message)); }