public void SaveFavorites()
        {
            BlobCollection blobs = new BlobCollection();

            foreach (string applicationName in _favoritesUpdateCache.Keys)
            {
                ShellDrillDownMenuItem favoritesMenu = _favoritesUpdateCache[applicationName];
                XmlDocument            xmlDocument   = XmlToShellDrillDownMenuItemTransformer.Transform(favoritesMenu);

                Blob blob = CreateBlob(applicationName, xmlDocument);

                if (blob != null)
                {
                    blobs.Add(blob);
                }
            }

            CreateOrUpdateBlobParameters parameters = new CreateOrUpdateBlobParameters
            {
                ContainerName = GetContainerName(),
                Blobs         = blobs
            };

            CreateOrUpdateBlobRequest request = new CreateOrUpdateBlobRequest();

            request.CreateOrUpdateBlobParameters = parameters;

            SettingsService.CreateOrUpdateBlob(request);
        }
        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;
                }));
            }
        }