Ejemplo n.º 1
0
        public virtual async Task Init()
        {
            var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudTableClient();

            _table = client.GetTableReference("kalixleotablecontext");
            await _table.CreateIfNotExistsAsync().ConfigureAwait(false);

            _azureTable = new AzureTableContext(_table, null);
        }
Ejemplo n.º 2
0
 public AzureObjectRepository(AzureTableContext dbAzureTableContext) : base(dbAzureTableContext, NullLogger.Instance)
 {
     IsReadOnly        = true;
     AzureTableContext = dbAzureTableContext;
     AddType((TestEntity x) => new TestModel(x));
     AddType((ParentEntity x) => new ParentModel(x));
     AddType((ChildEntity x) => new ChildModel(x));
     Initialize();
 }
Ejemplo n.º 3
0
        public virtual void Init()
        {
            var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudTableClient();

            _table = client.GetTableReference("kalixleotablecontext");
            _table.CreateIfNotExists();

            _azureTable = new AzureTableContext(_table, null);
        }
Ejemplo n.º 4
0
        public void InsertOrReplaceEntity <T>(string nombreTabla, T entidad, bool createTable = false) where T : ITableEntity
        {
            using (var context = new AzureTableContext(cloudStorageAccount.TableEndpoint.AbsoluteUri, cloudStorageAccount.Credentials, maxAttempts, waitSeconds))
            {
                if (createTable)
                {
                    context.CreateTableIfNotExists(nombreTabla);
                }

                context.InsertOrReplaceEntity(entidad, nombreTabla);
            }
        }
Ejemplo n.º 5
0
        public T GetEntity <T>(string nombreTabla, string partitionKey, string rowKey, bool createTable = false)
            where T : ITableEntity, new()
        {
            using (var context = new AzureTableContext(cloudStorageAccount.TableEndpoint.AbsoluteUri, cloudStorageAccount.Credentials, maxAttempts, waitSeconds))
            {
                if (createTable)
                {
                    context.CreateTableIfNotExists(nombreTabla);
                }

                return(context.GetEntity <T>(nombreTabla, partitionKey, rowKey));
            }
        }
Ejemplo n.º 6
0
        protected override ObjectRepositoryBase CreateRepository()
        {
            var account = CloudStorageAccount.DevelopmentStorageAccount;
            var client  = account.CreateCloudTableClient();
            var storage = new AzureTableContext(client);

            client.GetTableReference("ChildEntity").DeleteIfExistsAsync().GetAwaiter().GetResult();
            client.GetTableReference("ParentEntity").DeleteIfExistsAsync().GetAwaiter().GetResult();
            client.GetTableReference("TestEntity").DeleteIfExistsAsync().GetAwaiter().GetResult();

            var objectRepo = new AzureObjectRepository(storage);

            objectRepo.OnException += ex => Console.WriteLine(ex.ToString());
            objectRepo.WaitForInitialize().GetAwaiter().GetResult();

            objectRepo.Add(_testModel);
            objectRepo.Add(_parentModel);
            objectRepo.Add(_childModel);

            return(objectRepo);
        }
Ejemplo n.º 7
0
        public void ConfigureServices(IServiceCollection services)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            services.AddResponseCompression(x => x.EnableForHttps = true);
            services.AddMvc().AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.NullValueHandling     = NullValueHandling.Include;
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                options.SerializerSettings.Formatting            = IsProduction ? Formatting.None : Formatting.Indented;
            });
            services.AddSingleton <Chrome>();
            services.AddSingleton <ScrapeService>();

            ObjectRepository objectRepository;
            {
                var liteDb  = Configuration.GetConnectionString("LiteDb");
                var azureDb = Configuration.GetConnectionString("AzureStorage");

                IStorage storage = null;

                if (!String.IsNullOrEmpty(liteDb))
                {
                    var connectionString = new ConnectionString(liteDb);
                    DbFileName = connectionString.Filename;
                    var liteDbDatabase = new LiteDatabase(connectionString);
                    liteDbDatabase.Engine.Shrink();
                    storage = new LiteDbStorage(liteDbDatabase);
                }
                else if (!String.IsNullOrEmpty(azureDb))
                {
                    var cloudStorageAccount = CloudStorageAccount.Parse(azureDb);
                    storage = new AzureTableContext(cloudStorageAccount.CreateCloudTableClient());
                }
                else
                {
                    throw new Exception("Connection string for either 'AzureStorage' or 'LiteDb' should been specified.");
                }

                objectRepository = new ObjectRepository(storage, NullLoggerFactory.Instance);

                services.AddSingleton(storage);
                services.AddSingleton(objectRepository);
            }

            var scrapers = GetType().Assembly.GetTypes().Where(v => v.IsSubclassOf(typeof(GenericScraper))).ToList();

            foreach (var s in scrapers)
            {
                services.AddSingleton(typeof(GenericScraper), s);
            }

            services.AddWebEncoders(o =>
            {
                var textEncoderSettings = new TextEncoderSettings();
                textEncoderSettings.AllowRange(UnicodeRanges.All);
                o.TextEncoderSettings = textEncoderSettings;
            });
            services.AddTransient(x => new TableViewModelFactory(x.GetRequiredService <ObjectRepository>()));
            services.AddSingleton <ScriptService>();
            services.AddSingleton <SmsRuleProcessor>();
            services.AddSingleton <UpdateService>();
            services.AddLogging();
            services.AddSession();
            services.AddControllers().AddNewtonsoftJson();
            services.AddHangfire(x => { });
            services.AddDataProtection().AddKeyManagementOptions(options =>
            {
                options.XmlRepository = new ObjectRepositoryXmlStorage(objectRepository);
            });
            services.AddAuthorization();
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(x =>
            {
                x.AccessDeniedPath = "/Auth";
                x.LoginPath        = "/Auth";
                x.LogoutPath       = "/Auth/Logout";
            });
        }
        public void Test_AzureContext_CreateTables()
        {
            AzureTableContext.DeleteTables();
            AzureTableContext.CreateTables();
            var client = _account.CreateCloudTableClient();
            client.ListTables().Count().ShouldEqual(1);

            var context = new AzureTableContext();
            context.AddEntity(new Review { Title = "blah", PublicationDate = DateTime.Now, StarRating = (int)StarRatings.Three, ReviewType = (int) ReviewTypes.Film });
            context.AddEntity(new Review { Title = "test", PublicationDate = DateTime.Now.AddDays(-7), ReviewType=(int) ReviewTypes.Music });
            context.SaveChanges();

            var queryResults = context.Reviews.ToList();
            queryResults.Count().ShouldEqual(2);
        }