private void UpdateDoorEnabledState(ACConfiguration configuration)
        {
            if (_systemProperties == null || string.IsNullOrEmpty(_systemProperties.Address))
            {
                return;
            }

            var enabledACUnits = configuration.ACElements.OfType <ACUnit>().Select(acUnit => new Tuple <string, bool>(acUnit.Id, acUnit.IsEnabled));

            _client.UpdateDoorEnabledStates(_systemProperties.AdminUser, _systemProperties.AdminPassword, enabledACUnits.ToArray()).Wait();
        }
        public sealed override void ApplyConfiguration(ACConfiguration configuration)
        {
            ACUtil.Log(false, "DemoACPlugin.ConfigurationManager", "Configuration applied.");

            // Store the server id - used for connected/disconnected events and when rebuilding the configuration
            _client.ServerId = configuration.ACServer.Id;

            UpdateDoorEnabledState(configuration);
            UpdateEventTypeEnabledState(configuration);

            // Other plug-ins might e.g. need to connect to peers listed in the configuration,
            // or need to look up elements to determine the type or read some custom properties.
        }
        public override void Init(ACConfiguration configuration)
        {
            ACUtil.Log(false, "DemoACPlugin.DemoAccessControlSystem", "Initializing access control system.");

            _systemProperties = new SystemProperties();
            _client           = new DemoClient(_systemProperties);

            _commandManager          = new CommandManager(_systemProperties, _client);
            _configurationManager    = new ConfigurationManager(_systemProperties, _client, configuration);
            _connectionManager       = new ConnectionManager(_client);
            _credentialHolderManager = new CredentialHolderManager(_systemProperties, _client);
            _eventManager            = new EventManager(_client);
            _stateManager            = new StateManager(_client);

            // Pass the ACAlarmRepository to a separate class for handling two-way alarm synchronization, if needed
            _alarmSynchronizer = new AlarmSynchronizer(_client, ACAlarmRepository);
        }
        public ConfigurationManager(SystemProperties systemProperties, DemoClient client, ACConfiguration configuration)
        {
            _systemProperties          = systemProperties;
            _client                    = client;
            _client.UserRightsChanged += _client_UserRightsChanged; // Implemented in PersonalizedConfigurationManger.cs

            if (configuration == null)
            {
                // Configuration will be null when initially creating a system. Make up a new server id.
                _client.ServerId = Guid.NewGuid().ToString();
            }
            else
            {
                ApplyConfiguration(configuration);
            }
        }
        private ACConfiguration BuildConfiguration(DoorControllerDescriptor[] doorControllers, DoorDescriptor[] doors, EventDescriptor[] eventDescriptors)
        {
            var elements = new List <ACElement>();

            // Add element types
            elements.Add(ElementTypes.ServerType);
            elements.Add(ElementTypes.DoorControllerType);

            // Add event types
            elements.AddRange(EventTypes.ServerEventTypes);

            foreach (var eventDescriptor in eventDescriptors)
            {
                var acEventType = TypeConverter.ToACEventType(eventDescriptor, !_disabledEventTypes.Contains(eventDescriptor.EventId));
                elements.Add(acEventType);
            }

            // Add state types
            elements.AddRange(StateTypes.ServerStateTypes);
            elements.AddRange(StateTypes.DoorStateTypes);

            // Add command types
            elements.AddRange(CommandTypes.DoorCommands);

            // Look up the all events, which can be fired on a door
            // OBS: In the Demo Access Control application, events with source "DoorController" are actually fired on the door.
            var doorEventTypeIds = eventDescriptors.Where(e => e.SourceType == "Door" || e.SourceType == "DoorController").Select(ed => ed.EventId.ToString());

            elements.Add(ElementTypes.CreateDoorType(doorEventTypeIds));

            // Look up the all events, which can be fired on an access point
            var apEventTypeIds = eventDescriptors.Where(ed => ed.SourceType == "AccessPoint").Select(ed => ed.EventId.ToString());

            elements.Add(ElementTypes.CreateAccessPointType(apEventTypeIds));

            // Add server element
            elements.Add(TypeConverter.CreateACServer(_client.ServerId, _systemProperties.Address));

            // Add door controllers
            foreach (var doorController in doorControllers)
            {
                elements.Add(TypeConverter.ToACUnit(doorController));
            }

            // Add doors and access points
            foreach (var door in doors)
            {
                door.Enabled = !_disabledDoors.Contains(door.DoorId);
                elements.AddRange(TypeConverter.ToACUnits(door));
            }

            try
            {
                return(ACConfiguration.CreateACConfiguration(DateTime.UtcNow, elements));
            }
            catch (ACConfigurationException ex)
            {
                ACUtil.Log(true, "DemoACPlugin.ConfigurationManager", "Error building configuration: " + ex.Message);
                return(null);
            }
        }
 public SystemManagers(SystemProperties systemProperties, ConfigurationCache configurationCache, ACConfiguration configuration, IACAlarmRepository alarmRepository)
 {
     CommandManager          = new CommandManager(this, configurationCache);
     ConfigurationManager    = new ConfigurationManager(this, systemProperties, configurationCache, configuration);
     ConnectionManager       = new ConnectionManager(this, alarmRepository, systemProperties);
     CredentialHolderManager = new CredentialHolderManager(this, systemProperties);
     EventManager            = new EventManager(configurationCache);
     StateManager            = new StateManager(this, configurationCache);
 }