How does event-driven programming background code look like? - events

We always use event driver programming to create desktop applications with user interfaces. In such frameworks we only associate functions to events. But we can never see how does it work in the background. How does the real application generated by the framework look like. What does the main function contain. I imagine something like the following :
int main()
{
while(true)
{
wait_for_an_event();
handle_the_recived_event();
}
}
If you have any clarifications, details about this, I would be so greatuful

Based on your comment about using .NET
Events on .Net are a way to signal notifications to clients of a class. They are also built in and are fairly easy to implement.
You can read about them here: Events Tutorial

Related

Avalonia + ReactiveUI - pharmacist for Events() generation

I'm trying to get my head around Avalonia in general, and the Reactive UI integration in particular. From googling around, I understand that Avalonia pulled away the Avalonia support in ReactiveUI, and tries to integrate ReactiveUI into Avalonia itself, to support a sometimes unstable Avalonia API.
I'm implementing a flow where a double tap on a DataGrid row should open a details windows, which I can do by adding a handler for the DoubleTapped event in the code behind. However, I was wondering if I could do this in a Reactive UI way, in a WhenActivated() implementation, by observing the DoubleTapped event.
In the ReactiveUI documentation, I see that there is a Pharmacist integration, which generates the observables for these events. However, when I fetch a reference to the DataGrid in the code behind, and try to hook into the DoubleTapped via
myDataGrid.Events(). ..., I don't get to see any events. Does this imply that there's no such support in Avalonia at this time?
Finally, while I'm at it, if I forget about the Reactive UI support, and use a straight-forward event handler, I need to do some stuff to detect whether it was a row that was double tapped, or something else (such as the header). I have to do this, because there's no EventSetter implementation in Avalonia as I understand it.
Somebody who knows if Avalonia will support this in the future?
Edit: in the end I used ReactiveUI somewhat similar to
TreeView.GetObservable(DoubleTappedEvent)
.Subscribe(async x =>
{
var selectedItem = TreeView.SelectedItem;
if (selectedItem is TreeNodeViewModel treeNodeViewModel)
{
await ViewModel!.ActivateResource(treeNodeViewModel);
}
}).DisposeWith(d);
An attached behaviour can also help to bind events to perform logic. There is a sample that looks like it could work provided the DoubleTappedEvent is being fired.
Avalonia Docs - Creating and binding Attached Properties
The dev tools should help show the event your are looking for tunnel and bubble though the DataGrid?
Pharmacist does not support Avalonia. They are working on ReactiveMarbles.ObservableEvents, which as of right now, doesn't work on generic classes, but they're working on fixing it.

How to automate the process of IVR

Could anyone let me know how to automate the process of IVR like to make unit testing on IVR composer without making testing calling every time? Thanks
Kind of depends on what skills you have and what test you want, but here are some options:
Back2Back: probably the quickest and easiest solution is to have 2 copies of your IVR. Make one call the other and (depending on which of the two you want to test) have one be passive (= do nothing until hangup) and let the other run the flow/script you want to test.
Test tool: take something you can script or code to build a call generator tool. Usually this is something like FreeSwitch or if you have code skills, a SIP stack like PJSIP where you build your own sip client. There are also some commercial options in this area, google for something like "SIP Test Tool" and you'll probably find something.
Get creative: I've seen QA engineers abuse standard HTTP web test tool to generate SIP messages. Anything capable of scripted responses (so you can send ACK and such) can work here, but depends on your specific needs. It can be a cheap and easy solution if you know what you're doing and you don't need things like interactive audio.
If I understood the question correctly, you can write a simple app for that testing using Dasha.
Sample DSL (DashaScript) code:
start node root {
do {
#connectSafe("<PHONE_NUMBER>"); //make Dasha call your IVR
}
transitions {
step2: goto step2 on #messageHasIntent("press_one"); //use conversational AI to understand that IVR says "press one to ..."
}
}
node step2 {
do {
#sendDTMF("1"); //make selection by sending DTMF code
}
transitions {
step3: goto step3 on #messageHasIntent("press_two");
}
}
node step3 {
do {
#sendDTMF("2");
}
}
//etc......
So you can design test suites for IVRs and even generate them automatically or make it a part of your CI/CD process.
If you need any help, feel free to join our dev community or drop me a line at vlad#dasha.ai.
Cheers

Xamarin Forms - calling a shared code method from the platform project

I have read the two other questions on SO regarding this and I wanted to know if there is a good solution for that now / best practice.
Long story short, we use an SDK which is written natively and we've wrapped it so that it works on Xamarin.Android and Xamarin.iOS. It has asynchronous callback methods. I need to call a method in the shared code when a callback is received in the Android project for instance.
There's a lot of info for doing the opposite - using DependencyService. How about in my scenario? Does anyone have experience with an app like this and what's the best approach to keep code clean and do this using MVVM?
The options I know are:
Using a static App instance - this is what we currently do.
MessagingCenter
Anything else?
Actually I've never seen anyone recommend usage of MessagingCenter for anything else than communication between ViewModels so I am not sure it is recommended here. Also, I need to know the sender object type so I need a reference to the class in the platform specific project.
I would recommend you to use messagingCenter to pass data or call method between shared project and platform project. You can just send a new object instead of the class in the platform specific project.
Also, have a look at using eventhandler as I mentioned in this answer may help someone who want to call from the shared project into the platform specific one.
BTW, I mean you can even pass an object as TSender if it is not necessary to use:
MessagingCenter.Send<Object>(new object(), "Hi");
MessagingCenter.Subscribe<Object>(new object(), "Hi", (sender) =>
{
// Do something whenever the "Hi" message is received
});

Clear explanation of Dialog implementation on bot framework V4

Is there someone who can explain how to code dialog from bot framework properly?
I'm trying to code from scratch using the empty bot template to understand every pieces of code and why and how they piece together. But even after reading so many times I don't how it is properly implemented or coding for dialogs in Microsoft Bot Framework. I've read the documentation from microsoft many times and many version or doc from microsoft but still can't comprehend how it link together every piece of code. Even blogs or website i found did not explain why such pieces of code is needed but just ask you to add this and that. I understand concept but not the mechanics. The code seems to span from startup.cs, yourMainBotLogic.cs, dialogClassName.cs, BotAccessors.cs which confuse me which are the steps the program is run on and how.
Please explain in detail why the pieces of code/components is needed/what use it has and why it has to be there in such files (e.g. Startup.cs). For example;
var accessors = new BotAccessors(conversationState) { ConversationDialogState = conversationState.CreateProperty<DialogState>("DialogState"), }; return accessors;
Create a accessor for the DialogState and then return it. This is just example and my description of the code might not be right.
Your question about how everything fits together is a bit broad, but I will attempt some explanation:
startup.cs: bot configuration should be loaded here, and singletons created. Including IStatePropertyAccessors. Many of the samples contain a BotConfig file with bot specific setup code, and call it from startup. Many samples also contain a bot file. Bot files can make loading some bot services easier. But, they aren't necessary. Ids and passwords can still be retrieved from App Settings, or web.config and your code can create the services.
Some things usually initialized in startup are:
ICredentialProvider is used by the sdk to create the BotAdapter and provide JWT Token Auth. For single appid/password bots, the SDK provides a SimpleCredentialProvider. If your bot is using the integration libraries, you can create one during the IBot initialization, or just supply the botConfig with appid/pass:
webapi:
public static void Register(HttpConfiguration config)
{
config.MapBotFramework(botConfig =>
{
var appId = ConfigurationManager.AppSettings[MicrosoftAppCredentials.MicrosoftAppIdKey];
var pass = ConfigurationManager.AppSettings[MicrosoftAppCredentials.MicrosoftAppPasswordKey];
botConfig.UseMicrosoftApplicationIdentity(appId, pass);
}
}
netcore:
public void ConfigureServices(IServiceCollection services)
{
services.AddBot(options =>
{
options.CredentialProvider = new SimpleCredentialProvider(appId, appPassword);
});
}
IStorage is an implementation for interacting with a state store. The sdk provides MemoryStorage CosmosDbStorage and AzureBlobStorage These are each just using JsonSerializer to store and retrieve objects from the underlying storage.
BotState are objects that provide keys into the IStorage implementation. The SDK provides three examples:
ConversationState scoped by {channelId}/conversations/{conversationId}
UserState scoped by {channelId}/users/{userId}
PrivateConversationState scoped by {channelId}/conversations/{conversationId}/users/{userId}
IStatePropertyAccessors These are an implementation layer providing for typed access into the scoped BotState explained above. When a get/set is performed, the actual state store is queried and persisted (through an internal cache provided by the sdk).
BotAccessors.cs is just a container to hold the state classes and IStatePropertyAccessors. This isn't needed, but is for convenience.
yourMainBotLogic.cs: this is where the adapter's OnTurn implementation exists, and should load the dialog stack and process the user's message. The dialog stack is managed by a dialog set that contains an IStatePropertyAccessor of DialogData type. When a get is performed on this property accessor by calling create context, the state store is queried to fill the dialog stack of the DialogContext.
dialogClassName.cs is a dialog implementation. The specific dialog types are delineated here: Dialog types Examples of how to use them are in the samples on github and documentation.
As with other asp.net applications, startup is run when the application first loads (see aspnet-web-api-poster or lifecycle-of-an-aspnet-mvc-5-application and note that the Microsoft.Bot.Builder.Integration.AspNet.Core uses an IApplicationBuilder extension to add the message handler to the request pipeline ApplicationBuilderExtensions and Microsoft.Bot.Builder.Integration.AspNet.WebApi uses an HttpMessageHandler implementation). However, you can choose to not use the integration libraries, and create your own controllers. Like this sample: MVC-Bot
V4 additional references
Implement sequential conversation flow
Create advanced conversation flow using branches and loops
Gather user input using a dialog prompt
Managing state
Save user and conversation data
Implement custom storage for your bot

Are there MVC embedded system GUI examples?

I'd like to apply the MVC pattern to a GUI we are developing for an embedded system. In this case my understanding is we would need to provide the underlying framework for listener/event actions between the Controller and View. Also, I have seen some examples where the Model send an event to the View, but perhaps that is not correct. Does that seem correct?
Does anyone know of a framework targeted to embedded devices that may have this capability?
If your embedded device supports Java, eRCP would be the best GUI framework in that case.
Check out: http://www.eclipse.org/ercp/
Model sends event to view is a way to notify the view updated about things has been changed in model. It's normal communication between M & V in MVC. However, the "view" here should be a generic view which is bound via an "observable" interface, not a concrete one.
For example:
Abstract View: Clock (generic interface)
Concrete View: Digital Clock, Analog Clock <--implementation of Clock
Model: Time <-- "knows" Clock but not Digital or Analog...
I could suggest the Qt Toolkit. But you don't give any mention of your platform capabilities.
If you are working on a linux platform. Try Enlightenment the best GUI I have ever seen.....

Resources