internal void OnSerializingMethod(StreamingContext context)
        {
            ComputeChecksum();

            if (IsDeltaSource)
            {
                // Do not save identities that are present in the baseline
                IdentityAndIndexList = IndexToIdentity.Where(p => !IsInBaseline(p.Key)).ToList();

                for (int i = 0; i <= BaselineIndexesEnd; i++)
                {
                    UpdateAndProductIndex.Remove(i);
                    UpdateAndClassificationIndex.Remove(i);
                }

                foreach (var typeEntry in BaselineSource.UpdateTypeMap)
                {
                    if (UpdateTypeMap.ContainsKey(typeEntry.Key))
                    {
                        UpdateTypeMap.Remove(typeEntry.Key);
                    }
                }
            }
            else
            {
                IdentityAndIndexList = IndexToIdentity.ToList();
            }
        }
Exemplo n.º 2
0
        private int AddUpdateEntry(Update update, XDocument updateXmlDoc)
        {
            var newUpdateIndex = Identities.Count;

            Identities.Add(update.Identity);

            IdentityToIndex.Add(update.Identity, newUpdateIndex);
            IndexToIdentity.Add(newUpdateIndex, update.Identity);

            if (update is Detectoid)
            {
                UpdateTypeMap.Add(newUpdateIndex, (uint)UpdateType.Detectoid);
                Categories.TryAdd(update.Identity, update);
            }
            else if (update is Classification)
            {
                UpdateTypeMap.Add(newUpdateIndex, (uint)UpdateType.Classification);
                Categories.TryAdd(update.Identity, update);
            }
            else if (update is Product)
            {
                UpdateTypeMap.Add(newUpdateIndex, (uint)UpdateType.Product);
                Categories.TryAdd(update.Identity, update);
            }
            else if (update is SoftwareUpdate)
            {
                UpdateTypeMap.Add(newUpdateIndex, (uint)UpdateType.Software);
                Updates.TryAdd(update.Identity, update);
            }
            else if (update is DriverUpdate)
            {
                UpdateTypeMap.Add(newUpdateIndex, (uint)UpdateType.Driver);
                Updates.TryAdd(update.Identity, update);
            }

            ExtractAndIndexTitle(newUpdateIndex, updateXmlDoc);

            AddedUpdates.Add(newUpdateIndex, update);

            AddUpdateBundleInformation(newUpdateIndex, update.Identity, updateXmlDoc);
            AddPrerequisiteInformation(newUpdateIndex, update.Identity, updateXmlDoc);
            AddUpdateFileInformationToIndex(newUpdateIndex, update.Identity, updateXmlDoc);
            ExtractSupersedingInformation(newUpdateIndex, update.Identity, updateXmlDoc);

            if (update is DriverUpdate)
            {
                ExtractAndIndexDriverMetadata(newUpdateIndex, updateXmlDoc);
            }

            ExtractAndIndexKbArticle(newUpdateIndex, updateXmlDoc, update);

            return(newUpdateIndex);
        }
        internal void OnDeserialized()
        {
            if (!IsDeltaSource)
            {
                // There is no baseline, so the index end is -1; all indexes will be considered in the delta
                BaselineIndexesEnd = -1;
                BaselineIdentities = new SortedSet <Identity>();

                // Rebuild index to identity and identity to index from the flat list
                IndexToIdentity = IdentityAndIndexList.ToDictionary(p => p.Key, p => p.Value);
                IdentityToIndex = IdentityAndIndexList.ToDictionary(p => p.Value, p => p.Key);
            }
            else
            {
                ValidateBaseline();

                // Merge baseline with delta indexes to create a complete index
                IdentityAndIndexList.AddRange(BaselineSource.IdentityAndIndexList);

                // Rebuild index to identity and identity to index from the flat list
                IndexToIdentity = IdentityAndIndexList.ToDictionary(p => p.Key, p => p.Value);
                IdentityToIndex = IdentityAndIndexList.ToDictionary(p => p.Value, p => p.Key);

                // Unlike BaselineIndexes, BaselineIdentities is not serialized to save space. Build it from BaselineIndexes
                BaselineIdentities = new SortedSet <Identity>(IndexToIdentity.Where(p => IsInBaseline(p.Key)).Select(p => p.Value));

                foreach (var typeEntry in BaselineSource.UpdateTypeMap)
                {
                    UpdateTypeMap.Add(typeEntry.Key, typeEntry.Value);
                }
            }

            Identities = new SortedSet <Identity>(IdentityToIndex.Keys);

            Updates    = new ConcurrentDictionary <Identity, Update>();
            Categories = new ConcurrentDictionary <Identity, Update>();

            // Create update placeholders
            InstantiateUpdatePlaceholders();

            // Populate indexes
            UpdatesIndex         = Updates;
            CategoriesIndex      = Categories;
            ProductsIndex        = Categories.Values.OfType <Product>().ToDictionary(p => p.Identity);
            ClassificationsIndex = Categories.Values.OfType <Classification>().ToDictionary(c => c.Identity);
            DetectoidsIndex      = Categories.Values.OfType <Detectoid>().ToDictionary(d => d.Identity);
        }