Esempio n. 1
0
 /// <summary>
 /// Joins the data specified in <paramref name="otherInsurance"/> with the current <see cref="InsuranceBase"/>.
 /// In essence this means that the list of assemblies specified in the current instance is joined with those specified in <paramref name="otherInsurance"/>.
 /// </summary>
 /// <exception cref="ArgumentException">
 /// An <see cref="ArgumentException"/> is thrown if <paramref name="otherInsurance"/> doesn't match the current instance.
 /// Whether or not they match can be determined with the <see cref="MatchesWith"/> method.
 /// </exception>
 /// <exception cref="ArgumentNullException"></exception>
 /// <param name="otherInsurance">The <see cref="InsuranceBase"/> to join with the current instance.</param>
 public virtual void JoinWith(InsuranceBase otherInsurance)
 {
     if (otherInsurance == null)
     {
         throw new ArgumentNullException("otherInsurance");
     }
     if (_machineId != otherInsurance._machineId)
     {
         throw new ArgumentException();
     }
     if (_dateTime != otherInsurance._dateTime)
     {
         throw new ArgumentException();
     }
     foreach (var item in otherInsurance._assemblies)
     {
         // Can't use _assemblies.Contains() because AssemblyName.Equals() is inherited from Object
         bool contains = false;
         foreach (var assembly in _assemblies)
         {
             if (assembly.FullName == item.FullName)
             {
                 contains = true;
                 break;
             }
         }
         if (!contains)
         {
             _assemblies.Add(item);
         }
     }
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
 /// <summary>
 /// Determines if the data specified in <paramref name="otherInsurance"/> matches with the current <see cref="InsuranceBase"/>.
 /// </summary>
 /// <remarks>
 /// The data of matching <see cref="InsuranceBase"/> instances can be joined by calling <see cref="JoinWith"/> on one of the instances.
 /// </remarks>
 /// <param name="otherInsurance"><see cref="InsuranceBase"/> to determine matchability for.</param>
 /// <param name="includeAssemblies">Whether to also verify if <paramref name="otherInsurance"/> also specifies the same insured assemblies.</param>
 public virtual bool MatchesWith(InsuranceBase otherInsurance, bool includeAssemblies)
 {
     if (otherInsurance == null ||
         _insuranceId != otherInsurance._insuranceId ||
         _machineId != otherInsurance._machineId ||
         _dateTime != otherInsurance._dateTime)
     {
         return(false);
     }
     if (!includeAssemblies)
     {
         return(true);
     }
     if (_assemblies.Count != otherInsurance._assemblies.Count)
     {
         return(false);
     }
     foreach (var item in otherInsurance._assemblies)
     {
         // Can't use _assemblies.Contains() because AssemblyName.Equals() is inherited from Object
         bool contains = false;
         foreach (var assembly in _assemblies)
         {
             if (assembly.FullName == item.FullName)
             {
                 contains = true;
                 break;
             }
         }
         if (!contains)
         {
             return(false);
         }
     }
     return(true);
 }
 /// <summary>
 /// Determines if the data specified in <paramref name="otherInsurance"/> matches with the current <see cref="InsuranceBase"/>.
 /// </summary>
 /// <remarks>
 /// The data of matching <see cref="InsuranceBase"/> instances can be joined by calling <see cref="JoinWith"/> on one of the instances.
 /// </remarks>
 /// <param name="otherInsurance"><see cref="InsuranceBase"/> to determine matchability for.</param>
 /// <param name="includeAssemblies">Whether to also verify if <paramref name="otherInsurance"/> also specifies the same insured assemblies.</param>
 public virtual bool MatchesWith(InsuranceBase otherInsurance, bool includeAssemblies)
 {
   if (otherInsurance == null
       || _insuranceId != otherInsurance._insuranceId
       || _machineId != otherInsurance._machineId
       || _dateTime != otherInsurance._dateTime)
     return false;
   if (!includeAssemblies)
     return true;
   if (_assemblies.Count != otherInsurance._assemblies.Count)
     return false;
   foreach (var item in otherInsurance._assemblies)
   {
     // Can't use _assemblies.Contains() because AssemblyName.Equals() is inherited from Object
     bool contains = false;
     foreach (var assembly in _assemblies)
     {
       if (assembly.FullName == item.FullName)
       {
         contains = true;
         break;
       }
     }
     if (!contains)
       return false;
   }
   return true;
 }
 /// <summary>
 /// Joins the data specified in <paramref name="otherInsurance"/> with the current <see cref="InsuranceBase"/>.
 /// In essence this means that the list of assemblies specified in the current instance is joined with those specified in <paramref name="otherInsurance"/>.
 /// </summary>
 /// <exception cref="ArgumentException">
 /// An <see cref="ArgumentException"/> is thrown if <paramref name="otherInsurance"/> doesn't match the current instance.
 /// Whether or not they match can be determined with the <see cref="MatchesWith"/> method.
 /// </exception>
 /// <exception cref="ArgumentNullException"></exception>
 /// <param name="otherInsurance">The <see cref="InsuranceBase"/> to join with the current instance.</param>
 public virtual void JoinWith(InsuranceBase otherInsurance)
 {
   if (otherInsurance == null)
     throw new ArgumentNullException("otherInsurance");
   if (_machineId != otherInsurance._machineId)
     throw new ArgumentException();
   if (_dateTime != otherInsurance._dateTime)
     throw new ArgumentException();
   foreach (var item in otherInsurance._assemblies)
   {
     // Can't use _assemblies.Contains() because AssemblyName.Equals() is inherited from Object
     bool contains = false;
     foreach (var assembly in _assemblies)
     {
       if (assembly.FullName == item.FullName)
       {
         contains = true;
         break;
       }
     }
     if (!contains)
       _assemblies.Add(item);
   }
 }