示例#1
0
        private questStatus read(PWTrackerLoggingEntities dbContext, LogId logId, out Quest.Services.Dbio.PWTrackerLogging.Logs log)
        {
            // Initialize
            log = null;


            try
            {
                log = dbContext.Logs.Where(r => r.Id == logId.Id).SingleOrDefault();
                if (log == null)
                {
                    return(new questStatus(Severity.Error, String.Format("ERROR: {0}.{1}: {2}",
                                                                         this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                         String.Format("Id {0} not found", logId.Id))));
                }
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);

                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, " The DbEntityValidationException errors are: ", fullErrorMessage);
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     exceptionMessage)));
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
示例#2
0
        public questStatus Log(int userSessionId, int severity, string module, string message)
        {
            // Initialize
            questStatus status = null;
            LogId       logId  = null;

            Log log = new Log();

            log.UserSessionId = userSessionId;
            log.Severity      = severity;
            log.Module        = module;
            log.Message       = message;
            log.Created       = DateTime.Now;

            // Create the emailRecipient
            using (PWTrackerLoggingEntities dbContext = new PWTrackerLoggingEntities())
            {
                status = create(dbContext, log, out logId);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
            }

            return(new questStatus(Severity.Success));
        }
示例#3
0
        public questStatus List(QueryOptions queryOptions, out List <Log> logList, out QueryResponse queryResponse)
        {
            // Initialize
            questStatus status = null;

            logList       = null;
            queryResponse = null;


            using (PWTrackerLoggingEntities dbContext = new PWTrackerLoggingEntities())
            {
                using (DbContextTransaction tx = dbContext.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    try
                    {
                        PropertyInfo[] dbProperties = typeof(Quest.Services.Dbio.PWTrackerLogging.Logs).GetProperties().ToArray();
                        List <Quest.Services.Dbio.PWTrackerLogging.Logs> _logsList = dbContext.Logs.Where(BuildWhereClause(queryOptions, dbProperties))
                                                                                     .OrderBy(BuildSortString(queryOptions.SortColumns))
                                                                                     .Skip(queryOptions.Paging.PageSize * (queryOptions.Paging.PageNumber - 1))
                                                                                     .Take(queryOptions.Paging.PageSize).ToList();
                        if (_logsList == null)
                        {
                            return(new questStatus(Severity.Warning));
                        }
                        logList = new List <Log>();
                        foreach (Quest.Services.Dbio.PWTrackerLogging.Logs _log in _logsList)
                        {
                            Log log = new Log();
                            BufferMgr.TransferBuffer(_log, log);
                            logList.Add(log);
                        }
                        status = BuildQueryResponse(_logsList.Count, queryOptions, out queryResponse);
                        if (!questStatusDef.IsSuccess(status))
                        {
                            return(status);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                             this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                             ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
                    }
                }
            }
            return(new questStatus(Severity.Success));
        }
示例#4
0
        /*----------------------------------------------------------------------------------------------------------------------------------
        * CRUD
        *---------------------------------------------------------------------------------------------------------------------------------*/
        public questStatus Create(Log log, out LogId logId)
        {
            // Initialize
            questStatus status = null;

            logId = null;

            // Data rules.
            log.Created = DateTime.Now;

            // Create the log
            using (PWTrackerLoggingEntities dbContext = new PWTrackerLoggingEntities())
            {
                status = create(dbContext, log, out logId);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
示例#5
0
        private questStatus update(PWTrackerLoggingEntities dbContext, Log log)
        {
            // Initialize
            questStatus status = null;


            try
            {
                // Read the record.
                LogId logId = new LogId(log.Id);
                Quest.Services.Dbio.PWTrackerLogging.Logs _log = null;
                status = read(dbContext, logId, out _log);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }

                // Update the record.
                BufferMgr.TransferBuffer(log, _log);
                dbContext.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);

                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, " The DbEntityValidationException errors are: ", fullErrorMessage);
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     exceptionMessage)));
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }
示例#6
0
        public questStatus Read(DbMgrTransaction trans, LogId logId, out Log log)
        {
            // Initialize
            questStatus status = null;

            log = null;


            // Perform read.
            using (PWTrackerLoggingEntities dbContext = new PWTrackerLoggingEntities())
            {
                Quest.Services.Dbio.PWTrackerLogging.Logs _log = null;
                status = read((PWTrackerLoggingEntities)trans.DbContext, logId, out _log);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                log = new Log();
                BufferMgr.TransferBuffer(_log, log);
            }
            return(new questStatus(Severity.Success));
        }
示例#7
0
        /*----------------------------------------------------------------------------------------------------------------------------------
        * Logs
        *---------------------------------------------------------------------------------------------------------------------------------*/
        private questStatus create(PWTrackerLoggingEntities dbContext, Log log, out LogId logId)
        {
            // Initialize
            logId = null;


            // Perform create
            try
            {
                Quest.Services.Dbio.PWTrackerLogging.Logs _log = new Quest.Services.Dbio.PWTrackerLogging.Logs();
                BufferMgr.TransferBuffer(log, _log);
                dbContext.Logs.Add(_log);
                dbContext.SaveChanges();
                if (_log.Id == 0)
                {
                    return(new questStatus(Severity.Error, "Log not created"));
                }
                logId = new LogId(_log.Id);
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);

                String fullErrorMessage = string.Join("; ", errorMessages);
                String exceptionMessage = string.Concat(ex.Message, " The DbEntityValidationException errors are: ", fullErrorMessage);
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     exceptionMessage)));
            }
            catch (System.Exception ex)
            {
                return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}",
                                                                     this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                                                     ex.InnerException != null ? ex.InnerException.Message : ex.Message)));
            }
            return(new questStatus(Severity.Success));
        }