Beispiel #1
0
        internal ContentController(IMetadataSource metadataSource, IUpdateContentSource contentSource, MetadataFilter filter)
        {
            MetadataSource = metadataSource;
            ContentSource  = contentSource;

            var updatesWithFiles = MetadataSource.GetUpdates(filter).Where(u => u.HasFiles);

            UpdateFiles = updatesWithFiles.SelectMany(u => u.Files).Distinct().ToDictionary(
                f => $"{f.GetContentDirectoryName().ToLower()}/{f.Digests[0].HexString.ToLower() + System.IO.Path.GetExtension(f.FileName).ToLower()}");
        }
Beispiel #2
0
        /// <summary>
        /// Instantiate the server and serve updates from the local repo
        /// </summary>
        /// <param name="metadataSource">The update metadata source to serve updates from</param>
        /// <param name="filter">The filter for which updates to serve.</param>
        /// <param name="serviceConfig">Service configuration.</param>
        public ServerSyncWebService(IMetadataSource metadataSource, MetadataFilter filter, ServerSyncConfigData serviceConfig)
        {
            MetadataSource       = metadataSource;
            ServiceConfiguration = serviceConfig;

            UpdatesFilter = filter;

            Categories      = metadataSource.GetCategories();
            FilteredUpdates = metadataSource.GetUpdates(filter).ToDictionary(u => u.Identity);

            // If an update contains bundled updates, those bundled updates must also be made available to downstream servers
            var bundledUpdates = FilteredUpdates.Values.Where(u => u.IsBundle).SelectMany(u => u.BundledUpdates).Distinct().ToList();

            foreach (var bundledUpdateId in bundledUpdates)
            {
                if (!FilteredUpdates.ContainsKey(bundledUpdateId))
                {
                    FilteredUpdates.Add(bundledUpdateId, metadataSource.GetUpdate(bundledUpdateId));
                }
            }

            // Build the lookup tables by products and classifications
            ProductsIndex        = new Dictionary <Guid, List <Update> >();
            ClassificationsIndex = new Dictionary <Guid, List <Update> >();

            foreach (var update in FilteredUpdates.Values)
            {
                if (update.HasProduct)
                {
                    foreach (var productId in update.ProductIds)
                    {
                        if (!ProductsIndex.ContainsKey(productId))
                        {
                            ProductsIndex[productId] = new List <Update>();
                        }

                        ProductsIndex[productId].Add(update);
                    }
                }

                if (update.HasClassification)
                {
                    foreach (var classificationId in update.ClassificationIds)
                    {
                        if (!ClassificationsIndex.ContainsKey(classificationId))
                        {
                            ClassificationsIndex[classificationId] = new List <Update>();
                        }

                        ClassificationsIndex[classificationId].Add(update);
                    }
                }
            }
        }
        /// <summary>
        /// Create a content controller from the specified metadata and update content sources.
        /// </summary>
        /// <param name="metadataSource">The source of update metadata. Used to build the list of known files to serve.</param>
        /// <param name="contentSource">The source of content. Used to read update content and send it to clients.</param>
        public ClientSyncContentController(IMetadataSource metadataSource, IUpdateContentSource contentSource)
        {
            ContentSource = contentSource;

            var updatesWithFiles = metadataSource.GetUpdates().Where(u => u.HasFiles).ToList();

            UpdateFiles = updatesWithFiles.SelectMany(u => u.Files).GroupBy(f => f.Digests[0].DigestBase64).Select(g => g.First()).ToDictionary(
                f => {
                // TODO: fix; hack; this is an internal implementation detail; must be exposed from server-server-sync library
                byte[] hashBytes = Convert.FromBase64String(f.Digests[0].DigestBase64);
                var cachedContentDirectoryName = string.Format("{0:X}", hashBytes.Last());

                return($"{cachedContentDirectoryName.ToLower()}/{f.Digests[0].HexString.ToLower()}");
            });
        }
Beispiel #4
0
        /// <summary>
        /// Print updates from the store
        /// </summary>
        /// <param name="options">Print options, including filters</param>
        public void PrintUpdates(QueryMetadataOptions options)
        {
            var filter = FilterBuilder.MetadataFilterFromCommandLine(options as IMetadataFilterOptions);

            if (filter == null)
            {
                return;
            }

            filter.FirstX = options.FirstX;

            // Apply filters specified on the command line
            List <Update> filteredUpdates;

            if (options.Classifications || options.Products || options.Detectoids)
            {
                filteredUpdates = MetadataSource.GetCategories(filter);
                if (!options.Classifications)
                {
                    filteredUpdates.RemoveAll(u => u is Classification);
                }

                if (!options.Products)
                {
                    filteredUpdates.RemoveAll(u => u is Product);
                }

                if (!options.Detectoids)
                {
                    filteredUpdates.RemoveAll(u => u is Detectoid);
                }
            }
            else if (options.Updates || options.Drivers)
            {
                filteredUpdates = MetadataSource.GetUpdates(filter);

                if (options.Drivers)
                {
                    filteredUpdates.RemoveAll(u => !(u is DriverUpdate));
                }
            }
            else
            {
                filteredUpdates = new List <Update>();
            }

            if (filteredUpdates.Count == 0)
            {
                Console.WriteLine("No data found");
            }
            else
            {
                Console.Write("\r\nQuery results:\r\n-----------------------------");

                if (!options.CountOnly)
                {
                    foreach (var update in filteredUpdates)
                    {
                        PrintUpdateMetadata(update, MetadataSource);
                    }
                }

                Console.WriteLine("-----------------------------\r\nMatched {0} entries", filteredUpdates.Count);
            }
        }