Example #1
0
        public IActionResult ImportFile(int id, ImportCsvDefinition importCsvDefinition, IFormFile formFile)
        {
            try
            {
                if (formFile.Length > 0)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        formFile.CopyTo(memoryStream);

                        var fileImport = new FileImport()
                        {
                            FileName    = formFile.FileName,
                            ContentType = formFile.ContentType,
                            FileContent = memoryStream.ToArray()
                        };

                        this.fileRepository.ImportFile(id, importCsvDefinition, fileImport);
                    }
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #2
0
        /// <summary>
        /// Loads the input tab delimited file.
        /// </summary>
        /// <param name="path">The path.</param>
        public void LoadInputFileTabDelim(string path)
        {
            const bool isFirstRowHeader = true;
            DataTable  dt = FileImport.ReadCsvFile(path, isFirstRowHeader, "\t");

            inputData = new InputData(dt);
        }
Example #3
0
        /// <summary>
        /// Loads the input CSV file .
        /// </summary>
        /// <param name="path">The path.</param>
        public void LoadInputFileCsv(string path)
        {
            // first row must always be header
            const bool isFirstRowHeader = true;
            DataTable  dt = FileImport.ReadCsvFile(path, isFirstRowHeader);

            inputData = new InputData(dt);
        }
Example #4
0
        /// <summary>
        /// Loads the gazetteer file.
        /// </summary>
        /// <param name="path">The path.</param>
        public void LoadGazetteerFile(string path)
        {
            // first row must always be header
            const bool isFirstRowHeader = true;
            DataTable  dt = FileImport.ReadCsvFile(path, isFirstRowHeader);

            gazetteerData     = new GazetteerData(dt);
            gazetteerFileName = path;
        }
Example #5
0
    void Start()
    {
        gameObject.GetComponent <Rigidbody>().isKinematic = true;

        ballState   = 0; // 持っている
        whichRobo   = 0; // Robo0が
        catchBuffer = 0;

        SceneInfo = FileImport.ReadCSV("test");
    }
Example #6
0
        public void LoadInputTabDelim()
        {
            //Given
            string path = Path.GetFullPath(@"inputTabs.csv");

            //When
            var dataTable = FileImport.ReadCsvFile(path, true, "\t");

            //Then
            Assert.AreEqual(2, dataTable.Rows.Count);
            Assert.AreEqual("MARINDUQUE", dataTable.Rows[0][0]);
            Assert.AreEqual("BOAC", dataTable.Rows[0][1]);
            Assert.AreEqual("MARINDUQUE", dataTable.Rows[1][0]);
            Assert.AreEqual("BO\tAC", dataTable.Rows[1][1]);
        }
Example #7
0
        public FileImport ImportFile(int index)
        {
            using (var uow = DataManager.Current.StartUnitOfWork())
            {
                YokogawaFile yokoFile = FileUtility.GetFile(index);

                if (yokoFile == null)
                {
                    return(null);
                }

                FileImport result = uow.ImportFile(yokoFile);

                return(result);
            }
        }
Example #8
0
        public async Task <string> CreateFileImport(string path)
        {
            using (var scope = GlobalServices.Container.BeginLifetimeScope())
            {
                var repository = scope.Resolve <ICloudSpeedRepository>();
                var entity     = new FileImport()
                {
                    Path = path
                };
                await repository.CreateFileImport(entity);

                await repository.Commit();

                return(entity.Id);
            }
        }
Example #9
0
        public bool DeleteFileImport(int fileIndex)
        {
            FileImport fileImport = GetFileImport(fileIndex);

            if (fileImport != null)
            {
                // delete all the meter data for this import
                var query = _session.CreateQuery("delete from MeterData where FileImportID = :fileImportId");
                query.SetInt32("fileImportId", fileImport.FileImportID);
                query.ExecuteUpdate();

                // delete the import
                _session.Delete(fileImport);

                return(true);
            }

            return(false);
        }
Example #10
0
        private void NewFolder()
        {
            EnterStringForm frm = new EnterStringForm();

            frm.Text = "Enter Directory Name";
            if (DialogResult.OK == frm.ShowDialog())
            {
                XmlNode    node         = tree.SelectedNode.Tag as XmlNode;
                XmlElement newDirectory = node.OwnerDocument.CreateElement("Directory", WixFiles.WixNamespaceUri);
                newDirectory.SetAttribute("Name", frm.SelectedString);
                newDirectory.SetAttribute("Id", FileImport.GenerateValidIdentifier(frm.SelectedString, newDirectory, Wizard.WixFiles));
                node.AppendChild(newDirectory);

                TreeNode treeNode = new TreeNode();
                treeNode.Text               = frm.SelectedString;
                treeNode.ImageIndex         = ImageListFactory.GetImageIndex("Directory");
                treeNode.SelectedImageIndex = treeNode.ImageIndex;
                treeNode.SelectedImageIndex = treeNode.ImageIndex;
                treeNode.Tag = newDirectory;
                tree.SelectedNode.Nodes.Add(treeNode);
                tree.SelectedNode.Expand();
                treeNode.EnsureVisible();
            }
        }
    /// <summary>
    /// Import files.
    /// </summary>
    private void Import(object parameter)
    {
        try
        {
            object[]        parameters  = (object[])parameter;
            string[]        items       = (string[])parameters[0];
            CurrentUserInfo currentUser = (CurrentUserInfo)parameters[3];

            if ((items.Length > 0) && (currentUser != null))
            {
                resultListValues.Clear();
                errorFiles.Clear();
                hdnValue.Value    = null;
                hdnSelected.Value = null;
                string siteName        = CMSContext.CurrentSiteName;
                string targetAliasPath = ValidationHelper.GetString(parameters[1], null);

                bool imported    = false; // Flag - true if one file was imported at least
                bool importError = false; // Flag - true when import failed

                TreeProvider tree = new TreeProvider(currentUser);
                TreeNode     tn   = tree.SelectSingleNode(siteName, targetAliasPath, TreeProvider.ALL_CULTURES, true, null, false);
                if (tn != null)
                {
                    // Check if CMS.File document type exist and check if document contains required columns (FileName, FileAttachment)
                    DataClassInfo fileClassInfo = DataClassInfoProvider.GetDataClass("CMS.File");
                    if (fileClassInfo == null)
                    {
                        AddError(GetString("newfile.classcmsfileismissing"));
                        return;
                    }
                    else
                    {
                        FormInfo      fi        = new FormInfo(fileClassInfo.ClassFormDefinition);
                        FormFieldInfo fileFfi   = null;
                        FormFieldInfo attachFfi = null;
                        if (fi != null)
                        {
                            fileFfi   = fi.GetFormField("FileName");
                            attachFfi = fi.GetFormField("FileAttachment");
                        }
                        if ((fi == null) || (fileFfi == null) || (attachFfi == null))
                        {
                            AddError(GetString("newfile.someofrequiredfieldsmissing"));
                            return;
                        }
                    }

                    DataClassInfo dci = DataClassInfoProvider.GetDataClass(tn.NodeClassName);

                    if (dci != null)
                    {
                        // Check if "file" and "folder" are allowed as a child document under selected document type
                        bool          fileAllowed     = false;
                        bool          folderAllowed   = false;
                        DataClassInfo folderClassInfo = DataClassInfoProvider.GetDataClass("CMS.Folder");
                        if ((fileClassInfo != null) || (folderClassInfo != null))
                        {
                            string[] paths;
                            foreach (string fullFileName in items)
                            {
                                paths = fullFileName.Substring(rootPath.Length).Split('\\');
                                // Check file
                                if (paths.Length == 1)
                                {
                                    if (!fileAllowed && (fileClassInfo != null) && !DataClassInfoProvider.IsChildClassAllowed(dci.ClassID, fileClassInfo.ClassID))
                                    {
                                        AddError(GetString("Tools.FileImport.NotAllowedChildClass"));
                                        return;
                                    }
                                    else
                                    {
                                        fileAllowed = true;
                                    }
                                }

                                // Check folder
                                if (paths.Length > 1)
                                {
                                    if (!folderAllowed && (folderClassInfo != null) && !DataClassInfoProvider.IsChildClassAllowed(dci.ClassID, folderClassInfo.ClassID))
                                    {
                                        AddError(GetString("Tools.FileImport.FolderNotAllowedChildClass"));
                                        return;
                                    }
                                    else
                                    {
                                        folderAllowed = true;
                                    }
                                }

                                if (fileAllowed && folderAllowed)
                                {
                                    break;
                                }
                            }
                        }

                        // Check if user is allowed to create new file document
                        if (fileAllowed && !currentUser.IsAuthorizedToCreateNewDocument(tn, "CMS.File"))
                        {
                            AddError(GetString("accessdenied.notallowedtocreatedocument"));
                            return;
                        }

                        // Check if user is allowed to create new folder document
                        if (folderAllowed && !currentUser.IsAuthorizedToCreateNewDocument(tn, "CMS.Folder"))
                        {
                            AddError(GetString("accessdenied.notallowedtocreatedocument"));
                            return;
                        }
                    }

                    string   cultureCode      = ValidationHelper.GetString(parameters[2], "");
                    string[] fileList         = new string[1];
                    string[] relativePathList = new string[1];

                    // Begin log
                    AddLog(GetString("tools.fileimport.importingprogress"));

                    string msgImported = GetString("Tools.FileImport.Imported");
                    string msgFailed   = GetString("Tools.FileImport.Failed");

                    // Insert files selected in datagrid to list of files to import
                    foreach (string fullFileName in items)
                    {
                        // Import selected files only
                        fileList[0]         = fullFileName;
                        relativePathList[0] = fullFileName.Substring(rootPath.Length);

                        // Remove extension if needed
                        if (!chkIncludeExtension.Checked)
                        {
                            relativePathList[0] = Regex.Replace(relativePathList[0], "(.*)\\..*", "$1");
                        }

                        try
                        {
                            FileImport.ImportFiles(siteName, targetAliasPath, cultureCode, fileList, relativePathList, currentUser.UserID, chkDeleteImported.Checked);

                            // Import of a file succeeded, fill the output lists
                            resultListValues.Add(new string[] { fullFileName, msgImported, true.ToString() });

                            imported = true; // One file was imported
                            AddLog(HTMLHelper.HTMLEncode(fullFileName));
                        }
                        catch (Exception ex)
                        {
                            // File import failed
                            errorFiles.Add(fullFileName);
                            importError = true;

                            // Fill the output lists
                            resultListValues.Add(new string[] { fullFileName, msgFailed + " (" + HTMLHelper.HTMLEncode(ex.Message) + ")", false.ToString() });

                            AddError(msgFailed + " (" + HTMLHelper.HTMLEncode(ex.Message) + ")");

                            // Abort importing the rest of files for serious exceptions
                            if (!(ex is UnauthorizedAccessException))
                            {
                                return;
                            }
                        }
                    }
                }
                // Specified alias path not found
                else
                {
                    AddError(GetString("Tools.FileImport.AliasPathNotFound"));
                    return;
                }

                if (filesList.Count > 0)
                {
                    if (!importError)
                    {
                        if (imported)
                        {
                            AddError(GetString("Tools.FileImport.FilesWereImported"));
                            return;
                        }
                    }
                    else
                    {
                        AddError(GetString("Tools.FileImport.FilesNotImported"));
                        return;
                    }
                }
            }
            // No items selected to import
            else
            {
                AddError(GetString("Tools.FileImport.FilesNotImported"));
                return;
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state == CMSThread.ABORT_REASON_STOP)
            {
                // When canceled
            }
            else
            {
                // Log error
                LogExceptionToEventLog(ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            LogExceptionToEventLog(ex);
        }
    }
Example #12
0
        public FileImport ImportFile(YokogawaFile yokoFile)
        {
            FileImport result = GetFileImport(yokoFile.Index);

            if (result != null)
            {
                return(result);
            }

            var data = yokoFile.GetData();

            var count = 0;

            if (data != null)
            {
                count = data.Count();
            }

            using (var statelessSession = _sessionFactory.OpenStatelessSession())
                using (var statelessTransaction = statelessSession.BeginTransaction())
                {
                    try
                    {
                        result = new FileImport()
                        {
                            FileIndex  = yokoFile.Index,
                            FilePath   = yokoFile.FilePath,
                            ImportDate = DateTime.Now,
                            LineCount  = count
                        };

                        statelessSession.Insert(result);

                        if (count > 0)
                        {
                            var items = data.Select(x => new MeterData()
                            {
                                FileIndex = yokoFile.Index,
                                LineIndex = x.LineIndex,
                                Header    = x.Header,
                                TimeStamp = x.TimeStamp,
                                Value     = x.Value
                            });

                            foreach (var item in items)
                            {
                                statelessSession.Insert(item);
                            }
                        }

                        statelessTransaction.Commit();

                        return(result);
                    }
                    catch
                    {
                        statelessTransaction.Rollback();
                        throw;
                    }
                    finally
                    {
                        statelessSession.Close();
                    }
                }
        }
Example #13
0
        public BaseModel <object> ImportFile([FromBody] FileImport data)
        {
            BaseModel <object> _baseModel = new BaseModel <object>();
            ErrorModel         _error     = new ErrorModel();

            string    Token     = _account.GetHeader(Request);
            LoginData loginData = _account._GetInfoUser(Token);

            if (loginData == null)
            {
                return(_baseModel = new BaseModel <object>
                {
                    data = null,
                    status = 0,
                    error = new ErrorModel
                    {
                        code = Constant.ERRORDATA,
                        message = "Phiên đăng nhập hết hạn hoặc bạn chưa truyền Token"
                    }
                });
            }
            try
            {
                if (string.IsNullOrEmpty(data.base64) && data.fileByte == null)
                {
                    return(_baseModel = new BaseModel <object>
                    {
                        data = null,
                        status = 0,
                        error = new ErrorModel
                        {
                            code = Constant.ERRORDATA,
                            message = "Chưa có file upload"
                        }
                    });
                }

                if (!data.extension.Equals("txt"))
                {
                    return(_baseModel = new BaseModel <object>
                    {
                        data = null,
                        status = 0,
                        error = new ErrorModel
                        {
                            code = Constant.ERRORDATA,
                            message = "Sai định dạng File, vui lòng thử lại!"
                        }
                    });
                }

                byte[] _fileByte = null;

                if (data.fileByte != null)
                {
                    _fileByte = data.fileByte;
                }
                else
                {
                    _fileByte = Convert.FromBase64String(data.base64);
                }

                string _path = Constant.USER_DATA_UPLOAD_FOLDER + "/" + loginData.Id + "/Import/";

                string _targetPath = Path.Combine(_hostingEnvironment.ContentRootPath, _path);

                if (!Directory.Exists(_targetPath))
                {
                    Directory.CreateDirectory(_targetPath);
                }

                string _fileName = _targetPath + "Items" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + data.filename + "." + data.extension;
                System.IO.File.WriteAllBytes(_fileName, _fileByte);
                try
                {
                    string dataString = Encoding.UTF8.GetString(Convert.FromBase64String(data.base64));

                    List <ItemsImportModel> list = JsonConvert.DeserializeObject <List <ItemsImportModel> >(dataString);

                    list.ForEach(s => s.Type = _context.DBTypeItems.Where(db => db.IdType == data.idLoai).Select(se => se.Name).FirstOrDefault());

                    list.ForEach(s => s.IdType = data.idLoai);

                    if (list.Count() <= 0)
                    {
                        return(_baseModel = new BaseModel <object>
                        {
                            data = null,
                            status = 0,
                            error = new ErrorModel
                            {
                                code = Constant.ERRORDATA,
                                message = "File import không có dữ liệu!"
                            }
                        });
                    }

                    _baseModel.status = 1;
                    _baseModel.data   = list;
                    return(_baseModel);
                }
                catch (Exception ex)
                {
                    return(_baseModel = new BaseModel <object>
                    {
                        data = null,
                        status = 0,
                        error = new ErrorModel
                        {
                            code = Constant.ERRORCODE,
                            message = "Lỗi dữ liệu trong file import hoặc không đúng mẫu, không thể convert" + ex.Message
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                return(_baseModel = new BaseModel <object>
                {
                    data = null,
                    status = 0,
                    error = new ErrorModel
                    {
                        code = Constant.ERRORCODE,
                        message = "Upload file import thất bại: " + ex.Message
                    }
                });
            }
        }
Example #14
0
        private void SaveFile(int accountId, ImportCsvDefinition importCsvDefinition, FileImport fileImport, List <BankTransaction> transactionList)
        {
            var file = new BankFile();

            file.AccountId   = accountId;
            file.FileContent = fileImport.FileContent;
            file.ContentType = fileImport.ContentType;
            file.FileName    = fileImport.FileName;

            AddTransactions(file, transactionList);

            ApplyBestRule(file.Transactions);

            base.Add(file);
        }
Example #15
0
        public void ImportFile(int accountId, ImportCsvDefinition importCsvDefinition, FileImport fileImport)
        {
            VaidateImportColumnIndex(importCsvDefinition);
            var transactionList = ParseFile(importCsvDefinition, fileImport.FileContent);

            SaveFile(accountId, importCsvDefinition, fileImport, transactionList);
            UpdateImportCsvDefinition(accountId, importCsvDefinition);
        }
Example #16
0
        private void ImportFilesInComponent(TreeNode node, XmlNode componentNode, string[] files)
        {
            if (componentNode.Name == "Component")
            {
                bool mustExpand = (node.Nodes.Count == 0);

                CurrentTreeView.SuspendLayout();

                bool foundReg = false;
                foreach (string file in files)
                {
                    if (Path.GetExtension(file).ToLower() == ".reg")
                    {
                        foundReg = true;
                        break;
                    }
                }

                bool importRegistryFiles = false;
                if (foundReg == true)
                {
                    DialogResult result = MessageBox.Show(this, "Import Registry (*.reg) files to Registry elements?", "Import?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                    else if (result == DialogResult.Yes)
                    {
                        importRegistryFiles = true;
                    }
                }

                WixFiles.UndoManager.BeginNewCommandRange();
                StringBuilder errorMessageBuilder = new StringBuilder();

                foreach (string file in files)
                {
                    FileInfo fileInfo = new FileInfo(file);
                    try
                    {
                        if (fileInfo.Extension.ToLower() == ".reg" && importRegistryFiles)
                        {
                            RegistryImport regImport = new RegistryImport(WixFiles, fileInfo, componentNode);
                            regImport.Import(node);
                        }
                        else
                        {
                            FileImport fileImport = new FileImport(WixFiles, fileInfo, componentNode);
                            fileImport.Import(node);
                        }
                    }
                    catch (WixEditException ex)
                    {
                        errorMessageBuilder.AppendFormat("{0} ({1})\r\n", fileInfo.Name, ex.Message);
                    }
                    catch (Exception ex)
                    {
                        string        message = String.Format("An exception occured during the import of \"{0}\"! Please press OK to report this error to the WixEdit website, so this error can be fixed.", fileInfo.Name);
                        ExceptionForm form    = new ExceptionForm(message, ex);
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            ErrorReporter reporter = new ErrorReporter();
                            reporter.Report(ex);
                        }
                    }
                }

                if (errorMessageBuilder.Length > 0)
                {
                    MessageBox.Show(this, "Import failed for the following files:\r\n\r\n" + errorMessageBuilder.ToString(), "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                ShowNode(componentNode);

                if (mustExpand)
                {
                    node.Expand();
                }

                CurrentTreeView.ResumeLayout();
            }
        }
Example #17
0
 public async Task CreateFileImport(FileImport entity)
 {
     await DbContext.FileImports.AddAsync(entity);
 }
Example #18
0
        /// <summary>
        /// Scan a DAT file and look for signatures
        /// </summary>
        static void SearchDat(string filename)
        {
            Console.WriteLine($"Searching {filename} for valid entries...");

            // Statistics:
            HashSet <string>          unhandled    = new HashSet <string>();
            Dictionary <string, long> entryTypes   = new Dictionary <string, long>();
            Dictionary <int, long>    messageTypes = new Dictionary <int, long>();
            DateTime         earliest   = DateTime.MaxValue;
            DateTime         latest     = DateTime.MinValue;
            HashSet <string> properties = new HashSet <string>();
            int duplicateContacts       = 0;
            int duplicateMessages       = 0;

            var datFile = new DatFile();
            var rdr     = new FileReader();

            Parser.DefaultDumpFormat = DumpFormat.Hex;
            //Parser.Debug = true;

            HexDumperConsole console = new HexDumperConsole();

            Parser.Dumper.Console = console;

            rdr.Open(filename);

            datFile.MainHeader.Read(rdr);

            FileImport fi = new FileImport()
            {
                Filename = filename, ImportDate = DateTime.Now
            };

            _context.FileImports.Add(fi);
            _context.SaveChanges();

            var fileImportId = fi.Id;

            byte prev0 = 0;
            byte prev1 = 0;
            long ix    = 0;

            //rdr.GoTo(0x265280);
            //console.ColorSpan = new ColorSpan(ConsoleColor.Green, 0x265290, 0x265290 + 4 + 146);

            try
            {
                while (true)
                {
                    Data8 d = new Data8();
                    d.Read(rdr);

                    if (prev0 == 0x23 && d.Value == 0xA3)
                    {
                        string code = prev1.ToString("X2");
                        Parser.Dumper.OnInfo($"Found sig with code: {code}");
                        entryTypes[code] = entryTypes.GetValueOrDefault(code) + 1;

                        if (datFile.ValidSigs.Contains(prev1))
                        {
                            var pos = rdr.Position;
                            rdr.GoTo(pos - (4 + 4 + 4 + 3));

                            datFile.PolyChunk.Read(rdr);

                            if (datFile.PolyChunk.CurrentType == typeof(E0Entry))
                            {
                                E0Entry entry = ((E0Entry)datFile.PolyChunk.CurrentChunk);
                                int     mtype = entry.entrySubtype.Value;
                                messageTypes[mtype] = messageTypes.GetValueOrDefault(mtype) + 1;
                                if (entry.timestamp.Value < earliest)
                                {
                                    earliest = entry.timestamp.Value;
                                }
                                if (entry.timestamp.Value > latest)
                                {
                                    latest = entry.timestamp.Value;
                                }

                                var msg = ToMessage((E0Entry)datFile.PolyChunk.CurrentChunk);

                                if (_context.Messages.Any(m => m.Hash == msg.Hash))
                                {
                                    duplicateMessages++;
                                }
                                else
                                {
                                    msg.FileImportId = fileImportId;
                                    _context.Messages.Add(msg);
                                    _context.SaveChanges();
                                }
                            }

                            if (datFile.PolyChunk.CurrentType == typeof(E5Entry))
                            {
                                E5Entry e = (E5Entry)datFile.PolyChunk.CurrentChunk;

                                e.Properties.Keys.ToList().ForEach(p => properties.Add(p));

                                var ct = ToContact(e);

                                if (_context.Contacts.Any(c => c.Hash == ct.Hash))
                                {
                                    duplicateContacts++;
                                }
                                else
                                {
                                    foreach (var pv in e.Properties)
                                    {
                                        var ctp = new ContactProperty()
                                        {
                                            UIN   = e.UIN,
                                            Name  = pv.Key,
                                            Value = pv.Value,
                                        };
                                        _context.ContactProperties.Add(ctp);
                                    }

                                    ct.FileImportId = fileImportId;
                                    _context.Contacts.Add(ct);
                                    _context.SaveChanges();
                                }
                            }

                            prev0 = prev1 = 0;
                            d.StartNew();
                        }
                        else
                        {
                            if (!unhandled.Contains(code))
                            {
                                unhandled.Add(code);
                                Parser.Dumper.OnInfo("Unhandled signatures: " + string.Join(", ", unhandled.ToArray()));
                            }
                        }
                    }

                    if (prev1 == 0x50 && prev0 == 0x3B && d.Value == 0xC1)
                    {
                        // Long message format
                        var pos = rdr.Position;
                        rdr.GoTo(pos - (4 + 4 + 4 + 3));

                        datFile.LongMessage.Read(rdr);

                        string code = "Long";
                        entryTypes[code] = entryTypes.GetValueOrDefault(code) + 1;

                        int mtype = datFile.LongMessage.entrySubtype.Value;
                        messageTypes[mtype] = messageTypes.GetValueOrDefault(mtype) + 1;

                        if (datFile.LongMessage.timestamp.Value < earliest)
                        {
                            earliest = datFile.LongMessage.timestamp.Value;
                        }
                        if (datFile.LongMessage.timestamp.Value > latest)
                        {
                            latest = datFile.LongMessage.timestamp.Value;
                        }

                        var msg = ToMessage(datFile.LongMessage);
                        if (_context.Messages.Any(m => m.Hash == msg.Hash))
                        {
                            duplicateMessages++;
                        }
                        else
                        {
                            msg.FileImportId = fileImportId;
                            _context.Messages.Add(msg);
                            _context.SaveChanges();
                        }

                        prev0 = prev1 = 0;
                        d.StartNew();
                    }

                    // Go on scanning
                    prev1 = prev0;
                    prev0 = d.Value;
                    ix++;

                    if (ix % 256 * 16 == 0)
                    {
                        Parser.Dumper.OnInfo("");
                    }
                }
            }
            catch (ParserEOFException)
            {
                Parser.Dumper.OnInfo("End of file.");
            }
            catch (Exception ex)
            {
                Parser.Dumper.OnInfo("Unhandled Exception: " + ex.Message);
            }

            StringBuilder sb = new StringBuilder();

            Console.WriteLine("");
            Console.WriteLine("Statistics for file: " + filename);
            sb.Append("Statistics for file: " + filename + Environment.NewLine);

            Console.WriteLine("");
            Console.WriteLine("Unhandled signatures: " + string.Join(", ", unhandled.ToArray()));
            sb.Append("Unhandled signatures: " + string.Join(", ", unhandled.ToArray()));

            Console.WriteLine("");
            Console.WriteLine("Duplicated Contacts: " + duplicateContacts);
            sb.Append("Duplicated Contacts: " + duplicateContacts);

            Console.WriteLine("");
            Console.WriteLine("Duplicated Messages: " + duplicateMessages);
            sb.Append("Duplicated Messages: " + duplicateMessages);

            Console.WriteLine("");
            Console.WriteLine("Earliest message: " + earliest.ToString("yyyy-MM-dd HH:mm:ss"));
            Console.WriteLine("Latest message  : " + latest.ToString("yyyy-MM-dd HH:mm:ss"));
            sb.Append("Latest message  : " + latest.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
            sb.Append("Earliest message: " + earliest.ToString("yyyy-MM-dd HH:mm:ss") + "\n");

            Console.WriteLine("Entry types:\n" + entryTypes.Dump());
            sb.Append("Entry types:\n" + entryTypes.Dump());

            Console.WriteLine("");
            Console.WriteLine("Message types:\n" + messageTypes.Dump());
            sb.Append("Message types:\n" + messageTypes.Dump());

            Console.WriteLine("");
            Console.WriteLine("Contact properties: " + string.Join(", ", properties.ToArray()));

            fi.Statistics            = sb.ToString();
            _context.Entry(fi).State = EntityState.Modified;
            _context.SaveChanges();
        }