Beispiel #1
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Environment.CurrentDirectory)
                                .AddJsonFile("local.settings.json", true, true)
                                .AddEnvironmentVariables()
                                .Build();
            var SqlConnection = configuration["Values:SqlConnectionString"];

            builder.Services.AddDbContext <UserDbContext>(
                options => options.UseSqlServer(SqlConnection));

            DocumentDBRepository <dynamic> .Initialize();

            builder.Services.AddSingleton <InsertActionFilterAttribute>();
            builder.Services.AddScoped <CosmosHelper <dynamic> >();
        }
        public async Task AppendToCosmos <T>(string action, string collection, T obj) where T : class, new()
        {
            try
            {
                if (string.IsNullOrEmpty(collection) || string.IsNullOrEmpty(action) || obj == null)
                {
                    return;
                }

                var json       = JsonConvert.SerializeObject(obj);
                var dictionary = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);

                //add custom columns for event db
                dictionary.Add("Action", action);
                //dictionary.Add("updateTime", DateTime.Now);

                var jsonstring = DictionaryToJson(dictionary);
                await DocumentDBRepository <dynamic> .CreateItemAsync(jsonstring, collection);
            }
            catch (Exception ex)
            {
                return;
            }
        }
 public async Task <IList <dynamic> > GetByLastUpdatedTime <T>(string collectionName, string lastUpdatedTime)
 {
     return(await DocumentDBRepository <dynamic> .QueryDataByLastRefreshTime(collectionName, lastUpdatedTime));
 }