Example #1
0
        /// <summary>
        /// Method called to remove oldest QuerryInfo entities and all connected elements in Items and ItemParams from database that exceed history range.
        /// </summary>
        public void QueryRemower_Work()
        {
            var      db    = new AppDatabase.AllegroAppContext();
            DateTime teraz = DateTime.Now;
            int      numberOfItemsToBeRemoved = db.QueryInfo.Select(x => x.Querry).Distinct().Count() - 3;


            if (numberOfItemsToBeRemoved > 0)
            {
                var stringOfQueryToBeRemoved     = db.QueryInfo.OrderBy(y => y.Date).Distinct().Select(x => x.Querry).Take(numberOfItemsToBeRemoved).ToList();
                var TmpListOfAllItemsToBeRemoved = new List <QueryInfo>();

                foreach (var item in stringOfQueryToBeRemoved)
                {
                    foreach (var item2 in db.QueryInfo.Where(x => x.Querry == item).ToList())
                    {
                        TmpListOfAllItemsToBeRemoved.Add(item2);
                    }
                }

                foreach (var item in TmpListOfAllItemsToBeRemoved)
                {
                    RemoveAllEntitiesWithID(item.Id);
                    //RemovePictures(item.Id, item.Querry);
                }
            }
            else
            {
                RemoveOutdatedQuery(teraz);
            }
        }
Example #2
0
        /// <summary>
        /// Method removes entities from ItemParams with Querry_Id equal to queryId
        /// </summary>
        /// <param name="queryId"></param>
        public void RemoveFromItemParamsElements(int queryId)
        {
            var db          = new AppDatabase.AllegroAppContext();
            var toBeRemoved = db.ItemParams.Where(x => x.Querry_id == queryId).ToList();

            foreach (var entity in toBeRemoved)
            {
                db.ItemParams.Remove(entity);
            }
            db.SaveChanges();
        }
Example #3
0
        /// <summary>
        /// Method removes Old query results, if current query already exists in datatabase
        /// </summary>
        /// <returns>bool true if old querry wa removed</returns>
        public void RemoveOutdatedQuery(DateTime LastTime)
        {
            using (var db = new AppDatabase.AllegroAppContext())
            {
                var LatestQuery = db.QueryInfo.OrderByDescending(r => r.Date).Select(q => q.Querry).FirstOrDefault();

                var timeDiference          = LastTime.AddSeconds(-15);
                var SearchForOutdatedQuery = db.QueryInfo.Where(x => x.Querry == LatestQuery && x.Date < timeDiference);


                if (SearchForOutdatedQuery.Any())
                {
                    foreach (var item in SearchForOutdatedQuery)
                    {
                        RemoveAllEntitiesWithID(item.Id);
                        //RemovePictures(item.Id, item.Querry);
                    }
                }

                db.SaveChanges();
            }
        }