示例#1
0
        public void TestDispatchFunc()
        {
            var sub1Orig = new Sub1();
            var sub2Orig = new Sub2();

            var dispatcher = new PerTypeDispatcher<Base, Base>(false)
            {
                (Sub1 sub1) => sub1,
                (Sub2 sub2) => sub2
            };

            dispatcher.Dispatch(sub1Orig).Should().BeSameAs(sub1Orig);
            dispatcher.Dispatch(sub2Orig).Should().BeSameAs(sub2Orig);
        }
示例#2
0
        public void TestDispatchAction()
        {
            var sub1Orig = new Sub1();
            Sub1 sub1Dispatched = null;
            var sub2Orig = new Sub2();
            Sub2 sub2Dispatched = null;

            var dispatcher = new PerTypeDispatcher<Base>(false)
            {
                (Sub1 sub1) => sub1Dispatched = sub1,
                (Sub2 sub2) => sub2Dispatched = sub2
            };

            dispatcher.Dispatch(sub1Orig);
            sub1Dispatched.Should().BeSameAs(sub1Orig);

            dispatcher.Dispatch(sub2Orig);
            sub2Dispatched.Should().BeSameAs(sub2Orig);
        }
示例#3
0
        /// <summary>
        /// Adds the selection highlighting for a <see cref="EntityBase{TCoordinates,TTemplate}"/>
        /// </summary>
        /// <param name="entity">The <see cref="EntityBase{TCoordinates,TTemplate}"/> to add the selection highlighting for</param>
        private Model GetSelectionHighlighting(Entity entity)
        {
            if (entity.TemplateData.Collision == null)
            {
                return(null);
            }

            var selectionHighlight = new PerTypeDispatcher <Collision <Vector2>, Model>(ignoreMissing: true)
            {
                (Circle circle) =>
                {
                    // Create a circle around the entity based on the radius
                    var   hightlight = new Model(XMesh.Get(Engine, "Engine/Circle.x"));
                    float scale      = circle.Radius / 20 + 1;
                    hightlight.PreTransform = Matrix.Scaling(scale, 1, scale);
                    return(hightlight);
                },
                (Box box) =>
                {
                    // Create a rectangle around the entity based on the box corners
                    var highlight = new Model(XMesh.Get(Engine, "Engine/Rectangle.x"));

                    // Determine the component-wise minimums and maxmimums and the absolute difference
                    var min = new Vector2(
                        Math.Min(box.Minimum.X, box.Maximum.X),
                        Math.Min(box.Minimum.Y, box.Maximum.Y));
                    var max = new Vector2(
                        Math.Max(box.Minimum.X, box.Maximum.X),
                        Math.Max(box.Minimum.Y, box.Maximum.Y));
                    var diff = max - min;

                    highlight.PreTransform = Matrix.Scaling(diff.X, 1, diff.Y) * Matrix.Translation(min.X, 0, -min.Y);
                    return(highlight);
                }
            }.Dispatch(entity.TemplateData.Collision);

            if (selectionHighlight != null)
            {
                selectionHighlight.Name = entity.Name + " Selection";
            }
            return(selectionHighlight);
        }
        /// <summary>
        /// Reads the <see cref="DefaultCapability"/>s from <see cref="Store.Model.Feed.CapabilityLists"/> and creates a coressponding model for turning <see cref="AccessPoints.DefaultAccessPoint"/> on and off.
        /// </summary>
        private void LoadDefaultAccessPoints()
        {
            var dispatcher = new PerTypeDispatcher <Capability>(ignoreMissing: true)
            {
                (FileType fileType) =>
                {
                    var model = new FileTypeModel(fileType, IsCapabillityUsed <AccessPoints.FileType>(fileType));
                    FileTypes.Add(model);
                    _capabilityModels.Add(model);
                },
                (UrlProtocol urlProtocol) =>
                {
                    var model = new UrlProtocolModel(urlProtocol, IsCapabillityUsed <AccessPoints.UrlProtocol>(urlProtocol));
                    UrlProtocols.Add(model);
                    _capabilityModels.Add(model);
                },
                (AutoPlay autoPlay) =>
                {
                    var model = new AutoPlayModel(autoPlay, IsCapabillityUsed <AccessPoints.AutoPlay>(autoPlay));
                    AutoPlay.Add(model);
                    _capabilityModels.Add(model);
                },
                (ContextMenu contextMenu) =>
                {
                    var model = new ContextMenuModel(contextMenu, IsCapabillityUsed <AccessPoints.ContextMenu>(contextMenu));
                    ContextMenu.Add(model);
                    _capabilityModels.Add(model);
                }
            };

            if (_integrationManager.MachineWide)
            {
                dispatcher.Add((DefaultProgram defaultProgram) =>
                {
                    var model = new DefaultProgramModel(defaultProgram, IsCapabillityUsed <AccessPoints.DefaultProgram>(defaultProgram));
                    DefaultProgram.Add(model);
                    _capabilityModels.Add(model);
                });
            }

            dispatcher.Dispatch(AppEntry.CapabilityLists.CompatibleCapabilities());
        }
示例#5
0
        /// <inheritdoc/>
        public override void Apply(AppEntry appEntry, Feed feed, ITaskHandler handler, bool machineWide)
        {
            #region Sanity checks
            if (appEntry == null)
            {
                throw new ArgumentNullException(nameof(appEntry));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            var capabilities = appEntry.CapabilityLists.CompatibleCapabilities().ToList();
            var target       = new FeedTarget(appEntry.InterfaceUri, feed);

            var dispatcher = new PerTypeDispatcher <Capability>(ignoreMissing: true);
            if (WindowsUtils.IsWindows)
            {
                dispatcher.Add((Store.Model.Capabilities.FileType fileType) => Windows.FileType.Register(target, fileType, machineWide, handler));
                dispatcher.Add((Store.Model.Capabilities.UrlProtocol urlProtocol) => Windows.UrlProtocol.Register(target, urlProtocol, machineWide, handler));
                dispatcher.Add((Store.Model.Capabilities.AutoPlay autoPlay) => Windows.AutoPlay.Register(target, autoPlay, machineWide, handler));
                dispatcher.Add((ComServer comServer) => Windows.ComServer.Register(target, comServer, machineWide, handler));
                if (machineWide || WindowsUtils.IsWindows8)
                {
                    dispatcher.Add((AppRegistration appRegistration) => Windows.AppRegistration.Register(target, appRegistration, capabilities.OfType <VerbCapability>(), machineWide, handler));
                }
                if (machineWide)
                {
                    dispatcher.Add((Store.Model.Capabilities.DefaultProgram defaultProgram) => Windows.DefaultProgram.Register(target, defaultProgram, handler));
                }
            }
            else if (UnixUtils.IsUnix)
            {
                dispatcher.Add((Store.Model.Capabilities.FileType fileType) => Unix.FileType.Register(target, fileType, machineWide, handler));
                dispatcher.Add((Store.Model.Capabilities.UrlProtocol urlProtocol) => Unix.UrlProtocol.Register(target, urlProtocol, machineWide, handler));
                dispatcher.Add((Store.Model.Capabilities.DefaultProgram defaultProgram) => Unix.DefaultProgram.Register(target, defaultProgram, machineWide, handler));
            }

            dispatcher.Dispatch(capabilities);
        }