static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var exception = e.ExceptionObject; if (exception == null) { return; } if ((exception is WrappedException) == false) { _exceptionHandling.HandleException((Exception)exception); } }
private void ProcessHandleMultiple(EPStatementAgentInstanceHandle handle, IDictionary <NamedWindowConsumerView, NamedWindowDeltaData> deltaPerConsumer) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QNamedWindowCPMulti(_exceptionHandlingService.EngineURI, deltaPerConsumer, handle, _schedulingService.Time); } try { using (handle.StatementAgentInstanceLock.AcquireWriteLock()) { try { if (handle.HasVariables) { _variableService.SetLocalVersion(); } foreach (var entryDelta in deltaPerConsumer) { var newData = entryDelta.Value.NewData; var oldData = entryDelta.Value.OldData; entryDelta.Key.Update(newData, oldData); } // internal join processing, if applicable handle.InternalDispatch(); } catch (Exception ex) { _exceptionHandlingService.HandleException(ex, handle, ExceptionHandlerExceptionType.PROCESS); } finally { if (handle.HasTableAccess) { _tableService.TableExprEvaluatorContext.ReleaseAcquiredLocks(); } } } } finally { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().ANamedWindowCPMulti(); } } }
//ASP.NET MVC3 异常处理 摘抄 //http://blog.csdn.net/kufeiyun/article/details/8191673 //为全局提供未捕获的异常处理,和用于 Controller 的过滤器是互补的 //由MVC控制器调用所引发的异常将由其 Filter 处理,handled以后不会抛到这里 //而由程序运行过程中自身产生的异常,在没有处理的情况下会一路抛到此处 protected void Application_Error() { var exception = Server.GetLastError(); Server.ClearError(); _exceptionHandling.HandleException(exception); }
public async Task HandleException_ExceptionIsNull_LogsMessage() { var mocks = CreateMocks(); var handler = new ExceptionHandlingService(mocks.alertService.Object, mocks.logger.Object); await handler.HandleException(null); mocks.logger.Verify(x => x.Log("Unknown Error \n"), Times.Once); }
public async Task HandleException_ExceptionIsNull_DisplaysAlert() { var mocks = CreateMocks(); var handler = new ExceptionHandlingService(mocks.alertService.Object, mocks.logger.Object); await handler.HandleException(null); mocks.alertService.Verify(x => x.DisplayAlert("Unknown Error", "Unknown Error"), Times.Once); }
public async Task HandleException_ValidCall_DisplaysExceptionMessage() { var mocks = CreateMocks(); var exception = new Exception("Message"); var handler = new ExceptionHandlingService(mocks.alertService.Object, mocks.logger.Object); await handler.HandleException(exception); mocks.alertService.Verify(x => x.DisplayExceptionMessage(exception), Times.Once); }
public async Task HandleException_ValidCall_LogsMessage() { var mocks = CreateMocks(); var exception = new Exception("Message"); var handler = new ExceptionHandlingService(mocks.alertService.Object, mocks.logger.Object); await handler.HandleException(exception); mocks.logger.Verify(x => x.Log(It.IsAny <string>()), Times.Once); }
//ASP.NET MVC3 异常处理 摘抄 //http://blog.csdn.net/kufeiyun/article/details/8191673 //为全局提供未捕获的异常处理,和用于 Controller 的过滤器是互补的 //由MVC控制器调用所引发的异常将由其 Filter 处理,handled以后不会抛到这里 //而由程序运行过程中自身产生的异常,在没有处理的情况下会一路抛到此处 protected void Application_Error() { var exception = Server.GetLastError(); Server.ClearError(); if ((exception is WrappedException) == false) { _exceptionHandling.HandleException(exception); } }
//ASP.NET MVC3 异常处理 摘抄 //http://blog.csdn.net/kufeiyun/article/details/8191673 //为全局提供未捕获的异常处理,和用于 Controller 的过滤器是互补的 //由MVC控制器调用所引发的异常将由其 Filter 处理,handled以后不会抛到这里 //而由程序运行过程中自身产生的异常,在没有处理的情况下会一路抛到此处 protected void Application_Error() { var exception = Server.GetLastError(); if (exception == null) { return; } Server.ClearError(); _exceptionHandling.HandleException(exception); }
public override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); //UrlHelper url = new UrlHelper(filterContext.RequestContext); //filterContext.Result = new RedirectResult(url.Action("AboutError", "AboutError")); Exception exception = filterContext.Exception; _exceptionHandling.HandleException(exception); filterContext.Result = new HttpStatusCodeResult(500); filterContext.ExceptionHandled = true; }
//ASP.NET MVC3 异常处理 摘抄 //http://blog.csdn.net/kufeiyun/article/details/8191673 //为全局提供未捕获的异常处理,和用于 Controller 的过滤器是互补的 //由MVC控制器调用所引发的异常将由其 Filter 处理,handled以后不会抛到这里 //而由程序运行过程中自身产生的异常,在没有处理的情况下会一路抛到此处 protected void Application_Error() { var exception = Server.GetLastError(); if (exception == null) { return; } DbEntityValidationException dbEntityException = exception as DbEntityValidationException; Server.ClearError(); _exceptionHandling.HandleException(exception); }
public void StoppedStatement(String contextName, String statementName, int statementId, String epl, ExceptionHandlingService exceptionHandlingService) { ContextManagerEntry entry = _contexts.Get(contextName); if (entry == null) { Log.Warn("Stop statement for statement '" + statementName + "' failed to locate corresponding context manager '" + contextName + "'"); return; } try { entry.ContextManager.StopStatement(statementName, statementId); } catch (Exception ex) { exceptionHandlingService.HandleException(ex, statementName, epl, ExceptionHandlerExceptionType.STOP); } }
public int ExecuteNonQuery(CommandType commandType, string commandText, List <CommandParameter> parameterList) { if (_database == null) { return(0); } DbCommand cmd; if (commandType == CommandType.Text) { cmd = _database.GetSqlStringCommand(commandText); } else if (commandType == CommandType.StoredProcedure) { cmd = _database.GetStoredProcCommand(commandText); } else { throw new NotImplementedException("不支持的CommandType"); } if (parameterList != null && parameterList.Count > 0) { foreach (CommandParameter item in parameterList) { DbParameter parameter = cmd.CreateParameter(); parameter.ParameterName = item.ParameterName; parameter.Value = item.Value; cmd.Parameters.Add(parameter); } } try { return(_database.ExecuteNonQuery(cmd)); } catch (Exception exception) { string logMessage = commandText; if (parameterList != null) { logMessage += Environment.NewLine + JsonHelper.Serializer(parameterList); } logMessage += Environment.NewLine + exception.StackTrace; _log.Write(exception.Message, logMessage, TraceEventType.Error); Exception exceptionToThrow; _exceptionHandling.HandleException(exception, out exceptionToThrow); throw exceptionToThrow; } }
public override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); //UrlHelper url = new UrlHelper(filterContext.RequestContext); //filterContext.Result = new RedirectResult(url.Action("AboutError", "AboutError")); Exception exception = filterContext.Exception; //如果是 WrappedException ,就不再重复记录日志了 if ((exception is WrappedException) == false) { _exceptionHandling.HandleException(exception); } filterContext.Result = new HttpStatusCodeResult(500); filterContext.ExceptionHandled = true; }
public override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); //TODO:异常时日志不记录 //LogService.Instance.Write( // filterContext.Exception.Message + "\r\n" + filterContext.Exception.StackTrace,TraceEventType.Error); //UrlHelper url = new UrlHelper(filterContext.RequestContext); //filterContext.Result = new RedirectResult(url.Action("AboutError", "AboutError")); Exception exception = filterContext.Exception; _exceptionHandling.HandleException(exception); filterContext.Result = new HttpStatusCodeResult(500); filterContext.ExceptionHandled = true; }
private void DownloadThreadMethod() { while (true) { FileDownloadQueueEntity item; if (_itemQueue.TryDequeue(out item)) { try { Download(item); } catch (Exception ex) { _exceptionHandling.HandleException(ex); } } else { Thread.Sleep(10 * 1000); continue; } } }
private void _webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { _count--; if (_count > 0) { return; } try { //mshtml.IHTMLDocument2 htmlDoc = _webBrowser.Document as mshtml.IHTMLDocument2; HtmlDocument doc = _webBrowser.Document; HtmlElement movieItemListRegion = doc.GetElementById("movieItemListRegion"); if (movieItemListRegion == null) { return; } MovieTimesBundle bundle = new MovieTimesBundle(); _nextDate = null; HtmlElement valueDateRegion = doc.GetElementById("valueDateRegion"); HtmlElementCollection dateLiCollection = valueDateRegion.GetElementsByTagName("li"); for (int i = 0; i < dateLiCollection.Count; i++) { HtmlElement dateLiItem = dateLiCollection[i]; if (dateLiItem.OuterHtml.Contains("class=curr")) { //20160304 string dateStr = dateLiItem.GetAttribute("_date"); if (_dateList.Contains(dateStr)) { return; } _dateList.Add(dateStr); bundle.Date = new DateTime( int.Parse(dateStr.Substring(0, 4)), int.Parse(dateStr.Substring(4, 2)), int.Parse(dateStr.Substring(6, 2))); if (i < dateLiCollection.Count - 1) { _nextDate = dateLiCollection[i + 1].GetElementsByTagName("a")[0].GetAttribute("href"); } break; } } HtmlElementCollection listBCollection = movieItemListRegion.GetElementsByTagName("b"); foreach (HtmlElement listBItem in listBCollection) { MovieEntity movie = new MovieEntity(); movie.MtimeId = int.Parse(listBItem.GetAttribute("_movieid")); movie.Name = listBItem.GetElementsByTagName("a")[0].GetAttribute("title"); movie.Image = listBItem.GetElementsByTagName("img")[0].GetAttribute("src"); //模拟点击 mshtml.IHTMLElement movieItem = (mshtml.IHTMLElement)listBItem.DomElement; movieItem.click(); //详情 HtmlElement movieDetailRegion = doc.GetElementById("movieDetailRegion"); HtmlElementCollection detailPCollection = movieDetailRegion.GetElementsByTagName("p"); HtmlElementCollection detailSpan = detailPCollection[0].GetElementsByTagName("span"); if (detailSpan.Count == 1) { movie.Director = detailSpan[0].InnerText.Replace("导演:", ""); } else if (detailSpan.Count == 2) { movie.Director = detailSpan[0].InnerText.Replace("导演:", ""); movie.Actor = detailSpan[1].InnerText.Replace("主演:", ""); //主演有可能没有,如动画片 } detailSpan = detailPCollection[1].GetElementsByTagName("span"); if (detailSpan.Count == 1) { movie.Type = detailSpan[0].InnerText.Replace("类型:", ""); } else if (detailSpan.Count == 2) { movie.Time = detailSpan[0].InnerText.Replace("时长:", ""); //时长有可能没有 movie.Type = detailSpan[1].InnerText.Replace("类型:", ""); } //场次 HtmlElement showtimesRegion = doc.GetElementById("showtimesRegion"); HtmlElementCollection showtimeTRCollection = showtimesRegion.GetElementsByTagName("tr"); foreach (HtmlElement trItem in showtimeTRCollection) { MovieTimesEntity timesEntity = new MovieTimesEntity(); timesEntity.Movie = movie.Id; HtmlElementCollection tdList = trItem.GetElementsByTagName("td"); HtmlElementCollection pList = tdList[0].GetElementsByTagName("p"); //0点首映的片子,排片表第一行是“次日场”三个字 if (pList.Count == 0) { continue; } timesEntity.Time = DateTime.Parse(bundle.Date.ToShortDateString() + " " + pList[0].InnerText); timesEntity.EndTime = pList[1].InnerText; pList = tdList[1].GetElementsByTagName("p"); timesEntity.ShowType = pList[0].InnerText; timesEntity.Language = pList[1].InnerText; pList = tdList[2].GetElementsByTagName("p"); timesEntity.ScreeningRoom = pList[0].InnerText; movie.TimesList.Add(timesEntity); } bundle.MovieList.Add(movie); } _bundleList.Add(bundle); } catch (Exception ex) { _exceptionHandling.HandleException(ex); return; } if (String.IsNullOrEmpty(_nextDate) == false) { _webBrowser.Navigate(_nextDate); } else { _webBrowser.DocumentCompleted -= _webBrowser_DocumentCompleted; if (Complete != null) { CinemaSpiderCompleteEventArgs args = new CinemaSpiderCompleteEventArgs() { Settings = _settings, MovieTimesBundleList = _bundleList }; Complete(this, args); } } }
internal FileUploadResult Save(SaveArgs args) { FileUploadResult result = new FileUploadResult(); //流长度在关闭释放流之后就取不到了 int length = (int)(args.Stream.Length / 1024); FileStream fsWrite = null; Stream stream = null; string storeFileName; #region 存储文件 try { string targetDir = Path.Combine(_serverRootDir, "FileStore", args.Domain.ToString()); if (Directory.Exists(targetDir) == false) { Directory.CreateDirectory(targetDir); } storeFileName = Guid.NewGuid().ToString() + args.FileExtension; string outputFileName = Path.Combine(targetDir, storeFileName); ////Path.Combine 是 \, HTTP 地址用的是 / ////但是序列化时,会对 / 转义成 \/ //result.RelativeUri = "FileStore" + "/" + _site.SiteInfo.Code + "/" + storeFileName; byte[] buffer = new byte[4096]; fsWrite = new FileStream(outputFileName, FileMode.Create); stream = args.Stream; stream.Position = 0; int read = 0; do { read = stream.Read(buffer, 0, buffer.Length); fsWrite.Write(buffer, 0, read); } while (read > 0); } catch (Exception ex) { _exceptionHandling.HandleException(ex); result.Message = ex.Message; result.Success = false; return(result); } finally { if (fsWrite != null) { fsWrite.Flush(); fsWrite.Close(); fsWrite.Dispose(); } if (stream != null) { stream.Close(); stream.Dispose(); } } #endregion //存储数据库记录 FileRecord record = new FileRecord(); record.Id = args.Id; record.Domain = args.Domain; record.FileName = args.FileName; record.StoredFileName = storeFileName; record.Length = length; record.MD5 = args.MD5; record.UploadDate = args.UploadDate; record.UploadIPAddress = args.UploadIPAddress; _dataBase.Insert(record); result.Success = true; result.Id = args.Id; result.StoreFilePath = String.Format("FileStore/{0}/{1}", args.Domain, storeFileName); return(result); }