I'm modelling a process in code using Fluent Builder API (https://docs.camunda.org/manual/7.12/user-guide/model-api/bpmn-model-api/fluent-builder-api/) and I want to insert a terminating event (not end event). I cannot manage to find it (in code or in documentation) does it exist? How do I model it?
Unfortunately, this is not directly supported by the fluent model API. But it can be achieved by modifying the eventDefinition:
// plain simple generated bpmn
BpmnModelInstance bpmn = Bpmn.createExecutableProcess()
.startEvent()
.serviceTask()
.endEvent().done();
// find the end event instance in the model (might require filtering by id if more than one)
EndEvent endEvent = bpmn.getModelElementsByType(EndEvent.class).stream().findFirst().get();
// create an EventDefinition for terminate
TerminateEventDefinition terminateEventDefinition = bpmn.newInstance(TerminateEventDefinition.class);
// add that event definition to the endEvent instance
endEvent.getEventDefinitions().add(terminateEventDefinition);
Related
I am writing a small WinRT program to async create a folder and a file. The simplified code is like below:
auto createFolderOp = ApplicationData::Current->LocalFolder->CreateFolderAsync(L"DummyFolder", CreationCollisionOption::OpenIfExists);
create_task(createFolderOp).then([](task<StorageFolder ^> folder)
{
StorageFolder ^tempFolder;
tempFolder = uploadFolder.get();
return tempFolder->CreateFileAsync(L"DummyFile.txt", CreationCollisionOption::ReplaceExisting);
}).then([] (task<StorageFile ^> dummyFile)
{
StorageFile ^file;
file = dummyFile.get();
FileIO::WriteTextAsync(file, L"Dummy Content");
});
During the execution of this code, I want to update my UI on each step. For example I have a textblock and in each step I want to update it to show different text, such as:
Create Folder Succeed...
Create File Succeed...
Write File Succeed...
etc.
How can I access to the UI element from Async task? What is the best practice of doing this?
You need to update the UI from the UI thread. I wrote a post a while ago about getting to the UI thread from different types of Windows Phone apps, it should be applicable to Windows RT Apps as well: http://robwirving.com/2013/07/17/guide-to-getting-to-the-ui-thread-for-any-type-of-windows-phone-8-app/
If you're using Windows Xaml, you should be able to get the Dispatcher from the CoreWindow object and run a lambda using the dispatcher's RunAsync method.
If you're trying to get to the UI thread from a WinRT component, well that's a bit more difficult, but I have a method here: http://robwirving.com/2014/06/02/getting-to-the-ui-thread-from-a-windows-phone-winrt-component/
You can just capture the UI element variable and update it in the lambda body.
We are building some plugins in Microsoft Dynamics CRM by inheriting from IPlugin. We have these configured so they fire whenever an Account is updated.
The problem is the plugins are calling our services, which causes our service to respond with an update. We are doing some pretty hacky things right now to prevent these cyclical updates from happening.
We were wondering if there was a way to pass a value to the IOrganizationService service (the web service) that a plugin can look at. Our other system could send a flag ("hey, don't bothing sending an update!") and the plugin could skip calling back.
Can we pass parameters from web service to the plugins?
Good idea could be usage of custom flag-field. For example you add bit field and call it CallFromExternalSystem. So when you make an update from your external system through IOranizationService you just fill this flag with true field and in plugin you can check condition that this field is present in fields list so you have no need to call external system endpoint again.
We decided the correct solution was to use the value found in IPluginExecutionContext.InputParameters["Target"]. In the case of an Update, this returns an Entity containing attributes for all the attributes that were updated.
We basically have a list of attribute names we cared about. We loop through names and see if any of them appear in the entity attribute list. If so, we send an update to our other system. The good news is, Dynamics CRM ignores updates where the values don't actually change, so trying to update a value to itself is no-op.
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity entity = (Entity)context.InputParameters["Target"];
string[] fields = new string[] { "name", "statecode", "address1_line1" };
bool hasUpdates = fields.Where(f => entity.Attributes.Contains(f)).Any();
if (!hasUpdates)
{
return;
}
}
I'm new to F#, and I'm putting myself through some exercises to learn the language. The one I'm currently trying to do is to write a unit test for a custom Castle.Windsor Facility, and I am trying to Mock the Kernel to raise a "ComponentRegistered" event.
The tools I'm using are FsUnit/xUnit/Foq.
My Code:
let event = Event<_,_>()
let kernel = Mock<IKernel>()
.SetupEvent(fun k -> <# k.ComponentRegistered #>)
.Publishes(event.Publish)
.Create()
Error Message:
Error 4 The event 'ComponentRegistered' has a non-standard type. If
this event is declared in another CLI language, you may need to access
this event using the explicit add_ComponentRegistered and
remove_ComponentRegistered methods for the event. If this event is
declared in F#, make the type of the event an instantiation of either
'IDelegateEvent<>' or
'IEvent<,_>'. C:\Workbench\EvilDev\evildev.commons\Tests\EvilDev.Commons.Windsor.Tests\Auto
Resolver Facility Specification.fs 35 53 EvilDev.Commons.Windsor.Tests
How do I mock/trigger this sort of event from F#?
This type of event can be specified using a DelegateEvent:
let event = DelegateEvent<ComponentDataDelegate>()
let kernel =
Mock<IKernel>()
.SetupEventByName("ComponentRegistered")
.Publishes(event.Publish)
.Create()
kernel.add_ComponentRegistered(fun _ _ ->
printf "Bingo"
)
event.Trigger([|"x";Mock.Of<IHandler>()|])
The add and remove handlers for the event can be discovered via reflection using the Type.GetEvent method.
I have extended the Foq API to allow events to be specified by name, so that you can specify the event name (untyped) to workaround the non-standard event type compiler error.
The change set to add the new SetupEventByName method has been committed. If you need this right now you can either build from source or simply add the latest Foq.fs to your project. This feature will be in Foq 1.5 which I will try and push in the next day or so.
Using doctrine 2.1 (and zend framework 1.11, not that it matters for this matter), how can I do post persist and post update actions, that involves re-saving to the db?
For example, creating a unique token based on the just generated primary key' id, or generating a thumbnail for an uploaded image (which actually doesn't require re-saving to the db, but still) ?
EDIT - let's explain, shall we ?
The above is actually a question regarding two scenarios. Both scenarios relate to the following state:
Let's say I have a User entity. When the object is flushed after it has been marked to be persisted, it'll have the normal auto-generated id of mysql - meaning running numbers normally beginning at 1, 2, 3, etc..
Each user can upload an image - which he will be able to use in the application - which will have a record in the db as well. So I have another entity called Image. Each Image entity also has an auto-generated id - same methodology as the user id.
Now - here is the scenarios:
When a user uploads an image, I want to generate a thumbnail for that image right after it is saved to the db. This should happen for every new or updated image.
Since we're trying to stay smart, I don't want the code to generate the thumbnail to be written like this:
$image = new Image();
...
$entityManager->persist($image);
$entityManager->flush();
callToFunctionThatGeneratesThumbnailOnImage($image);
but rather I want it to occur automatically on the persisting of the object (well, flush of the persisted object), like the prePersist or preUpdate methods.
Since the user uploaded an image, he get's a link to it. It will probably look something like: http://www.mysite.com/showImage?id=[IMAGEID].
This allows anyone to just change the imageid in this link, and see other user's images.
So in order to prevent such a thing, I want to generate a unique token for every image. Since it doesn't really need to be sophisticated, I thought about using the md5 value of the image id, with some salt.
But for that, I need to have the id of that image - which I'll only have after flushing the persisted object - then generate the md5, and then saving it again to the db.
Understand that the links for the images are supposed to be publicly accessible so I can't just allow an authenticated user to view them by some kind of permission rules.
You probably know already about Doctrine events. What you could do:
Use the postPersist event handler. That one occurs after the DB insert, so the auto generated ids are available.
The EventManager class can help you with this:
class MyEventListener
{
public function postPersist(LifecycleEventArgs $eventArgs)
{
// in a listener you have the entity instance and the
// EntityManager available via the event arguments
$entity = $eventArgs->getEntity();
$em = $eventArgs->getEntityManager();
if ($entity instanceof User) {
// do some stuff
}
}
}
$eventManager = $em->getEventManager():
$eventManager->addEventListener(Events::postPersist, new MyEventListener());
Be sure to check e. g. if the User already has an Image, otherwise if you call flush in the event listener, you might be caught in an endless loop.
Of course you could also make your User class aware of that image creation operation with an inline postPersist eventHandler and add #HasLifecycleCallbacks in your mapping and then always flush at the end of the request e. g. in a shutdown function, but in my opinion this kind of stuff belongs in a separate listener. YMMV.
If you need the entity id before flushing, just after creating the object, another approach is to generate the ids for the entities within your application, e. g. using uuids.
Now you can do something like:
class Entity {
public function __construct()
{
$this->id = uuid_create();
}
}
Now you have an id already set when you just do:
$e = new Entity();
And you only need to call EntityManager::flush at the end of the request
In the end, I listened to #Arms who commented on the question.
I started using a service layer for doing such things.
So now, I have a method in the service layer which creates the Image entity. After it calls the persist and flush, it calls the method that generates the thumbnail.
The Service Layer pattern is a good solution for such things.
I am writing a small app that links into Umbraco (a small stand-alone console application that will eventually run as a scheduled task on the server) and I'm using the Umbraco APIs (4.5.2) to make changes to the database/document.
Here is a fragment of what I'm doing:
IEnumerable<Document> documents = Document.GetChildrenForTree(parentDocumentId);
foreach (Document doc in documents.Where(d => d.Published))
{
doc.getProperty("myData").Value = "some data"; // Exception here
// ...other stuff here...
}
However I always get a NullReferenceException because there are no properties. This confuses me because I can see that there are 5 properties in the umbraco interface.
A colleague suggested that I use a Node instead of a document, however I can't even create one as I get a NullReferenceException from the Node class constructor.
Node myNode = new Node(-1); // NullReferenceException here
Does anyone have any ideas?
The document class gets/sets information from the umbraco database. Since your running code in an out of band console application it can't find the umbraco context. Therefore throwing a null reference exception.
You need to run the code inside of the umbraco process. There is a asmx webservice that exists for third party integration. /umbraco/webservices/api/documentservice.asmx
Another way of achieving this could be to use linq2umbraco.
for further details see http://our.umbraco.org/forum/core/41-feedback/7699-UmbracoLinq-in-console-app--Having-some-troubles
I checked out the 4.5.2 source recently, to find that populating Document and Node objects only requires a connection using umbracoDbDsn. So if you have an AppSetting called umbracoDbDsn which points to a valid Umbraco database instance, you'll be good.
HTH,
Benjamin