示例#1
0
        static void Main(string[] args)
        {
            System.Console.Out.WriteLine("Started C# Publisher");
            GravityCS.GravityInteractor g = new GravityCS.GravityInteractor();
            g.Init(".Net Gravity Test Publisher");
            System.Console.Out.WriteLine("Gravity Initialized");

            g.RegisterDataProduct("CSTestDataProduct", GravityCS.GravityTransportType.TCP);
            System.Console.Out.WriteLine("Registered CSTestDataProduct");

            g.RegisterService("CSTestRequest", GravityCS.GravityTransportType.TCP, delegate(String serviceID, GravityCS.DataProduct dataProducts)
            {
                MultiplicationOperandsPB.Builder multRequest = MultiplicationOperandsPB.CreateBuilder();
                dataProducts.getProtobufObject(multRequest);

                MultiplicationResultPB.Builder multResult = MultiplicationResultPB.CreateBuilder();
                multResult.Result = multRequest.MultiplicandA * multRequest.MultiplicandB; //Do the calculation

                GravityCS.DataProduct result = new GravityCS.DataProduct("MultResult");
                result.setData(multResult.Build());

                return(result);
            });
            System.Console.Out.WriteLine("Registered CSTestRequest");

            bool quit  = false;
            int  value = 0;

            while (!quit)
            {
                GravityCS.DataProduct testDP = new GravityCS.DataProduct("CSTestDataProduct");
                //testDP.setData();
                BasicCounterDataProductPB.Builder proto = BasicCounterDataProductPB.CreateBuilder();
                value++;
                proto.Count = value;

                testDP.setData(proto.Build());
                g.Publish(testDP);

                System.Console.Out.WriteLine("Published Data Product");

                System.Threading.Thread.Sleep(1000);
            }

            g.UnregisterDataProduct("CSTestDataProduct");
        }
示例#2
0
        static void Main(string[] args)
        {
            GravityCS.GravityInteractor g = new GravityCS.GravityInteractor();
            g.Init(".Net Gravity Test Subscriber");

            g.Subscribe("CSTestDataProduct", delegate(IList <GravityCS.DataProduct> dataProducts) {
                foreach (GravityCS.DataProduct d in dataProducts)
                {
                    BasicCounterDataProductPB.Builder counterPB = BasicCounterDataProductPB.CreateBuilder();
                    d.getProtobufObject(counterPB);
                    System.Console.Out.WriteLine("Count: {0}", counterPB.Count);
                }
            });

            bool   quit = false;
            Random rand = new Random();

            while (!quit)
            {
                //Let's try out making requests
                MultiplicationOperandsPB.Builder multRequest = MultiplicationOperandsPB.CreateBuilder();
                multRequest.MultiplicandA = rand.Next(10);
                multRequest.MultiplicandB = rand.Next(10);

                GravityCS.DataProduct dp = new GravityCS.DataProduct("CSTestRequest");
                dp.setData(multRequest.Build());
                g.Request("CSTestRequest", dp, delegate(String serviceID, String requestID, GravityCS.DataProduct dataProduct)
                {
                    MultiplicationResultPB.Builder multResult = MultiplicationResultPB.CreateBuilder();
                    dataProduct.getProtobufObject(multResult);
                    System.Console.Out.WriteLine("{0} x {1} = {2}", multRequest.MultiplicandA, multRequest.MultiplicandB, multResult.Result);
                });

                System.Threading.Thread.Sleep(1000);
            }
        }