Silverlight 4 callback is accumulating with each button press - silverlight

I'm writing a Silverlight 4 application using "Silverlight 4 Unleashed" as a foundation.
I have a ChildWindow for loggin in with Username, Password, and Remember Me. The OK button is tied to my AuthUserViewModel SignIn using RelayCommand.
Since I'm just starting, I don't have any data validation yet and noticed something weird.
If I click "OK" on my Login child window, my Action callback tells me I have invalid credentials in a MessageBox...which is perfect. I'm using my own Authentication service for various reasons.
However, if I click "OK" again, my service gets called once, but the Action callback is fired twice, telling me I have invalid credentials. If I press "OK" again, the service is called once, but the Action callback is fired three times, and so on and so on.
Why would it be doing that?
Here is the offending code:
public void SignIn(AuthUserDataModel authUser, Action<ErrorContainer> callback)
{
EnsureClient();
client.SignInCompleted += (sender, result) =>
callback(new ErrorContainer
{
AsyncException = result.Error,
CustomError = result.Result.CustomMessage //holds "Invalid credentials"
});
client.SignInAsync(authUser);
}
Like I said, the button event is fired once, the web service is called once, but the callback is fired an amount equaling the number of times I press OK.
Thank you.

Ah! your client object is a field, and you ensured that it is shared across calls. It prevent it from being initialized on each SignIn call, but each time you add an handler to the SignInCompleted vent before executing the SignInAsyncFunction.
Therefore it's normal that the handler gets executed one time by subsequent SignIn.
To prevent this, you have 2 approaches:
1) create a new client in each SignIn call (it will be garbage collected later)
2) attach your handler when you initialize the client.
ie in your EnsureClient, you should have something like:
if(client == null)
{
client = new MyClient();
client.SignInCompleted +=(sender,result) =>{...};
}
and in the SignIn function:
EnsureClient();
client.SignInAsync(authUser);

Related

react add/edit user not working simultaneously

We are using React 16.1.1 version along with Redux.
If already one react forms Add user process is going on , which is taking a bit longer time, application not allowing to add another user again ( if earlier process is not completed ). Save button not getting hit again.
Is it possible to have concerent ( add user events ) multiple user addition one after another even though its taking longer duration
Sample Code below
If AddUser request is taking long time, then application wont allow to add another new user immidiately if we do so.
/* Saga File ************************************/
export function* watchAddUser() {
while (true) {
const action = yield take(CREATE_USER_REQUEST)
try {
const response = yield call(userService.addUser, {
userData: action.payload.userdata
})
yield put(addUserSuccess(response))
// Call for User listing service
const responseForUserList = yield call(userService.index)
} catch (error) {
yield put(addUserFailure(error.data))
}
}
}
/* Saga File ************************************/
Is it possible to have one saga action is yet processing , still we are initiating same action again.
Ex:
If user "ABC" record is getting added via addUser form, this process is taking more than 2 minutes time. Backend java thread is running to complete the process.
Meanwhile we came on user listing page to add new record and and start another user record "xyz" creation, which is not working as first user record call saga process is not completed.
Is it possible to achieve it , like shown in above example assuming "CREATE_USER_REQUEST" process is not completed, so how to make is another user creation working ?
Found below link to overcome new async call request.
https://github.com/redux-saga/redux-saga/tree/master/docs/api#spawnfn-args
yield spawn(userList, action)
"creates a detached task. A detached task remains independent from its parent and acts like a top-level task. The parent will not wait for detached tasks to terminate before returning and all events which may affect the parent or the detached task are completely independents (error, cancellation)."
It is working now.
Thank you

Show/hide toastbar on sending service call & and after receiving response

I want a toastbar that should display a message to the user before calling a service and hides it after getting the service response.How can I do this??I mean i dont need the expire time to hide it .It should be hidden only after getting the service response.
You can create a ToastBar.Status and show/dispose it manually:
ToastBar.Status s = ToastBar.getInstance().createStatus();
s.setIcon(FontImage.createMaterial(icon, stl, 4));
s.setMessage(msg);
s.setExpires(-1);
s.show();
When you are done with this just call s.clear().

Symfony - catch automatic redirection to login_path

I need to catch/stop/do own stuff before redirection to the security.yml´s login_path when user is not signed in. Security example:
access_control:
- { path: ^/xy, role: ROLE_USER }
I tried to use kernel.request and kernel.controller services but these both actions are triggered after the redirection. I just need to do some own stuff, but every time I go to /xy (not signed), I am instantly redirected to login_path. And I am unable to stop it. We are using FOSUserBundle.
Thanks for help!
Define an event listener on kernel.request, then check if you are inside the appropriate page (the login page, in your case), then do whatever you want with the response (redirect, create a new response, you name it)

Not getting a notification when trying to use real-time database communications

I'm trying to use web sockets to add a new notification to my app. I'm using Backand as my server, and can't seem to get a grasp on responding to the new event. Here's my server side code to send the event:
//Action: Update - After data saved and committed
function backandCallback(userInput, dbRow, parameters, userProfile) {
//Send to array of users
socket.emitUsers("new_notification",userInput, ["admins"]);
return {};
}
And my client code to receive it:
//Wait for server updates on 'items' object
Backand.on('new_notification', function (data) {
//Get the 'items' object that have changed
console.log(data);
});
But when I try to receive the event in my app code, I never see a notification of type "new_notification". Can someone please let me know what's going on?
Make sure you are using emitRole instead of emitUsers. The code above emits to a user array, but it looks like you want to send a notification to the "admins" role. Change this to emitRole() and you should be ok.
For role you want to keep it case sensitive so it will be:
socket.emitRole("items_updated",userInput, "Admin");
For users the syntax is:
socket.emitUsers("items_updated",userInput, ["user2#gmail.com","user1#gmail.com"]);

Log changes detected to domaincontext based on haschanges and getchanges

I have a Silverlight application that is using Entity Framework 4. In the app, it is possible for the user to add/remove string representations of Active Directory group names into the configuration - changes are not saved in the backend until the 'save' button is clicked.
When 'save' is clicked, Entity Framework updates the backend with the changes to the DomainContext. This is working as expected. But I want to log the changes being made and send them out in an email each time before context.SubmitChanges() fires. What is the easiest way to log the changes? I already have code that I can reuse to email the changes to be logged.
I am looking at context.ADGroupRules.EntityContainer.GetChanges() and can see AddedEntities and RemovedEntities properties in there but I'm not sure how to 'get at' the highlighted string in the included snip in order to log it.
if (command == "Save")
{
if (_context.HasChanges)
{
var changeSet = _context.ADGroupRules.EntityContainer.GetChanges();
//log and email changes here
_context.SubmitChanges(OnSubmitCompleted, null);
}
}
I have figured it out.
if (command == "Save")
{
if (_context.HasChanges)
{
var changeSet = _context.ADGroupRules.EntityContainer.GetChanges();
foreach (var entity in changeSet.AddedEntities.OfType<ADGroupRule>())
{
ADGroupRule rule = (ADGroupRule)entity;
Console.WriteLine(rule.ADGroupName);//simulate logging-emailing
}

Resources