public void BuildNavigation()
        {
            List <SAMenuItemDTO> arrangedMenuItems = new List <SAMenuItemDTO>();

            //Remove the ff lines to disable caching
            if (CacheHelper.GetFromCacheWithCheck <List <SAMenuItemDTO> >("arrangedMenuItems") != null &&
                CacheHelper.GetFromCacheWithCheck <List <SAMenuItemDTO> >("arrangedMenuItems").Count > 0)
            {
                arrangedMenuItems = CacheHelper.GetFromCacheWithCheck <List <SAMenuItemDTO> >("arrangedMenuItems");
                this.view.BindNavigationMenu(arrangedMenuItems);
                return;
            }
            //Remove the ff lines to disable caching

            NavigationData data = new NavigationData();

            MenuFilterSection menu = MenuFilterSection.GetConfig();
            List <string>     ids  = menu.GetItemsToBeRemove();

            string               filter    = string.Join(",", ids.ToArray());
            MenuOrderSection     menuOrder = MenuOrderSection.GetConfig();
            List <SAMenuItemDTO> menuItems = data.GetAllUsedDiagrams(filter);

            if (menuOrder.MenuOrders.Count > 0)
            {
                foreach (MenuOrder item in menuOrder.MenuOrders)
                {
                    SAMenuItemDTO order = menuItems.FirstOrDefault(c => c.ID == item.Id);
                    if (order != null)
                    {
                        arrangedMenuItems.Insert(item.Order, order);
                    }
                }

                if (menuItems.Count > menuOrder.MenuOrders.Count)
                {
                    foreach (MenuOrder item in menuOrder.MenuOrders)
                    {
                        var order = menuItems.FirstOrDefault(c => c.ID == item.Id);
                        if (order != null)
                        {
                            menuItems.Remove(order);
                        }
                    }
                    arrangedMenuItems.AddRange(menuItems);
                }
            }
            else
            {
                arrangedMenuItems = menuItems.OrderBy(diag => diag.Text).ToList();
            }

            //Remove the ff lines to disable caching
            CacheHelper.AddToCacheWithCheck("arrangedMenuItems", arrangedMenuItems);
            //Remove the ff lines to disable caching

            this.view.BindNavigationMenu(arrangedMenuItems);
        }
Beispiel #2
0
        /// <summary>
        /// Gets all the the used diagrams.
        /// </summary>
        /// <param name="filter">SQL filter (where ....)</param>
        /// <returns>List of menus with child items. Like in System Architect.</returns>
        public List <SAMenuItemDTO> GetAllUsedDiagrams(string filter)
        {
            List <SAMenuItemDTO> cachedMenu = CacheHelper.GetFromCacheWithCheck <List <SAMenuItemDTO> >(cache, "sa_menu_key");

            if (cachedMenu != null)
            {
                return(cachedMenu);
            }

            IDataReader reader = db.ExecuteReader(CommandType.Text,
                                                  string.Concat(GlobalStringResource.Data_GetAllUsedDiagramsQuery,
                                                                !string.IsNullOrEmpty(filter) ?
                                                                string.Format(GlobalStringResource.NavData_TypeNotIn, filter) : string.Empty)
                                                  );
            List <SAMenuItemDTO> treeViewItems = new List <SAMenuItemDTO>();

            int typeIndex = reader.GetOrdinal(GlobalStringResource.Type);

            while (reader.Read())
            {
                Int16 value = reader.GetInt16(typeIndex);
                if (value > 0)
                {
                    SAMenuItemDTO item = new SAMenuItemDTO();
                    string        name = TypesReader.DiagramTypes[value];

                    item.ID         = value;
                    item.Text       = name;
                    item.ChildItems = GetSubDiagrams((int)value);

                    if (item.ChildItems.Count > 0)
                    {
                        treeViewItems.Add(item);
                    }
                }
            }
            reader.Close();
            reader.Dispose();

            CacheHelper.AddToCacheWithCheck(cache, GlobalStringResource.Data_sa_menu_key,
                                            treeViewItems);
            return(treeViewItems);
        }