Exemplo n.º 1
0
        public void WriteToDataBase(string pathToLogFile)
        {
            var modelList = CreatetModelList(pathToLogFile);

            using (LogFileContext context = new LogFileContext())
            {
                foreach (var item in modelList)
                {
                    context.logInfo.Add(item);
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private async Task GetTitleAsync(List <TempInfoFiles> list, int start, int end)
        {
            await Task.Run(() =>
            {
                int count = 0;
                using (LogFileContext context = new LogFileContext())
                {
                    Writer <InfoAboutFile> writerInfoFile = new Writer <InfoAboutFile>(context);

                    Stream stream     = null;
                    Encoding encoding = null;
                    string title      = null;

                    for (int i = start; i < end; i++)
                    {
                        CreateStream(list, ref stream, ref encoding, i);
                        try
                        {
                            using (StreamReader reader = new StreamReader(stream, encoding))
                            {
                                while (reader.EndOfStream != true)
                                {
                                    title = reader.ReadLine();
                                    if (title.Contains("title"))
                                    {
                                        title = title.Split(new[] { "<title>", "</title>" }, StringSplitOptions.RemoveEmptyEntries)[1];
                                        break;
                                    }
                                }
                            }
                            context.FilesInfo.Add(ModelInfoAboutFileFill(list[i], title));
                            //writerInfoFile.WriteToDb(ModelInfoAboutFileFill(list[i], title));
                        }
                        catch (ArgumentOutOfRangeException e)
                        {
                            context.FilesInfo.Add(ModelInfoAboutFileFill(list[i], string.Empty));
                            //writerInfoFile.WriteToDb(ModelInfoAboutFileFill(list[i], string.Empty));
                        }

                        catch (Exception e)
                        {
                            context.FilesInfo.Add(ModelInfoAboutFileFill(list[i], string.Empty));
                            //writerInfoFile.WriteToDb(ModelInfoAboutFileFill(list[i], string.Empty));
                        }
                        Console.WriteLine(count++);
                    }
                    context.SaveChanges();
                }
            });
        }