We have been using high level API's to connect to dynamo db and fetching the data. Pagination was not setup before but since we have lot of data now, we want to setup pagination.
var scanConditions = new List<ScanCondition>();
scanConditions.Add(new ScanCondition("PartitionKey", ScanOperator.BeginsWith, "data"));
var files = await Context.ScanAsync(scanConditions).GetRemainingAsync();
return files.Select(i => i.Data).OrderByDescending(i => i.Date).ToList();
I read the aws documetation but did not find any info regarding pagination for high level api. Is pagination available for high level api? If not what options do I have here?
Thanks
You can use paginator methods using this .NET API
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/DynamoDBv2/TIDynamoDBv2PaginatorFactory.html
THis is part of the AWS SDK for .NET V3.
Related
Good morning.
I am a bit confused about these two repositories(graphql-dotnet/graphql-dotnet/ and graphql-dotnet/server/).
https://github.com/graphql-dotnet/graphql-dotnet/ and
https://github.com/graphql-dotnet/server
They are both under the same organization and there is some overlap of contributors, but I'm a bit lost about deciding which one to use.
I would like to build a dotnet 5 application that hosts a graphql endpoint. In a nutshell that is my goal.
I noticed that the graphql-dotnet/server/repository has inbuilt some helpers such as.
serviceCollection
.AddGraphQL((options, provider) =>
{
options.EnableMetrics = HostEnvironment.IsDevelopment();
var logger = provider.GetRequiredService<ILogger<Startup>>();
options.UnhandledExceptionDelegate = ctx => logger.LogError("{Error} occurred", ctx.OriginalException.Message);
})
.AddSystemTextJson()
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = HostEnvironment.IsDevelopment())
.AddWebSockets()
.AddDataLoader()
.AddGraphTypes(typeof(ApplicationSchema))
Which allows my DI to be setup nice and easy. Its counterpart, the graphql-dotnet/graphql-dotnet/ does not.
So my question is "which one should I use exclusivly? Which one is recomended, by secondary goals are to add jwt authentication and finally federation support. But those two are far down the line.
One of my coworkers went ahead and used graphql-dotnet/graphql-dotnet/ and his server application has a lot more configuration than the documentation of graphql-dotnet/server/ so how do I know which one do I use?
Can any one recommend any documentation that highlights the difference between the two of them?
The main graphql-dotnet repo is the "core" library of GraphQL components. The server repo contains ASP.NET specific extensions. It uses the core library. If you use the server project, you are also using the core library.
GraphQL itself can be used with any protocol, it is not required to be used with HTTP or JSON. So the core library does not have any HTTP or ASP.NET dependencies.
If you are using ASP.NET, then the server project is the quickest way to get started. If you want to use Subscriptions, then the server project provides that functionality.
If you don't need subscriptions and if you want a bit more control over how the framework handles the HTTP request, then it would be easier to write your own controller or middleware.
Using JWT authentication is handled by ASP.NET and can be used in either scenario. Federation can also be used in either scenario.
I need to read following redis metrics
1. Version
2. Uptime
3. No of Jobs
4. Overall Health
5. Memory Stats (Allocated, Size in use)
6. Latency Details
in ASP.Net MVC application.
My question is
how can consume radis API in MVC controller to get above metrics?
Is there any other way(best practice) to do this?
I have read the redis metrics using StackExchange.Redis NuGet package in following way
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost,allowAdmin=true");
IServer server = redis.GetServer("localhost", {portnumber});
var redisConfigurations = server.Info().ToList();
Is there any way to flush aws API gateway cache for the particular stage through c# code?
I have a requirement to synchronize my api with frequently changing data at the backend.
Once data updated in database my code should clear the api gateway cache so that user will see the updated result on the UI.
I found articles in aws which uses CLI commands to clear cache.
Below is the link for reference
Please help me to find the similar c# code for the same.
{
AmazonAPIGatewayClient amazonAPIGatewayClient = new
AmazonAPIGatewayClient(Amazon.RegionEndpoint.EUWest1);
FlushStageCacheRequest req = new FlushStageCacheRequest
{
RestApiId = "APIID",
StageName = "yourAPIstagename"
};
FlushStageCacheResponse response =
amazonAPIGatewayClient.FlushStageCacheAsync(req).Result;
}
Using Information via Microsoft.Azure.Management.Fluent I'm trying to get to information about Web Jobs. I'm able to use it to get information about Web Apps, Service Buses, Resource Groups, App Services, etc.
But I haven't been able to find a way to get to the Web Job level. In Azure the Web Jobs are located at the level
https://ms.portal.azure.com/#resource/subscriptions/{SubId}/resourceGroups/{ApServiceName}/providers/Microsoft.Web/sites/{ApServiceName}/webJobs
Using Microsoft.Azure.Management.Fluent I haven't been able to find a way to get to the Web Jobs level. Is this possible via the Microsoft.Azure.Management.Fluent?
Is this possible via the Microsoft.Azure.Management.Fluent?
Based on my exerpience, No. According to Azure SDK source code, it seems that there is no way to get the WebJob level.
If we want to get WebJob level, Azure supplies the WebJob API for us to operate on WebJob. About authorization for the WebJob API, we could refer to the this blog.
I had a need to execute some management API code for WebJobs and found that it is now possible, although it's not easy to find it in the API documentation.
You can do it by installing the Microsoft.Azure.Management.AppService.Fluent package (I think it's also possible to do it the non-fluent management SDK too, although I didn't try this).
Getting access to the methods for managing a WebJob can be done like this:
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
class MyWebJobsManagementClass
{
public async Task DoSomeWebJobsManagement()
{
var jobs = await Azure
.Authenticate() // See the docs for how to authenticate with this SDK
.WithSubscription("your-subscription-id")
.AppServices
.Inner
.WebApps
.ListWebJobsWithHttpMessagesAsync("resource-group-name", "app-service-name")
}
}
It's through the non-obvious AppServices.Inner that you can get a reference to an IWebAppsOperations instance which then lets you perform quite a few operations on the WebJobs, including starting and stopping them.
Authentication Side note
If you're looking for a way to authenticate with Azure.Identity, instead of the file based credentials approach they used to use with these older SDKs, then there is a way to achieve this even though it's not supported "out-the-box".
There's a GitHub repo which contains an example of how to achieve this. I think it's by one of the developers on the Microsoft team, but isn't officially supported by Microsoft. There is no NuGet package for it and they recommend just copying the bits you need.
I actually found that the code in that sample repo was overly complex for my needs and in my case that all I needed was this. Note, I've copied this from my F# project without testing it, so I might have made a mistake in the conversion to C#, but hopefully it's close enough that you get the idea.
class AzureIdentityFluentCredentialAdapter : AzureCredentials
{
public AzureIdentityFluentCredentialAdapter(string tenantId)
: base(default(DeviceCredentialInformation), tenantId, AzureEnvironment.AzureGlobalCloud)
{
}
public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var creds = DefaultAzureCredential() // Use the new Azure.Identity library to get access tokens
var accessToken = await creds.GetTokenAsync(
new TokenRequestContent(new [] { "https://management.azure.com/.default" }),
cancellationToken);
return await TokenCredentials(accessToken.Token)
.ProcessHttpRequestAsync(request, cancellationToken);
}
}
This example doesn't do any token caching, but for my purposes I wasn't too bothered about this. It's also hardcoded the scope that I request the token for because I knew I was only going to be using this with the Azure management API.
OData is now supported in .NET Core and 7.2.0 was released. But can it be used with MongoDB? I have searched, but I could not find anything that says one way or the other.
EDIT:
I've found a nuget package https://www.nuget.org/packages/microsoft.aspnetcore.odata and in ConfigureServices I've added this:
And this seems to work for me:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddOData();
services.AddSingleton<IODataModelManger, ODataModelManager>(DefineEdmModel);
...
}
private ODataModelManager DefineEdmModel(IServiceProvider services)
{
var modelManager = new ODataModelManager();
var builder = new ODataConventionModelBuilder();
builder.EntitySet<TestDTO>(nameof(TestDTO));
builder.EntityType<TestDTO>().HasKey(ai => ai.Id); // the call to HasKey is mandatory
modelManager.AddModel(nameof(Something), builder.GetEdmModel());
return modelManager;
}
Controller
[HttpGet("all")]
public async Task<IQueryable<TestDTO>> Get()
{
// plug your entities source (database or whatever)
var test = await TestService.GetTest();
var modelManager = (IODataModelManger)HttpContext.RequestServices.GetService(typeof(IODataModelManger));
var model = modelManager.GetModel(nameof(Something));
var queryContext = new ODataQueryContext(model, typeof(TestDTO), null);
var queryOptions = new ODataQueryOptions(queryContext, HttpContext.Request, Provider);
return queryOptions
.ApplyTo(test, new ODataQuerySettings
{
HandleNullPropagation = HandleNullPropagationOption.True
}, null)
.Cast<TestDTO>();
}
Service
public async Task<IQueryable<TestDTO>> GetTest()
{
return await GenericRepository.TestAll();
}
Repositories
public async Task<IQueryable<TEntity>> TestAll()
{
var res = new GetManyResult<TEntity>();
try
{
DateTime startTime = DateTime.Now;
var collection = GetCollection<TEntity>().AsQueryable();
var entities = collection.ToArray<TEntity>().AsQueryable();
return entities
}
But is this the best way to do it?
I mean, shouldn't the collection contain only the elements that meet the filters, beeing more optimised?
If yes, how do I achieve this?
I think theres only currently one connected service available in the visual studio market place for MongoDB. Link Here.
ODBC Driver for MongoDB provides high-performance and feature-rich
connectivity solution for ODBC-based applications to access MongoDB
databases from Windows, MacOS, Linux. Full support for standard ODBC
API functions, MongoDB data types and SQL queries implemented in our
driver makes interaction of your database applications with MongoDB
fast, easy and extremely handy.
Looks like it would handle all of the things you'd expect it to when connecting to MongoDB.
However it's worth noting that, that is only a trail and I've been unable to find any 'open source' versions
MongoDB OData Connector
http://cdn.cdata.com/help/DGB/cd/
Its not free https://www.cdata.com/drivers/mongodb/download/
Overview
The MongoDB OData Connector application enables you to securely access data from MongoDB in popular formats like OData, JSONP, SOAP, RSS, and more.
The Getting Started section explains how to establish the connection to MongoDB. In this section, you will find a guide to setting required connection properties and allowing the OData connector to access MongoDB tables.
The Supported OData section shows the OData syntax supported by the OData connector and points out any limitations when querying live data.
The OData connector can be installed as a stand-alone application or integrated with your server. In the Server Configuration section you will find information on how to install the OData connector on an existing server configuration. System requirements are also listed here. You will also find instructions on how to manage users and deploy SSL. Logging details the available logging resources.
The OData API enables access to your data from any application with Web connectivity. The OData connector supports all major authentication schemes. This section documents HTTP methods supported by the server, server responses, and supported authentication schemes.
The Data Model section lists the tables, views, and stored procedures available for the application.