Example #1
0
 private void Load(ApplicationInstanceRecord record)
 {
     if (record == null)
     {
         throw new ArgumentNullException("record");
     }
     Current = record;
     OnLoaded();
 }
Example #2
0
        public void LoadInstance()
        {
            ApplicationInstanceRecord instance = _instanceStore.GetInstance();

            if (instance == null)
            {
                throw new Exception("Instance has not been created.");
            }
            Load(instance);
        }
        public void Save(ApplicationInstanceRecord record)
        {
            using (RegistryKey registryKey1 = RegistryKey.OpenBaseKey(Hive, View))
            {
                using (RegistryKey registryKey2 = registryKey1.OpenSubKey(KeyName, true))
                {
                    if (registryKey2 == null)
                    {
                        throw new Exception("Registry structure invalid.");
                    }

                    registryKey2.SetValue(ApplicationInstanceRecord.NuGetFrameworkNamesKey, record.NuGetFrameworkNames);
                }
            }
        }
        private ApplicationInstanceRecord Get()
        {
            var instanceRecord = new ApplicationInstanceRecord();

            using (RegistryKey registryKey1 = RegistryKey.OpenBaseKey(Hive, View))
            {
                using (RegistryKey registryKey2 = registryKey1.OpenSubKey(KeyName, false))
                {
                    if (registryKey2 == null)
                    {
                        return(instanceRecord);
                    }

                    foreach (string str in registryKey2.GetValueNames())
                    {
                        if (str == ApplicationInstanceRecord.InstallDirectoryKey)
                        {
                            var value = registryKey2.GetValue(str);
                            instanceRecord.InstallDirectory = value.ToString();
                            continue;
                        }
                        if (str == ApplicationInstanceRecord.NuGetFrameworkNamesKey)
                        {
                            var value = registryKey2.GetValue(str);
                            instanceRecord.NuGetFrameworkNames = value.ToString();
                            continue;
                        }
                    }
                }
            }

#if DEBUG
            if (string.IsNullOrWhiteSpace(instanceRecord.InstallDirectory))
            {
                instanceRecord.InstallDirectory = Directory.GetParent(Assembly.GetEntryAssembly().Location).FullName;
            }
#endif

            if (!instanceRecord.IsValid())
            {
                throw new Exception("Registry install directory is missing.");
            }

            return(instanceRecord);
        }