private void ReadHardwareIdIndexes()
        {
            if (IsDeltaSource)
            {
                // Recursively read the indexes from all baselines
                BaselineSource.ReadHardwareIdIndexes();
            }

            // Build a reverse lookup from metadata index to update index
            if (DriverToMetadataMap == null)
            {
                DriverToMetadataMap = DeserializeIndexFromArchive <Dictionary <int, KeyValuePair <int, int> > >(DriverToMetadataMapEntryName);

                MetadataToDriverMap = new Dictionary <int, int>();
                foreach (var driverEntry in DriverToMetadataMap)
                {
                    var metadataCount      = driverEntry.Value.Value;
                    var metadataStartIndex = driverEntry.Value.Key;
                    for (int i = 0; i < metadataCount; i++)
                    {
                        MetadataToDriverMap.Add(metadataStartIndex + i, driverEntry.Key);
                    }
                }
            }

            HardwareIdMap = DeserializeIndexFromArchive <Dictionary <string, List <int> > >(HardwareIdIndexEntryName);
            MetadataToComputerHardwareIdMap = DeserializeIndexFromArchive <Dictionary <int, List <Guid> > >(ComputerHardwareIdIndexEntryName);

            DriverVersionIndex      = DeserializeIndexFromArchive <Dictionary <int, DriverVersion> >(DriverVersionIndexEntryName);
            DriverFeatureScoreIndex = DeserializeIndexFromArchive <Dictionary <int, List <DriverFeatureScore> > >(DriverFeatureScoreIndexEntryName);
        }
        private string GetUpdateTitle(int updateIndex)
        {
            lock (this)
            {
                // lazy load the titles index
                if (UpdateTitlesIndex == null)
                {
                    ReadTitlesIndex();
                }
            }

            string title;

            if (UpdateTitlesIndex.TryGetValue(updateIndex, out title))
            {
                return(title);
            }
            else if (IsDeltaSource)
            {
                title = BaselineSource.GetUpdateTitle(updateIndex);
            }
            else
            {
                throw new Exception($"Update title for {IndexToIdentity[updateIndex]} was not found");
            }

            return(title);
        }
 private int GetDriverIndex(int metadataIndex)
 {
     if (MetadataToDriverMap.TryGetValue(metadataIndex, out int driverIndex))
     {
         return(driverIndex);
     }
     else if (IsDeltaSource)
     {
         return(BaselineSource.GetDriverIndex(metadataIndex));
     }
     else
     {
         throw new IndexOutOfRangeException("Driver metadata index cannot be found");
     }
 }
 private bool HasFeatureScores(int metadataIndex)
 {
     if (DriverFeatureScoreIndex.ContainsKey(metadataIndex))
     {
         return(true);
     }
     else if (IsDeltaSource)
     {
         return(BaselineSource.HasFeatureScores(metadataIndex));
     }
     else
     {
         return(false);
     }
 }
 private DriverVersion GetDriverVersion(int metadataIndex)
 {
     if (DriverVersionIndex.TryGetValue(metadataIndex, out DriverVersion version))
     {
         return(version);
     }
     else if (IsDeltaSource)
     {
         return(BaselineSource.GetDriverVersion(metadataIndex));
     }
     else
     {
         throw new IndexOutOfRangeException("Driver version index cannot be found");
     }
 }
 private List <Guid> GetComputerHardwareIds(int metadataIndex)
 {
     if (MetadataToComputerHardwareIdMap.TryGetValue(metadataIndex, out List <Guid> computerHardwareIds))
     {
         return(computerHardwareIds);
     }
     else if (IsDeltaSource)
     {
         return(BaselineSource.GetComputerHardwareIds(metadataIndex));
     }
     else
     {
         throw new IndexOutOfRangeException("Driver version index cannot be found");
     }
 }
 private List <DriverFeatureScore> GetFeatureScores(int metadataIndex)
 {
     if (DriverFeatureScoreIndex.TryGetValue(metadataIndex, out List <DriverFeatureScore> featureScores))
     {
         return(featureScores);
     }
     else if (IsDeltaSource)
     {
         return(BaselineSource.GetFeatureScores(metadataIndex));
     }
     else
     {
         throw new IndexOutOfRangeException("Driver version index cannot be found");
     }
 }
 private bool HasComputerHardwareIds(int metadataIndex)
 {
     if (MetadataToComputerHardwareIdMap.ContainsKey(metadataIndex))
     {
         return(true);
     }
     else if (IsDeltaSource)
     {
         return(BaselineSource.HasComputerHardwareIds(metadataIndex));
     }
     else
     {
         return(false);
     }
 }
 private bool IsBundle(int updateIndex)
 {
     EnsureBundlesIndexLoaded();
     if (BundlesIndex.ContainsKey(updateIndex))
     {
         return(true);
     }
     else if (IsInBaseline(updateIndex))
     {
         return(BaselineSource.IsBundle(updateIndex));
     }
     else
     {
         return(false);
     }
 }
Пример #10
0
        private List <Prerequisite> GetPrerequisites(int updateIndex)
        {
            EnsurePrerequisitesIndexLoaded();

            if (PrerequisitesIndex.ContainsKey(updateIndex))
            {
                return(PrerequisitesIndex[updateIndex]);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.GetPrerequisites(updateIndex));
            }
            else
            {
                throw new Exception("The update does not have prerequisites");
            }
        }
Пример #11
0
        private bool HasPrerequisites(int updateIndex)
        {
            EnsurePrerequisitesIndexLoaded();

            if (PrerequisitesIndex.ContainsKey(updateIndex))
            {
                return(true);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.HasPrerequisites(updateIndex));
            }
            else
            {
                return(false);
            }
        }
Пример #12
0
        private List <Guid> GetUpdateClassificationIds(int updateIndex)
        {
            EnsureProductClassificationIndexLoaded();

            if (UpdateAndClassificationIndex.ContainsKey(updateIndex))
            {
                return(UpdateAndClassificationIndex[updateIndex]);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.GetUpdateClassificationIds(updateIndex));
            }
            else
            {
                throw new Exception($"Update {this[updateIndex]} does not have classifications");
            }
        }
Пример #13
0
        private bool HasClassification(int updateIndex)
        {
            EnsureProductClassificationIndexLoaded();

            if (UpdateAndClassificationIndex.ContainsKey(updateIndex))
            {
                return(true);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.HasClassification(updateIndex));
            }
            else
            {
                return(false);
            }
        }
        private IEnumerable <Identity> GetBundledUpdates(int updateIndex)
        {
            EnsureBundlesIndexLoaded();

            if (BundlesIndex.TryGetValue(updateIndex, out var result))
            {
                return(result.Select(index => this[index]));
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.GetBundledUpdates(updateIndex));
            }
            else
            {
                throw new Exception($"Update {this[updateIndex]} is not a bundle");
            }
        }
        private List <int> IsBundled(int updateIndex)
        {
            EnsureBundlesIndexLoaded();

            if (IsBundledTable.ContainsKey(updateIndex))
            {
                return(IsBundledTable[updateIndex]);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.IsBundled(updateIndex));
            }
            else
            {
                throw new Exception($"Cannot find bundling information for update {this[updateIndex]}");
            }
        }
Пример #16
0
        /// <summary>
        /// Deletes the temporary directory that contains XML metadata
        /// </summary>
        public void Dispose()
        {
            if (OutputFile != null)
            {
                WriteIndex();
                OutputFile.Finish();
                OutputFile.Close();
                OutputFile = null;
            }
            else if (InputFile != null)
            {
                InputFile.Close();
                InputFile = null;
            }

            if (IsDeltaSource && BaselineSource != null)
            {
                BaselineSource.Dispose();
                BaselineSource = null;
            }
        }
Пример #17
0
        /// <summary>
        /// Returns a stream over the update XML metadata
        /// </summary>
        /// <param name="updateId">The update ID to get XML metadata for</param>
        /// <returns>Stream of the XML metadata</returns>
        public Stream GetUpdateMetadataStream(Metadata.Identity updateId)
        {
            if (InputFile == null)
            {
                throw new Exception("Query result is not in read mode");
            }

            if (IsDeltaSource && BaselineIdentities.Contains(updateId))
            {
                return(BaselineSource.GetUpdateMetadataStream(updateId));
            }
            else
            {
                var entryIndex = InputFile.FindEntry(GetUpdateXmlPath(updateId), true);
                if (entryIndex < 0)
                {
                    throw new KeyNotFoundException();
                }

                return(InputFile.GetInputStream(entryIndex));
            }
        }
        private string GetKbArticle(int updateIndex)
        {
            lock (this)
            {
                if (KbArticleIndex == null)
                {
                    ReadKbArticleIndex();
                }
            }

            if (KbArticleIndex.TryGetValue(updateIndex, out string title))
            {
                return(title);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.GetKbArticle(updateIndex));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Checks if the metadata source contains URL information for a file identified by its content checksum
        /// </summary>
        /// <param name="checksum">The file contents checksum</param>
        /// <returns>True if the store contains file URL information, false otherwise</returns>
        public bool HasFile(string checksum)
        {
            lock (this)
            {
                if (Files == null)
                {
                    ReadFilesIndex();
                }
            }

            if (Files.TryGetValue(checksum, out UpdateFileUrl fileUrl))
            {
                return(true);
            }
            else if (IsDeltaSource)
            {
                return(BaselineSource.HasFile(checksum));
            }
            else
            {
                return(false);
            }
        }
        private List <UpdateFile> GetFiles(int updateIndex)
        {
            lock (this)
            {
                if (UpdateFilesIndex == null)
                {
                    ReadUpdateFilesIndex();
                }
            }

            if (UpdateFilesIndex.TryGetValue(updateIndex, out List <UpdateFile> files))
            {
                return(files);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.GetFiles(updateIndex));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Retrieves url information for a file
        /// </summary>
        /// <param name="checksum">The file checksum</param>
        /// <returns>Update URL information</returns>
        public UpdateFileUrl GetFile(string checksum)
        {
            lock (this)
            {
                if (Files == null)
                {
                    ReadFilesIndex();
                }
            }

            if (Files.TryGetValue(checksum, out UpdateFileUrl fileUrl))
            {
                return(fileUrl);
            }
            else if (IsDeltaSource)
            {
                return(BaselineSource.GetFile(checksum));
            }
            else
            {
                throw new Exception($"The metadata source does not contain a file entry with checksum {checksum}");
            }
        }
        /// <summary>
        /// Gets driver metadata entries that match the specified HW ID. This method is recursive across all delta baselines.
        /// </summary>
        /// <param name="hardwareId">Device hardware id</param>
        /// <returns>List of driver metadata indexes that match the device hardware id</returns>
        private List <int> GetDriverMetadataForHardwareId(string hardwareId)
        {
            lock (this)
            {
                if (HardwareIdMap == null)
                {
                    ReadHardwareIdIndexes();
                }
            }

            List <int> matchedDriverMetadataIndexes = new List <int>();

            if (HardwareIdMap.ContainsKey(hardwareId))
            {
                matchedDriverMetadataIndexes.AddRange(HardwareIdMap[hardwareId]);
            }

            if (IsDeltaSource)
            {
                matchedDriverMetadataIndexes.AddRange(BaselineSource.GetDriverMetadataForHardwareId(hardwareId));
            }

            return(matchedDriverMetadataIndexes);
        }
        /// <summary>
        /// Checks if an update has been superseded, and if yes, returns the index of the update that superseded it
        /// </summary>
        /// <param name="updateIdentity">Update identity to check if superseded</param>
        /// <returns>-1 if the update was not superseded, index of superseding update otherwise</returns>
        int GetSupersedingUpdateIndex(Identity updateIdentity)
        {
            lock (this)
            {
                // lazy load the superseded index
                if (SupersededUpdates == null)
                {
                    ReadSupersededIndex();
                }
            }

            if (SupersededUpdates.TryGetValue(updateIdentity.ID, out int supersedingIndex))
            {
                return(supersedingIndex);
            }
            else if (IsDeltaSource)
            {
                return(BaselineSource.GetSupersedingUpdateIndex(updateIdentity));
            }
            else
            {
                return(-1);
            }
        }
        IReadOnlyList <Guid> GetSupersededUpdates(int updateIndex)
        {
            lock (this)
            {
                // lazy load the superseded index
                if (SupersedingUpdates == null)
                {
                    ReadSupersedingIndex();
                }
            }

            if (SupersedingUpdates.TryGetValue(updateIndex, out List <Guid> supersededList))
            {
                return(supersededList);
            }
            else if (IsInBaseline(updateIndex))
            {
                return(BaselineSource.GetSupersededUpdates(updateIndex));
            }
            else
            {
                return(null);
            }
        }