Exemplo n.º 1
0
        /// <summary>
        /// CTOR
        /// </summary>
        public TilePageViewModel()
        {
            this.configurationFile = new TileViewConfigurationFile();

            // Intialize commands
            this.InitializeCommands();

            // Create the main grid
            this.CreateMainGrid(this.numberOfColumns, 150, this.numberOfRows, 110);

            this.openHardwareManagementService = DependencyFactory.Resolve<IOpenHardwareMonitorManagementService>(ServiceNames.OpenHardwareMonitorManagementService);
            this.applicationConfigFile = DependencyFactory.Resolve<IConfigurationFile>(ConfigFileNames.ApplicationConfig);

            for (int r = 0; r < this.numberOfRows; r++)
            {
                for (int c = 0; c < this.numberOfColumns; c++)
                {
                    var tile = this.configurationFile.Tiles.Where(t => t.GridRow == r && t.GridColumn == c).FirstOrDefault();

                    if (tile != null)
                    {
                        var sensor = this.openHardwareManagementService.GetSensor(tile.SensorCategory, tile.SensorName, tile.SensorType);

                        if (sensor != null)
                            this.AddSensorTile(sensor, tile.GridRow, tile.GridColumn, tile.SensorCategory);
                    }
                    else
                    {
                        TileViewDropTarget dropTarget = new TileViewDropTarget();
                        dropTarget.SetValue(Grid.RowProperty, r);
                        dropTarget.SetValue(Grid.ColumnProperty, c);
                        this.MainGrid.Children.Add(dropTarget);
                    }
                }
            }

            // Register for events
            DependencyFactory.Resolve<IEventAggregator>(GeneralConstants.EventAggregator).GetEvent<OpenHardwareMonitorManagementServiceTimerTickEvent>().Subscribe(this.OpenHardwareMonitorManagementServiceTimerTickEventHandler, ThreadOption.UIThread);
            DependencyFactory.Resolve<IEventAggregator>(GeneralConstants.EventAggregator).GetEvent<SensorTilePositionChangedEvent>().Subscribe(this.SensorTilePositionChangedEventHandler, ThreadOption.UIThread);
            DependencyFactory.Resolve<IEventAggregator>(GeneralConstants.EventAggregator).GetEvent<SensorTileAddedEvent>().Subscribe(this.SensorTileAddedEventHandler, ThreadOption.UIThread);
            DependencyFactory.Resolve<IEventAggregator>(GeneralConstants.EventAggregator).GetEvent<SensorTileDeletedEvent>().Subscribe(this.SensorTileDeletedEventHandler, ThreadOption.UIThread);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sensor-Tile position changed
        /// </summary>
        /// <param name="args"></param>
        private void SensorTileDeletedEventHandler(SensorTileDeletedEventArgs args)
        {
            if (args.DeletedSensorTile != null)
            {
                int gridRow = Convert.ToInt32(args.DeletedSensorTile.GetValue(Grid.RowProperty));
                int gridColumn = Convert.ToInt32(args.DeletedSensorTile.GetValue(Grid.ColumnProperty));

                this.MainGrid.Children.Remove(args.DeletedSensorTile);

                // Create new drop target
                TileViewDropTarget dropTarget = new TileViewDropTarget();
                dropTarget.SetValue(Grid.RowProperty, gridRow);
                dropTarget.SetValue(Grid.ColumnProperty, gridColumn);
                this.MainGrid.Children.Add(dropTarget);

                this.configurationFile.DeleteSensorTile(args.DeletedSensorTile.HardwareSensor.Name, gridRow, gridColumn);
            }
        }