예제 #1
0
 /// <summary>
 /// Initializes a new instance of <see cref="CleanUpInsurance"/> built from the data specified.
 /// </summary>
 /// <param name="creationData"></param>
 /// <param name="assemblyNames"></param>
 private CleanUpInsurance(InsuranceData creationData, IEnumerable <AssemblyName> assemblyNames)
 {
     _data       = creationData;
     _assemblies = new List <AssemblyName>(assemblyNames);
     _timeStamp  = DateTime.Now;
     _uniqueId   = Guid.NewGuid();
 }
예제 #2
0
        /// <summary>
        /// Creates an insurance for the <paramref name="assemblyNames"/>.
        /// The method of insuring is based on the <see cref="CleanUpInsuranceFlags"/> set in the user's configuration.
        /// </summary>
        /// <param name="creationData"></param>
        /// <param name="assemblyNames">The assemblies to insure cleanup for.</param>
        /// <returns></returns>
        public static CleanUpInsurance CreateInsurance(InsuranceData creationData, IEnumerable <AssemblyName> assemblyNames)
        {
            var insurance = new CleanUpInsurance(creationData, assemblyNames);

            if (insurance._assemblies.Count == 0)
            {
                return(insurance);
            }
            if (creationData.Flags.IsSpecified(CleanUpInsuranceFlags.TrackByFile))
            {
                insurance.CreateFileInsurance();
            }
            if (creationData.Flags.IsSpecified(CleanUpInsuranceFlags.TrackByRegistry))
            {
                insurance.CreateRegistryInsurance();
            }
            if (creationData.Flags.IsSpecified(CleanUpInsuranceFlags.ByWatchService))
            {
                insurance.CreateWatchingProcessInsurance();
            }
            return(insurance);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of <see cref="CleanUpInsurance"/> built from the data specified.
        /// </summary>
        /// <exception cref="ArgumentException">
        /// An <see cref="ArgumentException"/> is thrown if <paramref name="insuranceFile"/> and <paramref name="insuranceRegistryKey"/> don't match.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// An <see cref="ArgumentNullException"/> is thrown if both <paramref name="insuranceFile"/> and <paramref name="insuranceRegistryKey"/> are null.
        /// </exception>
        /// <param name="insuranceFile"></param>
        /// <param name="insuranceRegistryKey"></param>
        /// <param name="insuranceProcess"></param>
        private CleanUpInsurance(InsuranceFile insuranceFile, InsuranceRegistryKey insuranceRegistryKey, Process insuranceProcess)
        {
            _insuranceFile        = insuranceFile;
            _insuranceProcess     = insuranceProcess;
            _insuranceRegistryKey = insuranceRegistryKey;
            var flags = (_insuranceFile != null ? CleanUpInsuranceFlags.TrackByFile : CleanUpInsuranceFlags.None)
                        | (_insuranceProcess != null ? CleanUpInsuranceFlags.ByWatchService : CleanUpInsuranceFlags.None)
                        | (_insuranceRegistryKey != null ? CleanUpInsuranceFlags.TrackByRegistry : CleanUpInsuranceFlags.None);
            InsuranceBase insuranceBase = null;

            if (_insuranceFile != null)
            {
                insuranceBase = _insuranceFile;
                if (_insuranceRegistryKey != null)
                {
                    if (!insuranceBase.MatchesWith(_insuranceRegistryKey, false))
                    {
                        throw new ArgumentException("The InsuranceFile and InsuranceRegistryKey don't match.", "insuranceFile");
                    }
                    insuranceBase.JoinWith(_insuranceRegistryKey);
                }
            }
            else if (_insuranceRegistryKey != null)
            {
                insuranceBase = _insuranceRegistryKey;
            }
            if (insuranceBase == null)
            {
                throw new ArgumentNullException("insuranceFile",
                                                "At least one of both insuranceFile and insuranceRegistryKey needs to be initialized.");
            }
            _assemblies = new List <AssemblyName>(insuranceBase.Assemblies);
            _timeStamp  = insuranceBase.TimeStamp;
            _uniqueId   = insuranceBase.InsuranceIdentifier;
            _data       = new InsuranceData(insuranceBase.InstallerDescription, flags,
                                            _insuranceFile != null ? Path.GetDirectoryName(_insuranceFile.FileName) : null,
                                            _insuranceRegistryKey != null ? Path.GetDirectoryName(_insuranceRegistryKey.RegistryKeyName) : null,
                                            null);
        }
 /// <summary>
 /// Creates an insurance for the <paramref name="assemblyNames"/>.
 /// The method of insuring is based on the <see cref="CleanUpInsuranceFlags"/> set in the user's configuration.
 /// </summary>
 /// <param name="creationData"></param>
 /// <param name="assemblyNames">The assemblies to insure cleanup for.</param>
 /// <returns></returns>
 public static CleanUpInsurance CreateInsurance(InsuranceData creationData, IEnumerable<AssemblyName> assemblyNames)
 {
   var insurance = new CleanUpInsurance(creationData, assemblyNames);
   if (insurance._assemblies.Count == 0)
     return insurance;
   if (creationData.Flags.IsSpecified(CleanUpInsuranceFlags.TrackByFile))
     insurance.CreateFileInsurance();
   if (creationData.Flags.IsSpecified(CleanUpInsuranceFlags.TrackByRegistry))
     insurance.CreateRegistryInsurance();
   if (creationData.Flags.IsSpecified(CleanUpInsuranceFlags.ByWatchService))
     insurance.CreateWatchingProcessInsurance();
   return insurance;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="CleanUpInsurance"/> built from the data specified.
 /// </summary>
 /// <param name="creationData"></param>
 /// <param name="assemblyNames"></param>
 private CleanUpInsurance(InsuranceData creationData, IEnumerable<AssemblyName> assemblyNames)
 {
   _data = creationData;
   _assemblies = new List<AssemblyName>(assemblyNames);
   _timeStamp = DateTime.Now;
   _uniqueId = Guid.NewGuid();
 }
 /// <summary>
 /// Initializes a new instance of <see cref="CleanUpInsurance"/> built from the data specified.
 /// </summary>
 /// <exception cref="ArgumentException">
 /// An <see cref="ArgumentException"/> is thrown if <paramref name="insuranceFile"/> and <paramref name="insuranceRegistryKey"/> don't match.
 /// </exception>
 /// <exception cref="ArgumentNullException">
 /// An <see cref="ArgumentNullException"/> is thrown if both <paramref name="insuranceFile"/> and <paramref name="insuranceRegistryKey"/> are null.
 /// </exception>
 /// <param name="insuranceFile"></param>
 /// <param name="insuranceRegistryKey"></param>
 /// <param name="insuranceProcess"></param>
 private CleanUpInsurance(InsuranceFile insuranceFile, InsuranceRegistryKey insuranceRegistryKey, Process insuranceProcess)
 {
   _insuranceFile = insuranceFile;
   _insuranceProcess = insuranceProcess;
   _insuranceRegistryKey = insuranceRegistryKey;
   var flags = (_insuranceFile != null ? CleanUpInsuranceFlags.TrackByFile : CleanUpInsuranceFlags.None)
               | (_insuranceProcess != null ? CleanUpInsuranceFlags.ByWatchService : CleanUpInsuranceFlags.None)
               | (_insuranceRegistryKey != null ? CleanUpInsuranceFlags.TrackByRegistry : CleanUpInsuranceFlags.None);
   InsuranceBase insuranceBase = null;
   if (_insuranceFile != null)
   {
     insuranceBase = _insuranceFile;
     if (_insuranceRegistryKey != null)
     {
       if (!insuranceBase.MatchesWith(_insuranceRegistryKey, false))
         throw new ArgumentException("The InsuranceFile and InsuranceRegistryKey don't match.", "insuranceFile");
       insuranceBase.JoinWith(_insuranceRegistryKey);
     }
   }
   else if (_insuranceRegistryKey != null)
     insuranceBase = _insuranceRegistryKey;
   if (insuranceBase == null)
     throw new ArgumentNullException("insuranceFile",
                                     "At least one of both insuranceFile and insuranceRegistryKey needs to be initialized.");
   _assemblies = new List<AssemblyName>(insuranceBase.Assemblies);
   _timeStamp = insuranceBase.TimeStamp;
   _uniqueId = insuranceBase.InsuranceIdentifier;
   _data = new InsuranceData(insuranceBase.InstallerDescription, flags,
                                     _insuranceFile != null ? Path.GetDirectoryName(_insuranceFile.FileName) : null,
                                     _insuranceRegistryKey != null ? Path.GetDirectoryName(_insuranceRegistryKey.RegistryKeyName) : null,
                                     null);
 }
예제 #7
0
 /// <summary>
 /// Registers the shared assemblies to the GAC.
 /// When done, <see cref="_gacRegistered"/> is set to true.
 /// </summary>
 private void RegisterAssemblies()
 {
   lock (_gacSyncRoot)
   {
     if (_gacRegistered) return;
     var assemblies = DetermineGacAssemblies();
     // First insure the removal of those assemblies.
     var insuranceData = new InsuranceData(HostCore.Configuration.Application.GacInstallerDescription,
                                           HostCore.Configuration.User.GacCleanUpInsuranceFlags,
                                           HostCore.Configuration.Application.GacCleanUpInsuranceFolder,
                                           HostCore.Configuration.Application.GacCleanUpInsuranceRegistryKey,
                                           HostCore.Configuration.Application.WatcherExecutable);
     _insurance = CleanUpInsurance.CreateInsurance(insuranceData, assemblies);
     GC.ReRegisterForFinalize(this);
     // Then install the assemblies.
     try
     {
       var cache = new AssemblyCache(insuranceData.Installer);
       foreach (var assembly in assemblies)
         cache.InstallAssembly(assembly, InstallBehaviour.Default);
     }
     catch (UnauthorizedAccessException)
     {
       _insurance.Dispose(insuranceData.Flags);
       throw;
     }
     _gacRegistered = true;
   }
 }