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 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); } }
public override global::System.Data.DataSet Clone() { RequestSummaryData cln = ((RequestSummaryData)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public RequestSummaryData GetRequestSummaryData(HttpContext context) { if (null == context) { throw new ArgumentNullException("context"); } RequestSummaryData data = null; try { // Create the directory if it doesn't already exist. if (!Directory.Exists(Path.Combine(Statistic.GetStatisticsPath(context), "Requests"))) { Directory.CreateDirectory(Path.Combine(Statistic.GetStatisticsPath(context), "Requests")); } lock (lockObject) { string fileName = Path.Combine(Statistic.GetStatisticsPath(context), @"Requests\Summary.xml"); // Try to get the login statistics data from the cache. // If the data is not in the cache, try to load the file. // At last, if the file doesn't exist, create a new data object. object obj = context.Cache.Get("RequestSummaryData"); if ((null != obj) && obj.GetType().Equals(typeof(RequestSummaryData))) { data = (RequestSummaryData)obj; } else if (File.Exists(fileName)) { data = new RequestSummaryData(); data.ReadXml(fileName); } else { data = new RequestSummaryData(); } } } catch (UnauthorizedAccessException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch (SecurityException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch (Exception ex) { HandleException(Statistic.GetStatisticsPath(context), ex); } return(data); }
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")); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { RequestSummaryData ds = new RequestSummaryData(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
internal void SaveRequestSummaryData(HttpContext context, RequestSummaryData data) { if (null == context) { throw new ArgumentNullException("context"); } if (null == data) { throw new ArgumentNullException("data"); } lock (lockObject) { string fileName = Path.Combine(Statistic.GetStatisticsPath(context), @"Requests\Summary.xml"); // At last, write the data back to the login statistics file and // put the data object back to the cache. try { data.WriteXml(fileName); } catch (UnauthorizedAccessException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch (SecurityException ex) { HandleNoAccessException(Statistic.GetStatisticsPath(context), ex); } catch (Exception ex) { HandleException(Statistic.GetStatisticsPath(context), ex); } context.Cache.Insert("RequestSummaryData", data, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); RequestSummaryData ds = new RequestSummaryData(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "TRequestSummaryDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); RequestSummaryData ds = new RequestSummaryData(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "TRequestSummaryDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { RequestSummaryData ds = new RequestSummaryData(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }