public void CreateScanException(Exception ex, ScanExceptionType exType, string shortDesc, string fullPath) { using (var ctx = new FreeSpaceContext()) { var instance = new ScanException { CreatedStamp = DateTime.Now, ExceptionType = (int)exType, Path = fullPath, ShortDesc = shortDesc, Source = ex.Source, HResult = ex.HResult, Message = ex.Message, StackTrace = ex.StackTrace, ExceptionName = ex.GetType().ToString() }; var fnf = ex as FileNotFoundException; if (fnf != null) { instance.InnerExceptionMessage = fnf.InnerException?.Message; instance.ExceptionName = fnf.GetType().ToString(); } var dnf = ex as DirectoryNotFoundException; if (dnf != null) { instance.InnerExceptionMessage = dnf.InnerException?.Message; instance.ExceptionName = dnf.GetType().ToString(); } var ptl = ex as PathTooLongException; if (ptl != null) { instance.InnerExceptionMessage = ptl.InnerException?.Message; instance.ExceptionName = ptl.GetType().ToString(); } var ua = ex as UnauthorizedAccessException; if (ua != null) { instance.InnerExceptionMessage = ua.InnerException?.Message; instance.ExceptionName = ua.GetType().ToString(); } var ioe = ex as IOException; if (ioe != null) { instance.InnerExceptionMessage = ioe.InnerException?.Message; instance.ExceptionName = ioe.GetType().ToString(); } ctx.ScanExceptions.Add(instance); ctx.SaveChanges(); } }
public static void CreateScanException(Exception ex, ScanExceptionType scanExType, string shortDesc, string fullPath) { var repo = new Repo(); repo.CreateScanException(ex, scanExType, shortDesc, fullPath); }