HappyTeaKid
HappyTeaKid
CC#
Created by HappyTeaKid on 3/8/2023 in #help
❔ POST with MultipartFormDataContent; x.Add(new StreamContent(File.OpenRead(filePath)) not working
As I'm trying to send a file it says the file is empty. Even tough it exsists. Any idea how can I attach the file via different method?
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, EndpointURL);

var body = new MultipartFormDataContent();

if (!File.Exists(filePath))
{
MobilOrderUtils.LogDebug("File does not exist:" + filePath);
return -99;
}


var test = new StreamContent(File.OpenRead(filePath));

body.Add(new StreamContent(File.OpenRead(filePath)), "file", fileName); //Does not work

body.Add(new StringContent(dealId.ToString()), "deal_id");
request.Content = body;

var response = client.SendAsync(request).Result;
//response.EnsureSuccessStatusCode();
string res = await response.Content.ReadAsStringAsync();

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, EndpointURL);

var body = new MultipartFormDataContent();

if (!File.Exists(filePath))
{
MobilOrderUtils.LogDebug("File does not exist:" + filePath);
return -99;
}


var test = new StreamContent(File.OpenRead(filePath));

body.Add(new StreamContent(File.OpenRead(filePath)), "file", fileName); //Does not work

body.Add(new StringContent(dealId.ToString()), "deal_id");
request.Content = body;

var response = client.SendAsync(request).Result;
//response.EnsureSuccessStatusCode();
string res = await response.Content.ReadAsStringAsync();

4 replies
CC#
Created by HappyTeaKid on 3/3/2023 in #help
❔ Get value out of deserialized json object.
I need to get value out of meta, from the "object". As for now I also use this: Dictionary<string, object> msg = (Dictionary<string, object>)result; But since its generic Im not sure how to access the field value. Any help? These dont work: var result = data["meta"]["object"].Value<string>(); var result = data.SelectToken("meta.object").ToString(); var result = data.Descendants() .OfType<JProperty>() .FirstOrDefault(x => x.Name == "object") ?.Value; And here is the json:
{
"v":1,
"matches_filters":{
"current":[
]
},
"meta":{
"action":"updated",
"id":1,
"is_bulk_update":false,
"matches_filters":{
"current":[

]
},
"object":"organization",
"permitted_user_ids":[
125421,
12312,
123123
],
"pipedrive_service_name":false,
"timestamp":1231415,
},
"current":{
"address_route":"Mama",
"related_closed_deals_count":0
},
"event":"updated",
"retry":0
}
{
"v":1,
"matches_filters":{
"current":[
]
},
"meta":{
"action":"updated",
"id":1,
"is_bulk_update":false,
"matches_filters":{
"current":[

]
},
"object":"organization",
"permitted_user_ids":[
125421,
12312,
123123
],
"pipedrive_service_name":false,
"timestamp":1231415,
},
"current":{
"address_route":"Mama",
"related_closed_deals_count":0
},
"event":"updated",
"retry":0
}
14 replies
CC#
Created by HappyTeaKid on 1/27/2023 in #help
✅ Pick random elements from array based on seed and randomise the order based also on seed.
I have an array with unique objects. I'm writing this in fronted, Javascript and it looks should take these parameters: let arrayWithObjects [new obj(x,y), new obj(a,b), new obj(d,e)... ] ; function getRandomCards( seed, arrayWithObjects, newArrayLength){ //some code return [x,y]; }; Seed is the parameter given by the user. ArrayWithObjects is the array that I should take the objects out. NewArrayLength should be the amount of object to pick. TLDR: Create a new array with a specified count by the user of unique objects from different array and then randomise the order(with seed parameter so that the outcome is repeatable), JavaScript.
15 replies
CC#
Created by HappyTeaKid on 11/12/2022 in #help
ConsoleApp Freeze user input for 1sec [Answered]
I need to freeze user input for 1 second after the last user input. What i use for the input in a do while loop is this: input = Console.ReadKey(true); Then I call the method: public void timeout(){ Stopwatch sw = new Stopwatch(); Random random = new Random(); var ranNum = random.Next(650, 950);
sw.Start(); while (true) { if (sw.Elapsed.TotalMilliseconds > ranNum) { break; } } sw.Stop(); } Problem is that it still reads user input while the timout is happening. System thread freeze also do not work. Please advice!
32 replies
CC#
Created by HappyTeaKid on 9/19/2022 in #help
POST SQL Identity keeps returning id = 0 [Answered]
18 replies