private static void _init()
 {
     if (!LS.IsExistInCache(cachekey))
     {
         var instances = (from t in Assembly.GetExecutingAssembly().GetTypes()
                          where t.GetInterfaces().Contains(typeof(IDiscountRule)) &&
                          t.GetConstructor(Type.EmptyTypes) != null
                          select Activator.CreateInstance(t) as IDiscountRule).ToDictionary(x => x.GetType().Name);
         instances.SetMeToCache(cachekey);
     }
     rules = LS.GetFromCache <Dictionary <string, IDiscountRule> >(cachekey);
 }
Esempio n. 2
0
        public void Execute()
        {
            string key    = "image.existchek.lastid";
            int    fromID = 0;

            if (LS.IsExistInCache(key))
            {
                fromID = LS.GetFromCache <int>(key);
            }

            using (Db _db = new Db())
            {
                var products = _db.Products.Where(x => x.HasImage && x.ID > fromID)
                               .Select(x => new
                {
                    x.ID,
                    x.Image
                }).Take(1000).ToList();
                LS.SetToCache(products.Select(x => x.ID).DefaultIfEmpty(0).Max(), key);
                foreach (var p in products)
                {
                    if (!string.IsNullOrEmpty(p.Image))
                    {
                        var path = HostingEnvironment.MapPath("~" + p.Image);
                        if (path.Contains("wwwroot"))
                        {
                            if (!System.IO.File.Exists(path))
                            {
                                var sql = string.Format("UPDATE [{0}] SET [Image] = null, HasImage = 0  WHERE [ID] = {1} ",
                                                        "Products",
                                                        p.ID //,
                                                             // p.Image.Replace("'", @"''") //fix string insert
                                                        );
                                _db.Database.ExecuteSqlCommand(sql);
                            }
                        }
                    }
                    else
                    {
                        var sql = string.Format("UPDATE [{0}] SET [Image] = null, HasImage = 0  WHERE [ID] = {1} ",
                                                "Products",
                                                p.ID //,
                                                     // p.Image.Replace("'", @"''") //fix string insert
                                                );
                        _db.Database.ExecuteSqlCommand(sql);
                    }
                }
            }
        }
        public void Execute()
        {
            lock (_lock)
            {
                string key = "image.importsync.lock";

                if (LS.IsExistInCache(key) && LS.GetFromCache <bool>(key))
                {
                    return; // already running
                }
                LS.SetToCache(true, key);
                using (Db _db = new Db())
                {
                }

                //laset process
                LS.SetToCache(false, key);
            }
        }