Ejemplo n.º 1
0
        /// <summary>
        /// 处理访问参数
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private AccessLogEntity InitAccessLog(System.Web.HttpContext context)
        {
            string          realIp  = GetRealClientIp(context);
            string          urlHost = new RequestHelp().GetHost(context);
            string          urlRaw  = context.Request.RawUrl.ToString();
            AccessLogEntity entity  = new AccessLogEntity();

            entity.WebSiteName = urlHost;
            entity.UrlAddress  = context.Request.Url.ToString();
            if (context.Session != null)
            {
                entity.SessionID = context.Session.SessionID;
            }
            if (context.Request != null)
            {
                entity.IPAddress       = realIp;
                entity.Browser         = context.Request.Browser.Browser;
                entity.BrowserID       = context.Request.Browser.Id;
                entity.BrowserVersion  = context.Request.Browser.Version;
                entity.BrowserType     = context.Request.Browser.Type;
                entity.BrowserPlatform = context.Request.Browser.Platform;
                if (context.Request.UrlReferrer != null)
                {
                    entity.PUrlAddress = context.Request.UrlReferrer.ToString();
                }
            }
            entity.EnabledMark = true;
            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建前台页面访问日志
        /// </summary>
        /// <param name="accessLogEntity"></param>
        private void InsertAccessLog(AccessLogEntity entity)
        {
            entity = InitAccessLog(entity, true);
            AccessLogApp accessLogApp = new AccessLogApp();

            accessLogApp.Createlog(entity);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建前台页面访问日志
        /// </summary>
        /// <param name="accessLogEntity"></param>
        public void CreateAccessLog(System.Web.HttpContext context, bool IsAsync)
        {
            if (IsAsync)
            {
                AccessLogEntity entity = InitAccessLog(context);
                HttpCookie      cookie = context.Request.Cookies.Get(CLINETID);
                if (cookie != null && !string.IsNullOrEmpty(cookie.Value))
                {
                    entity.ClientID = cookie.Value;
                }
                else
                {
                    string clientIds = Guid.NewGuid().ToString();
                    entity.ClientID = clientIds;
                    cookie          = new HttpCookie(CLINETID);
                    cookie.Name     = CLINETID;
                    cookie.Value    = clientIds;
                    cookie.Expires  = DateTime.Now.AddYears(1);
                    entity.ClientID = clientIds;

                    context.Response.Cookies.Set(cookie);
                }
                Thread thread = new Thread(new ThreadStart(() =>
                {
                    InsertAccessLog(entity);
                }));
                thread.Start();
            }
            else
            {
                AccessLogEntity entity = InitAccessLog(context);
                InsertAccessLog(entity);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 处理访问参数
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private AccessLogEntity InitAccessLog(AccessLogEntity entity, bool IsProcessWebSite)
        {
            WebSiteApp    app           = new WebSiteApp();
            WebSiteEntity webSiteEntity = app.GetModelByUrlHost(entity.WebSiteName);

            if (webSiteEntity != null)
            {
                entity.WebSiteId = webSiteEntity.Id;
            }
            return(entity);
        }
Ejemplo n.º 5
0
 public void SubmitForm(AccessLogEntity accessLogEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         accessLogEntity.Modify(keyValue);
         service.Update(accessLogEntity);
     }
     else
     {
         accessLogEntity.Create();
         service.Insert(accessLogEntity);
     }
 }
Ejemplo n.º 6
0
        //
        public static List <AccessLogEntity> GetAccessLog
        (
            string constring
        )
        {
            //
            List <AccessLogEntity> listLog = new List <AccessLogEntity>();

            //
            using (var connection = new SqlConnection(constring))
            {
                //
                connection.Open();
                //
                string tsql = Build_6_Tsql_SelectLog(LogType.Info);
                //
                using (var command = new SqlCommand(tsql, connection))
                {
                    //
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        //
                        while (reader.Read())
                        {
                            //
                            int             id_Column  = Convert.ToInt32(reader["ID_Column"]);
                            string          pageName   = (string)reader["PageName"];
                            System.DateTime accessDate = (DateTime)reader["AccessDate"];
                            string          ipValue    = (string)reader["IPValue"];
                            //
                            AccessLogEntity Obj = new AccessLogEntity();
                            //
                            Obj.Id_Column  = id_Column;
                            Obj.PageName   = pageName;
                            Obj.AccessDate = accessDate;
                            Obj.IPValue    = ipValue;
                            //
                            listLog.Add(Obj);
                        }
                    }
                }
            }
            //
            return(listLog);
        }
Ejemplo n.º 7
0
        //
        public void CrearExcel()
        {
            //
            string nombreHoja = "LOG";


            //
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            ExcelPackage excel = new ExcelPackage();

            //
            using (excel = new ExcelPackage(new FileInfo(_resultFilePath)))
            {
                //
                excel.Workbook.Worksheets.Add(nombreHoja);
                excel.Save();

                //
                var hojaActual = excel.Workbook.Worksheets[nombreHoja];


                //-----------------------------------------------------------
                // ENCABEZADO
                //-----------------------------------------------------------

                //
                List <string> headerNames = new List <string>();
                //
                headerNames.Add("PAGE_NAME");
                headerNames.Add("ACCESS_DATE");
                headerNames.Add("IP_VALUE");

                //
                for (int index = 0; index < headerNames.Count; index++)
                {
                    //
                    string cellPosition = string.Format(@"{0}1", GetCellPositionFromIndex((index + 1)));
                    string cellValue    = headerNames[index];

                    //
                    hojaActual.Cells[cellPosition].Value = cellValue;
                    hojaActual.Cells[cellPosition].Style.Font.Color.SetColor(System.Drawing.Color.White);
                    hojaActual.Cells[cellPosition].Style.Font.Bold        = true;
                    hojaActual.Cells[cellPosition].Style.Fill.PatternType = ExcelFillStyle.Solid;
                    hojaActual.Cells[cellPosition].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.SaddleBrown);
                    hojaActual.Cells[cellPosition].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thick);
                }

                //------------------------------------------------------------------
                // CONTENIDO
                //------------------------------------------------------------------
                for (int index = 0; index < this._listadoAccessLog.Count; index++)
                {
                    //
                    AccessLogEntity accessLogEntity = this._listadoAccessLog[index];
                    string          cellPosition    = string.Empty;
                    string          cellValue       = string.Empty;

                    // PAGE_NAME
                    cellPosition = string.Format(@"A{0}", (index + 2));
                    cellValue    = accessLogEntity.PageName;
                    hojaActual.Cells[cellPosition].Value = cellValue;
                    hojaActual.Cells[cellPosition].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);

                    // ACCESS_DATE
                    cellPosition = string.Format(@"B{0}", (index + 2));
                    cellValue    = accessLogEntity.AccessDate.ToString();
                    hojaActual.Cells[cellPosition].Value = cellValue;
                    hojaActual.Cells[cellPosition].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);

                    // IP_VALUE
                    cellPosition = string.Format(@"C{0}", (index + 2));
                    cellValue    = accessLogEntity.IPValue;
                    hojaActual.Cells[cellPosition].Value = cellValue;
                    hojaActual.Cells[cellPosition].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
                }

                //--------------------------------------------------------------------
                // FORMATEAR DOCUMENTO
                //--------------------------------------------------------------------
                hojaActual.Cells.AutoFitColumns();
                hojaActual.View.ShowGridLines = false;
                hojaActual.View.FreezePanes(2, 1);
                excel.Save();
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 创建访问日志
 /// </summary>
 /// <param name="accessLogEntity"></param>
 public void Createlog(AccessLogEntity accessLogEntity)
 {
     accessLogEntity.Id   = Common.GuId();
     accessLogEntity.Date = DateTime.Now;
     service.Insert(accessLogEntity);
 }