public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // Read database connection string and open database.
            var dbConnString = CloudConfigurationManager.GetSetting("AdsDbConnectionString");
            db = new AdsContext(dbConnString);

            // Open storage account using credentials from .cscfg file.
            var storageAccount = CloudStorageAccount.Parse
                (RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            Trace.TraceInformation("Creating images blob container");
            var blobClient = storageAccount.CreateCloudBlobClient();
            imagesBlobContainer = blobClient.GetContainerReference("images");
            if (imagesBlobContainer.CreateIfNotExists())
            {
                // Enable public access on the newly created "images" container.
                imagesBlobContainer.SetPermissions(
                    new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Blob
                    });
            }

            Trace.TraceInformation("Creating images queue");
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            imagesQueue = queueClient.GetQueueReference("images");
            imagesQueue.CreateIfNotExists();

            bool result = base.OnStart();
            Trace.TraceInformation("Storage initialized");
            return result;
        }
Example #2
0
 public AdsFamilyAttributesRepository(AdsContext context, IMapper mapper) :
     base(context.FamilyAttributes, vm => context.FamilyAttributes.FirstOrDefault(a => a.FamilyAttributeId == vm.FamilyAttributeId),
          familyAttributeId =>
          context.FamilyAttributes.FirstOrDefault(fa => fa.FamilyAttributeId == familyAttributeId), mapper)
 {
     _context = context;
 }
Example #3
0
        public static async Task SeedAsync(AdsContext context, UserManager <ApplicationUser> userManager)
        {
            if (!await context.Users.AnyAsync(x => x.Email == "*****@*****.**"))
            {
                var user = new ApplicationUser()
                {
                    Email     = "*****@*****.**",
                    UserName  = "******",
                    FirstName = "Admin",
                    LastName  = "Admin"
                };
                await userManager.CreateAsync(user, "password");

                await userManager.AddToRoleAsync(user, "Admin");
            }
            if (!await context.Users.AnyAsync(x => x.Email == "*****@*****.**"))
            {
                var user = new ApplicationUser()
                {
                    Email     = "*****@*****.**",
                    UserName  = "******",
                    FirstName = "member",
                    LastName  = "member"
                };
                await userManager.CreateAsync(user, "password");

                await userManager.AddToRoleAsync(user, "Member");
            }
        }
        static void Main()
        {
            AdsContext context = new AdsContext();

            context.Ads.Count();
            //SlowWay(context); //Time elapsed for slow query: 00:00:00.0610211
            //FasterWay(context); //Time elapsed for fast query: 00:00:00.0158581
        }
Example #5
0
 public void Invoke(AdsContext context, RequestHandler next)
 {
     if (!Capture(context))
     {
         next();
     }
     Bubble(context);
 }
Example #6
0
        public AdsContext GetArticleDbContext()
        {
            var options = new DbContextOptionsBuilder <AdsContext>()
                          .UseInMemoryDatabase(databaseName: "InMemoryArticleDatabase")
                          .Options;
            var dbContext = new AdsContext(options);

            return(dbContext);
        }
 private static void NonOptimized(AdsContext db)
 {
     var adds = db.Ads.ToList()
                .Where(a => a.AdStatus.Status == "Published")
                .Select(a => new
     {
         a.Title,
         Category = (a.Category == null ? " null" : a.Category.Name),
         Town     = (a.Town == null ? " null " : a.Town.Name),
         a.Date
     }).ToList().OrderBy(a => a.Date);
 }
Example #8
0
        static void Main(string[] args)
        {
            var db = new AdsContext();

            Console.WriteLine(db.Ads.Count());
            var sw = new Stopwatch();

            sw.Stop();

            SlowVersion(db, sw);


            //OptimizedVersion(db, sw);
        }
Example #9
0
        public static async Task SeedAsync(AdsContext context)
        {
            if (!context.Roles.Any())
            {
                foreach (var role in GetPreconfiguredRoles())
                {
                    await context.Roles.AddRangeAsync(new IdentityRole()
                    {
                        Name = role, NormalizedName = role.ToUpper()
                    });
                }

                await context.SaveChangesAsync();
            }
        }
        public static void ExecuteWithInclude()
        {
            Stopwatch watchStopwatch = new Stopwatch();

            watchStopwatch.Start();
            AdsContext       context = new AdsContext();
            IEnumerable <Ad> dbSet   = context.Ads.Include("AdStatus").Include("Category").Include("Town").Include("AspNetUser");

            foreach (var ad in dbSet)
            {
                Console.WriteLine($"{ad.Title} {ad.AdStatus?.Status} {ad.Category?.Name} {ad.Town?.Name} {ad.AspNetUser?.UserName}");
            }

            watchStopwatch.Stop();
            Console.WriteLine($"Execution without includes: {watchStopwatch.Elapsed}");
        }
Example #11
0
        private static void Opitmized()
        {
            Stopwatch  stopwatch = new Stopwatch();
            AdsContext context   = new AdsContext();

            context.Ads.Count();
            stopwatch.Start();
            IEnumerable <string> ads = context.Ads.Select(ad => ad.Title);

            foreach (string ad in ads)
            {
                Console.WriteLine(ad);
            }
            stopwatch.Stop();

            File.AppendAllText("optimized.txt", stopwatch.Elapsed.ToString() + Environment.NewLine);
        }
Example #12
0
        private static void NonOptimized()
        {
            Stopwatch  stopwatch = new Stopwatch();
            AdsContext context   = new AdsContext();

            context.Ads.Count();
            stopwatch.Start();
            IEnumerable <Ad> ads = context.Ads;

            foreach (Ad ad in ads)
            {
                Console.WriteLine(ad.Title);
            }
            stopwatch.Stop();

            File.AppendAllText("non-optimized.txt", stopwatch.Elapsed.ToString() + Environment.NewLine);
        }
        private static void SlowWay(AdsContext context)
        {
            Stopwatch slowway = new Stopwatch();

            slowway.Start();

            var ads = context.Ads.ToList().Where(ad => ad.AdStatus?.Status == "Published").Select(ad => new
            {
                ad.Title,
                CategoryName = ad.Category?.Name,
                TownName     = ad.Town?.Name,
                Date         = ad.Date
            }).ToList().OrderBy(arg => arg.Date);

            foreach (var ad in ads)
            {
                Console.WriteLine($"{ad.Title} {ad.CategoryName} {ad.TownName} {ad.Date}");
            }

            slowway.Stop();
            Console.WriteLine($"Time elapsed for slow query: {slowway.Elapsed}");
        }
        static void Main(string[] args)
        {
            var db = new AdsContext();

            Console.WriteLine(db.Ads.Count());
            Console.WriteLine("---Non Optimized ");
            var sw = new Stopwatch();

            sw.Start();

            var totalNoNOptimizedTime = 0;
            var totalOptimizedTime    = 0;

            var nonOpitmizedTotalTime = 0;

            for (int i = 0; i < 10; i++)
            {
                db.Database.ExecuteSqlCommand(@"CHECKPOINT; DBCC DROPCLEANBUFFERS;");
                NonOptimized(db);
                var timeToRun = sw.Elapsed;
                totalNoNOptimizedTime += timeToRun.Milliseconds;
                Console.WriteLine("Time : " + timeToRun.Milliseconds);
                sw.Restart();
            }
            Console.WriteLine("Average time :" + totalNoNOptimizedTime / 10);
            Console.WriteLine();
            Console.WriteLine("---Optimized");
            sw.Restart();
            for (int i = 0; i < 10; i++)
            {
                db.Database.ExecuteSqlCommand(@"CHECKPOINT; DBCC DROPCLEANBUFFERS;");
                Optimized(db);
                var timeToRun = sw.Elapsed;
                totalOptimizedTime += timeToRun.Milliseconds;
                Console.WriteLine("Time : " + timeToRun.Milliseconds);
                sw.Restart();
            }
            Console.WriteLine("Average time :" + totalOptimizedTime / 10);
        }
Example #15
0
        private static void SlowVersion(AdsContext db, Stopwatch sw)
        {
            var addsTitle = db.Ads;

            sw.Start();
            var fullSelectTime = 0;

            for (int i = 0; i < 10; i++)
            {
                db.Database.ExecuteSqlCommand(@"CHECKPOINT; DBCC DROPCLEANBUFFERS;");
                foreach (var ad in addsTitle)
                {
                    Console.WriteLine("         " + ad.Title);
                }
                var selectTime = sw.Elapsed.Milliseconds;
                Console.WriteLine(selectTime + " miliseconds");
                fullSelectTime += selectTime;
                sw.Restart();
            }

            Console.WriteLine(fullSelectTime / 10 + " miliseconds - average time ");
            sw.Stop();
        }
        private static void FasterWay(AdsContext context)
        {
            Stopwatch fastwatch = new Stopwatch();

            fastwatch.Start();
            var adsInfo = context.Ads
                          .Where(ad => ad.AdStatus.Status == "Published")
                          .OrderBy(ad => ad.Date)
                          .Select(ad => new
            {
                ad.Title,
                CategoryName = ad.Category.Name,
                TownName     = ad.Town.Name,
                ad.Date
            });

            foreach (var adInfo in adsInfo)
            {
                Console.WriteLine($"{adInfo.Title} {adInfo.TownName} {adInfo.CategoryName} {adInfo.Date}");
            }

            fastwatch.Stop();
            Console.WriteLine($"Time elapsed for fast query: {fastwatch.Elapsed}");
        }
 public EfCreateCommentCommand(AdsContext context)
 {
     _context = context;
 }
Example #18
0
 public EfEditAdCommand(AdsContext context, UserManager <ApplicationUser> userManager) : base(context)
 {
     _userManager = userManager;
 }
Example #19
0
 protected EfCommand(AdsContext context)
 {
     Context = context;
 }
Example #20
0
		public AdsRepository()
		{
			_db = new AdsContext();
		}
Example #21
0
 // Executes while the handler chain returns to the previous middleware
 protected abstract void Bubble(AdsContext context);
 public EfGetCategoriesCommand(AdsContext context)
 {
     _context = context;
 }
 public AdsCategoriesRepository(AdsContext context, IMapper mapper) :
     base(context.Categories, (vm) => context.Categories.FirstOrDefault(c => c.CategoryId == vm.CategoryId),
          categoryId => context.Categories.FirstOrDefault(c => c.CategoryId == categoryId), mapper)
 {
     _context = context;
 }
 public EfGetCommentCommand(AdsContext context)
 {
     _context = context;
 }
 public EfEditOfferCommand(AdsContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
Example #26
0
 // Executes while the handler chain progresses to the next middleware
 // Return true to prevent further propagation on the request handler chain
 protected abstract bool Capture(AdsContext context);
Example #27
0
 public EfDeleteAdCommand(AdsContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
Example #28
0
 /// <summary>
 /// Constructor of the channel service controller
 /// </summary>
 /// <param name="context">Database context</param>
 public ChannelsController(AdsContext context)
 {
     _context = context;
 }
Example #29
0
 /// <summary>
 /// Constructor of the advertisement service controller
 /// </summary>
 /// <param name="context">Database context</param>
 public AdsController(AdsContext context)
 {
     _context = context;
 }
Example #30
0
 public EfListAdCommand(AdsContext context) : base(context)
 {
 }
Example #31
0
 public EfDeleteOfferCommand(UserManager <ApplicationUser> userManager, AdsContext context)
 {
     _userManager = userManager;
     _context     = context;
 }