Update Scheduler after signal r

Hi,

We are using Signal R to update the data source of our scheduler, we are only passing the newly added object not the entire datasource via Signal R.  We've tried just adding the new object to the data source (and calling State Has Changed) but that doesn't work and we don't really want to get all the data again if we can help it. Edit: We can't get all the data again as we are getting an exception "cannot access a disposed object" which seems to be when we include an EventTemplate.

How should this work? We've tried all the Syncfusion and SignalR samples we can find online and they don't work, we just need a Scheduler refresh method, which all the other controls seem to have.

Thanks,

Alex


8 Replies

VD Vinitha Devi Murugan Syncfusion Team August 20, 2021 09:28 AM UTC

Hi Alex, 
 
Greetings from Syncfusion Support. 
 
We have prepared sample for Scheduler with SignalR which can be downloaded from the following link. 
 
 
HubConnection connection;  
  
    protected override async Task OnInitializedAsync()  
    {  
        connection = newHubConnectionBuilder().WithUrl(https://localhost:44363/ScheduleHub).Build();  
        connection.On<List<AppointmentData>>("RecieveData", OnDataChange);  
        connection.On<View>("ChangeView", OnChangeView);  
        connection.On<DateTime>("ChangeDate", OnChangeDate);  
        await connection.StartAsync();  
    }  
    public void OnActionCompleted(ActionEventArgs<AppointmentData> args)  
    {  
        if (args.ActionType== ActionType.EventCreate || args.ActionType == ActionType.EventRemove || args.ActionType == ActionType.EventChange)  
        {  
            connection.InvokeAsync("SendData", DataSource);  
        }  
    }  
    public void OnNavigating(NavigatingEventArgs args)  
    {  
        if (args.Action == "view")  
        {  
            connection.InvokeAsync("SendViewData", Enum.Parse(typeof(View), args.CurrentView.ToString(), true));  
        }  
        if (args.Action == "date")  
        {  
            connection.InvokeAsync("SendSelectedDateData", args.CurrentDate);  
        }  
    }  
    Task OnChangeView(View view)  
    {  
        this.CurrView = view;  
        this.StateHasChanged();  
        return Task.CompletedTask;  
    }  
    Task OnChangeDate(DateTime date)  
    {  
        this.SelectedDate = date;  
        this.StateHasChanged();  
        return Task.CompletedTask;  
    }  
    Task OnDataChange(List<AppointmentData> data)  
    {  
        this.DataSource = data;  
        this.StateHasChanged();  
        return Task.CompletedTask;  
    }  
 
Hub page:  
   public class ScheduleHub:Hub  
    {  
        public async Task SendData(List<Index.AppointmentData> data)  
        {  
            await Clients.Others.SendAsync("RecieveData", data);  
        }  
  
        public async Task SendViewData(View data)  
        {  
            await Clients.Others.SendAsync("ChangeView", data);  
        }  
  
        public async Task SendSelectedDateData(DateTime data)  
        {  
            await Clients.Others.SendAsync("ChangeDate", data);  
        }  
    }  
 
Please try the above sample and let us know if you need any further assistance.  
 
Regards,  
Vinitha 
 



AL Alex August 21, 2021 11:24 AM UTC

Hi, as already mentioned we are not sending (nor I doubt would anyone) all the data again in the SignalR event (and we've already seen this example - as mentioned above)


Task OnDataChange(List data)


it is only the new appointment


Task OnDataChange(AppointmentData data)


so we need a way to refresh the scheduler


Thanks,

Alex



AL Alex August 25, 2021 10:54 AM UTC

Hi, any update on this?  It's a major blocker at the moment.



NR Nevitha Ravi Syncfusion Team August 25, 2021 01:55 PM UTC

Hi Alex, 

Sorry for the delay in getting back to you. 

We have modified the sample to pass the respective appointments (newly created, edited, deleted events) and update the list of dataSource collection based on that. Please try the following sample and let us know if you need any further assistance. 

    public void OnActionCompleted(ActionEventArgs<AppointmentData> args) 
    { 
        if (args.ActionType == ActionType.EventCreate || args.ActionType == ActionType.EventRemove || args.ActionType == ActionType.EventChange) 
        { 
            connection.InvokeAsync("SendData", args.AddedRecords, args.ChangedRecords, args.DeletedRecords); 
        } 
    } 
 
 
Task OnDataChange(List<AppointmentData> addedData, List<AppointmentData> changedData, List<AppointmentData> deletedData) 
    { 
        List<AppointmentData> appointmentData = this.DataSource.ToList(); 
        if (addedData != null && addedData.Count > 0) 
        { 
            foreach(AppointmentData data in addedData) 
            { 
                appointmentData.Add(data); 
            } 
        } 
        if (changedData != null && changedData.Count > 0) 
        { 
            foreach (AppointmentData data in changedData) 
            { 
                int index = appointmentData.FindIndex(m => m.Id == data.Id); 
                if (index >= 0) 
                { 
                    appointmentData[index] = data; 
                } 
            } 
        } 
        if (deletedData != null && deletedData.Count > 0) 
        { 
            foreach (AppointmentData data in deletedData) 
            { 
                int index = appointmentData.FindIndex(m => m.Id == data.Id); 
                if (index >= 0) 
                { 
                    appointmentData.RemoveAt(index); 
                } 
            } 
        } 
        this.DataSource = appointmentData; 
        this.StateHasChanged(); 
        return Task.CompletedTask; 
    } 
 


Regards, 
Nevitha 



AL Alex August 26, 2021 06:38 PM UTC

Thanks for this - but not quite following how this proves anything?  If we comment out all the code below the appointment still gets added so not sure what this is doing?  We've tried this on our example and still not working.




VD Vinitha Devi Murugan Syncfusion Team August 27, 2021 11:31 AM UTC

Hi Alex, 
 
Thanks for your update. 
 
We have validated your reported scenario “ comment out all the code, the appointment still gets added so not sure what this is doing ” at our end with our previously shared sample and let you know that when you perform CRUD actions by default it reflect in owned user and below shared code is to update the events for other users who is using the application concurrently. 
 
For example if 3 users using the scheduler at a time, if user-1 creating a meeting event it will created on user-1 scheduler by default. We are using below code to update the events for other users(user-2 and user-3). If you comment out below code, event will create for user-1 but not for other users. 
 
 
Task OnDataChange(List<AppointmentDataaddedDataList<AppointmentDatachangedDataList<AppointmentDatadeletedData 
    {  
        List<AppointmentDataappointmentData = this.DataSource.ToList();  
        if (addedData != null && addedData.Count > 0 
        {  
            foreach(AppointmentData data in addedData 
            {  
                appointmentData.Add(data);  
            }  
        }  
        if (changedData != null && changedData.Count > 0 
        {  
            foreach (AppointmentData data in changedData 
            {  
                int index = appointmentData.FindIndex(m => m.Id == data.Id);  
                if (index >= 0 
                {  
                    appointmentData[index] = data 
                }  
            }  
        }  
        if (deletedData != null && deletedData.Count > 0 
        {  
            foreach (AppointmentData data in deletedData 
            {  
                int index = appointmentData.FindIndex(m => m.Id == data.Id);  
                if (index >= 0 
                {  
                    appointmentData.RemoveAt(index);  
                }  
            }  
        }  
        this.DataSource = appointmentData 
        this.StateHasChanged();  
        return Task.CompletedTask 
    }  
 
Also, we have checked our previously shared sample for all CRUD cases which working fine at our end. So can please share the details of exact issue which you are facing at your end to serve you better. 
 
Regards, 
Vinitha 



AL Alex August 28, 2021 11:33 AM UTC

This is our code, the reservation is received and we've updated the datasource (this.Reservations) as suggested, the scheduler spinner displays but the reservation is not added.





VD Vinitha Devi Murugan Syncfusion Team August 30, 2021 12:24 PM UTC

Hi Alex, 
Thanks for your update. 
We have created a new incident under your Direct trac account to follow up with this query. We suggest you to follow up with the incident for further updates. Please log in using the below link.   
Regards, 
Vinitha 


Loader.
Up arrow icon