public void Add <T>(string name, T newValue)
        {
            RegistryEntity <T> registryEntity = new RegistryEntity <T>(name, newValue, _registryValueKind);

            try
            {
                _windowsRegistryWriter.Write(registryEntity);
            }
            catch (SerializationException e)
            {
                throw e;
            }
        }
        public T Get <T>(string name)
        {
            RegistryEntity <T> registryEntity = null;

            try
            {
                registryEntity = _windowsRegistryReader.Read <T>(name);
            }
            catch (SerializationException e)
            {
                throw e;
            }
            return(registryEntity.Value);
        }
Example #3
0
 public void Write <T>(RegistryEntity <T> registryEntity)
 {
     try
     {
         byte[] serializedValue = _byteArraySerializer?.Serialize(registryEntity.Value);
         _registryKey?.SetValue(registryEntity.Name, serializedValue, registryEntity.RegistryValueKind);
     }
     catch (Exception e) when(e is ArgumentException || e is ObjectDisposedException ||
                              e is UnauthorizedAccessException || e is SecurityException || e is IOException)
     {
         Console.WriteLine(e.ToString());
     }
     catch (SerializationException e)
     {
         throw e;
     }
 }
        public IList <RegistryEntity <T> > ReadAll <T>()
        {
            IList <RegistryEntity <T> > registryEntities = new List <RegistryEntity <T> >();

            string[] names = GetValuesNames();

            if (names != null)
            {
                foreach (string name in names)
                {
                    RegistryEntity <T> registryEntity = Read <T>(name);
                    registryEntities.Add(registryEntity);
                }
            }

            return(registryEntities);
        }
        public void AddAll <T>(IList <T> newValues)
        {
            IList <RegistryEntity <T> > registryEntities = new List <RegistryEntity <T> >();
            int actualItemCount = _windowsRegistryReader.GetActualItemCount();

            try
            {
                for (int i = 0; i < newValues.Count; i++)
                {
                    T newValue = newValues[i];

                    string             nextId         = Convert.ToString(actualItemCount + i);
                    RegistryEntity <T> registryEntity = new RegistryEntity <T>(nextId, newValue, _registryValueKind);
                    registryEntities.Add(registryEntity);
                }

                _windowsRegistryWriter.WriteAll(registryEntities);
            }
            catch (SerializationException e)
            {
                throw e;
            }
        }