Update Running workflow with dynamicUpdateMap - workflow-foundation-4.5

I have a workflow running and i'm trying to update it dynamically. It is a Flowchart and i'm trying to change the Next property of a FlowStep.
The problem is that when loading WorkflowApplication.Load(workflowApplicationInstance, map); the instance with the map, i got the error:
In order for an implementation map to be directly applied to a workflow instance, the root of the definition must not have any public/imported children or public/imported delegates.
i tried saving the map to file and to database, because i saw in other examples, the map is saved with extension file.map not file.xaml of file.xml. Anyway it was useless, it's still not loading.

Solved that. The problem was when calling PrepareForUpdate and CreateUpdateMap methods, from their API, i was calling them with ActivityBuilder parameter and it should have been Activity. So having the ActivityBuilder of a workflow you can obtain the activity of it like this:
ActivityBuilder workflowDefinition;
Activity flowcharWorkflow = workflowDefinition.Implementation as Flowchart();
if your workflow definition has a root of flowchart.

Related

CKAN: Get user object or id when a context object is not available in extension

When writing a CKAN extension, I can create a custom GET-able method, which automatically receives the context.
e.g.
#side_effect_free
def custom_method(context, data_dict):
# Do something with the context and/or data_dict
The context argument above, which is basically injected by CKAN, contains, among other things, the user object which can be used to identify the user.
In other cases, like for example in a template helper, how can I get access to the user information? Ideally, I would like to have a context object just as above, so that I can call for example package_search and the rest of the actions provided in the toolkit.
Turns out that when calling actions, skipping the context variable will cause ckan to add it later inside the call, so there's no need to provide the context yourself. Also, if you want information on the user, the g variable from Flask has everything you need.

How to read the result of Flow in Android Compose #Composable function for non-GUI consumption (e.g. for writing in repository)

I am introducing DataStore in my Android Compose app for storing user preferences. While I am not happy about keeping the DataStore instance as a attribute of Context instance - because the Context is accessible from the #Composable only (and not in, e.g. repository) - I am still going for it.
Lets assume (following the references tutorial), that getEmail is the function that reads the DataStore key-value pair and that returns the Flow instance.
My intention is to put the following (approxiamte) code into one of my top-level #Composable, which has AppContainer as an argument - such composables are very top level:
var email = getEmail.collectAsState("") //or should I use single()?
appContainer.salesOrderRespository.setEmail(email)
But I am afraid to do this in this very crude way in which I have wrote this above. E.g. I am concerned about the following things:
should I put this code in some scope (because its collectAsState can block the GUI thread), like:
val scope = rememberCoroutineScope()
scope.launch {
var email = getEmail.collectAsState("") //or should I use single()?
appContainer.salesOrderRespository.setEmail(email)
}
Can I use construction var email = getEmail.collectAsState("") - email can not be accessible immediately, it is assigned asynchronously. That is why I may need something like this (just imagination):
getEmail.collectAsState("").onReadingDone( it - > { appContainer.salesOrderRespository.setEmail(it) })
And, of course, I am eager to execute this code as early as possible. Almost of my repositories are in need of configuration data and if application is starting and going ahead while still reading the configuration data from the DataStore, then the app will not work as expected.
So - I am trying to to just one thing - read DataStore (1. as attribute of the Context, because there is no other proper global instance to whom I can create such attribute; 2. inside #Composable, because Context can be accessed from the #Composable only) and assigne the read value to the attributes of one or more repositories. But I observed that this operation is very complex and involved many concerns. I listed them. That is my question is quite long and complex, but it effectively tries to tackle one simple thing only - reading+assigning.
You don't have to use the Context helper. Instead, I would look into integrating Hilt and injecting your data store into your repository.
Here is a blog about the technique.
https://medium.com/androiddevelopers/datastore-and-dependency-injection-ea32b95704e3

Scoped properties for Application Insights

I would like to know if there is an elegant way to add scoped properties to Application Insights, something similar to Serilog:
var yearEnricher = new PropertyEnricher("Year", year);
using (LogContext.PushProperties(yearEnricher))
{
// ...
}
In the previous example every log created within the using block will have the property Year stamped on it.
I figured out how to do this when I want the property to be present within the whole request pipeline:
var requestTelemetry = context.Features.Get<RequestTelemetry>();
requestTelemetry?.Properties.Add(propertyName, propertyValue.ToString());
Sometimes I want to create a logging scope in code that is not related to the web context so it doesn't make sense to rely on the IHttpContextAccessor. I acknowledge I could leverage OperationTelemetry and TelemetryClient.StartOperation to achieve my goal but it is cumbersome as I've to implement a few properties in which I've no interest (such as Name, Success, Duration...).
Is there a better way than relying on OperationTelemetry?
If you don't want to use OperationTelemetry, you might want to look into implementing your own ITelemetryInitializer (see documentation here).
It should be fairly easy to implement a stack-like global structure to hold the properties you want to push, and pop the stack on your Dispose method.
Note that you'll probably need to utilize CallContext in order for your stacks to be thread safe.

Changing Mule Flow Threading Profile at runtime

I have a requirement in hand where I need to change the Mule Flow Threading Behavior at runtime without the need of bouncing the whole Mule Container. I figured out few different ways to achieve this, but none of them are working.
I tried accessing the Mule Context Registry and from there I was trying to do a lookup of "FlowConstructLifecycleManager" Object so that I can tap in there and access the threading profile of the object and reset those values, then stop and start the flow programmatically in order to get the change applied in the flow. I am stuck in this approach as I was unable to get hold of the FlowConstructLifecycleManager Object neither from the Mule Spring Registry nor from the Transient Registry. I was able to get hold of the Flow object though which has a direct reference to that FlowConstructLifecycleManager Object. But, unfortunately, they made this object as protected and didn't expose any method for us to access this object.
Since I was unable to access this FlowConstructLifecycleManager directly from Mule implemented Flow class, I decided to extend this Flow class and just add another public method to it so that I can access FlowConstructLifecycleManager object from Flow object programmatically. But, I am stuck in this approach as well as even if I am putting my version of the same Flow class packaged and dropped in lib/user folder of the container, it is still not picking up my version of the class, and loading the original version instead.
It would be of great help if I can get any pointer on the approach of solving either my first or second problem.
Thanks in advance,
Ananya
In our company, we are building a dashboard from where we should be able to start/stop any flow or change the processing power of any flow by increasing/ decreasing the active threads for a flow or changing the pollen polling frequency. All of these should be done at runtime without any server downtime.
Anyway, I made it working finally. I had to patch up the mule-core jar and expose few objects so that I can get to the thread profile object and tweak the values at runtime and stop/ start the flow to reflect the changes to take effect. I know this is little bit messy and but it works.
Thanks,
Ananya

NEventStore RavenDB - Obtain Commit Data

I'm working through a basic example of working with NEventStore with RavenDB and I've hit a stumbling block.
I've managed to succesfully commit my events to the RavenDB datasource, but now I need to pull them back out, to replay them (CQRS - ES) pattern.
I can bring back the Collection of EventMesssage objects by usng the NEventStore IStoreEvents Unterface like this :-
public IEnumerable<EventMessage> GetEvents(Guid aggregateRootId)
{
using (var stream = _store.OpenStream(aggregateRootId, 0))
{
return stream.CommittedEvents;
}
}
In each EventMessage, I can access the Header & the Body Properties. In the body property is the actual event that i have submitted, which i want to pull out and inspect.
I'm not sure if what I'm trying to achieve is correct.
Should I be using the Raven IDocumentStore class to retrieve the event objects or should this be done via NEventstore Stream.
At basic level what you're doing is correct: it's the same code shown in the quick-start NEventstore sample code.
If you work in a more DDD context, probably you should emit events from your Aggregates using the CommonDomain library that is embedded in NEventStore, and retrieve them from IRepository Interface.
You could find some example in the web.
One of them is a my training project: https://github.com/williamverdolini/CQRS-ES-Todos (some notes about that). I'm not using RavenDB and I'm still learnig...but could be useful ;-)