Exemple #1
0
 public static List <PageView> GetPageViews(string Path)
 {
     try
     {
         List <PageView>   PageViews = new List <PageView>();
         DataTable         dt        = new DataTable();
         SiteData.DBAccess DBAccess  = new SiteData.DBAccess();
         using (SqlCommand dbcmd = new SqlCommand {
             CommandType = CommandType.StoredProcedure, CommandText = "GetPageViews"
         })
         {
             dt        = DBAccess.OpenDataTable(dbcmd);
             PageViews = PopulateClassListFromDataTable <PageView>(dt);
         }
         return(PageViews);
         //System.Xml.Serialization.XmlSerializer Serializer = new System.Xml.Serialization.XmlSerializer(PageViews.GetType());
         //if (System.IO.File.Exists(Path))
         //{
         //    Stream PathStream = File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         //    StreamReader objStreamReader = new StreamReader(PathStream);
         //    PageViews = (List<PageView>)Serializer.Deserialize(objStreamReader);
         //    objStreamReader.Close();
         //    PathStream.Close();
         //    PathStream.Dispose();
         //    return PageViews;
         //}
         //return null;
     }
     catch (Exception ex)
     {
         string Body = "An error was encountered: " + Environment.NewLine + ex.ToString();
         Utils.SendEmail("*****@*****.**", "*****@*****.**", "error encountered", Body);
         return(null);
     }
 }
    //todo: add create instance stuff to significantly reduce the codebase.
    #endregion

    #region PageView Data

    public static List <PageView> GetPageViews()
    {
        try
        {
            List <PageView>   PageViews = new List <PageView>();
            DataTable         dt        = new DataTable();
            SiteData.DBAccess DBAccess  = new SiteData.DBAccess();
            using (SqlCommand dbcmd =
                       new SqlCommand {
                CommandType = CommandType.StoredProcedure, CommandText = "GetPageViews"
            })
            {
                dt        = DBAccess.OpenDataTable(dbcmd);
                PageViews = PopulateClassListFromDataTable <PageView>(dt);
            }
            return(PageViews);
        }
        catch (Exception ex)
        {
            string Body = "An error was encountered: " + Environment.NewLine + ex.ToString();
            Utils.SendEmail("*****@*****.**", "*****@*****.**", "error encountered", Body);
            return(null);
        }
    }
    public static bool InsertPageView(string Path, string PageURL, string userHostAddress, string userAgent, string browser,
                                      string crawler, string MyReferrer)
    {
        try
        {
            List <PageView> PageViews = new List <PageView>();
            PageView        pageView  = new PageView();
            pageView.PageUrl         = PageURL;
            pageView.UserHostAddress = userHostAddress;
            pageView.UserAgent       = userAgent;
            pageView.Browser         = browser;
            pageView.Crawler         = crawler;
            pageView.Referrer        = MyReferrer;
            pageView.DateVisited     = DateTime.Now;

            SiteData.DBAccess DBAccess = new SiteData.DBAccess();
            using (SqlCommand dbcmd = new SqlCommand {
                CommandType = CommandType.StoredProcedure, CommandText = "InsertPageView"
            })
            {
                //( @id bigint,
                //@userhostaddress varchar(max),
                //@pageurl varchar(max),
                //@useragent varchar(max),
                //@browser varchar(max),
                //@crawler varchar(max),
                //@referrer varchar(max),
                //@datevisited datetime)

                dbcmd.Parameters.AddWithValue("id", pageView.Id);
                dbcmd.Parameters.AddWithValue("userhostaddress", pageView.UserHostAddress);
                dbcmd.Parameters.AddWithValue("pageurl", pageView.PageUrl);
                dbcmd.Parameters.AddWithValue("useragent", pageView.UserAgent);
                dbcmd.Parameters.AddWithValue("browser", pageView.Browser);
                dbcmd.Parameters.AddWithValue("crawler", pageView.Crawler);
                dbcmd.Parameters.AddWithValue("referrer", pageView.Referrer);
                dbcmd.Parameters.AddWithValue("datevisited", DateTime.Now);

                DBAccess.ExecuteSQL(dbcmd);
            }
            //System.Xml.Serialization.XmlSerializer Serializer = new System.Xml.Serialization.XmlSerializer(PageViews.GetType());
            //if (System.IO.File.Exists(Path))
            //{
            //    Stream PathStream = File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //    StreamReader objStreamReader = new StreamReader(PathStream);
            //    PageViews = (List<PageView>)Serializer.Deserialize(objStreamReader);
            //    objStreamReader.Close();
            //    PathStream.Close();
            //    PathStream.Dispose();
            //    PathStream = File.Open(Path, FileMode.Truncate, FileAccess.Write, FileShare.Write);
            //    StreamWriter objStreamWriter = new StreamWriter(PathStream);
            //    PageViews.Reverse();
            //    PageViews.Add(pageView);
            //    Serializer.Serialize(objStreamWriter, PageViews);
            //    objStreamWriter.Close();
            //}
            //else
            //{
            //    PageViews.Add(pageView);
            //    Stream PathStream = File.Open(Path, FileMode.Create, FileAccess.Write, FileShare.Write);
            //    StreamWriter objStreamWriter = new StreamWriter(PathStream);
            //    Serializer.Serialize(objStreamWriter, PageViews);
            //    objStreamWriter.Close();
            //    PathStream.Close();
            //    PathStream.Dispose();
            //}
            return(true);
        }
        catch (Exception ex)
        {
            string Body = "An error was encountered: " + Environment.NewLine + ex.ToString();
            Utils.SendEmail("*****@*****.**", "*****@*****.**", "error encountered", Body);
            return(false);
        }
    }