예제 #1
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);
            }
        }
        private void AddEntryes()
        {
            #region ValueType
            ValueType valueIntType    = new ValueType("int");
            ValueType valueStringType = new ValueType("string");
            ValueType valueFloatType  = new ValueType("float");
            ValueType valueBoolType   = new ValueType("bool");
            ValueTypes.Add(valueIntType);
            ValueTypes.Add(valueStringType);
            ValueTypes.Add(valueFloatType);
            ValueTypes.Add(valueBoolType);
            SaveChanges();
            #endregion

            #region DeviceType
            DeviceType deviceLaptopType = new DeviceType("Ноутбук", Properties.Resources.Laptop);
            DeviceTypes.Add(deviceLaptopType);
            SaveChanges();
            #endregion

            #region Devices
            Device device1 = new Device(deviceLaptopType.ID, "Samsung NC10");
            Device device2 = new Device(deviceLaptopType.ID, "ASUS K50IN");
            Devices.Add(device1);
            Devices.Add(device2);
            SaveChanges();
            #endregion

            #region CharacteristicType
            CharacteristicType characteristicType_Webcam       = new CharacteristicType(deviceLaptopType.ID, "Веб-камера", valueBoolType.ID);
            CharacteristicType characteristicType_VideoCard    = new CharacteristicType(deviceLaptopType.ID, "Видеокарта", valueStringType.ID);
            CharacteristicType characteristicType_WorkingHours = new CharacteristicType(deviceLaptopType.ID, "Время работы", valueIntType.ID);
            CharacteristicType characteristicType_Screen       = new CharacteristicType(deviceLaptopType.ID, "Диагональ экрана", valueFloatType.ID);
            CharacteristicType characteristicType_Storage      = new CharacteristicType(deviceLaptopType.ID, "Накопитель", valueIntType.ID);
            CharacteristicType characteristicType_RAM          = new CharacteristicType(deviceLaptopType.ID, "Оперативная память", valueIntType.ID);
            CharacteristicType characteristicType_CPU          = new CharacteristicType(deviceLaptopType.ID, "Процессор", valueStringType.ID);
            CharacteristicTypes.Add(characteristicType_Webcam);
            CharacteristicTypes.Add(characteristicType_VideoCard);
            CharacteristicTypes.Add(characteristicType_WorkingHours);
            CharacteristicTypes.Add(characteristicType_Screen);
            CharacteristicTypes.Add(characteristicType_Storage);
            CharacteristicTypes.Add(characteristicType_RAM);
            CharacteristicTypes.Add(characteristicType_CPU);
            SaveChanges();
            #endregion

            #region Characteristics
            //1 Samsung NC10
            Characteristic char1_Webcam       = new Characteristic(device1.ID, characteristicType_Webcam.ID, "true");
            Characteristic char1_VideoCard    = new Characteristic(device1.ID, characteristicType_VideoCard.ID, "Intel GMA 952 (встроенная)");
            Characteristic char1_WorkingHours = new Characteristic(device1.ID, characteristicType_WorkingHours.ID, "6");
            Characteristic char1_Screen       = new Characteristic(device1.ID, characteristicType_Screen.ID, "10,20");
            Characteristic char1_Storage      = new Characteristic(device1.ID, characteristicType_Storage.ID, "80");
            Characteristic char1_RAM          = new Characteristic(device1.ID, characteristicType_RAM.ID, "1");
            Characteristic char1_CPU          = new Characteristic(device1.ID, characteristicType_CPU.ID, "Intel 945GSE");
            Characteristics.Add(char1_Webcam);
            Characteristics.Add(char1_VideoCard);
            Characteristics.Add(char1_WorkingHours);
            Characteristics.Add(char1_Screen);
            Characteristics.Add(char1_Storage);
            Characteristics.Add(char1_RAM);
            Characteristics.Add(char1_CPU);
            //2 ASUS K50IN
            Characteristic char2_Webcam       = new Characteristic(device2.ID, characteristicType_Webcam.ID, "true");
            Characteristic char2_VideoCard    = new Characteristic(device2.ID, characteristicType_VideoCard.ID, "NVIDIA GeForce G 102M (дискретная)");
            Characteristic char2_WorkingHours = new Characteristic(device2.ID, characteristicType_WorkingHours.ID, "6");
            Characteristic char2_Screen       = new Characteristic(device2.ID, characteristicType_Screen.ID, "15,6");
            Characteristic char2_Storage      = new Characteristic(device2.ID, characteristicType_Storage.ID, "250");
            Characteristic char2_RAM          = new Characteristic(device2.ID, characteristicType_RAM.ID, "2");
            Characteristics.Add(char2_Webcam);
            Characteristics.Add(char2_VideoCard);
            Characteristics.Add(char2_WorkingHours);
            Characteristics.Add(char2_Screen);
            Characteristics.Add(char2_Storage);
            Characteristics.Add(char2_RAM);
            SaveChanges();
            #endregion
        }