Calling Host Method from Workflow - workflow-foundation-4

I want to call method that resides on the host executable that I am using to execute a workflow with WorkflowInvoker.Invoke.
I have found examples of this via an interface using [ExternalDataExchange], but all of these are examples are for Workflow 3.5, nothing for 4 or 4.5. It also appears that the ExternalDataExchange has been deprecated on 4+.
Does anyone have an example of doing this in WF 4.5?

Your host needs to register extensions by doing something like:
yourWFApp.Extensions.Add<ISomeInterface>(
() => { return AnObjectThatImplmentsISomeInterface;});
Then, your activities can use that extension by doing:
ISomeInterface hostInterface = activityContext.GetExtension<ISomeInterface>();
hostInterface.CallTheHost();

Related

Error Deploying Asp.Net Minimal API (Top level statements) to lambda using CDK

I have a CDK solution with a stack etc and in the same solution i have created a ASP.NET minimal API Lambda project.
When I deploy using the CDK I'm getting the ERROR:
Internal Server Error
When I check the logs I can see the Error:
Error: executable assembly /var/task/lambdaMinimalApi.dll was not found..
I know what this error is, it is trying to find the Lambda function thinking its a libary, but mine is an executable. I know this as when i deploy the lambda with:
dotnet lambda deploy-function
through trial an error i found out this:
.NET Lambda projects that use C# top level statements like this project must be deployed as an executable assembly instead of a class library. To indicate to Lambda that the .NET function is an executable assembly the Lambda function handler value is set to the .NET Assembly name. This is different then deploying as a class library where the function handler string includes the assembly, type and method name.
Following this and just using the assembly name I can deploy and everything works.
But when it comes to the CDK I get the internal server error mentioned above.
My public repo is here: https://github.com/RollsChris/cdk-twitter-clone-dotnet
I think it will be a good example to add to the official examples if I can get it to work?
I have tried various forms of Code.From**, and searched the internet far and wide.
Most examples are using a lambda function written in javascript but the CDK is using .NET.
Thanks
Looking at your repo and the error message in the question...
Error: executable assembly /var/task/lambdaMinimalApi.dll was not
found.
Could it be the project is outputing a DLL called lambdaMinimalAPI but your code is specifying different casing (pascal casing API at the end)
var lambdaFunction = new Function(this, "lambdaMinimalAPI", new FunctionProps
{
Runtime = Runtime.DOTNET_6,
Code = Code.FromAsset("src/lambdaMinimalApi",assetOptions),
Handler = "lambdaMinimalApi",
Environment = new Dictionary<string, string>
{
["userProfilesTable"] = userProfilesTable.TableName,
["tweetsTable"] = tweetsTable.TableName,
},
MemorySize = 256,
Timeout = Duration.Seconds(30),
Architecture = Architecture.X86_64
});
Hanlder should be like so:
Handler = "lambdaMinimalAPI", // UPPERCASE API

How to setup ElmahCore for a Console Application?

I want to log errors for a console application using Elmah.I've found ElmahCore and elmah.io.core but I don't know how to setup any of them on a console app.I'm using .net core.
ELMAH (the open source project) doesn't work with .NET Core. ElmahCore has a lot of dependencies to ASP.NET Core, but if you really wanted to, you could do something like this:
class Program
{
static void Main(string[] args)
{
var log = new MemoryErrorLog();
log.Log(new Error(new Exception()));
var errors = new List<ErrorLogEntry>();
var result = log.GetErrors(0, 10, errors);
Console.WriteLine(result);
Console.WriteLine(errors);
Console.ReadLine();
}
}
You can replace MemoryErrorLog with a target logger of your choice.
The package named elmah.io.core is a deprecated package from elmah.io. elmah.io is (among other things) a commercial cloud version of ELMAH, where you store all of your errors in the cloud (list of differences between ELMAH and elmah.io). elmah.io works with .NET core through either the Elmah.Io.Client NuGet package or using one of the integrations for popular logging frameworks like Serilog and NLog.
I wouldn't recommend you to use ElmahCore for logging in a console application. It is created for ASP.NET Core. There are much better options for logging from a console application, like the mentioned logging frameworks.

How to implement a splashscreen in a Poco application

I find a way to catch an event/message which notify the "application loaded" event, to be able to close a splashscreen. Maybe Poco implements it directly but i haven't found any clue in the Application class documentation or code.
Have you tried to use the application member function bool initialized()?
I'm using the Mitk framework, and i will have to modify some code there ; the used CommonTk framework can manage a callback dedicated for splashscreen closing. Thus, there is no event published by Poco to allow this feature.
i using POCO Thread for splash screen (where i can catch / handle status of thread). My application is programmed in WinAPI (Win32, VS C++ 2008 EE), so i using WinAPI timmers; the main message pump is also in separated thread...
Here is my WinApi32 example full code & VS90 project: WLEZLEY_SPLASH_POCO_EXAMPLE.ZIP
PS: It works since version 1.4.5 of POCO, but also works with POCO v1.7.2 (actual version is included). You can try study my code and you try it yourself.

Getting and storing the path of file in asp.net 5

In previous version of asp.net the HostingEnvironment had MapPath method to get and store the path of the file but in ASP.net 5 I can't use it.
var filepath = HostingEnvironment.MapPath(#"~/Data/product.json");
Are you using RC1?
In RC1 it depends if you are writing a console or web app. In console apps, you cannot use DI anymore but PlatformServices.Default.
PlatformServices.Default.Application gives you access to the base path of your application for example. The type of the static property is IRuntimeEnvironment. And having the base path of your app, you can easily build the path to files you need...
If you are building a web app, you should be able to inject IRuntimeEnvironment to your startup and use it from there.
You have to add a reference to the Microsoft.Extensions.PlatformAbstractions package to all that stuff.
See also my post here for more details
Despite IHostingEnvironment provides MapPath() method you may also need UnmapPath() too. Another useful method might be IsPathMapped().
You can find all of them here: Reading a file in MVC 6.
And all of them, thanks to PlatformServices availability, work in Consolse, MVC, and ClassLib apps.
HTH

simple webservice code?

i write a simple webservice code in asp.net when i build the service and run the service it is working fine. when i try to access the webservice it is giving some problem , problem means i am not getting that method (webservice method). After completing writing the webserivce i take a asp.net page (.aspx) and in solution explorer i add a webservices and it is added successfully. but when i adding namespace it is not getting the service name ( i not able to add the namespace of websercice
I am not exactly sure what could be the problem but you should only need to do the following to use the web service:
// Look at what you named your web reference, in my example it is
// called MyWebService. Check your solution explorer for the actual name.
// This is the alias you should be using.
MyWebService.YourWebServiceName ws = new MyWebService.YourWebServiceName();
var result = ws.MyMethod(someparameter);

Resources