public void map(LinkSourceInfo oParam, DataRow tempdr) { oParam.SysNo = Util.TrimIntNull(tempdr["SysNo"]); oParam.URLSource = Util.TrimNull(tempdr["URLSource"]); oParam.VisitCount = Util.TrimIntNull(tempdr["VisitCount"]); oParam.CountDate = Util.TrimNull(tempdr["CountDate"]); }
private bool IsBookmark(LinkSourceInfo info) { if (string.IsNullOrEmpty(info.Anchor)) { return(false); } var index = info.Anchor.IndexOf('#'); return(index != -1 && index < info.Anchor.Length - 1); }
public int Insert(LinkSourceInfo oParam) { string sql = @"INSERT INTO LinkSource ( URLSource, VisitCount, CountDate ) VALUES ( @URLSource, @VisitCount, @CountDate );set @SysNo = SCOPE_IDENTITY();"; SqlCommand cmd = new SqlCommand(sql); SqlParameter paramSysNo = new SqlParameter("@SysNo", SqlDbType.Int, 4); SqlParameter paramURLSource = new SqlParameter("@URLSource", SqlDbType.NVarChar, 300); SqlParameter paramVisitCount = new SqlParameter("@VisitCount", SqlDbType.Int, 4); SqlParameter paramCountDate = new SqlParameter("@CountDate", SqlDbType.NVarChar, 10); paramSysNo.Direction = ParameterDirection.Output; if (oParam.URLSource != AppConst.StringNull) { paramURLSource.Value = oParam.URLSource; } else { paramURLSource.Value = System.DBNull.Value; } if (oParam.VisitCount != AppConst.IntNull) { paramVisitCount.Value = oParam.VisitCount; } else { paramVisitCount.Value = System.DBNull.Value; } if (oParam.CountDate != AppConst.StringNull) { paramCountDate.Value = oParam.CountDate; } else { paramCountDate.Value = System.DBNull.Value; } cmd.Parameters.Add(paramSysNo); cmd.Parameters.Add(paramURLSource); cmd.Parameters.Add(paramVisitCount); cmd.Parameters.Add(paramCountDate); return(SqlHelper.ExecuteNonQuery(cmd, out oParam.SysNo)); }
public int Count(LinkSourceInfo oLink) { string sql = @" if exists( select top 1 * from linksource where urlsource=@urlsource and countdate=@countdate) update linksource set visitcount = visitcount + @visitcount where urlsource=@urlsource and countdate=@countdate else insert into linksource(urlsource, countdate, visitcount) values(@urlsource, @countdate, @visitcount)" ; sql = sql.Replace("@urlsource", Util.ToSqlString(oLink.URLSource)); sql = sql.Replace("@countdate", Util.ToSqlString(oLink.CountDate)); sql = sql.Replace("@visitcount", oLink.VisitCount.ToString()); SqlCommand cmd = new SqlCommand(sql); return(SqlHelper.ExecuteNonQuery(cmd)); }
public void Count(string urlSource) { //使用这个hash缓存,将每次的urlsource更新数据库为50次一更新。 //优点就是减少了数据库的负担 //缺点 1 urlSource如果很多,就会比较占用内存, 如果达到1000条以上,要考虑更新算法,保持条目不要太多。 // 2 会出现隔天计数的情况,也就是说50个点击才更新,所以会在第二天才因为日期原因,强制更新。如果需要解决,可以增加一个daemon。不过这个daemon 的具体策略还需要考虑。 // 3 重启会使内存中的数据丢失,造成点击率偏差。 如果需要解决,可以考虑在application end 事件中处理。 lock ( locker ) { if (!ht.Contains(urlSource)) { //如果不包含这个url,就生成一个。 LinkSourceInfo oLinkSource = new LinkSourceInfo(); oLinkSource.CountDate = DateTime.Now.ToString(AppConst.DateFormat); oLinkSource.URLSource = urlSource; oLinkSource.VisitCount = 1; ht.Add(urlSource, oLinkSource); } else { LinkSourceInfo oLinkSource = ht[urlSource] as LinkSourceInfo; string nowTime = DateTime.Now.ToString(AppConst.DateFormat); //如果ht中的url不是今天的记录,就先更新昨天的记录数到数据库。并将今天这个url设置为1。 if (oLinkSource.CountDate != nowTime) { new LinkSourceDac().Count(oLinkSource); oLinkSource.CountDate = nowTime; oLinkSource.VisitCount = 1; } else { //如果是今天的,计数加一 oLinkSource.VisitCount++; //如果当前计数大于500,就更新到数据库。 if (oLinkSource.VisitCount >= 5) { new LinkSourceDac().Count(oLinkSource); // oLinkSource.VisitCount = 0; } } } } }
public void Import() { if (!AppConfig.IsImportable) { throw new BizException("Is Importable is false"); } /* do not use the following code after Data Pour in */ string sql = " select top 1 * from linksource "; DataSet ds = SqlHelper.ExecuteDataSet(sql); if (Util.HasMoreRow(ds)) { throw new BizException("the table linksource is not empty"); } TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { string sql1 = @"select * from ipp2003..visitsourcelog" ; DataSet ds1 = SqlHelper.ExecuteDataSet(sql1); foreach (DataRow dr1 in ds1.Tables[0].Rows) { LinkSourceInfo oInfo = new LinkSourceInfo(); map(oInfo, dr1); oInfo.CountDate = Util.TrimDateNull(oInfo.CountDate).ToString(AppConst.DateFormat); new LinkSourceDac().Insert(oInfo); } scope.Complete(); } }
public static void AddFileLinkSource(this Dictionary <string, List <LinkSourceInfo> > fileLinkSources, LinkSourceInfo source) { var file = source.Target; if (!fileLinkSources.TryGetValue(file, out List <LinkSourceInfo> sources)) { sources = new List <LinkSourceInfo>(); fileLinkSources[file] = sources; } sources.Add(source); }
private static void AddOrUpdate(Dictionary <string, ImmutableList <LinkSourceInfo> > dict, string path, LinkSourceInfo source) => dict[path] = dict.TryGetValue(path, out var sources) ? sources.Add(source) : ImmutableList.Create(source);
private void AddUidLinkSource(Dictionary <string, List <LinkSourceInfo> > uidLinkSources, LinkSourceInfo source) { var file = source.Target; if (!uidLinkSources.TryGetValue(file, out List <LinkSourceInfo> sources)) { sources = new List <LinkSourceInfo>(); uidLinkSources[file] = sources; } sources.Add(source); }