Exemplo n.º 1
0
        public static void ChangeMode(ControlMode mode)
        {
            var transforms = GetTransforms();

            var          searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSI_System");
            const string propName = "System";

            Util.WmiQueryForeach(searcher, (obj, index) => MsiWmiInstance.FromWmi(index, propName, obj), (obj, instance) =>
            {
                if (instance.Index == 9)
                {
                    if (instance.IsValid())
                    {
                        int value = Convert.ToInt32(obj.GetPropertyValue(propName));
                        value     = transforms[mode](value);
                        obj.SetPropertyValue(propName, value);
                        obj.Put();
                    }
                    else
                    {
                        throw new InvalidWmiInstanceException();
                    }
                }
            });
        }
Exemplo n.º 2
0
        public static ControlMode GetCurrentMode()
        {
            var transforms = GetTransforms();

            var          searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSI_System");
            const string propName = "System";
            ControlMode? result   = null;

            Util.WmiQueryForeach(searcher, (obj, index) => MsiWmiInstance.FromWmi(index, propName, obj), (obj, instance) =>
            {
                if (instance.Index == 9)
                {
                    if (instance.IsValid())
                    {
                        int value = Convert.ToInt32(obj.GetPropertyValue(propName));

                        foreach (var pair in transforms)
                        {
                            if (value == pair.Value(value))
                            {
                                result = pair.Key;
                            }
                        }
                    }
                }
            });

            return(result.Value);
        }
Exemplo n.º 3
0
        private void RefreshFromDb()
        {
            bool init = false;

            Util.WmiQueryForeach(_searcher, (obj, index) => MsiWmiInstance.FromWmi(index, _propName, obj), (obj, instance) =>
            {
                if (instance.Index == 10)
                {
                    if (instance.IsValid())
                    {
                        Value = fromRaw(Convert.ToInt32(obj.GetPropertyValue(_propName)));
                        init  = true;
                    }
                    else
                    {
                        throw new InvalidWmiInstanceException();
                    }
                }
            });

            if (!init)
            {
                throw new InvalidWmiInstanceException();
            }
        }
        private void RefreshFromDb()
        {
            _instances = new List <MsiWmiInstance>();

            Util.WmiQueryForeach(
                _searcher,
                (obj, index) => MsiWmiInstance.FromWmi(index, _propertyName, obj, (x) => x <= 150),
                (obj, model) => _instances.Add(model));

            _instances = _instances.Where((x) => _indexWhiteList.Contains(x.Index)).ToList();

            if (!IsValid())
            {
                throw new AdvancedModeInvalidException();
            }
        }
Exemplo n.º 5
0
        public void Commit()
        {
            Util.WmiQueryForeach(_searcher, (obj, index) => MsiWmiInstance.FromWmi(index, _propName, obj), (obj, instance) =>
            {
                if (instance.Index == 10)
                {
                    if (instance.IsValid())
                    {
                        obj.SetPropertyValue(_propName, toRaw(Value));
                        obj.Put();
                    }
                    else
                    {
                        throw new InvalidWmiInstanceException();
                    }
                }
            });

            RefreshFromDb();
        }
        public void Commit()
        {
            if (!IsValid())
            {
                throw new AdvancedModeInvalidException();
            }

            Util.WmiQueryForeach(
                _searcher,
                (obj, index) => MsiWmiInstance.FromWmi(index, _propertyName, obj, (x) => x <= 150),
                (obj, model) =>
            {
                if (_indexWhiteList.Contains(model.Index))
                {
                    int value = (int)_instances.Where((x) => x.Index == model.Index).First().Value;
                    obj.SetPropertyValue(_propertyName, value);
                    obj.Put();
                }
            }
                );

            RefreshFromDb();
        }