Exemplo n.º 1
0
        private void UpdateRequestSummary()
        {
            // Get the data.
            RequestSummaryData data = service.GetRequestSummaryData(context);

            if (data != null)
            {
                // Find the row for the current month.
                RequestSummaryData.TRequestSummaryRow row = null;
                foreach (RequestSummaryData.TRequestSummaryRow r in data.TRequestSummary.Rows)
                {
                    DateTime date = r.Month;
                    if ((date.Year == context.Timestamp.Year) && (date.Month == context.Timestamp.Month))
                    {
                        row = r;
                        row.RequestCount = row.RequestCount + 1;
                        break;
                    }
                }

                // If the current month was not found, it must be added to the data.
                if (null == row)
                {
                    row              = data.TRequestSummary.NewTRequestSummaryRow();
                    row.Month        = new DateTime(context.Timestamp.Year, context.Timestamp.Month, 1, 0, 0, 0);
                    row.RequestCount = 1;
                    row.VisitsCount  = 0;
                    data.TRequestSummary.Rows.Add(row);
                }

                // Save the data.
                service.SaveRequestSummaryData(context, data);
            }
        }
Exemplo n.º 2
0
        private void LoadRequestData()
        {
            RequestStatisticService service = (RequestStatisticService)Portal.API.Statistics.Statistic.GetService(typeof(RequestStatisticService));
            RequestSummaryData      data    = service.GetRequestSummaryData(Context);
            //data.TRequestSummary.DefaultView.Sort = "Month DESC";

            List <RequestSummaryEntry> entries = new List <RequestSummaryEntry>();
            // Max. number of months to display will be set to 12 (1 year).
            int monthCount = data.TRequestSummary.Rows.Count > 12 ? 12 : data.TRequestSummary.Rows.Count;

            for (int monthIndex = 0; monthIndex < monthCount; ++monthIndex)
            {
                RequestSummaryData.TRequestSummaryRow row = (RequestSummaryData.TRequestSummaryRow)data.TRequestSummary.Rows[(data.TRequestSummary.Rows.Count - 1) - monthIndex];
                RequestSummaryEntry entry = new RequestSummaryEntry();
                entry.Month          = row.Month;
                entry.RequestsPerDay = GetRequestsPerDay(row.Month, row.RequestCount);
                entry.VisitsPerDay   = GetVisitsPerDay(row.Month, row.VisitsCount);
                entry.TotalRequests  = row.RequestCount;
                entry.TotalVisits    = row.VisitsCount;
                entries.Add(entry);
            }

            repeaterOverview.DataSource = entries;
            repeaterOverview.DataBind();

            // Show the error message, if an error is occured in the service.
            Exception ex = service.ConsumeLastException();

            if (ex != null)
            {
                _errorMsg.Visible = true;
                _errorMsg.Text    = ex.Message;
            }
        }
        private void LoadSummaryData()
        {
            // Use ConfigAgent to get the month to view.
            ConfigAgent configAgent = ((IStateProcessor)Parent).ConfigAgent;

            RequestStatisticService service = (RequestStatisticService)Portal.API.Statistics.Statistic.GetService(typeof(RequestStatisticService));
            RequestUrlData          urlData = service.GetRequestUrlData(Context, configAgent.Month);

            RequestSummaryData summaryData = service.GetRequestSummaryData(Context);

            // Contains all entries for the summary table.
            List <RequestSummaryEntry> entries = new List <RequestSummaryEntry>();

            // Calculate total requests of this month.
            double totalRequests = 0.0;

            foreach (RequestUrlData.TRequestUrlRow row in urlData.TRequestUrl.Rows)
            {
                totalRequests += row.RequestCount;
            }

            DataRow[] rows        = summaryData.TRequestSummary.Select("Month = " + configAgent.Month.ToString(@"#MM\/dd\/yyyy#"));
            double    totalVisits = 0.0;

            if (rows.Length > 0)
            {
                RequestSummaryData.TRequestSummaryRow row = (RequestSummaryData.TRequestSummaryRow)rows[0];
                totalVisits = row.VisitsCount;
            }

            // Get the number of days.
            int      dayCount = 1;
            DateTime now      = DateTime.Now;

            if ((now.Year == configAgent.Month.Year) && (now.Month == configAgent.Month.Month))
            {
                // Current month, so we use the days since 1st of this month.
                dayCount = now.Day;
            }
            else
            {
                dayCount = DateTime.DaysInMonth(configAgent.Month.Year, configAgent.Month.Month);
            }

            entries.Add(new RequestSummaryEntry(Language.GetText(Portal.API.Module.GetModuleControl(this), "sumRequests"), totalRequests));
            entries.Add(new RequestSummaryEntry(Language.GetText(Portal.API.Module.GetModuleControl(this), "sumVisits"), totalVisits));
            //entries.Add(new RequestSummaryEntry("", 0.0));
            entries.Add(new RequestSummaryEntry(Language.GetText(Portal.API.Module.GetModuleControl(this), "requestsPerDay"), totalRequests / (double)dayCount));
            entries.Add(new RequestSummaryEntry(Language.GetText(Portal.API.Module.GetModuleControl(this), "visitsPerDay"), totalVisits / (double)dayCount));

            repeaterSummary.DataSource = entries;
            repeaterSummary.DataBind();

            labelMonthlySummary.Text = string.Format(Language.GetText(Portal.API.Module.GetModuleControl(this), "monthlyStatisticTitle"), configAgent.Month.ToString("MMMM"), configAgent.Month.ToString("yyyy"));
        }