コード例 #1
0
        protected void ExportByViewsButton_Click(Object sender, EventArgs e)
        {
            GenericExportManager <CategoryViewSummary> exportManager = GenericExportManager <CategoryViewSummary> .Instance;
            GenericExportOptions <CategoryViewSummary> options       = new GenericExportOptions <CategoryViewSummary>();

            options.CsvFields = new string[] { "CategoryName", "Views" };

            SortableCollection <KeyValuePair <ICatalogable, int> > categoryViews = PageViewDataSource.GetViewsByCategory("ViewCount DESC");

            // CONVERT TO SUMMARY LIST TO GENERATE CSV
            IList <CategoryViewSummary> viewsSummay = new List <CategoryViewSummary>();

            foreach (KeyValuePair <ICatalogable, int> dataRow in categoryViews)
            {
                viewsSummay.Add(new CategoryViewSummary(dataRow.Key.Name, dataRow.Value));
            }

            options.ExportData = viewsSummay;
            options.FileTag    = "POPULAR_CATEGORIES_BY_VIEWS";
            exportManager.BeginExport(options);
        }
コード例 #2
0
        private void initViewChart(bool forceRefresh)
        {
            string       cacheKey     = "3C26BAC7-1D53-40ef-920B-5BDB705F363B";
            CacheWrapper cacheWrapper = Cache[cacheKey] as CacheWrapper;

            if (forceRefresh || (cacheWrapper == null))
            {
                SortableCollection <KeyValuePair <ICatalogable, int> > categoryViews = PageViewDataSource.GetViewsByCategory(_Size, 0, "ViewCount DESC");
                if (categoryViews.Count > 0)
                {
                    //BUILD BAR CHART
                    ViewsChart.Series["Views"].Points.Clear();
                    for (int i = 0; i < categoryViews.Count; i++)
                    {
                        DataPoint point = new DataPoint(ViewsChart.Series["Views"]);
                        point.SetValueXY(categoryViews[i].Key.Name, new object[] { categoryViews[i].Value });
                        ViewsChart.Series["Views"].Points.Add(point);
                    }
                    ViewsChart.DataBind();

                    //CACHE THE DATA
                    cacheWrapper = new CacheWrapper(categoryViews);
                    Cache.Remove(cacheKey);
                    Cache.Add(cacheKey, cacheWrapper, null, LocaleHelper.LocalNow.AddMinutes(5).AddSeconds(-1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
                }
                else
                {
                    //NO CATEGORIES HAVE BEEN VIEWED YET OR PAGE TRACKING IS NOT AVAIALBEL
                    this.Controls.Clear();
                    Panel noViewsPanel = new Panel();
                    noViewsPanel.CssClass = "emptyData";
                    Label noViewsMessage = new Label();
                    noViewsMessage.Text = "No categories have been viewed or page tracking is disabled.";
                    noViewsPanel.Controls.Add(noViewsMessage);
                    this.Controls.Add(noViewsPanel);
                }
            }
            else
            {
                //USE CACHED VALUES
                SortableCollection <KeyValuePair <ICatalogable, int> > categoryViews = (SortableCollection <KeyValuePair <ICatalogable, int> >)cacheWrapper.CacheValue;
                //BUILD BAR CHART
                ViewsChart.Series["Views"].Points.Clear();
                for (int i = 0; i < categoryViews.Count; i++)
                {
                    DataPoint point = new DataPoint(ViewsChart.Series["Views"]);
                    point.SetValueXY(categoryViews[i].Key.Name, new object[] { categoryViews[i].Value });
                    ViewsChart.Series["Views"].Points.Add(point);
                }
                ViewsChart.DataBind();

                ViewsGrid.DataSource = categoryViews;
                ViewsGrid.DataBind();
            }
            DateTime cacheDate = (cacheWrapper != null) ? cacheWrapper.CacheDate : LocaleHelper.LocalNow;

            CacheDate1.Text = string.Format(CacheDate1.Text, cacheDate);
            CacheDate2.Text = string.Format(CacheDate2.Text, cacheDate);
        }