private List <Referrer> getReferrersFromFile(FileInfo file, DateTime day) { List <Referrer> referrers = new List <Referrer>(); XmlDocument doc = new XmlDocument(); doc.Load(file.FullName); XmlNodeList nodes = doc.SelectNodes("referrers/referrer"); foreach (XmlNode node in nodes) { Referrer refer = new Referrer() { Url = node.Attributes["url"] == null ? null : new Uri(node.Attributes["url"].InnerText), Count = node.Attributes["count"] == null ? 0 : int.Parse(node.Attributes["count"].InnerText), Day = day, PossibleSpam = node.Attributes["isSpam"] == null ? false : bool.Parse(node.Attributes["isSpam"].InnerText), ReferrerUrl = new Uri(node.InnerText), Id = Guid.NewGuid() }; refer.MarkOld(); referrers.Add(refer); } return(referrers); }
/// <summary> /// Inserts a Referrer. /// </summary> /// <param name="referrer"> /// Must be a valid Referrer object. /// </param> public override void InsertReferrer(Referrer referrer) { Referrer.Referrers.Add(referrer); referrer.MarkOld(); var day = Referrer.Referrers.FindAll(r => r.Day.ToShortDateString() == referrer.Day.ToShortDateString()); this.WriteReferrerFile(day, referrer.Day); }
/// <summary> /// Gets all Referrers from the database. /// </summary> /// <returns>List of Referrers.</returns> public override List<Referrer> FillReferrers() { deleteOldReferrers(); List<Referrer> referrers = new List<Referrer>(); string connString = ConfigurationManager.ConnectionStrings[connStringName].ConnectionString; string providerName = ConfigurationManager.ConnectionStrings[connStringName].ProviderName; DbProviderFactory provider = DbProviderFactories.GetFactory(providerName); using (DbConnection conn = provider.CreateConnection()) { conn.ConnectionString = connString; conn.Open(); using (DbCommand cmd = conn.CreateCommand()) { string sqlQuery = "SELECT ReferrerId, ReferralDay, ReferrerUrl, ReferralCount, Url, IsSpam " + "FROM " + tablePrefix + "Referrers "; cmd.CommandText = sqlQuery; cmd.CommandType = CommandType.Text; using (DbDataReader rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { Referrer refer = new Referrer() { Id = rdr.GetGuid(0), Day = rdr.GetDateTime(1), ReferrerUrl = new Uri(rdr.GetString(2)), Count = rdr.GetInt32(3), Url = rdr.IsDBNull(4) ? null : new Uri(rdr.GetString(4)), PossibleSpam = rdr.IsDBNull(5) ? false : rdr.GetBoolean(5) }; referrers.Add(refer); refer.MarkOld(); } } } } } return referrers; }
/// <summary> /// Gets all Referrers from the database. /// </summary> /// <returns> /// List of Referrers. /// </returns> public override List<Referrer> FillReferrers() { this.DeleteOldReferrers(); var referrers = new List<Referrer>(); using (var conn = this.CreateConnection()) { if (conn.HasConnection) { using (var cmd = conn.CreateTextCommand(string.Format("SELECT ReferrerId, ReferralDay, ReferrerUrl, ReferralCount, Url, IsSpam FROM {0}Referrers WHERE BlogId = {1}blogid ", this.tablePrefix, this.parmPrefix))) { cmd.Parameters.Add(conn.CreateParameter(FormatParamName("blogid"), Blog.CurrentInstance.Id.ToString())); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { var refer = new Referrer { Id = rdr.GetGuid(0), Day = rdr.GetDateTime(1), ReferrerUrl = new Uri(rdr.GetString(2)), Count = rdr.GetInt32(3), Url = rdr.IsDBNull(4) ? null : new Uri(rdr.GetString(4)), PossibleSpam = rdr.IsDBNull(5) ? false : rdr.GetBoolean(5) }; referrers.Add(refer); refer.MarkOld(); } } } } } return referrers; }
/// <summary> /// Gets all Referrers from the database. /// </summary> /// <returns> /// List of Referrers. /// </returns> public override List<Referrer> FillReferrers() { this.DeleteOldReferrers(); var referrers = new List<Referrer>(); var connString = ConfigurationManager.ConnectionStrings[this.connStringName].ConnectionString; var providerName = ConfigurationManager.ConnectionStrings[this.connStringName].ProviderName; var provider = DbProviderFactories.GetFactory(providerName); using (var conn = provider.CreateConnection()) { if (conn != null) { conn.ConnectionString = connString; conn.Open(); using (var cmd = conn.CreateCommand()) { var sqlQuery = string.Format("SELECT ReferrerId, ReferralDay, ReferrerUrl, ReferralCount, Url, IsSpam FROM {0}Referrers ", this.tablePrefix); cmd.CommandText = sqlQuery; cmd.CommandType = CommandType.Text; using (var rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { var refer = new Referrer { Id = rdr.GetGuid(0), Day = rdr.GetDateTime(1), ReferrerUrl = new Uri(rdr.GetString(2)), Count = rdr.GetInt32(3), Url = rdr.IsDBNull(4) ? null : new Uri(rdr.GetString(4)), PossibleSpam = rdr.IsDBNull(5) ? false : rdr.GetBoolean(5) }; referrers.Add(refer); refer.MarkOld(); } } } } } } return referrers; }