Exemplo n.º 1
0
 public SaveFileResult Save(Stream dataStream)
 {
     try
     {
         new XmlSerializerNamespaces().Add(string.Empty, string.Empty);
         XmlWriterSettings settings = new XmlWriterSettings {
             CheckCharacters    = true,
             CloseOutput        = false,
             Indent             = true,
             OmitXmlDeclaration = true
         };
         using (XmlWriter writer = XmlWriter.Create(dataStream, settings))
         {
             new XmlSerializer(base.GetType()).Serialize(writer, this);
             writer.Flush();
         }
     }
     catch (Exception exception)
     {
         string completeInnerStackTrace = ExceptionWriter.GetCompleteInnerStackTrace(exception);
         Trace.WriteLine(exception.Message);
         Trace.WriteLine(completeInnerStackTrace);
         return(new SaveFileResult(exception));
     }
     return(SaveFileResult.SuccessfulSave);
 }
        public DiskWriterTests()
        {
            rig = TestRig.CreateMultiFile();
            diskManager = rig.Engine.DiskManager;

            writer = new ExceptionWriter();
            diskManager.Writer = writer;
            handle = new ManualResetEvent(false);
            rig.Manager.Stop();
        }
Exemplo n.º 3
0
        public static string HandleException(Exception ex)
        {
            // do not write or process abort exceptions
            if ((ex as ProcessAbortException) != null)
            {
                return(string.Empty);
            }

            ProcessModule mainModule;

            using (var currentProcess = Process.GetCurrentProcess())
            {
                // we might want to write a dump file (wich is huge!)
                if (ConfigurationManager.AppSettings["WriteDumpFile"] == "true")
                {
                    var outputFileName = Path.Combine(DefaultHandler.Destination, string.Format("{0:yyyy-MM-dd--HH-mm-ss}.dmp", DateTime.Now));
                    DumpWriter.CreateMiniDump(currentProcess, outputFileName);
                }

                mainModule = currentProcess.MainModule;
                var mainModuleName = mainModule.FileName;

                var logEntry = new XElement(
                    "Exception",
                    new XElement(
                        "GenericInfo",
                        new XElement("Timestamp", DateTime.Now),
                        new XElement("ExecutingMainModule", mainModuleName),
                        new XElement("ContextCache", ContextCache)),
                    ScanException(ex));

                var exceptionText = logEntry.ToString(SaveOptions.None);

                foreach (var exceptionWriter in ExceptionWriter)
                {
                    try
                    {
                        exceptionWriter.Write(logEntry);
                    }
                    catch (Exception writerException)
                    {
                        ExceptionWriter.Remove(exceptionWriter);
                        HandleException(
                            new TechnicalException(
                                "Exception while writing exception. The responsible writer will be removed.",
                                writerException,
                                new KeyValuePair <string, object>("responsible writer", exceptionWriter)));
                    }
                }

                return(exceptionText);
            }
        }
Exemplo n.º 4
0
        private void run(string commandLine, bool seekCommandFile)
        {
            if (splitCommandFromRest(commandLine).If(out var command, out var rest))
            {
                if (command == "help")
                {
                    generateHelp();
                }
                else if (rest.IsEmpty())
                {
                    if (seekCommandFile)
                    {
                        FileName file = @$ "~\AppData\Local\{Application}\{command}.cli";
                        if (!file.Exists())
                        {
                            ExceptionWriter.WriteLine($"Command file {file} doesn't exist");
                        }

                        var text = file.Text;
                        run(text, false);
                    }
Exemplo n.º 5
0
 public virtual void HandleException(Exception exception) => ExceptionWriter.WriteExceptionLine(exception);
Exemplo n.º 6
0
 protected void dispose()
 {
     StandardWriter?.DisposeIfDisposable();
     ExceptionWriter?.DisposeIfDisposable();
 }
 protected override void OnException(ExceptionContext filterContext)
 {
     _logger.Error("");
     _logger.Error(" ERROR in " + filterContext.Controller);
     ExceptionWriter.WriteErrorDetailed(_logger, filterContext.Exception);
 }
        public string Import(HttpPostedFileBase upload, string imagePath)
        {
            _logger.Info(" upload.FileName = " + upload.FileName);

            var ext = System.IO.Path.GetExtension(upload.FileName);

            if (_fileContext.IsAllowedExtension(ext))
            {
                _logger.Info(" import started...");
                List <Drink> drinks = null;
                try
                {
                    drinks = _fileContext.Import(upload.InputStream);
                }
                catch (Exception e)
                {
                    _logger.Error(" Неправильная структура файла!");
                    ExceptionWriter.WriteErrorDetailed(_logger, e);
                }

                _logger.Info(" import ended...");

                if (drinks != null)
                {
                    foreach (var drink in drinks)
                    {
                        //Если по каким-то причинам при импорте не нашлась картинка по указанному пути берем дефолтную
                        string path = GetPathDefaultImg(imagePath);
                        try
                        {
                            //Сохраняем файл в хранилище
                            path = SaveFile(drink.ImgPath, imagePath);
                        }
                        catch (Exception e)
                        {
                            _logger.Error(" Указан неверный путь к файлу!");
                            ExceptionWriter.WriteErrorDetailed(_logger, e);
                        }

                        DrinkEntity drinkEntity = new DrinkEntity
                        {
                            Id        = Guid.NewGuid(),
                            ImagePath = path,
                            Name      = drink.Name,
                            Count     = drink.Count,
                            CostPrice = drink.Cost
                        };

                        _printer.DrinkInfo(drinkEntity);
                        _drinkRepository.Add(drinkEntity);
                    }

                    _logger.Info(" before _db.SaveChanges()...");
                    _drinkRepository.SaveChanges();
                }
                else
                {
                    return(" Пустые данные!");
                }
            }
            else
            {
                return(" Файл имеет неверный формат!");
            }

            return("");
        }
Exemplo n.º 9
0
 public virtual void HandleException(Exception exception)
 {
     ExceptionWriter.WriteExceptionLine(exception);
     Environment.ExitCode = ErrorCode;
 }
Exemplo n.º 10
0
 protected void SaveError(Exception ex)
 {
     _logger.Error("");
     ExceptionWriter.WriteErrorDetailed(_logger, ex);
 }