コード例 #1
0
 public void Initialize()
 {
     driver  = new FirefoxDriver();
     js      = (IJavaScriptExecutor)driver;
     context = new ScrapeCityDbContext();
     helper  = new AddMonitorHelper();
 }
コード例 #2
0
 public void EditItem(int Id)
 {
     using (var context = new ScrapeCityDbContext())
     {
         _index.SaveObject(JObject.Parse(JsonConvert.SerializeObject(context.Monitors.Find(Id), Formatting.Indented, converters: new Newtonsoft.Json.Converters.StringEnumConverter())));
     }
 }
コード例 #3
0
        public void WipeAndCreateDatabase()
        {
            // drop database first
            ReallyDropDatabase(ConnectionString);

            // Now time to create the database from migrations
            // MyApp.Data.Migrations.Configuration is migration configuration class
            // this class is crated for you automatically when you enable migrations
            var initializer = new MigrateDatabaseToLatestVersion <ScrapeCityDbContext, ScrapeCity.Data.Migrations.Configuration>();

            // set DB initialiser to execute migrations
            Database.SetInitializer(initializer);

            // now actually force the initialisation to happen
            using (var context = new ScrapeCityDbContext())
            {
                context.Database.Initialize(true);
            }

            // And after the DB is created, you can put some initial base data
            // for your tests to use
            //using (var context = new ScrapeCityDbContext(/*connectionString*/))
            //{
            //    SeedContextForTests(context);
            //}
        }
コード例 #4
0
 public void Initialize()
 {
     driver = new FirefoxDriver();
     driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 3);
     context = new ScrapeCityDbContext();
     helper  = new EditMonitorHelper();
 }
コード例 #5
0
        public void UpdateMonitorIndex()
        {
            _index.ClearIndex();

            using (var context = new ScrapeCityDbContext())
            {
                var monitors = context.Monitors.ToList();
                foreach (var monitor in monitors)
                {
                    _index.AddObject(JObject.Parse(JsonConvert.SerializeObject(monitor, Formatting.Indented, converters: new Newtonsoft.Json.Converters.StringEnumConverter())));
                }
            }
        }
コード例 #6
0
 public void Initialize()
 {
     driver  = new FirefoxDriver();
     context = new ScrapeCityDbContext();
     helper  = new EditMonitorHelper();
 }
コード例 #7
0
 //TODO resolve dependancy
 public AbstractService()
 {
     this.context = new ScrapeCityDbContext();
 }
コード例 #8
0
        public override void Up()
        {
            var monitorUploadPath = Settings.ImagesServerUploadPath + "Monitor\\";

            using (var context = new ScrapeCityDbContext())
            {
                //this is not selecting the whole model because of forward compatability.
                // Ex. : if you add a new property and select the whole obj. when you have to run more than 1 migration
                // this one will fail because it cannot select the new properties as they're not in the DB
                var monitors = context.Monitors.Select(x => new {
                    x.Id,
                    MonitorPictures = x.MonitorImages.ToList(),
                    x.Brand.BrandName,
                    x.Model,
                    x.Thumbnail
                }).ToList();

                foreach (var monitor in monitors)
                {
                    var images = monitor.MonitorPictures;
                    foreach (var image in images)
                    {
                        var oldFileRelativePath = image.Uri;
                        var oldFileName         = oldFileRelativePath.Substring(oldFileRelativePath.LastIndexOf("/") + 1);
                        var fileName            = Guid.NewGuid().ToString() + ".jpg";

                        string hdddir = "";
                        if (Path.IsPathRooted(monitorUploadPath))
                        {
                            hdddir = Path.Combine(monitorUploadPath, monitor.BrandName, monitor.Model);
                        }
                        else
                        {
                            hdddir = Path.Combine(HttpRuntime.AppDomainAppPath, monitorUploadPath, monitor.BrandName, monitor.Model);
                        }

                        var oldHddDir = Path.Combine(hdddir, oldFileName);
                        var newHddDir = Path.Combine(hdddir, fileName);


                        try
                        {
                            System.IO.File.Move(oldHddDir, newHddDir);
                        }
                        catch (Exception)
                        {
                        }



                        var imageUrlPath = $@"/{monitor.BrandName}/{monitor.Model}/{fileName}";


                        if (monitor.Thumbnail != "/placeholder.jpg")
                        {
                            if (monitor.Thumbnail == image.Uri)
                            {
                                // Since we can't get the whole model, we have to update just the thumbnail, manually.
                                context.Database.ExecuteSqlCommand("UPDATE dbo.Monitors SET Thumbnail = @Thumbnail WHERE Id = @Id", new SqlParameter("Thumbnail", imageUrlPath), new SqlParameter("Id", monitor.Id));
                            }
                        }

                        image.Uri = imageUrlPath;
                    }
                    context.SaveChanges();
                }
            }
        }
コード例 #9
0
 public void Initialize()
 {
     driver  = new FirefoxDriver();
     context = new ScrapeCityDbContext();
 }