Ejemplo n.º 1
0
        void UpdateProperty(RegistrySyncInfo syncInfo)
        {
            lock (_registryOperationLock)
            {
                if (_suppressPropertyName == syncInfo.Property.Name)
                {
                    return;
                }

                _suppressPropertyName = syncInfo.Property.Name;
                if (syncInfo.Item is RegString str)
                {
                    syncInfo.Property.SetValue(this, str.Data);
                }
                else if (syncInfo.Item is RegInteger integer)
                {
                    syncInfo.Property.SetValue(this, integer.Data);
                }
                else if (syncInfo.Item is RegDecimal dec)
                {
                    syncInfo.Property.SetValue(this, dec.Data);
                }
                else if (syncInfo.Item is RegBooleanGroup blGr)
                {
                    syncInfo.Property.SetValue(this, blGr.GetItem(syncInfo.BlGroupPos));
                }
                _suppressPropertyName = null;
            }
        }
Ejemplo n.º 2
0
        public BaseViewModel()
        {
            var allProperties = typeof(T).GetProperties();

            PropertyChanged += (s, e) => UpdateRegistry(e.PropertyName);

            for (int i = 0; i < allProperties.Length; i++)
            {
                var attribute = allProperties[i].GetCustomAttribute <RegistrySyncAttribute>();
                if (attribute != null)
                {
                    var regItem = ABSRegistry.GetItem(attribute.RegistryPath);
                    if (regItem is RegGroup)
                    {
                        ABSLog.ThrowError("Cannot registry sync to a group.");
                    }

                    var syncInfo = new RegistrySyncInfo(allProperties[i], regItem, attribute.BooleanGroupPos);
                    _registrySyncProperties.Add(allProperties[i].Name, syncInfo);
                    AddEventHandlerToItem(syncInfo, regItem);

                    UpdateProperty(syncInfo);
                }
            }
        }
Ejemplo n.º 3
0
        void AddEventHandlerToItem(RegistrySyncInfo info, IRegItem regItem)
        {
            if (regItem is RegBooleanGroup blGr)
            {
                blGr.BooleanItemChanged += (s, e) =>
                {
                    if (info.BlGroupPos == e.Pos)
                    {
                        UpdateProperty(info);
                    }
                }
            }
            ;

            else
            {
                regItem.ItemChanged += (s, e) => UpdateProperty(info);
            }
        }