コード例 #1
0
        static void Main(string[] args)
        {
            var cfV2 = new ChannelFactory<IComplexNumber>("secondVersionEndUsers");
            var channelV2 = cfV2.CreateChannel();

            var z1 = new ComplexNumber();
            var z2 = new ComplexNumber();

            z1.Real = 1D;
            z1.Imaginary = 2D;

            z2.Real = 2D;
            z2.Imaginary = 1D;

            Console.WriteLine("*** Service Versioning: end-users of the second version ***\n");
            Console.WriteLine("\nPlease hit any key to run OR enter 'exit' to terminate.");
            string command = Console.ReadLine();

            while (command != "exit")
            {
                Console.WriteLine("Please hit any key to simulate secondVersionEndUsers: ");
                Console.ReadLine();

                using (new OperationContextScope((IContextChannel)channelV2))
                {
                    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Version", "http://custom/namespace", "v2.0"));
                    ComplexNumberArithmetics(channelV2, z1, z2);
                }

                Console.WriteLine("\nPlease hit any key to re-run OR enter 'exit' to terminate.");
                command = Console.ReadLine();
            }

           ((IClientChannel)channelV2).Close();
        }
コード例 #2
0
        public double Argument(ComplexNumber x)
        {
            Console.WriteLine("Invoked ARGUMENT operation.");

            var argumentX = Math.Atan(x.Imaginary / x.Real);

            return argumentX;
        }
コード例 #3
0
        public double Modulus(ComplexNumber x)
        {
            Console.WriteLine("Invoked MODULUS operation.");

            var modX = Math.Sqrt(x.Real * x.Real + x.Imaginary * x.Imaginary);

            return modX;
        }
コード例 #4
0
        public ComplexNumber Conjugate(ComplexNumber x)
        {
            Console.WriteLine("Invoked CONJUGATE Operation.");

            var z = new ComplexNumber();

            z.Real = x.Real;
            z.Imaginary = -1 * x.Imaginary;

            return z;
        }
コード例 #5
0
        public ComplexNumber Add(ComplexNumber x, ComplexNumber y)
        {
            Console.WriteLine("Invoked ADD operation.");

            var z = new ComplexNumber();

            z.Real = x.Real + y.Real;
            z.Imaginary = x.Imaginary + y.Imaginary;

            return z;
        }
コード例 #6
0
        public ComplexNumber Multiply(ComplexNumber x, ComplexNumber y)
        {
            Console.WriteLine("Invoked MULTIPLY Operation.");

            var z = new ComplexNumber();

            z.Real = x.Real * y.Real - x.Imaginary * y.Imaginary;
            z.Imaginary = x.Real * y.Imaginary + x.Imaginary * y.Real;

            return z;
        }
コード例 #7
0
        public ComplexNumber Subtract(ComplexNumber x, ComplexNumber y)
        {
            Console.WriteLine("Invoked SUBTRACT operation.");

            var z = new ComplexNumber();

            z.Real = x.Real - y.Real;
            z.Imaginary = x.Imaginary - y.Imaginary;

            return z;
        }
コード例 #8
0
        public ComplexNumber Divide(ComplexNumber x, ComplexNumber y)
        {
            Console.WriteLine("Invoked DIVIDE Operation.");

            var z = new ComplexNumber();

            var modulusY = Math.Sqrt(y.Real * y.Real + y.Imaginary * y.Imaginary);

            z.Real = (x.Real * y.Real + x.Imaginary * y.Imaginary) / (modulusY * modulusY);
            z.Imaginary = (x.Imaginary * y.Real - x.Real * y.Imaginary) / (modulusY * modulusY);

            return z;
        }
コード例 #9
0
 static void ComplexNumberArithmetics(IComplexNumber channel, ComplexNumber z1, ComplexNumber z2)
 {
     try
     {
         Console.WriteLine("{0} + {1} = {2}", f(z1), f(z2), f(channel.Add(z1, z2)));
         Console.WriteLine("{0} - {1} = {2}", f(z1), f(z2), f(channel.Subtract(z1, z2)));
         Console.WriteLine("{0} * {1} = {2}", f(z1), f(z2), f(channel.Multiply(z1, z2)));
         Console.WriteLine("{0} / {1} = {2}", f(z1), f(z2), f(channel.Divide(z1, z2)));
         Console.WriteLine("Conjugate[{0}] = {1}", f(z1), f(channel.Conjugate(z1)));
         Console.WriteLine("Reciprocal[{0}] = {1}", f(z1), f(channel.Reciprocal(z1)));
         Console.WriteLine("Modulus[{0}] = {1}", f(z1), channel.Modulus(z1));
         Console.WriteLine("Argument[{0}] = {1} Radians", f(z1), channel.Argument(z1));
     }
     catch (Exception fx)
     {
         Console.WriteLine(fx.Message);
     }
 }
コード例 #10
0
 static string f(ComplexNumber z)
 {
     return (String.Format("({0}, {1})", z.Real, z.Imaginary));
 }
コード例 #11
0
        public ComplexNumber Reciprocal(ComplexNumber x)
        {
            Console.WriteLine("Invoked RECIPROCAL operation.");

            var z = new ComplexNumber();
            var conjugateX = new ComplexNumber();

            var modulusX = Math.Sqrt(x.Real * x.Real + x.Imaginary * x.Imaginary);

            conjugateX.Real = x.Real;
            conjugateX.Imaginary = -1 * x.Imaginary;

            z.Real = conjugateX.Real / (modulusX * modulusX);
            z.Imaginary = conjugateX.Imaginary / (modulusX * modulusX);

            return z;
        }