コード例 #1
0
        public void AddModel(IShellPresentationModel model)
        {
            ApplicationBar applicationBar = new ApplicationBar();

            applicationBar.DataContext             = model;
            applicationBar.ActionMenuItemSelected += ActionMenuItemSelectedEventHandler;
            applicationBar.StartMenuItemExecuted  += StartMenuItemExecutedEventHandler;

            NavigationPane pane = new NavigationPane();

            pane.Title   = model.Module.Title;
            pane.Content = applicationBar;
            pane.Name    = model.Module.Id;
            pane.Tag     = model.Module;

            if (model.Module.Icon != null)
            {
                Rect          rect          = new Rect(0, 0, 24, 24);
                DrawingVisual drawingVisual = new DrawingVisual();

                using (DrawingContext drawingContext = drawingVisual.RenderOpen())
                {
                    drawingContext.DrawImage(model.Module.Icon, rect);
                }

                RenderTargetBitmap bitmap = new RenderTargetBitmap((int)rect.Width, (int)rect.Height, 96, 96, PixelFormats.Default);
                bitmap.Render(drawingVisual);

                pane.ImageSourceLarge = bitmap;
                pane.ImageSourceSmall = model.Module.Icon;
            }

            navigationBar.Items.Add(pane);
        }
コード例 #2
0
        private void ActivateModule(IShellModule module)
        {
            if (_activeModule != module)
            {
                _activeModule = module;

                EventHandler <DataEventArgs <IShellModule> > temp = ModuleActivating;

                if (temp != null)
                {
                    temp(this, new DataEventArgs <IShellModule>(_activeModule));
                }

                IShellPresentationModel model = GetPresentationModel(_activeModule);

                if (!model.IsInitialized)
                {
                    InitializeModel(model);
                }
                else
                {
                    OnModuleActivated();
                }
            }
        }
コード例 #3
0
        private void InitializeModel(IShellPresentationModel model)
        {
            model.IsInitialized    = true;
            model.StartMenuTopItem = new ShellDrillDownMenuItem()
            {
                Caption = StringResources.LoadingLabel_Content, IsEnabled = false
            };

            ThreadPool.QueueUserWorkItem(InitializeModelThread, model);
        }
コード例 #4
0
        public ShellInteractionService([ServiceDependency] WorkItem workItem, IShellModule module, [ServiceDependency] IShellModuleService shellModuleService)
        {
            _workItem           = workItem;
            _module             = module;
            _shellModuleService = shellModuleService;

            _actions = new ObservableCollection <ShellAction>();
            _actions.CollectionChanged += ActionsCollectionChangedEventHandler;
            _actionDictionary           = new Dictionary <ShellAction, ShellDrillDownMenuItem>();
            _actionOrderList            = new List <ShellAction>();

            ControlledWorkItem <ShellController> shellWorkItem = workItem.RootWorkItem.WorkItems.FindByType <ControlledWorkItem <ShellController> >().Last();

            shellModuleService.RegisterModule(module, workItem);
            _model = shellModuleService.GetPresentationModel(module);

            _shellView = shellWorkItem.SmartParts.FindByType <IShellView>().Last();
        }
コード例 #5
0
        private void InitializeModelThread(object state)
        {
            IShellPresentationModel model = state as IShellPresentationModel;

            try
            {
                ShellDrillDownMenuItem favoritesMenu = null;
                ShellDrillDownMenuItem startMenu     = null;
                List <AuthOperation>   operations    = new List <AuthOperation>();

                XmlDocument favoritesDoc = _favoritesService.GetFavorites(model.Module.Id);

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    startMenu = XmlToShellDrillDownMenuItemTransformer.Transform(model.Module.GetMenu());

                    if (favoritesDoc != null)
                    {
                        favoritesMenu = XmlToShellDrillDownMenuItemTransformer.Transform(favoritesDoc);
                    }
                    else
                    {
                        favoritesMenu = new ShellDrillDownMenuItem()
                        {
                            Caption  = StringResources.FavoritesMenu_Header,
                            IsFolder = true
                        };
                    }

                    AddOperations(startMenu, operations);
                    AddOperations(favoritesMenu, operations);
                }));

                bool isAuthorizationEnabled = true;

                if (operations.Count > 0)
                {
                    isAuthorizationEnabled = _authorizationService.CheckAuthorization(model.Module.Id, operations);
                }

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    foreach (AuthOperation operation in operations)
                    {
                        operation.MenuItem.IsAuthorized = operation.IsAuthorized;
                    }

                    model.FavoritesMenuTopItem = favoritesMenu;

                    if (model.FavoritesMenuTopItem != null)
                    {
                        model.FavoritesMenuTopItem.TreeChanged += (s, e) =>
                        {
                            _favoritesService.QueueForUpdate(model.Module.Id, model.FavoritesMenuTopItem);
                        };
                    }

                    if (_config.HideUnauthorizedMenuItems)
                    {
                        HideUnauthorizedMenuItems(startMenu);
                    }

                    model.StartMenuTopItem = startMenu;

                    OnModuleActivated();

                    if (!isAuthorizationEnabled)
                    {
                        ShellInteractionService interactionService = GetWorkItem(model.Module).Services.Get <IShellInteractionService>() as ShellInteractionService;
                        interactionService.ShowNotification(new ShellNotification(StringResources.Authorization_Notification, null));
                    }
                }));
            }
            catch (Exception ex)
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    model.StartMenuTopItem = new ShellDrillDownMenuItem()
                    {
                        Caption = "", IsEnabled = false
                    };
                    throw ex;
                }));
            }
        }