internal static Log GetFirstLog(string databaseConnectionString)
 {
     using (var db = new LoggingDataContext(databaseConnectionString))
     {
         return(db.Logs.FirstOrDefault());
     }
 }
 internal static List <Log> GetExceptionsFromDB(string databaseConnectionString)
 {
     using (var db = new LoggingDataContext(databaseConnectionString))
     {
         return(db.Logs.Where(e => e.Severity == "Error").ToList());
     }
 }
Exemple #3
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
        {
            dc.ExecuteCommand("DELETE FROM DBTranslatedColumnNames");
            dc.SubmitChanges();

            foreach (GridViewRow gvr in this.gvTables.Rows)
            {
                string name        = gvr.Cells[1].Text;
                string nameMKD     = (gvr.FindControl("tbNameMKD") as TextBox).Text;
                string description = (gvr.FindControl("tbDescription") as TextBox).Text;


                Broker.LoggingDataAccess.DBTranslatedColumnName newColName = new DBTranslatedColumnName();
                newColName.Name        = name;
                newColName.NameMKD     = nameMKD;
                newColName.Description = description;
                dc.DBTranslatedColumnNames.InsertOnSubmit(newColName);
                dc.SubmitChanges();
            }
            gvTables.DataSource = dc.DBTranslatedColumnNames;
            gvTables.DataBind();
        }
    }
 internal static void CleanLoggingDB(string databaseConnectionString)
 {
     using (var db = new LoggingDataContext(databaseConnectionString))
     {
         db.CategoryLogs.DeleteAllOnSubmit(db.CategoryLogs);
         db.Logs.DeleteAllOnSubmit(db.Logs);
         db.SubmitChanges();
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
        {
            List <ViewDBAccessedPage> tempList = dc.ViewDBAccessedPages.Where(c => c.Title != string.Empty).ToList();

            gvDBActivitiesBase.DataSource = tempList;
            gvDBActivitiesBase.DataBind();
        }
    }
Exemple #6
0
    //public int TotalRecords { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var model = new AttributeMappingSource().GetModel(typeof(DataClassesDataContext));
            using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
            {
                string ColName = "";
                List <Broker.LoggingDataAccess.DBTranslatedColumnName> columnList = new List <Broker.LoggingDataAccess.DBTranslatedColumnName>();

                foreach (var mt in model.GetTables())
                {
                    foreach (var dm in mt.RowType.PersistentDataMembers)
                    {
                        if (dm.DbType != null)
                        {
                            ColName = dm.MappedName;


                            //bool contains = false;
                            //foreach (Broker.LoggingDataAccess.DBTranslatedColumnName item in columnList)
                            //{
                            //    if (item.Name == ColName)
                            //    {
                            //        contains = true;
                            //    }

                            //}

                            //if (!contains)
                            //{
                            if (dc.DBTranslatedColumnNames.Where(c => c.Name == ColName).FirstOrDefault() == null)
                            {
                                Broker.LoggingDataAccess.DBTranslatedColumnName newColumn = new Broker.LoggingDataAccess.DBTranslatedColumnName();
                                newColumn.Name    = ColName;
                                newColumn.NameMKD = string.Empty;


                                dc.DBTranslatedColumnNames.InsertOnSubmit(newColumn);
                                dc.SubmitChanges();
                            }
                        }
                    }
                }


                //TotalRecords = dc.DBTranslatedColumnNames.Count();
                gvTables.DataSource = dc.DBTranslatedColumnNames;
                gvTables.DataBind();
            }
        }
    }
        internal static string GetFirstLogFormattedMessage(string databaseConnectionString)
        {
            using (var db = new LoggingDataContext(databaseConnectionString))
            {
                var log = db.Logs.Where(e => e.FormattedMessage.Contains("Extended Properties: value - testing title")).SingleOrDefault();
                if (log == null)
                {
                    return(null);
                }

                return(log.FormattedMessage);
            }
        }
        internal static string GetFirstErrorFormattedMessage(string databaseConnectionString)
        {
            using (var db = new LoggingDataContext(databaseConnectionString))
            {
                var log = db.Logs.Where(e => e.Severity == "error").SingleOrDefault();
                if (log == null)
                {
                    return(null);
                }

                return(log.FormattedMessage);
            }
        }
Exemple #9
0
        public JsonResult LogSearchGridDataRequested()
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.
            var gridModel        = new LogJqGridModel();
            var datacontextModel = new LoggingDataContext();

            // customize the default grid model with our custom settings
            LogSetupGrid(gridModel.LogGrid);

            // return the result of the DataBind method, passing the datasource as a parameter
            // jqGrid for ASP.NET MVC automatically takes care of paging, sorting, filtering/searching, etc
            return(gridModel.LogGrid.DataBind(datacontextModel.Logs.OrderByDescending(x => x.Date)));
        }
    protected void gvDBActivitiesBase_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int      id             = Convert.ToInt32(gvDBActivitiesBase.DataKeys[e.Row.RowIndex].Value.ToString());
            GridView gvDBActivities = (GridView)e.Row.FindControl("gvDBActivities");

            using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
            {
                ViewDBAccessedPage tempbase = dc.ViewDBAccessedPages.Where(c => c.ID == id).FirstOrDefault();
                List <ViewDBAccessedPageAction> templist = dc.ViewDBAccessedPageActions.Where(c => c.DbAccesedPagesID == tempbase.ID).ToList();

                gvDBActivities.DataSource = templist;
                gvDBActivities.DataBind();
            }
        }
    }
    protected void gvDBActivities_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int      id = (e.Row.DataItem as ViewDBAccessedPageAction).ID;
            GridView gvDBActivitiesUpdateFields = (GridView)e.Row.FindControl("gvDBActivitiesUpdateFields");

            string tempid = gvDBActivitiesUpdateFields.ID.ToString();

            using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
            {
                ViewDBAccessedPageAction  tempbase = dc.ViewDBAccessedPageActions.Where(c => c.ID == id).FirstOrDefault();
                List <ViewDBUpdatedTable> templist = dc.ViewDBUpdatedTables.Where(c => c.DBAccessedPageActionID == tempbase.ID).ToList();

                gvDBActivitiesUpdateFields.DataSource = templist;
                gvDBActivitiesUpdateFields.DataBind();
            }
        }
    }
Exemple #12
0
        private bool IgnoreFlagChecked(string value)
        {
            using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
            {
                DBLoggingControl tempControl = dc.DBLoggingControls.FirstOrDefault();
                //bool IsIgnored = dc.DBLoggingControls.FirstOrDefault().IgnoreNext;

                if (tempControl.IgnoreNext)
                {
                    if (value.StartsWith("-- Context"))
                    {
                        tempControl.IgnoreNext = false;
                        dc.SubmitChanges();
                    }

                    return(true);
                }

                return(false);
            }
        }
Exemple #13
0
        private bool IsInIgnoreList(string value)
        {
            using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
            {
                List <DBLoggingIgnoredTable> ignoreList = dc.DBLoggingIgnoredTables.ToList();


                foreach (DBLoggingIgnoredTable ignoredTable in ignoreList)
                {
                    if (value.Contains(ignoredTable.TableName))
                    {
                        DBLoggingControl tempControl = dc.DBLoggingControls.FirstOrDefault();
                        tempControl.IgnoreNext = true;
                        dc.SubmitChanges();

                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #14
0
        public override void WriteLine(string value)
        {
            //string temp = System.Text.RegularExpressions.Regex.Match(value, @"\[([^)]*)\]").Groups[1].Value;
            if (IsInIgnoreList(value))
            {
                return;
            }

            if (IgnoreFlagChecked(value))
            {
                return;
            }


            string sessionID = HttpContext.Current.Session.SessionID;
            int    userID    = Convert.ToInt32(HttpContext.Current.Session["UserID"]);

            using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
            {
                if (userID > 0)
                {
                    int activityTypeID   = 0;
                    int dBUpdatedTableID = 0;

                    int start  = 0;
                    var match2 = string.Empty;

                    if (value.StartsWith("SELECT"))
                    {
                        if (value.StartsWith("SELECT COUNT"))
                        {
                            return;
                        }
                        activityTypeID = 3;
                        start          = value.IndexOf("FROM") + 4;
                        match2         = value.Substring(start, value.IndexOf("AS") - start);
                    }
                    else
                    {
                        if (value.StartsWith("INSERT"))
                        {
                            activityTypeID   = 1;
                            dBUpdatedTableID = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().ID;
                            start            = value.IndexOf("INTO") + 4;
                            match2           = value.Substring(start, value.IndexOf("(") - start);
                        }
                        else
                        {
                            if (value.StartsWith("DELETE"))
                            {
                                activityTypeID   = 2;
                                dBUpdatedTableID = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().ID;
                                start            = value.IndexOf("FROM") + 4;
                                match2           = value.Substring(start, value.IndexOf("AS") - start);
                            }
                            else
                            {
                                if (value.StartsWith("UPDATE"))
                                {
                                    activityTypeID = 4;

                                    dBUpdatedTableID = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().ID;
                                    start            = value.IndexOf("FROM") + 4;
                                    match2           = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().TableName;
                                }
                                else
                                {
                                    if (value.StartsWith("-- @p"))
                                    {
                                        activityTypeID = 5;
                                        //start = string.Empty;
                                        //match2 = string.Empty;
                                    }
                                }
                            }
                        }
                    }


                    if (activityTypeID > 0)
                    {
                        if (activityTypeID < 5)
                        {
                            DBActivity activity = new DBActivity();

                            activity.ActivityTypeID = activityTypeID;
                            activity.Query          = value;
                            activity.UserID         = userID;
                            activity.SessionID      = sessionID;
                            activity.Date           = DateTime.Now;
                            activity.TableName      = match2.ToString();
                            if (dBUpdatedTableID > 0)
                            {
                                activity.DBUpdatedTableID = dBUpdatedTableID;
                            }

                            try
                            {
                                dc.DBActivities.InsertOnSubmit(activity);
                                dc.SubmitChanges();
                            }
                            catch { }
                        }
                        else
                        {
                            if (activityTypeID == 5)
                            {
                                DBActivityParameter activityParameter = new DBActivityParameter();
                                DBActivity          tempActivity      = dc.DBActivities.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(c => c.Date).FirstOrDefault();
                                //DBActivity tempActivity = DBActivity.Table.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(c => c.Date).FirstOrDefault();
                                if (tempActivity != null)
                                {
                                    int activityID = tempActivity.ID;

                                    string substring      = value.Substring(3);
                                    string parameterName  = substring.Split(':').First();
                                    int    startIndex     = value.IndexOf("[") + 1;
                                    string parameterValue = value.Substring(startIndex, value.IndexOf("]") - startIndex);

                                    int    startIndex2   = value.IndexOf("Input") + 6;
                                    string parameterType = value.Substring(startIndex2, (value.IndexOf("(") - 1) - startIndex2);

                                    string tempQuery = tempActivity.Query;
                                    if (parameterType.Contains("nvarchar"))
                                    {
                                        tempQuery = tempQuery.Replace(parameterName, "'" + parameterValue + "'");
                                    }
                                    else
                                    {
                                        tempQuery = tempQuery.Replace(parameterName, parameterValue);
                                    }

                                    tempActivity.Query = tempQuery;
                                    dc.SubmitChanges();

                                    activityParameter.DBActivityID = activityID;
                                    activityParameter.Value        = value;

                                    dc.DBActivityParameters.InsertOnSubmit(activityParameter);
                                    dc.SubmitChanges();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #15
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(IsPostBack))
        {
            var model = new AttributeMappingSource().GetModel(typeof(DataClassesDataContext));

            List <TableDetail> tableDetails = new List <TableDetail>();

            List <MetaTable> temp = model.GetTables().ToList();

            for (int i = 0; i < temp.Count; i++)
            {
                string tableName = temp[i].TableName;

                string prefix = tableName.Substring(0, 3);

                string tableWithoutPrefix = tableName.Substring(4);

                string tableNameInDB = "[" + prefix + "].[" + tableWithoutPrefix + "]";


                using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
                {
                    TableDetail newDetail = new TableDetail();

                    newDetail.Name = tableWithoutPrefix;

                    newDetail.Index  = i;
                    newDetail.Insert = true;
                    newDetail.Delete = true;
                    newDetail.Select = true;
                    newDetail.Update = true;

                    DBLoggingIgnoredTable tempIgnoredTable = dc.DBLoggingIgnoredTables.Where(c => c.TableName == tableWithoutPrefix).FirstOrDefault();

                    if (tempIgnoredTable != null)
                    {
                        int ignoredTableID = tempIgnoredTable.ID;

                        foreach (DBLoggingIgnoredTableActivity item in dc.DBLoggingIgnoredTableActivities.Where(c => c.DbLoggingIgnoredTableID == ignoredTableID).ToList())
                        {
                            switch (item.ActivityTypeID)
                            {
                            case 1:
                            {
                                newDetail.Insert = false;
                                break;
                            }

                            case 2:
                            {
                                newDetail.Delete = false;
                                break;
                            }

                            case 3:
                            {
                                newDetail.Select = false;
                                break;
                            }

                            case 4:
                            {
                                newDetail.Update = false;
                                break;
                            }

                            default:
                                break;
                            }
                        }
                    }

                    tableDetails.Add(newDetail);
                }
            }


            gvTables.DataSource = tableDetails;
            gvTables.DataBind();
        }
    }
Exemple #16
0
    protected void cbUpdate_changed(object sender, EventArgs e)
    {
        foreach (GridViewRow gvrow in gvTables.Rows)
        {
            CheckBox chk = (CheckBox)gvrow.FindControl("cbUpdate");

            if (chk != null & chk.Checked)
            {
                string tableName = gvTables.Rows[gvrow.RowIndex].Cells[0].Text;
                using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
                {
                    DBLoggingIgnoredTable ignoredTable = dc.DBLoggingIgnoredTables.Where(c => c.TableName == tableName).FirstOrDefault();

                    if (ignoredTable != null)
                    {
                        foreach (DBLoggingIgnoredTableActivity ignoredActivity in ignoredTable.DBLoggingIgnoredTableActivities)
                        {
                            if (ignoredActivity.ActivityTypeID == (int)Activities.UPDATE)
                            {
                                dc.DBLoggingIgnoredTableActivities.DeleteOnSubmit(ignoredActivity);
                            }
                        }
                        dc.SubmitChanges();

                        if (ignoredTable.DBLoggingIgnoredTableActivities.Count == 0)
                        {
                            dc.DBLoggingIgnoredTables.DeleteOnSubmit(ignoredTable);
                            dc.SubmitChanges();
                        }
                    }
                }
            }

            if (chk != null & chk.Checked == false)
            {
                //string tableName = gvTables.DataKeys[gvrow.RowIndex].Values[0].ToString();
                string tableName = gvTables.Rows[gvrow.RowIndex].Cells[0].Text;
                using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
                {
                    DBLoggingIgnoredTable ignoredTable = dc.DBLoggingIgnoredTables.Where(c => c.TableName == tableName).FirstOrDefault();

                    if (ignoredTable != null)
                    {
                        bool exists = false;

                        foreach (DBLoggingIgnoredTableActivity ignoredActivity in ignoredTable.DBLoggingIgnoredTableActivities)
                        {
                            if (ignoredActivity.ActivityTypeID == (int)Activities.UPDATE)
                            {
                                exists = true;
                            }
                        }

                        if (!exists)
                        {
                            DBLoggingIgnoredTableActivity newIgnoredActivity = new DBLoggingIgnoredTableActivity();
                            newIgnoredActivity.ActivityTypeID        = (int)Activities.UPDATE;
                            newIgnoredActivity.DBLoggingIgnoredTable = ignoredTable;
                            dc.DBLoggingIgnoredTableActivities.InsertOnSubmit(newIgnoredActivity);
                            dc.SubmitChanges();
                        }
                    }
                    else
                    {
                        ignoredTable           = new DBLoggingIgnoredTable();
                        ignoredTable.TableName = tableName;
                        dc.DBLoggingIgnoredTables.InsertOnSubmit(ignoredTable);

                        DBLoggingIgnoredTableActivity newIgnoredActivity = new DBLoggingIgnoredTableActivity();
                        newIgnoredActivity.ActivityTypeID        = (int)Activities.UPDATE;
                        newIgnoredActivity.DBLoggingIgnoredTable = ignoredTable;
                        dc.DBLoggingIgnoredTableActivities.InsertOnSubmit(newIgnoredActivity);
                        dc.SubmitChanges();
                    }
                }
            }
        }
    }