public override global::System.Data.DataSet Clone() { RequestUrlData cln = ((RequestUrlData)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public RequestUrlData GetRequestUrlData(HttpContext context) { if (null == context) { throw new ArgumentNullException("context"); } RequestUrlData 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\Requests_{0}_{1}.xml"); fileName = string.Format(CultureInfo.InvariantCulture, fileName, context.Timestamp.Year, context.Timestamp.Month); // 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(fileName); if ((null != obj) && obj.GetType().Equals(typeof(RequestUrlData))) { data = (RequestUrlData)obj; } else if (File.Exists(fileName)) { data = new RequestUrlData(); data.ReadXml(fileName); } else { data = new RequestUrlData(); } } } 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) { RequestUrlData ds = new RequestUrlData(); 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); }
private void LoadRequestData() { // Use ConfigAgent to get the month to view. ConfigAgent configAgent = ((IStateProcessor)Parent).ConfigAgent; RequestStatisticService service = (RequestStatisticService)Portal.API.Statistics.Statistic.GetService(typeof(RequestStatisticService)); RequestUrlData data = service.GetRequestUrlData(Context, configAgent.Month); data.TRequestUrl.DefaultView.Sort = data.TRequestUrl.RequestCountColumn.ColumnName + " DESC"; // Calculate the total logged requests. int totalRequests = 0; foreach (RequestUrlData.TRequestUrlRow row in data.TRequestUrl.Rows) { totalRequests += row.RequestCount; } List <RequestUrlEntry> entries = new List <RequestUrlEntry>(); int rank = 1; foreach (DataRowView rv in data.TRequestUrl.DefaultView) { RequestUrlData.TRequestUrlRow row = (RequestUrlData.TRequestUrlRow)rv.Row; RequestUrlEntry entry = new RequestUrlEntry(); entry.Rank = rank++; entry.RequestCount = row.RequestCount; entry.Percentage = (double)row.RequestCount / (double)totalRequests; entry.Url = row.Url; entry.Url = entry.Url.Substring(entry.Url.IndexOf('/') + 1); entry.Url = entry.Url.Substring(entry.Url.IndexOf('/') + 1); entry.Url = entry.Url.Substring(entry.Url.IndexOf('/')); entries.Add(entry); if (rank > 30) { break; } } labelMonthlyRequests.Text = string.Format(Language.GetText(Portal.API.Module.GetModuleControl(this), "monthlyRequestsTitle"), rank - 1, data.TRequestUrl.Rows.Count); repeaterTopUrls.DataSource = entries; repeaterTopUrls.DataBind(); }
private void UpdateMonthlyRequests() { string url = null; try { url = context.Request.Url.ToString(); } catch (NullReferenceException) { } if (url != null) { // Get the data. RequestUrlData data = service.GetRequestUrlData(context); if (data != null) { // Find the row for the currently requested URL. RequestUrlData.TRequestUrlRow row = null; foreach (RequestUrlData.TRequestUrlRow r in data.TRequestUrl.Rows) { if (string.Compare(r.Url, url, true, CultureInfo.InvariantCulture) == 0) { row = r; row.RequestCount = row.RequestCount + 1; break; } } // If the currently requested URL was not found, it must be added to the data. if (null == row) { row = data.TRequestUrl.NewTRequestUrlRow(); row.Url = url; row.RequestCount = 1; data.TRequestUrl.Rows.Add(row); } // Save the data. service.SaveRequestUrlData(context, data); } } }
internal void SaveRequestUrlData(HttpContext context, RequestUrlData 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\Requests_{0}_{1}.xml"); fileName = string.Format(CultureInfo.InvariantCulture, fileName, context.Timestamp.Year, context.Timestamp.Month); // 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(fileName, 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(); RequestUrlData ds = new RequestUrlData(); 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 = "TRequestUrlDataTable"; 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) { RequestUrlData ds = new RequestUrlData(); 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; }
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(); RequestUrlData ds = new RequestUrlData(); 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 = "TRequestUrlDataTable"; 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); }