Example #1
0
        /// <summary>
        /// Generate new data for all the widgets in the system
        /// This method takes time, but it happens in the background.
        /// </summary>
        public void GenerateDataForPersonsAndThemes()
        {
            InitRepo();

            //Remove old widgetdatas
            widgetRepo.ResetAllData();
            RemoveWidgetDatas(GetAllWidgetDatas());

            //Fill widgets with new widgetdata
            DataManager   dataManager = new DataManager();
            List <Widget> widgets     = widgetRepo.ReadWidgetsForItemtype(ItemType.Person).ToList();

            widgets.AddRange(widgetRepo.ReadWidgetsForItemtype(ItemType.Theme).ToList());
            int widgetCount = widgets.Count();

            //Extract data from informations
            List <WidgetData> widgetDatas = new List <WidgetData>();

            foreach (Widget widget in widgets)
            {
                for (int i = 0; i < widget.Items.Count(); i++)
                {
                    foreach (PropertyTag proptag in widget.PropertyTags)
                    {
                        WidgetData widgetData;
                        if (proptag.Name.ToLower().Equals("mentions"))
                        {
                            widgetData = dataManager.GetNumberOfMentionsForItem
                                             (widget.Items.ElementAt(i).ItemId, widget.WidgetId, "dd-MM");
                        }
                        else
                        {
                            widgetData = dataManager.GetPropvaluesForWidget
                                             (widget.Items.ElementAt(i).ItemId, widget.WidgetId, proptag.Name);
                        }
                        widgetData.Widget = widget;
                        widgetDatas.Add(widgetData);
                    }
                }
            }
            widgetRepo.CreateWidgetDatas(widgetDatas);

            //Remove overflowing items (temporary solution)
            new ItemManager().RemoveOverflowingItems();

            //Generate data for geolocation
            GenerateDataForGeolocation();
        }