Ejemplo n.º 1
0
        /// <summary>
        /// Creates the LayoutSpecProvider
        /// </summary>
        /// <param name="resource">The resource name of json resource in
        /// the given assembly.</param>
        /// <param name="assembly">Assembly which contains the specified resource</param>
        public LayoutSpecProvider(ILibraryViewCustomization customization, string resource, Assembly assembly = null) : base(false)
        {
            assembly = assembly == null?Assembly.GetExecutingAssembly() : assembly;

            var stream = assembly.GetManifestResourceStream(resource);

            //Get the spec from the stream
            var spec = LayoutSpecification.FromJSONStream(stream);

            customization.AddSections(spec.sections);
            this.customization = customization;
            this.customization.SpecificationUpdated += OnSpecificationUpdate;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Notifies the SearchModel update event with list of updated elements
        /// </summary>
        /// <param name="customization">ILibraryViewCustomization to update the
        /// specification and raise specification changed event.</param>
        /// <param name="elements">List of updated elements</param>
        private static void NotifySearchModelUpdate(ILibraryViewCustomization customization, IEnumerable <NodeSearchElement> elements)
        {
            var includes = elements
                           .Select(NodeItemDataProvider.GetFullyQualifiedName)
                           .Select(name => name.Split('.').First())
                           .Distinct()
                           .SkipWhile(s => s.Contains("://"))
                           .Select(p => new LayoutIncludeInfo()
            {
                path = p
            });

            customization.AddIncludeInfo(includes, "Add-ons");
        }
Ejemplo n.º 3
0
        internal static IDisposable SetupSearchModelEventsObserver(NodeSearchModel model, IEventController controller, ILibraryViewCustomization customization, int throttleTime = 200)
        {
            customization.SpecificationUpdated += (o, e) => controller.RaiseEvent("libraryDataUpdated");

            var observer = new EventObserver <NodeSearchElement, IEnumerable <NodeSearchElement> >(
                elements => NotifySearchModelUpdate(customization, elements), CollectToList
                ).Throttle(TimeSpan.FromMilliseconds(throttleTime));

            Action <NodeSearchElement> handler = (searchElement) =>
            {
                var libraryViewController = (controller as LibraryViewController);
                if ((libraryViewController != null) && (libraryViewController.disableObserver))
                {
                    return;
                }

                observer.OnEvent(searchElement);
            };
            Action <NodeSearchElement> onRemove = e => handler(null);

            //Set up the event callback
            model.EntryAdded   += handler;
            model.EntryRemoved += onRemove;
            model.EntryUpdated += handler;

            //Set up the dispose event handler
            observer.Disposed += () =>
            {
                model.EntryAdded   -= handler;
                model.EntryRemoved -= onRemove;
                model.EntryUpdated -= handler;
            };

            return(observer);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a layoutSpecProvider with access to the IconResourceProvider
 /// so that icon urls can be replaced with base64 encoded image data.
 /// </summary>
 /// <param name="customization"></param>
 /// <param name="iconProvider"></param>
 /// <param name="resource"></param>
 /// <param name="assembly"></param>
 public LayoutSpecProvider(ILibraryViewCustomization customization, IconResourceProvider iconProvider, string resource, Assembly assembly = null) :
     this(customization, resource, assembly)
 {
     this.iconProvider = iconProvider;
 }