Azure Cosmos DB Mongo API Bulk Operations using BulkExecutor .Net SDK - MongoBulkExecutor - azure-cosmosdb-mongoapi

MongoBulkExecutor provided in Microsoft.Azure.CosmosDB.BulkExecutor
has two overloads:
a)public MongoBulkExecutor(DocumentClient client, DocumentCollection documentCollection); shows deprecated
b)public MongoBulkExecutor(Uri serviceEndpoint, string masterKey, string databaseName, string collectionName, ConnectionPolicy connectionPolicy = null, ConsistencyLevel? desiredConsistencyLevel = null, JsonSerializerSettings serializerSettings = null);
Question:
a) The second overload also expects a Uri ServiceEndpoint. In the overview page we can see a URI. - Is that the value?
b) Master Key is asked as the second value, which is not found anywhere in the portal - Could you advise what should be taken.
I tried giving the uri from the portal , and masterkey as the username and the application breaks
with the following error
Method not found: 'Void Microsoft.Azure.Documents.Client.DocumentClient..ctor(System.Uri, System.String, System.EventHandler1<Microsoft.Azure.Documents.SendingRequestEventArgs>, Microsoft.Azure.Documents.Client.ConnectionPolicy, System.Nullable1<Microsoft.Azure.Documents.ConsistencyLevel>, Newtonsoft.Json.JsonSerializerSettings, Microsoft.Azure.Documents.ApiType, System.EventHandler1<Microsoft.Azure.Documents.ReceivedResponseEventArgs>, System.Net.Http.HttpMessageHandler, Microsoft.Azure.Documents.ISessionContainer, System.Nullable1, Microsoft.Azure.Documents.IStoreClientFactory)'.
Could you provide some documentation on how the MongoBulkExceutor could be made in use.
Or is it still version which cannot be used.

Related

Persistent connection string errors in .NET Core DB2 connector

I am migrating a full framework application to .NET Core. Under the full framework, it used the following connection string with the IBM .NET Connector for DB2:
"Server=localhost:50000;Database=testdb;"
The code then assigned UserID and Password properties from credentials vault.
Now, under Core, with the IBM .NET Core connector for DB2 specifically v.2.0.0.100 (long-term support, according to IBM), this connection string throws an exception when a connection string builder is created from it:
{System.ArgumentNullException: Value cannot be null.
at System.Threading.Monitor.ReliableEnter(Object obj, Boolean& lockTaken)
at IBM.Data.DB2.Core.DB2ConnPool.ReplaceConnStrPwd(String value, String newvalue, Boolean onlyPwd)
at IBM.Data.DB2.Core.DB2Connection.RemoveConnectionStringPassword(String value, Boolean bMask)
at IBM.Data.DB2.Core.DB2ConnectionStringBuilder..ctor(String connectionString)
There is no InnerException. I presume that some mandatory parameters of the connection string that I am not aware of have to be populated under Core, whereas under full framework they were optional. A careful read of IBM documents on DB2 connector Core yielded no mentions of connection string changes, unless I missed them. This blog post mentioned no such breaking changes.
Is anyone aware of mandatory connection string parameters that are missing from my connection string specifically for .NET Core connector?
UPDATE:
If I build the connection string manually, by concatenating the original one above with UserID=MyUser;Password=MyPWD;, and open a connection to the database, then DB2ConnectionStringBuilder works even with the original one above. I cannot wrap my head around it! This makes zero sense. The whole purpose of a connection string builder is to build connection strings from parameters, in a strongly-typed manner. Any ideas?
If you use & IBM.Data.DB2.Core (3.1) nuget package with a connection like:
server=my server;database=myDatabase;user id=myUser;password=MyPassword
Then OdbcConnectionStringBuilder will be enough (e.g.):
var db2Connection = "server=my server;database=myDatabase;user id=myUser;password=MyPassword";
var connectionBuilder = new OdbcConnectionStringBuilder(connection);
var Db2Connection = new Db2Connection(builder.ToString());
or something like this:
var password = builder["password"]?.ToString();
It works fine for me

Is "/literal/{param}/literal" a valid url template for a WCF restful service

I am trying to add a new endpoint to a WCF based REST service with the following URL template:
/books/{bookId}/pdf
but it gives an error saying:
The UriTemplate '/books/*/pdf' is not valid; the wildcard ('*') cannot appear in a variable name or literal, unless as a construct for a wildcard segment. Note that a wildcard segment, either a literal or a variable, is valid only as the last path segment in the template; the wildcard can appear only once. See the documentation for UriTemplate for more details.'
Here's the service contract:
[OperationContract]
[WebInvoke(UriTemplate = "/books/{bookId}/pdf", Method = "POST")]
Message GetBookPDF(string bookId);
Is this a limitation that the variable is only valid as the last part of the url? I couldn't find any link that confirms that.
I am sure that the variable needn’t configured in the last part of the URL.
My service contract
public interface ITestService
{
[OperationContract]
[WebInvoke(Method ="POST",UriTemplate ="/books/{id}/pdf")]
string Test(string id);
}
Result.
Please have a look at this link.
https://stackoverflow.com/questions/13956889/in-wcf-can-i-have-a-wildcard-character-in-a-literal-segment-of-my-uritemplate
The most likely scenario is that the UriTemplate can match multiple OperationContract, thus the error happened.
Feel free to let me know if the problem still exists.

How to get user's id inside an Entity Framework DbContext

I need to track database changes in net core 2.0 EF. It all works but I don't know how to get userId inside DbContext. I need to get UserId to assign changes to the user. I cannot simply run _userManager.GetUserId(HttpContext.User).ToString();. Any suggestions? Thanks in advance for your help.
In your ConfigureServices method in Startup.cs add:
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddEntityFrameworkSqlServer();
The services.AddEntityFrameworkSqlServer() bit adds the service resolver into your context, allowing you to utilize theGetService extension method on your context.
Then, inside your context you can do:
var httpContextAccessor = this.GetService<IHttpContextAccessor>();
The result may be null, particularly if the context is not running within a web application (i.e. during migrations, console apps utilizing your context, etc.). As a result, you should do proper null checking. The following uses C# 6's null-conditional operator:
var userId = httpContextAccessor?.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
Then, userId will either have the id of the currently logged in user or be null.

Invalid_request_parameter (create and sending envelopes)

I'm trying to use a service of DocuSign API in an abap project. I want to send a document to a specific email so it can be signed. But im getting the following error:
"errorCode": "INVALID_REQUEST_PARAMETER",## "message": "The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime, or 'envelope_ids' or 'transaction_ids' must be specified.
I tried the following:
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url (https://demo.docusign.net/restapi/v2/accounts/XXXXXX')
proxy_host = co_proxy_host
proxy_service = co_proxy_service
IMPORTING
client = lo_http_client
lo_http_client->request->set_method( method = 'POST').
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'X-DocuSign-Authentication'
value = get_auth_header( ). (json auth header)
CALL METHOD lo_http_client->request->set_cdata
EXPORTING
data = create_body( ).
This is my body:
CONCATENATE
`{`
`"emailSubject": "DocuSign REST API Quickstart Sample",`
`"emailBlurb": "Shows how to create and send an envelope from a document.",`
`"recipients": {`
`"signers": [{`
`"email": "test#email",`
`"name": "test",`
`"recipientId": "1",`
`"routingOrder": "1"`
`}]`
`},`
`"documents": [{`
`"documentId": "1",`
`"name": "test.pdf",`
`"documentBase64":` `"` l_encoded_doc `"`
`}],`
`"status": "sent"`
`}` INTO re_data.
The api request to get the Baseurl is working fine. (I know the error is quite specific what the problem is, but i cant find any sources on the docusign api documentation that one of the mentioned parameters should be added to the request)
Thank you in regards
The error message seems to indicate that you're Posting to an endpoint that requires certain query string parameters -- but you're not specifying them as expected in the query string. I'd suggest you check the DocuSign API documentation for the operation you are using, to determine what query string parameters it requires, and then ensure that you're including those parameters in your request URL.
If you can't figure this out using the documentation, then I'd suggest that you update your post to clarify exactly what URL (endpoint) you are using for the request, including any querystring parameters you're specifying in the URL. You can put fake values for things like Account ID, of course -- we just need to see the endpoint you are calling, and what qs params you're sending.
To create an envelope, use
https://demo.docusign.net/restapi/v2/accounts/XXXXXX/envelopes
instead of
https://demo.docusign.net/restapi/v2/accounts/XXXXXX
Thank you for all the answers, i found the mistake. Creating the request wasn´t the problem. I was using the wrong "sending"-method -_-.
now its working :)
lo_rest_client->post( EXPORTING io_entity = lo_request_entity ).

EntityFramework, AppHarbor and configuration variables

I'm having some trouble with EntityFramework (database first) and AppHarbor.
I'm trying to use the configuration string as inserted into the web.config by AppHarbor (I've added the metadata into the Sequelizer config option on the website), and I'm trying to add some additional values using code provided.
Currently I'm being a very bad person and embedding the string directly into my apps configuration provider - not good if the hosting provider switch DBs on us, so I'm looking to do it the proper way and use the values AppHarbor supply via the web.config.
This is the string as per provided by AppHarbor (passwords and server details removed):
metadata='res://*/MyDataEntities.csdl|res://*/MyDataEntities.ssdl|res://*/MyDataEntities.msl;';provider=System.Data.SqlClient;provider connection string='Server=servername.sequelizer.com;Database=databasename;User ID=username;Password=<snip>;'
If used "as is", that generates the following error:
The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource.
I then use the following code (purloined off of one of the AppHarbor support discussions) to append the required extra things EF needs...
if (String.IsNullOrWhiteSpace(ProductionDatabaseConnectionString))
{
// Get it on first read and cache it
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var connectionString = configuration.ConnectionStrings.ConnectionStrings["SQLAppHarbor001"].ConnectionString;
// Add the required extra metadata for EF4.x
if (!connectionString.Contains("MultipleActiveResultSets=True;"))
connectionString += "MultipleActiveResultSets=True;";
if (!connectionString.Contains("App=EntityFramework;"))
connectionString += "App=EntityFramework;";
configuration.ConnectionStrings.ConnectionStrings["SQLAppHarbor001"].ConnectionString = connectionString;
configuration.Save();
ProductionDatabaseConnectionString = connectionString;
}
return ProductionDatabaseConnectionString;
That produces the connection string as follows:
metadata='res://*/MyDataEntities.csdl|res://*/MyDataEntities.ssdl|res://*/MyDataEntities.msl;';provider=System.Data.SqlClient;provider connection string='Server=servername.sequelizer.com;Database=databasename;User ID=username;Password=<snip>;'MultipleActiveResultSets=True;App=EntityFramework;
But that produces the error:
Format of the initialization string does not conform to specification starting at index 165.
Index 165 being the start of "provider connection string".
The working connection string I use embedded, which currently works without issue, is:
metadata='res://*/MyDataEntities.csdl|res://*/MyDataEntities.ssdl|res://*/MyDataEntities.msl;';provider=System.Data.SqlClient;provider connection string='Server=servername.sequelizer.com;Database=databasename;User ID=username;Password=<snip>;multipleactiveresultsets=True;App=EntityFramework'
The only real differences being that the "multipleactiveresultsets=True;App=EntityFramework" entries are inside the "provider connection string" string rather than outside.
Other people seem to be using EntityFramework on AppHarbor using the supplied configuration variables fine, so what an I doing wrong?
Update: Multiple Active Result Sets (MARS) can now be enabled for the injected connection string by using the Sequelizer admin panel. This is the recommended approach since the web.config no longer needs to be modified, which causes an AppDomain reload during startup
I came up against this today! I did the following:
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var connectionString = configuration.ConnectionStrings.ConnectionStrings["ConnStringAlias"].ConnectionString;
if (!connectionString.Contains("multipleactiveresultsets=True;"))
{
connectionString = connectionString.TrimEnd('\'');
connectionString = connectionString += "multipleactiveresultsets=True;\'";
configuration.ConnectionStrings.ConnectionStrings["ConnStringAlias"].ConnectionString = connectionString;
configuration.Save();
}
The MultipleActiveResultSets property must be inside the provider connection string, which is why you received an error regarding the format of your connection string.
I seen a few 'solutions' around but none seemed to work for me, including the solution at the bottom of a support page of how to do exactly this on AppHarbor's site. The solution provided even sends the application into an infinite loop as the application will restart every time the web.config file is saved, which is every time in the example.