Exemplo n.º 1
0
        private void AttachedIncoming(InterceptedEventArgs e)
        {
            // If we can't read a string, leave this method.
            if (!e.Packet.CanRead<string>()) return;

            string value = e.Packet.ReadString();
            switch (value.ToLower())
            {
                case "block":
                {
                    e.IsBlocked = true;
                    break;
                }

                case "replace":
                {
                    // Replace the first string found in the packet.
                    e.Replacement.Replace<string>(0, "Replaced!");
                    break;
                }

                case "freeze":
                {
                    // Tell the contractor to continue reading data from local/remote endpoint.
                    // Does not wait for this method to finish, but the packet being processed
                    // can still be used: blocked/replaced
                    if (e.IsAsyncCapable)
                        e.ContinueRead();

                    // Simulate a long synchronous process for one second(1000ms).
                    Thread.Sleep(1000);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        // We can block/replace packets in attach methods.
        private void MyOutCallback(object sender, InterceptedEventArgs e)
        {
            // We can't read an integer for this packet, let's leave.
            if (!e.Packet.CanRead<string>()) return;

            string value = e.Packet.ReadString(0);
            switch (value)
            {
                // If the string value is "block", let's block it.
                case "block":
                {
                    e.IsBlocked = true;
                    break;
                }

                // If the string value is "replace", let's replace it with "REPLACED!".
                case "replace":
                {
                    e.Replacement.Replace<string>("REPLACED");
                    break;
                }

                // If the string value is "wait", let's do some heavy processing, and still allow data to come through.
                case "wait":
                {
                    // This will tell the caller to continue spitting out data, while we have it wait for this end result.
                    // We can still replace/block this packet while more data comes through.
                    e.ContinueRead();

                    // Simulate long process.
                    Thread.Sleep(5000);

                    // It turns out Clyde DOES want to replace this packet after waiting 5 seconds, god dammit.
                    e.Replacement.Replace<string>("We waited 5 seconds, and replaced. God dammit Clyde");

                    // Don't worry though, we got you, now you never have to worry about Clyde messing up your day ever again.
                    break;
                }
            }
        }