예제 #1
0
        void PrepareTask(ApplicationJumpTaskWrap task)
        {
            IApplicationJumpTaskInfoInternal taskInternal = task.ApplicationJumpTask;

            if (taskInternal.IsInitialized)
            {
                return;
            }
            string iconResourceName;

            if (task.ApplicationJumpTask.Icon == null)
            {
                task.IconResourcePath  = task.ApplicationJumpTask.IconResourcePath;
                task.IconResourceIndex = task.ApplicationJumpTask.IconResourceIndex;
                iconResourceName       = string.Format("{0}_{1}", task.IconResourcePath, task.IconResourceIndex);
            }
            else
            {
                if (task.ApplicationJumpTask.IconResourcePath != null)
                {
                    throw new ApplicationJumpTaskBothIconAndIconResourcePathSpecifiedException();
                }
                string iconResourcePath;
                if (!IconStorage.TryStoreIconToFile(task.ApplicationJumpTask.Icon, NativeResourceManager.ExpandVariables(IconStorageFolder), out iconResourceName, out iconResourcePath))
                {
                    throw new ApplicationJumpTaskInvalidIconException();
                }
                task.IconResourcePath  = iconResourcePath;
                task.IconResourceIndex = 0;
            }
            if (task.ApplicationJumpTask.CommandId == null)
            {
                taskInternal.SetAutoGeneratedCommandId(string.Format("{0}${1}${2}", task.ApplicationJumpTask.CustomCategory, task.ApplicationJumpTask.Title, iconResourceName));
            }
        }
예제 #2
0
        public virtual IEnumerable <RejectedApplicationJumpItem> Apply()
        {
            if (InteractionHelper.IsInDesignMode(this))
            {
                return new RejectedApplicationJumpItem[] { }
            }
            ;
            jumpActionsManager.BeginUpdate();
            try {
                foreach (JumpItem jumpItem in nativeJumpList)
                {
                    ApplicationJumpItemWrapper.FillWrapProperties(jumpItem);
                    ApplicationJumpTaskWrap jumpTask = jumpItem as ApplicationJumpTaskWrap;
                    if (jumpTask != null)
                    {
                        jumpActionsManager.RegisterAction(jumpTask, CommandLineArgumentPrefix, GetLauncherPath);
                    }
                }
                IEnumerable <Tuple <JumpItem, JumpItemRejectionReason> > nativeRejectedItems = nativeJumpList.Apply() ?? new Tuple <JumpItem, JumpItemRejectionReason>[] { };

                return(nativeRejectedItems.Select(i => new RejectedApplicationJumpItem(ApplicationJumpItemWrapper.Unwrap(i.Item1), i.Item2)).ToArray());
            } finally {
                jumpActionsManager.EndUpdate();
            }
        }
예제 #3
0
        protected virtual ApplicationJumpTaskInfo Find(string commandId)
        {
            if (InteractionHelper.IsInDesignMode(this))
            {
                return(null);
            }
            ApplicationJumpTaskWrap task = (ApplicationJumpTaskWrap)nativeJumpList.Find(commandId);

            return(task == null ? null : task.ApplicationJumpTask);
        }
        public void RegisterAction(IJumpAction jumpAction, string commandLineArgumentPrefix, Func <string> launcherPath)
        {
            if (!updating)
            {
                throw new InvalidOperationException();
            }
            Assert.IsNotNull(commandLineArgumentPrefix);
            Assert.IsNotNull(launcherPath);
            Assert.IsTrue(File.Exists(launcherPath()));
            Assert.IsNotNull(jumpAction.CommandId);
            ApplicationJumpTaskWrap applicationJumpTaskWrap = (ApplicationJumpTaskWrap)jumpAction;

            RegisteredActions.Add(applicationJumpTaskWrap.ApplicationJumpTask);
        }
        public void AddApplicationJumpTaskWithIcon_CheckIconJumpTaskIconResourcePath()
        {
            ImageSource icon = ApplicationJumpListServiceTestsImageSourceHelper.GetImageSource(
                AssemblyHelper.GetResourceUri(typeof(ApplicationJumpListServiceTests).Assembly, "Services/ApplicationJumpListService/demoicon.ico"));
            ApplicationJumpTaskInfo applicationJumpTask = applicationJumpListService.Items.Add("title", icon, () => { });

            applicationJumpListService.Apply();
            ApplicationJumpTaskWrap jumpTask = (ApplicationJumpTaskWrap)nativeJumpList.AppliedList.JumpItems.Single();

            Assert.IsNotNull(jumpTask.IconResourcePath);
            byte[] expectedIcon = StreamHelper.CopyAllBytes(
                AssemblyHelper.GetResourceStream(typeof(ApplicationJumpListServiceTests).Assembly, "Services/ApplicationJumpListService/demoicon.ico", true));
            byte[] actualIcon = File.ReadAllBytes(jumpTask.IconResourcePath);
            AssertHelper.AssertEnumerablesAreEqual(expectedIcon, actualIcon);
        }
예제 #6
0
        JumpItem PrepareItem(ApplicationJumpItemInfo item, JumpItem itemToReplace)
        {
            JumpItem itemWrap            = ApplicationJumpItemWrapper.Wrap(item);
            ApplicationJumpTaskWrap task = itemWrap as ApplicationJumpTaskWrap;

            if (task != null)
            {
                PrepareTask(task);
                JumpItem existingItem = nativeJumpList.Find(task.ApplicationJumpTask.CommandId);
                if (existingItem != null && existingItem != itemToReplace)
                {
                    throw new ApplicationJumpTaskDuplicateCommandIdException();
                }
            }
            ISupportInitialize itemInit = item;

            itemInit.EndInit();
            return(itemWrap);
        }
예제 #7
0
        public virtual bool AddOrReplace(ApplicationJumpTaskInfo jumpTask)
        {
            if (InteractionHelper.IsInDesignMode(this))
            {
                designModeItems.Add(jumpTask);
                return(true);
            }
            ApplicationJumpTaskWrap jumpTaskWrap = new ApplicationJumpTaskWrap(jumpTask);

            PrepareTask(jumpTaskWrap);
            ISupportInitialize itemInit = jumpTask;

            itemInit.EndInit();
            JumpItem existingItem = nativeJumpList.Find(jumpTask.CommandId);

            if (existingItem != null)
            {
                nativeJumpList[nativeJumpList.IndexOf(existingItem)] = jumpTaskWrap;
                return(false);
            }
            nativeJumpList.Add(jumpTaskWrap);
            return(true);
        }