Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // The Orleans silo environment is initialized in its own app domain in order to more
            // closely emulate the distributed situation, when the client and the server cannot
            // pass data via shared memory.
            AppDomain hostDomain = AppDomain.CreateDomain("OrleansHost", null, new AppDomainSetup
            {
                AppDomainInitializer          = InitSilo,
                AppDomainInitializerArguments = args,
            });

            Orleans.OrleansClient.Initialize("DevTestClientConfiguration.xml");

            // TODO: once the previous call returns, the silo is up and running.
            //       This is the place your custom logic, for example calling client logic
            //       or initializing an HTTP front end for accepting incoming requests.

            Console.WriteLine("Orleans Silo is running.\nPress Enter to terminate...");

            var observer    = new SystemObserver();
            var observerRef = SystemObserverFactory.CreateObjectReference(observer).Result;

            var systemGrain = SystemGrainFactory.GetGrain(0, "vehicle1");

            systemGrain.Subscribe(observerRef).Wait();

            var grain = DecodeGrainFactory.GetGrain(0);

            while (true)
            {
                grain.Decode(Console.ReadLine());
            }

            hostDomain.DoCallBack(ShutdownSilo);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // The Orleans silo environment is initialized in its own app domain in order to more
            // closely emulate the distributed situation, when the client and the server cannot
            // pass data via shared memory.

            // Removing this to make it a standalone silo.
            AppDomain hostDomain = AppDomain.CreateDomain("OrleansHost", null, new AppDomainSetup
            {
                AppDomainInitializer          = InitSilo,
                AppDomainInitializerArguments = args,
            });

            Orleans.GrainClient.Initialize("DevTestClientConfiguration.xml");

            // TODO: once the previous call returns, the silo is up and running.
            //       This is the place your custom logic, for example calling client logic
            //       or initializing an HTTP front end for accepting incoming requests.

            Console.WriteLine("Orleans Silo is running.\nPress Enter to terminate...");

            var deviceGrain = GrainClient.GrainFactory.GetGrain <IDeviceGrain>(3);

            deviceGrain.JoinSystem("vehicle1").Wait();

            deviceGrain = GrainClient.GrainFactory.GetGrain <IDeviceGrain>(4);
            deviceGrain.JoinSystem("vehicle1").Wait();

            deviceGrain = GrainClient.GrainFactory.GetGrain <IDeviceGrain>(5);
            deviceGrain.JoinSystem("vehicle1").Wait();

            var observer    = new SystemObserver();
            var observerRef = SystemObserverFactory.CreateObjectReference(observer).Result;

            var systemGrain = GrainClient.GrainFactory.GetGrain <ISystemGrain>(0, keyExtension: "vehicle1");

            systemGrain.Subscribe(observerRef).Wait();
            var grain = GrainClient.GrainFactory.GetGrain <IDecodeGrain>(0);

            while (true)
            {
                grain.Decode(Console.ReadLine());
            }

            //// this was part of prior sample. not changed in stand alone.
            ////while (true)
            ////{
            ////    var grain = GrainClient.GrainFactory.GetGrain<IDeviceGrain>(0);
            ////    grain.SetTemprature(double.Parse(Console.ReadLine()));
            ////}

            //// stand alone change.
            hostDomain.DoCallBack(ShutdownSilo);
        }