コード例 #1
0
ファイル: TimerService.cs プロジェクト: kouweizhong/vita
 private void SafeInvoke(Delegate[] delegates)
 {
     foreach (var d in delegates)
     {
         var evh = (EventHandler)d;
         try {
             evh(this, EventArgs.Empty);
         } catch (Exception ex) {
             _errorLog.LogError(ex);
         }
     }
 }
コード例 #2
0
 public HttpResponseMessage Get()
 {
     try
     {
         ItemsResponse <FaqCategory> response = new ItemsResponse <FaqCategory>();
         response.Items = _faqCategoryService.Get();
         return(Request.CreateResponse(HttpStatusCode.OK, response));
     }
     catch (Exception ex)
     {
         _errorService.LogError(ex);
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #3
0
 public HttpResponseMessage Get()
 {
     try
     {
         List <FaqIndexModel> response = new List <FaqIndexModel>();
         response = _faqService.Get();
         return(Request.CreateResponse(HttpStatusCode.OK, response));
     }
     catch (Exception ex)
     {
         _errorService.LogError(ex);
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #4
0
        public void Reload(object reason)
        {
            _loadStatus = CacheLoadStatus.Loading;
            if (_app.Status != EntityAppStatus.Connected) //stop if we're in shutdown
            {
                return;
            }
            var session = (EntitySession)this.OpContext.OpenSystemSession();

            try {
                session.LogMessage("------- Full-set cache - reloading/" + reason);
                var entSets = new Dictionary <Type, FullyCachedSet>();
                foreach (var entType in _settings.FullSetCacheTypes)
                {
                    if (_loadStatus != CacheLoadStatus.Loading)
                    {
                        session.LogMessage("------- Full-set cache - reload canceled.");
                        return; // stop if another cache invalidation request came in
                    }
                    var entInfo = _app.Model.GetEntityInfo(entType);
                    var cmd     = entInfo.CrudCommands.SelectAll;
                    var records = _dataStore.ExecuteSelect(session, cmd, null);
                    var entSet  = new FullyCachedSet(entInfo, records);
                    entSets.Add(entType, entSet);
                }
                this.EntitySets = entSets;
                LoadedOn        = _timeService.UtcNow;
                _loadStatus     = CacheLoadStatus.Loaded;
                session.LogMessage("------- Full-set cache - reloaded.");
            } catch (Exception ex) {
                _loadStatus = CacheLoadStatus.NonCurrent;
                _errorLog.LogError(ex, this.OpContext);
            } finally {
            }
        }
コード例 #5
0
 // Register
 public async Task<HttpResponseMessage> Register(RegisterUserRequest model)
 {    
     try
     {
         if (!ModelState.IsValid)
         {
             return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         if (_userService.GetByEmail(model.Email)>0)
         {
             return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Email Already Registered");
         }
         ItemResponse<int> resp = new ItemResponse<int>();
         resp.Item = _userService.Create(model);
         String emailGuid = Guid.NewGuid().ToString();
         _userService.CreateCode(resp.Item, emailGuid);
         await _emailService.SendEmailConfirmation(model.Email, emailGuid);
         return Request.CreateResponse(HttpStatusCode.OK, resp);
     }
     catch (Exception ex)
     {
         _errorLogService.LogError(ex);
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
     }
 }
コード例 #6
0
 private void Flush()
 {
     if (_flushing)
     {
         return;
     }
     if (!_app.IsConnected())
     {
         return;
     }
     lock (_lock) {
         try {
             _flushing = true;
             var start = _app.TimeService.ElapsedMilliseconds;
             var list  = DequeuAll();
             if (list.Count == 0)
             {
                 return;
             }
             //fire event
             Saving?.Invoke(this, new BackgroundSaveEventArgs(list));
             var session = (EntitySession)_app.OpenSystemSession();
             session.LogDisabled = true; //do not log operations; what we save are log entries themselves most of the time
             if (list.Count > 0)
             {
                 var byHandler = list.GroupBy(o => GetHandler(o));
                 foreach (var group in byHandler)
                 {
                     var handler = group.Key;
                     if (handler == null)
                     {
                         continue;
                     }
                     handler.SaveObjects(session, group.ToList());
                 }
             }
             //Get stats
             var recCount    = session.GetChangeCount();
             var startSaving = _app.TimeService.ElapsedMilliseconds;
             session.SaveChanges();
             var endSaving = _app.TimeService.ElapsedMilliseconds;
             //log stats
             if (_operationLog != null && OkToLogStatsMessage(list))
             {
                 var logEntry = new Logging.InfoLogEntry(session.Context, "Background save completed, records: {0}, save time: {1} ms, total time: {2} ms.",
                                                         recCount, (endSaving - startSaving), (endSaving - start));
                 _operationLog.Log(logEntry);
             }
         } catch (Exception ex) {
             //System.Diagnostics.Debugger.Break();
             _errorLog.LogError(ex);
         } finally {
             _flushing = false;
         }
     }
 }//method
コード例 #7
0
        /// <summary>
        /// Log a <see cref="ConfigurationError"/> to the <see cref="IErrorLogService"/>.
        /// </summary>
        /// <param name="serviceProvider">
        /// The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.
        /// </param>
        /// <param name="error">
        /// The <see cref="ConfigurationError"/> to log.
        /// </param>
        public static void LogError(IServiceProvider serviceProvider, ConfigurationError error)
        {
            if (null == serviceProvider)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            IErrorLogService errorLogService = GetErrorService(serviceProvider);

            errorLogService.LogError(error);
        }
コード例 #8
0
 public HttpResponseMessage GetAll()
 {
     try
     {
         ItemsResponse <ErrorLog> resp = new ItemsResponse <ErrorLog>();
         resp.Items = _errorService.GetAll();
         return(Request.CreateResponse(HttpStatusCode.OK, resp));
     }
     catch (Exception ex)
     {
         _errorService.LogError(ex);
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #9
0
ファイル: BaseApiController.cs プロジェクト: yuanfei05/vita
 protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
 {
     //Note: when exception is thrown here, it is not routed to exc filter, everything just crashes,
       // so be careful not to throw anything in controller.Initialize
       base.Initialize(controllerContext);
       try {
     WebContext = WebHelper.GetWebCallContext(this);
     if(WebContext == null)
       return;
     OpContext = WebContext.OperationContext;
     ErrorLog = OpContext.App.GetService<IErrorLogService>();
       } catch(Exception ex) {
     System.Diagnostics.Trace.WriteLine("Exception in controller.Initialize: " + ex.ToLogString());
     if(ErrorLog != null)
       ErrorLog.LogError(ex, OpContext);
       }
 }
コード例 #10
0
 public async Task SendAsync(OperationContext context, MailMessage message)
 {
     try {
         if (message.From == null)
         {
             message.From = new MailAddress(_settings.DefaultFrom);
         }
         if (!string.IsNullOrWhiteSpace(_settings.TestRedirectAllTo))
         {
             SetupRedirect(message);
         }
         var client = CreateClient();
         await client.SendMailAsync(message);
     } catch (Exception ex) {
         ex.Data["MailMessage"] = message.ToLogString();
         _errorLog.LogError(ex, context);
         throw;
     }
 }
コード例 #11
0
ファイル: BaseApiController.cs プロジェクト: kouweizhong/vita
 protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
 {
     //Note: when exception is thrown here, it is not routed to exc filter, everything just crashes,
     // so be careful not to throw anything in controller.Initialize
     base.Initialize(controllerContext);
     try {
         WebContext = WebHelper.GetWebCallContext(this);
         if (WebContext == null)
         {
             return;
         }
         OpContext = WebContext.OperationContext;
         ErrorLog  = OpContext.App.GetService <IErrorLogService>();
     } catch (Exception ex) {
         System.Diagnostics.Trace.WriteLine("Exception in controller.Initialize: " + ex.ToLogString());
         if (ErrorLog != null)
         {
             ErrorLog.LogError(ex, OpContext);
         }
     }
 }
コード例 #12
0
 /// <summary>
 /// Log an error when building the node graph.
 /// </summary>
 /// <param name="node">The node where the error occurred.</param>
 /// <param name="message"></param>
 protected void LogError(ConfigurationNode node, string message)
 {
     errorLogService.LogError(new ConfigurationError(node, message));
 }