|
Sorry, we need to do this at Web API level. The thing is that if some record is entered, updated or deleted using some API, another record needs to be added in some table using other API at the same time
Thanks
|
|
|
|
|
Wahaj Khan wrote: Sorry, we need to do this at Web API level That may not strictly be true though. You might think that you want to do this via Web API, but that is not the same as actually needing to do this via Web APIs.
The proposal here is not a good idea because you have introduced a transactional dependency into your API at this point. Suppose that the API that deletes the record happens successfully, and then calls the second API, which is down. What are you going to do at that point? Undelete the record?
If you are logging things happening at the database, let the database take care of the logging. Alternatively, you need to consider how to cope with failure conditions and look at techniques such as event passing, retry mechanisms, queues and the likes to see if they can help you in this situation.
Bottom line - your current design is borked if it's only relying on happy path scenarios.
|
|
|
|
|
Either create an instance of the controller class and call the action method directly, or have the API method pass the call through to another class which implements the logic, and call that from both.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wahaj Khan wrote: The question is how can we pass data from first API to other to solve this ?
I can only suppose that you think that you are going to do this via the following
1. First API does just the main part of the functionality
2. That API exits (in some meaning of that word).
3. The log happens which invokes another API call.
Can you make that happen? Yes I believe so. It involves delving into some of the semantics of how it handles some of a Web call for you. For example you can intercept errors.
Should you do it? If there is only one method that needs this then no. Just do it in the same code that does the first functionaliy. If you want to do it with more than one API call, then start figuring out how the call flow is actually handled before it gets to your code and after it leaves your code. You should keep in mind that doing it this way ADDS complexity. That is because when something goes wrong it can interfere with stuff in unexpected ways (for example how you handle errors from the second call.)
|
|
|
|
|
Hello to all,
I'm developing a test console app that refers to an external dll, made with VS2022 and .net core 3.1.
Th console App should work on debian 10 and an arm processor.
I've installed all the netcore packages on debian, ad I've tested the "hello word" app in dotnet core.
Now I'm trying to create a "single file" .netcore console application that uses an external dll.
I've managed to have a "single file" application for the console app and a "single file" dll for the external library.
Every time I try to start the console app the system gives me the error:
A fatal error occurred. The required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/root/.net/SPLX/eY3MeD2sHDeSKgxGgVmzXD_NUUU2hdE=/].
If this is a framework-dependent application, install the runtime in the global location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/install_location].
The .NET Core runtime can be found at:
- https:
Anyone knows how to solve this?
Thank you
|
|
|
|
|
I'm not sure whether this question is still relevant but it misses the most crucial piece: how does your project reference your library.
Anyways, the most convenient way of attaching external dependencies is Nuget package manager. You can learn more in official docs What is NuGet and what does it do? | Microsoft Docs[^]
|
|
|
|
|
i'm trying to update label named "timer" with values from my prank function
#pragma endregion
void prank()
{
Beep(1500, 200);
for(i=10;i>=0;i--)
{
Sleep(500);
this->timer->Text =i+"";
Beep(1500, 200);
}
}
private: System::Void joke_Load(System::Object ^ sender, System::EventArgs ^ e) {
TopMost = true;
backgroundWorker1->RunWorkerAsync(1);
}
private: System::Void button1_Click(System::Object ^ sender, System::EventArgs ^ e) {
joke^ nokno = gcnew joke();
nokno->Show();
}
private: System::Void label1_Click(System::Object ^ sender, System::EventArgs ^ e) {
}
public: System::Void backgroundWorker1_DoWork(System::Object ^ sender, System::ComponentModel::DoWorkEventArgs ^ e) {
prank();
}
public: System::Void backgroundWorker1_ProgressChanged(System::Object ^ sender, System::ComponentModel::DoWorkEventArgs ^ e)
{
this->timer->Text = i + "";
Beep(1500, 200);
}
private: System::Void start_Click(System::Object^ sender, System::EventArgs^ e) {
}
it's not supposed to be real timer or anything i just want it to happen in the background so i can make another actions.
the first Beep indicates for me that it starts but second one not really also i can't manage to use
backgroundWorker1_ProgressChanged
as you can see i have pitifully tried updating it ?traditional? way.
i'm learning to code by myself (also english so sorry ) and this is my first attempt to use background worker i could really use some suggestions and please keep them simple after all i'm simpleton?
modified 19-Apr-22 12:40pm.
|
|
|
|
|
Your prank function is running on a background thread, and cannot directly update any UI controls. When you try to set the timer's Text property, an exception will be thrown, but since you're not handing the RunWorkerCompleted event[^] to inspect the result, you never see it.
You need to call the BackgroundWorker.ReportProgress Method (System.ComponentModel) | Microsoft Docs[^] method to raise the ProgressChanged event on the UI thread to update the controls.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
public: System::Void joke_Load(System::Object^ sender, System::EventArgs^ e) {
bgwork->RunWorkerAsync();
}
public: System::Void labb_Click(System::Object^ sender, System::EventArgs^ e) {
Beep(2500, 100);
}
public: System::Void bgwork_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
{
for (i=10; i >=0; i--)
{
bgwork->ReportProgress(i);
Sleep(1000);
Beep(1500, 100);
}
e->Result =i;
}
public: System::Void bgwork_ProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e)
{
this->faketimer->Text =e->ProgressPercentage.ToString()+"";
}
public: System::Void bgwork_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e)
{
MessageBox::Show("ok", "ok", MessageBoxButtons::YesNo, MessageBoxIcon::Warning);
}
label "faketimer" still has default text
this piece with converting to string is something i saw in tutorial
i guess it will not work because my values are decrementing
|
|
|
|
|
|
yes i did , only left workerSupportsCancel to false because i don't really need this. I have abandoned that project couple days ago and now with another one i still have problem with the same thing
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
for (int day = 1; day <= 31; day++)
{
Beep(1500, 200);
Sleep(500);
backgroundWorker1->ReportProgress(day);
}
}
private: System::Void backgroundWorker1_ProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e) {
progressBar1->Value += e->ProgressPercentage;
this->days->Text = (e->ProgressPercentage.ToString() + " day");
}
private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e)
{
MessageBox::Show("next");
}
My backgroundWorker1->RunWorkerAsync(); is in form_load so it should start when i open it and still no success with this m*th*r******* label update.
There is also no beeping indicating this sh*t even works
Quote: I think i'm going to quit this sh*t start farming, somewhere nice with no internet access
|
|
|
|
|
It sounds like you haven't wired up the event handlers. Check the generated InitializeComponent method to make sure the three events (DoWork , ProgressChanged , and RunWorkerCompleted ) are connected to the relevant event handler methods.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
what i didnt understand a thing you just wrote and i would really appreciate if you could simplify and maybe show me some example
me big noob
i started programming like 2 months ago for real
and english is not my first language
|
|
|
|
|
I don't use C++, but there should be code similar to the Microsoft example:
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged); I believe for C++/CLI, it would be something like:
backgroundWorker1->DoWork += gcnew DoWorkEventHandler(this, &backgroundWorker1_DoWork); How to: Use Events in C++/CLI | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
ok everyting works
this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &f***::backgroundWorker1_DoWork);
this->backgroundWorker1->ProgressChanged += gcnew System::ComponentModel::ProgressChangedEventHandler(this, &f***::backgroundWorker1_ProgressChanged);
this->backgroundWorker1->RunWorkerCompleted += gcnew System::ComponentModel::RunWorkerCompletedEventHandler(this, &f***::backgroundWorker1_RunWorkerCompleted);
was indeed missing
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
while (true)
{
if (backgroundWorker1->CancellationPending)
{
e->Cancel = true;
}
if (progressBar1->Value == progressBar1->Maximum) Valuse==progressBar1->Maximum does not stop DoWork this "Maximum"
{
}
Beep(1500, 100);
backgroundWorker1->ReportProgress(50);
Sleep(500);
}
}
now i really got everything i needed thanks for help
|
|
|
|
|

private: System::Void start_Click(System::Object^ sender, System::EventArgs^ e) {
backgroundWorker1->RunWorkerAsync(1);
this->start->Visible = false;
}
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
while (true)
{
if (backgroundWorker1->CancellationPending)
{
e->Cancel = true;
}
if (progressBar1->Value == progressBar1->Maximum)
{
}
Beep(1500, 100);
backgroundWorker1->ReportProgress(50);
Sleep(500);
}
}
private: System::Void cancel_Click(System::Object^ sender, System::EventArgs^ e) {
backgroundWorker1->CancelAsync();
this->start->Visible = true;
}
private: System::Void backgroundWorker1_ProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e) {
progressBar1->Value += e->ProgressPercentage;
}
private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e) {
this->start->Visible = true;
progressBar1->Value = 0;
if (e->Cancelled)
{
MessageBox::Show("kiss my ass ");
}
else
{
MessageBox::Show("eat my sh*t ");
}
}
};
}
^
|
|
this sh*t above is from Add new comment | Free Source Code[^]
where i found one and only tutorial how to use background worker in c++ an not in c#
to this moment i was only using some formulas from it but now i coppied everything AND.....
it's not working
progress bar is not updating
i wasn't even sure if it works untill i added beep
and it works but not quite
not updating this f***ing progress bar
cancel button doesn't work (but it kinda does)
i'm really on the edge right now im this >< close to lose my sh*t
|
|
|
|
|
System.DirectoryServices.dll file has been added successfully to Visual C++ project through References in Solution Explorer
using namespace System.DirectoryServices;
void CClassName::MethodName(){
...
DirectorySearcher* directorySearcher = new DirectorySearcher();
directorySearcher->ClientTimeout = 60000;
...
}
file.cpp(1268): error C2059: syntax error : '.'
file.cpp(1701): error C2061: syntax error : identifier 'DirectorySearcher'
file.cpp(1701): error C2065: 'directorySearcher' : undeclared identifier
file.cpp(1701): error C2065: 'DirectorySearcher' : undeclared identifier
file.cpp(1268): error C2143: syntax error : missing ';' before '.'
file.cpp(1702): error C2228: left of '->Timeout' must have class/struct/union type
type is ''unknown-type''
file.cpp(1268): error C2871: 'System' : a namespace with this name does not exist
file.cpp(1702): error C3861: 'directorySearcher': identifier not found, even with argument-dependent lookup
By this way I need to set Request Timeout for SOAP WebService
modified 1-Apr-22 10:37am.
|
|
|
|
|
The first error message is telling you that there is something wrong with that using statement, as it does not recognise the use of the period character. The cause is likely to be in the preceding lines which you have not shown. Alternatively you have placed the directive in the wrong part of your source; see using directive - C# Reference | Microsoft Docs[^].
|
|
|
|
|
I have another using namespace just before and it is OK:
using namespace YarpaB2BService;
using namespace System.DirectoryServices;
I am working with Visual C++ .NET
|
|
|
|
|
I cannot find a definitive statement on this, but try the following:
using namespace System::DirectoryServices;
|
|
|
|
|
Sorry,
I have tried it. It's the same errors besides: file.cpp(1268):syntax error : '.'
And one new file.cpp(1268): 'DirectoryServices' : a namespace with this name does not exist
|
|
|
|
|
It cannot be the same syntax error. The message you show complains that you are still using the period instead of the double colon.
|
|
|
|
|
I am using double colon.
The error message "file.cpp(1268):syntax error : '.'" has disapiered
|
|
|
|
|
I'm running an ASP.NET Core 6 application on an IIS as a Rest Api calling Powershell scripts for specific tasks. It works well from my laptop (Windows 10) but doesn't work when I'm running it on a Windows Server 2019 Version 1809 Build 17763.1935. The error tells me that it cannnot find the assembly "Microsoft.Management.Infrastructure".
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Das System kann die angegebene Datei nicht finden.
File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
"Das System kann die angegebene Datei nicht finden." = "File not found."
Did anyone encounter that problem too? The server has the following things installed:
Microsoft .NET 6.0.3 - Windows Server Hosting
Microsoft .NET Runtime - 6.0.3 (x64)
Microsoft .NET Runtime - 6.0.3 (x86)
Microsoft .NET SDK 6.0.201 (x64)
Microsoft ASP.NET Core 6.0.3 - Shared Framework (x64)
Microsoft ASP.NET Core 6.0.3 - Shared Framework (x86)
Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.28.29913
Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.28.29913
IIS 10.0
Windows PowerShell 5.1
PowerShell 7.2.1
Now to test if it is the server setup missing something I wrote a little .net console application with this code
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell;
var initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ExecutionPolicy = ExecutionPolicy.Unrestricted;
using (PowerShell powerShell = PowerShell.Create(initialSessionState))
{
powerShell.AddCommand("whoami");
foreach (var item in powerShell.Invoke())
{
Console.WriteLine(item.BaseObject.ToString());
}
if (powerShell.HadErrors)
{
throw new Exception("powershell script had errors");
}
}
I can run this program on the server without problems. But if I copy-paste this exact code into my Api code it fails with the above error. Any ideas?
|
|
|
|
|
Chances are the account your ASP.NET site is running under does not have permissions to run Powershell. Try creating a normal user account and running your site under that account to test.
No, that is not a viable solution if it does work. The entire point of having such a restricted account is to prevent security issues if someone gets your code to execute something malicious.
|
|
|
|