コード例 #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);
        }
コード例 #2
0
 public async Task SetTemperature(double value)
 {
     if (this.State.LastValue < 100 && value >= 100)
     {
         Console.WriteLine("High temperature recorded {0}", value);
     }
     if (this.State.LastValue != value)
     {
         this.State.LastValue = value;
         await this.State.WriteStateAsync();
     }
     var systemGrain = SystemGrainFactory.GetGrain(0, this.State._System);
     var reading     = new TemperatureReading
     {
         DeviceId = this.GetPrimaryKeyLong(),
         Time     = DateTime.UtcNow,
         Value    = value
     };
     await systemGrain.SetTemperature(reading);
 }
        public Task <double> Get(string id)
        {
            var grain = SystemGrainFactory.GetGrain(0, id);

            return(grain.GetTemperature());
        }