public OperationStateTileViewModel(Unit unit)
        {
            Unit = unit;
            Title = Unit.ShortName;
            Description = Unit.Address;
            State = Unit.State;
            Index = Unit.SymbolicName;

            Unit.UnitStateChangedEvent += UnitStateChangedEvent;
        }
        public UnitOperationView(Unit unit)
        {
            InitializeComponent();

            this.Unit = unit;

            generalBusyProgress.Visibility = Core.Instance.IsBusy ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
            generalBusyProgress.IsIndeterminate = (generalBusyProgress.Visibility == System.Windows.Visibility.Visible);
            
            Core.Instance.CoreBusyStateChangedEvent += CoreBusyStateChangedEvent;
            CoreBusyStateChangedEvent(this, Core.Instance.IsBusy);

            unitTitle.Text = Unit.FullName.ToUpper();
            collectionView = CollectionViewSource.GetDefaultView(Unit.PresentationControls);
            collectionView.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
            operationControlList.ItemsSource = collectionView;
        }
        public NotificationAlarm(Unit unit, IAlarm alarm, bool ack)
        {
            this.Unit = unit;
            this.Date = DateTime.Now;
            this.State = alarm.State;
            this.Prefix = "UN";
            this.Code = alarm.Code;
            this.Description = alarm.Description;
            this.Ack = ack;

            string[] codeComp = alarm.Code.Split(new Char[] { '-' });

            if (codeComp.Length > 1)
            {
                this.Prefix = codeComp[0].Substring(0, 2).ToUpper();
            }
        }
Esempio n. 4
0
        public void Startup(SimpleCompleteHandler completion)
        {            
            SplashScreen = new Prism.Windows.SplashScreen();            
            SplashScreen.Show();

            ContentLoader contentLoader = new ContentLoader(delegate(double progressValue, string description)
            {
                MainThread.EnqueueTask(delegate()
                {                    
                    SplashScreen.progressLabel.Content = description;                    
                });
            });

            contentLoader.Enqueue(Resources.CORE_STARTUP_MESSAGE_0, delegate(object target)
            {
                Units = new List<Unit>();
                Journal = new Journal();
                PollManager = new PollManager();
                PollManager.PollManagerChangeStateEvent += CoreUpdateBusyState;
                PollManager.PollManagerUpdateUnitStateEvent += CoreUpdateUnitStateEvent;

                UpdateManager.Instance = new UpdateManager();
                AlarmNotificationCenter.Instance = new AlarmNotificationCenter();
            }, null);

            contentLoader.Enqueue(Resources.CORE_STARTUP_MESSAGE_1, delegate(object target)
            {
                try 
                {
                    AssemblySettings assemblySettings = AssemblySettings.Load("assembly.conf");

                    foreach (UnitSettings settings in assemblySettings.Units)
                    {
                        contentLoader.Enqueue(String.Format(Resources.CORE_STARTUP_MESSAGE_2, settings.FullName), delegate(object target1)
                        {
                            UnitSettings unitSettings = (UnitSettings)target1;

                            try
                            {
                                ManualResetEvent ContinueEvent = new ManualResetEvent(false);
                                Unit unit = new Unit(unitSettings, this.PollManager, this.Journal, delegate()
                                {
                                    ContinueEvent.Set();
                                });
                                ContinueEvent.WaitOne();
                                Units.Add(unit);

                                unit.Uri = new Uri("unit://" + Units.Count.ToString());

                                unit.UnitStateChangedEvent += delegate(object sender, ParamState state)
                                {
                                    CoreUpdateGeneralState();
                                };

                                unit.UnitAlarmUpdateEvent += delegate(object sender, IAlarm alarm)
                                {
                                    AlarmNotificationCenter.Instance.UpdateAlarm((Unit)sender, alarm);
                                };
                            }
                            catch (SystemException e)
                            {
                                System.Diagnostics.Debug.WriteLine(e.ToString());
                            }
                        }, settings);  
                    }

                    contentLoader.Enqueue(Resources.CORE_STARTUP_MESSAGE_3, delegate(object target2)
                    {
                        MainThread.EnqueueTask(delegate()
                        {
                            MainWindow.Instance = new MainWindow();
                            MainWindow.Instance.Show();
                            SplashScreen.Close();
                            SplashScreen = null;

                            CoreUpdateGeneralState();
                            PollManager.Start();
                        });
                        completion();  
                    }, null);
                }
                catch (SystemException e)
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                }                
            }, null);           
        }
        public void UpdateAlarm(Unit unit, IAlarm alarm)
        {
            lock (Alarms)
            {
                List<NotificationAlarm> alarms = new List<NotificationAlarm>(Alarms);

                foreach (var notificationAlarm in alarms)
                {
                    if (notificationAlarm.Unit.Uri.Equals(unit.Uri) && notificationAlarm.Code.Equals(alarm.Code))
                    {
                        if (notificationAlarm.State != alarm.State)
                        {
                            if (alarm.State == ParamState.Idle)
                            {
                                Alarms.Remove(notificationAlarm);

                                if (GeneralAlarmsStateChangedEvent != null)
                                {
                                    GeneralAlarmsStateChangedEvent(this);
                                }

                                CanPlayShortNotification = true;
                                return;
                            }

                            notificationAlarm.State = alarm.State;
                            notificationAlarm.Ack = false;

                            if (GeneralAlarmsStateChangedEvent != null)
                            {
                                GeneralAlarmsStateChangedEvent(this);
                            }

                            CanPlayShortNotification = true;

                            if (notificationAlarm.State == ParamState.C)
                            {
                                LongNotificationTimer.Stop();
                                LongNotificationTimer.Interval = 3000;
                                LongNotificationTimer.Start();
                            }
                        }

                        return;
                    }
                }

                if (alarm.State > ParamState.Idle)
                {
                    NotificationAlarm notificationAlarm = new NotificationAlarm(unit, alarm, false);
                    Alarms.Add(notificationAlarm);

                    if (GeneralAlarmsStateChangedEvent != null)
                    {
                        GeneralAlarmsStateChangedEvent(this);
                    }

                    CanPlayShortNotification = true;

                    if (notificationAlarm.State == ParamState.C)
                    {
                        LongNotificationTimer.Stop();
                        LongNotificationTimer.Interval = 3000;
                        LongNotificationTimer.Start();
                    }
                }
            }
        }