示例#1
0
        public override void Init()
        {
            //委托事件实现
            var heater = new Heater();

            heater.OnBoiled += new AlarmObserver().Alert;
            heater.OnBoiled += new ScreenObserver().Show;
            heater.BoilWater();

            //IObservable<>和IObserver<>实现
            var subject = new Ammeter();
            var alarm   = new MeterAlarm();
            var sms     = new MeterSMS();

            alarm.Subscribe(subject);
            sms.Subscribe(subject);
            subject.Publish();

            alarm.Unsubscribe();
            subject.Publish();

            alarm.Subscribe(subject);
            sms.Unsubscribe();
            subject.Publish();
        }
示例#2
0
 public MeterAlarm Update(MeterAlarm t)
 {
     throw new NotImplementedException();
 }
示例#3
0
 public MeterAlarm Save(MeterAlarm t)
 {
     _iogContext.MeterAlarms.Add(t);
     _iogContext.SaveChanges();
     return(t);
 }