示例#1
0
        private static void OnTimedEvent(string identity, Entities entities)
        {
            var originalTextRepository = new OriginalTextRepository(entities);

            try
            {
                PoccessTexts(identity, originalTextRepository, entities);

                entities = new Entities();
                var count = entities.OriginalTexts.Count(t => t.ProcessedText == null);

                if (count != 0)
                {
                    OnTimedEvent(identity, entities);
                }
            }
            catch (DbUpdateConcurrencyException e)
            {
                Console.WriteLine("DbUpdateConcurrencyException {0}", identity);

                entities = new Entities();
                var count = entities.OriginalTexts.Count(t => t.ProcessedText == null);

                if (count != 0)
                {
                    Console.WriteLine(identity);

                    OnTimedEvent(identity, new Entities());
                }
            }
            catch (DataException)
            {
                Console.WriteLine("DataException. Что-то пошло не так. Свяжитесь с системный администратором.");
            }
        }
示例#2
0
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            var entities = new Entities();

            var start = DateTime.Now;

            ProccessTexts(entities, start);
        }
        public TextDto GetTextById(int id)
        {
            using (var context = new Entities())
            {
                var singleOrDefault = context
                    .OriginalTexts
                    .SingleOrDefault(ot => ot.Id == id && ot.IsShared == true);

                return singleOrDefault != null ? singleOrDefault.ToDto() : null;
            }
        }
        public string GetCrazyTextById(int id)
        {
            using (var context = new Entities())
            {
                var singleOrDefault = context
                    .OriginalTexts
                    .SingleOrDefault(ot => ot.Id == id && ot.IsShared == true);

                return singleOrDefault != null ? singleOrDefault.ProcessedText : null;
            }
        }
 public List<TextDto> GetTextsFromMainPage()
 {
     using (var context = new Entities())
     {
         return context
             .OriginalTexts
             .Where(ot => ot.IsShared == true)
             .ToList()
             .Select(t => t.ToDto())
             .ToList();
     }
 }
 public List<string> GetTextsTitles()
 {
     using (var context = new Entities())
     {
         return context
             .OriginalTexts
             .Where(ot => ot.IsShared == true)
             .Select(ot => ot.Text)
             .ToList()
             .Select(text => text.FirstWords(3))
             .ToList();
     }
 }
示例#7
0
        private static void PoccessTexts(string identity, OriginalTextRepository originalTextRepository, Entities entities)
        {
            var testsToGenerate = originalTextRepository.GetAll(t => t.ProcessedText == null).Take(10).ToList();
            testsToGenerate
                .ForEach(
                    t =>
                    {
                        t.ProcessedText = "test - " + identity;
                        t.ProcessedDate = DateTime.Now;
                    }
                );

            entities.SaveChanges();
        }
示例#8
0
        private void PoccessTextsPart(OriginalTextRepository originalTextRepository, Entities entities)
        {
            var testsToGenerate = originalTextRepository
                .GetAll(t => t.ProcessedText == null)
                .Take(Config.PollingPartSize)
                .ToList();

            testsToGenerate
                .ForEach(
                    t =>
                    {
                        t.ProcessedText = GenerateMarkovChain(t.Text);
                        t.ProcessedDate = DateTime.Now;
                    }
                );

            entities.SaveChanges();
        }
 public OriginalTextRepository(Entities entities)
 {
     _entities = entities;
 }
 public OriginalTextRepository()
 {
     _entities = new Entities();
 }
示例#11
0
        /// <summary>
        /// Рекурсивная обработка не обработанных текстов
        /// </summary>
        /// <param name="entities">Экземпляр контекста</param>
        /// <param name="start">Время первого запуска метода</param>
        private void ProccessTexts(Entities entities, DateTime start)
        {
            //На основе контекста инициализируем репозиторий
            var originalTextRepository = new OriginalTextRepository(entities);
            //кол-во необработанных текстов
            var count = 1;

            while (count != 0)
            {
                //Пытаемся обработать порцию текстов
                try
                {
                    PoccessTextsPart(originalTextRepository, entities);
                }
                //если кто-то уже обработал текста повторяем попытку, если в базе еще остались необработанные текста
                catch (DbUpdateConcurrencyException dbocex)
                {
                    Logger.Error(dbocex);
                }
                catch (DataException dex)
                {
                    Logger.Error(dex);
                    break;
                }

                if (DateTime.Now.Subtract(start).Minutes >= Config.MaximumPoolingRuntimeInMinutes)
                {
                    break;
                }

                entities = new Entities();
                originalTextRepository = new OriginalTextRepository(entities);
                count = entities.OriginalTexts.Count(t => t.ProcessedText == null);
            }
        }
 public UserRepository(Entities entities)
 {
     _entities = entities;
 }
 public UserRepository()
 {
     _entities = new Entities();
 }