Exemple #1
0
        public static void SendNumbers(Uri queueAddress, int numberOfMessages)
        {
            NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None);
            ChannelFactory <IProductCalculator> factory =
                new ChannelFactory <IProductCalculator>(binding);

            factory.Open();
            IProductCalculator ipc = factory.CreateChannel(new EndpointAddress(queueAddress.ToString()));

            Random rand = new Random();

            for (int i = 0; i < numberOfMessages; i++)
            {
                int num1 = rand.Next(1, 10);
                int num2 = rand.Next(1, 10);
                ipc.CalculateProduct(num1, num2);
            }
            factory.Close();
        }
Exemple #2
0
    static void Main(string[] args)
    {
        // create an instance of the Calculator object
        Calculator calc = new Calculator();

        // upcast to IProductCalculator and call the method
        IProductCalculator pcalc = calc;
        int productResult        = pcalc.PerformCalculation(10, 10);

        // upcast to ISumCalculator and call the method
        ISumCalculator scalc     = calc;
        int            sumResult = scalc.PerformCalculation(10, 10);

        // print the result
        Console.WriteLine("Product result: {0}", productResult);
        Console.WriteLine("Sum Result: {0}", sumResult);

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Exemple #3
0
    static void Main(string[] args)
    {
        // create an object and upcast it to the combined interface
        ICombinedCalculator calc = new Calculator();

        // upcast to the base interfaces and call the method that each defines
        IProductCalculator prodCalc       = calc;
        int                    prodResult = prodCalc.CalculateProduct(10, 10);
        ISumCalculator         sumCalc    = calc;
        int                    calcResult = sumCalc.CalculateSum(10, 10);
        ISubtractionCalculator subCalc    = calc;
        int                    subResult  = subCalc.CalculateSubtraction(10, 2);

        // explicitly cast from one base interface to another
        prodCalc = (IProductCalculator)subCalc;


        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Exemple #4
0
 public BasketOfProducts(IProductCalculator calculator)
 {
     this.calculator = calculator;
 }