Пример #1
0
        private DataTable GetDistroRanking(DataTable dt)
        {
            const string Points = "Points";
            const string Rank   = "Rank";

            BLL.Points objPoints = new BLL.Points();
            List <distroTrend.Model.Points> listPoints;

            listPoints = objPoints.GetPoints(_connString);

            dt.Columns.Add(Points, typeof(Decimal)).SetOrdinal(2);

            foreach (DataRow dr in dt.Rows)
            {
                string tempDistroId = null;
                if (dr["Id"] != null)//distroId
                {
                    tempDistroId = dr["Id"].ToString();
                }
                int distroId = 0;

                if (tempDistroId != null)
                {
                    distroId = Convert.ToInt32(tempDistroId);
                }

                distroTrend.Model.Points point = listPoints.Where(x => x.distroId == distroId).FirstOrDefault();
                string points = "0";
                if (point != null)
                {
                    points = point.TotalPoints.ToString();
                }

                logger.Debug("distroId=" + distroId + ", points=" + points);

                dr[Points] = points;
            }

            DataView dv = dt.DefaultView;

            dv.Sort = "points desc";
            DataTable sortedDT = dv.ToTable();

            sortedDT.Columns.Add(Rank, typeof(Int32)).SetOrdinal(0);

            int rank = 1;

            foreach (DataRow dr in sortedDT.Rows)
            {
                dr[Rank] = rank;
                rank++;

                //dr["Name"] = "<a href='DistroMain.aspx?" + Helper.Constants.URL_PARAMETER_DISTRO_CODE + "=" + dr["Code"].ToString() + "'>" + dr["Name"] + "</a>";
                dr["Name"] = "<a href='DistroMain.aspx?" + Helper.Constants.URL_PARAMETER_DISTRO_ID + "=" + dr["Id"].ToString() + "'>" + dr["Name"] + "</a>";
            }

            return(sortedDT);
        }
Пример #2
0
        static void PointsUpdate()
        {
            BLL.Points pointsBL = new BLL.Points();

            string sqlConn = System.Configuration.ConfigurationManager.AppSettings["dbConnection"];

            string message = string.Empty;

            string url  = "https://distrowatch.com/dwres.php?resource=popularity";
            string data = GetWebSiteData(url);
            List <distroTrend.Model.Points> listDistroPoints = ParseDataDWPoints(data, sqlConn);

            foreach (distroTrend.Model.Points objPoints in listDistroPoints)
            {
                message = string.Empty;

                if (objPoints == null)
                {
                    message = objPoints.distroId + " is not found in DB. Inserting...";
                }
                else
                {
                    if (pointsBL.IsExists(sqlConn, objPoints.distroId, objPoints.Date))
                    {
                        pointsBL.Update(sqlConn, objPoints);
                    }
                    else
                    {
                        pointsBL.Insert(sqlConn, objPoints);
                    }
                }

                if (!string.IsNullOrEmpty(message))
                {
                    logger.Info(message);
                    Console.WriteLine(message);
                }
            }
        }