Ejemplo n.º 1
0
        /// <summary>
        /// Removes an authentication profile if it is not in use
        /// </summary>
        /// <param name="authenticationProfile">The profile to remove</param>
        /// <exception cref="InvalidOperationException">
        /// Thrown when the authentication profile is known to be in use by other records
        /// </exception>
        public void RemoveAuthenticationProfile(AuthenticationProfile authenticationProfile)
        {
            // TODO : Check drop through lists when this comes into play

            if (Devices.Count(x => x.AuthenticationProfileId == authenticationProfile.Id) > 0)
            {
                throw new InvalidOperationException("The given authentication profile " + authenticationProfile.Name + " is currently in use and cannot be removed");
            }

            AuthenticationProfiles.Remove(authenticationProfile);
        }
Ejemplo n.º 2
0
        public ObjectStoreContext()
        {
            var tenants = ObjectStore.Current.ReadAllObjects <Tenant>(ObjectStoreRoot);

            foreach (var tenant in tenants)
            {
                Tenants.Add(tenant);
            }

            var sites = ObjectStore.Current.ReadAllObjects <Site>(ObjectStoreRoot);

            foreach (var site in sites)
            {
                Sites.Add(site);
            }

            var devices = ObjectStore.Current.ReadAllObjects <Device>(ObjectStoreRoot);

            foreach (var device in devices)
            {
                Devices.Add(device);
            }

            var authenticationProfiles = ObjectStore.Current.ReadAllObjects <AuthenticationProfile>(ObjectStoreRoot);

            foreach (var authenticationProfile in authenticationProfiles)
            {
                AuthenticationProfiles.Add(authenticationProfile);
            }

            var deviceTypes = ObjectStore.Current.ReadAllObjects <DeviceType>(ObjectStoreRoot);

            foreach (var deviceType in deviceTypes)
            {
                DeviceTypes.Add(deviceType);
            }

            var unknownDeviceType = DeviceTypes.SingleOrDefault(x => x.Id == Guid.Empty);

            if (unknownDeviceType == null)
            {
                unknownDeviceType = new DeviceType
                {
                    Id    = Guid.Empty,
                    Name  = "{Not set}",
                    Notes = "This device type is reserved for items which have no device type set"
                };

                DeviceTypes.Add(unknownDeviceType);
            }

            Tenants.CollectionChanged += Tenants_CollectionChanged;
            Sites.CollectionChanged   += Sites_CollectionChanged;
            Devices.CollectionChanged += Devices_CollectionChanged;
            AuthenticationProfiles.CollectionChanged += AuthenticationProfiles_CollectionChanged;
            DeviceTypes.CollectionChanged            += DeviceTypes_CollectionChanged;

            var localTenant = Tenants.SingleOrDefault(x => x.Name.ToLowerInvariant() == "{local}");

            if (localTenant == null)
            {
                localTenant = new Tenant
                {
                    Id    = Guid.NewGuid(),
                    Name  = "{Local}",
                    Notes = "Local tenant"
                };

                Tenants.Add(localTenant);
            }

            var localSite = Sites.SingleOrDefault(x => x.Name.ToLowerInvariant() == "{local site}");

            if (localSite == null)
            {
                localSite = new Site
                {
                    Id       = Guid.NewGuid(),
                    TenantId = localTenant.Id,
                    Name     = "{Local Site}",
                    Notes    = "Local site"
                };

                Sites.Add(localSite);
            }
        }