Ejemplo 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();
            }
        }
Ejemplo 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.SaveChangesAsync();
                }
            });
        }
Ejemplo n.º 3
0
        private async Task RunTasksAsync(InfoAboutFile infoAboutFile)
        {
            List <TempInfoFiles> list;

            using (LogFileContext context = new LogFileContext())
            {
                list = context.logInfo.Select(x => new TempInfoFiles {
                    PathName = x.Path, Size = x.Size
                }).ToList();
            }
            int  countTread = 2;
            Task task0      = GetTitleAsync(list, 0, 1 * list.Count / countTread);
            Task task1      = GetTitleAsync(list, 1 * list.Count / countTread, 2 * list.Count / countTread);

            await Task.WhenAll(task0, task1);
        }
Ejemplo n.º 4
0
        public void  CreatModel(string path)
        {
            Reader reader   = new Reader();
            var    listTemp = reader.ReadFromFile(path);

            foreach (var item in listTemp)
            {
                logInfo = FillModel(item, logInfo);
                writerLogInfo.WriteToDb(logInfo);
            }

            List <string>        listIP       = new List <string>();
            List <TempInfoFiles> listFileName = new List <TempInfoFiles>();

            using (LogFileContext db = new LogFileContext())
            {
                listIP = db.logInfo.Select(x => x.IpAddress).Distinct().ToList();
            }
            Task task = GetOwnersIpsAsync(listIP, writerIpAddress, ipAddressCompany);
            Task t    = RunTasksAsync(infoAboutFile);

            task.Wait();
            t.Wait();
        }