Nest 2.0 enable trace - nest

I am on updating to the latest Nest version. Since I am getting not the expected results I am searching for replacement of the EnableTrace() method which was a method of ConnectionSettings on previous versions.

EnableTrace() will be back, but it's not available yet(have a look).
For now you can use this code to print out information about request and response:
var settings = new ConnectionSettings(connectionPool)
.DefaultIndex(indexName)
.DisableDirectStreaming()
.OnRequestCompleted(details =>
{
Debug.WriteLine("### ES REQEUST ###");
if(details.RequestBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.RequestBodyInBytes));
Debug.WriteLine("### ES RESPONSE ###");
if (details.ResponseBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.ResponseBodyInBytes));
})
.PrettyJson();
Make sure you have set .DisableDirectStreaming() on ConnectionSettings.
Hope it helps.

Related

How to get eTag value in Comos v4 sync api container.queryItems()

Facing this issue when using comsos v4 java async apis.
I am seeing eTag value, if used container.readItem(), but not in container.queryItems().
when I check response header data in queryItem response, eTag is coming as null.
Can anyone please tell me, if it's cosmos API bug or am I missing something?
responseDocuments
.byPage(1)
.log()
.flatMap(person-> {
person.getResults().stream().forEach(document-> {
if(document.get("optInStatus") != null) {
} else {
list.add(gson.fromJson(gson.toJson(document, LinkedHashMap.class), Person.class));
}
});
System.out.println(person.getResponseHeaders().get("etag")); // coming as null
System.out.println(person.getContinuationToken());
System.out.println(person.getResponseHeaders().toString());
return Flux.empty();
})
.blockLast();
if it's cosmos API bug or am I missing something?
There isn't anything you missed and I don't think this is a bug. I tried the REST API. It also won't give the _eTag property in the response header. If you need that system property when you query items, you can add that property to your POJO.

DownstreamContext of context not found

I'm trying to add a custom middleware to add parameters to the query.
According to some online search, you can do something like this:
{
//PreQueryStringBuilderMiddleware occurs after authorization
PreQueryStringBuilderMiddleware = async (ctx, next) =>
{
var upstreamRoute = ctx.DownstreamReRoute.UpstreamPathTemplate;
Log.Information($"{upstreamRoute}");
await next.Invoke();
}
};
See this answer
But for me it says HttpContext doesn't contain a definition of DownstreamReRoute.
Is there something I am missing or has this been changed?
Alright, turned out this did actually change and in an earlier versions this still works. But it looks like Ocelot is dead anyway from what I read.
var upstreamRoute = ctx.Items.DownstreamRoute().UpstreamPathTemplate
Use above code instead of
var upstreamRoute = ctx.DownstreamReRoute.UpstreamPathTemplate;
Such change was done between 15.0.6 and 16.0.0 Ocelot versions.
For details you can check them on github: https://github.com/ThreeMammals/Ocelot/compare/15.0.6...16.0.0

problem posting embeds in discord.net 2.0

So I have been trying to figure this out but I can't find any sources on discord.net 2.0.0-beta which I am currently using.
My question is how to post an embed in the chat, I know how to build one and what the different things do but when I do the method I used in 1.0 it comes up with an error regarding not being able to convert Discord.EmbedBuilder to Discord.Embed
Any help would be appreciated.
My Code:
var eb = new EmbedBuilder();
EmbedFooterBuilder efb = new EmbedFooterBuilder();
EmbedFieldBuilder ef = new EmbedFieldBuilder();
SocketGuild server = ((SocketGuildChannel)msg.Channel).Guild;
//Incorrect use
if (parameters.Length > 0)
{
await msg.Channel.SendMessageAsync($"**Correct Usage**: `{Syntax}`");
return;
}
eb.Title = server.Name;
eb.Description = "this is a really fancy description";
await msg.Channel.SendMessageAsync("", false, embed: eb);
Just call the Build() method on the EmbedBuilder instance.
There was an implicit conversion from EmbedBuilder -> Embed that was removed in the 2.0 development cycle.
You also can
var embed = new EmbedBuilder();
embed.WithTitle("Normal title");
embed.WithDescription("So cute description");
embed.WithFooter("Wawwww i love stanley");
Context.Channel.SendMessageAsync("", false, embed);

Google diff-match-patch : How to unpatch to get Original String?

I am using Google diff-match-patch JAVA plugin to create patch between two JSON strings and storing the patch to database.
diff_match_patch dmp = new diff_match_patch();
LinkedList<Patch> diffs = dmp.patch_make(latestString, originalString);
String patch = dmp.patch_toText(diffs); // Store patch to DB
Now is there any way to use this patch to re-create the originalString by passing the latestString?
I google about this and found this very old comment # Google diff-match-patch Wiki saying,
Unpatching can be done by just looping through the diff, swapping
DIFF_INSERT with DIFF_DELETE, then applying the patch.
But i did not find any useful code that demonstrates this. How could i achieve this with my existing code ? Any pointers or code reference would be appreciated.
Edit:
The problem i am facing is, in the front-end i am showing a revisions module that shows all the transactions of a particular fragment (take for example an employee details), like which user has updated what details etc. Now i am recreating the fragment JSON by reverse applying each patch to get the current transaction data and show it as a table (using http://marianoguerra.github.io/json.human.js/). But some JSON data are not valid JSON and I am getting JSON.parse error.
I was looking to do something similar (in C#) and what is working for me with a relatively simple object is the patch_apply method. This use case seems somewhat missing from the documentation, so I'm answering here. Code is C# but the API is cross language:
static void Main(string[] args)
{
var dmp = new diff_match_patch();
string v1 = "My Json Object;
string v2 = "My Mutated Json Object"
var v2ToV1Patch = dmp.patch_make(v2, v1);
var v2ToV1PatchText = dmp.patch_toText(v2ToV1Patch); // Persist text to db
string v3 = "Latest version of JSON object;
var v3ToV2Patch = dmp.patch_make(v3, v2);
var v3ToV2PatchTxt = dmp.patch_toText(v3ToV2Patch); // Persist text to db
// Time to re-hydrate the objects
var altV3ToV2Patch = dmp.patch_fromText(v3ToV2PatchTxt);
var altV2 = dmp.patch_apply(altV3ToV2Patch, v3)[0].ToString(); // .get(0) in Java I think
var altV2ToV1Patch = dmp.patch_fromText(v2ToV1PatchText);
var altV1 = dmp.patch_apply(altV2ToV1Patch, altV2)[0].ToString();
}
I am attempting to retrofit this as an audit log, where previously the entire JSON object was saved. As the audited objects have become more complex the storage requirements have increased dramatically. I haven't yet applied this to the complex large objects, but it is possible to check if the patch was successful by checking the second object in the array returned by the patch_apply method. This is an array of boolean values, all of which should be true if the patch worked correctly. You could write some code to check this, which would help check if the object can be successfully re-hydrated from the JSON rather than just getting a parsing error. My prototype C# method looks like this:
private static bool ValidatePatch(object[] patchResult, out string patchedString)
{
patchedString = patchResult[0] as string;
var successArray = patchResult[1] as bool[];
foreach (var b in successArray)
{
if (!b)
return false;
}
return true;
}

Magento SOAP unable to create order

The problem
I'm having trouble creating an order using the Magento SOAP api. I've got all the bare necessities in place (code snippet below) but everytime I try to create the order it fails with status code 1008 (See Magento Docs).
There is no fault message though, so I only know the order creation failed.
$cart_id = $magi->execute("cart.create");
$customerEntity = $magi->execute("customer.info",5);
$customerEntity["mode"] = "customer";
$customerAddressEntity = $magi->execute("customer_address.info",$customerEntity["default_billing"]);
$customerAddressEntity["mode"] = "billing";
$magi->execute("cart_customer.set", array($cart_id,$customerEntity));
$magi->execute("cart_customer.addresses", array($cart_id,array($customerAddressEntity)));
$productEntity = array("product_id" => 48,"qty" => 1);
$magi->execute("cart_product.add",array($cart_id,array($productEntity)));
$magi->execute("cart_payment.method",array($cart_id,array("method" => "banktransfer")));
$orderId = $magi->execute("cart.order", array($cart_id));
In the magento log the following messages are logged after this operation.
Undefined offset: 0/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php
Undefined variable: websiteId/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php.
(this entry repeats itself 3 times after this one, each half a second apart).
I am at a loss here, it was in working condition a couple of weeks ago and not much has changed since then.
More information
The $magi variable holds an object that is an abstraction for using the Magento Soap api. It also catches and logs all errors, hence no try/catch blocks in this code.
Magento version: 1.7.0.0
Php version 5.4.6
Server OS: Ubuntu 11.10 (development server)
Undefined offset:
0/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php
the error means there is an array that not have value for [ '0' ]
The first error:
Undefined offset: 0/var/www/cloud2u.nl/mccloud_n/app/code/core/Mage/Checkout/Model/Cart/Payment/Api.php
Is due to a bug in Api.php on this method:
protected function _preparePaymentData($data)
{
if (!(is_array($data) && is_null($data[0]))) {
return array();
}
return $data;
}
I was able to get rid of this problem replacing
if (!(is_array($data) && is_null($data[0])))
with
if (!(is_array($data) && !isset($data[0])))
During testing it works the same way and gets rid of the error.
I think your $productEntity is wrong.
$productEntity = array(
array("product_id" => 48,"qty" => 1);
);
and it makes the cart is empty.
^^