WPF UI is not updating, if external event raise the Task.
Hi, I have implemented the oracle notification, when some column value change in database table, it will raise the notification, so when I get the event
from oracle to WPF C# Client, then I'm hitting the database and reload the data and update the Gridcontrol.
here my GridControl data is refresh, but selected row is not updating
here, code is executing perfectly, no error, but Gridcontrol selected row is not updating. please check the last function
UpdateJobGridAfterNotify(Task<bool> tresult) where I'm updating the UI
Please let me know What's is Issue.
grid control Xaml code is
<dxg:GridControl Grid.Row="0" Name="JobReportGrid" AutoGenerateColumns="None"
ItemsSource="{Binding Path=TestJobListFromDB}" Focusable="True"
EnableSmartColumnsGeneration="False" SelectionMode="Row" SelectedItem="{Binding Path=SelectedJob, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" >
<dxmvvm:Interaction.Behaviors>
<utilityCommon:JobDetailGridCltCustomService/>
</dxmvvm:Interaction.Behaviors>
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem Alignment="Left" SummaryType="Count" DisplayFormat="{}{0}">
<dxg:GridSummaryItem.FixedTotalSummaryElementStyle>
<Style TargetType="Run">
<Setter Property="Text" >
<Setter.Value>
<MultiBinding Mode="OneWay" StringFormat="Showing {0} of {1} records">
<Binding Path="Value" />
<Binding RelativeSource="{RelativeSource AncestorType=dxg:GridControl}" Path="ItemsSource.Count" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</dxg:GridSummaryItem.FixedTotalSummaryElementStyle>
</dxg:GridSummaryItem>
</dxg:GridControl.TotalSummary>
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Job ID" AllowSorting="True" SortMode="Custom" FieldName="ID" />
<dxg:GridColumn Header="Job Name" AllowSorting="True" SortMode="Custom" FieldName="Name" />
<dxg:GridColumn Header="Test Case Count" AllowSorting="True" SortMode="Custom" FieldName="TestCaseCount" />
<dxg:GridColumn Header="Automation Host" AllowSorting="True" SortMode="Custom" FieldName="HostName" />
<dxg:GridColumn Header="Status" AllowSorting="True" SortMode="Custom" FieldName="JobStatus" />
<dxg:GridColumn Header="Created By" AllowSorting="True" SortMode="Custom" FieldName="CreatedBy" />
<dxg:GridColumn Header="Created Date" AllowSorting="True" SortMode="Custom" FieldName="CreatedOn" >
<dxg:GridColumn.EditSettings>
<dxe:DateEditSettings Mask="dd-MM-yyyy HH:mm:ss.fff" MaskUseAsDisplayFormat="True"/>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
<dxg:GridColumn Header="Modified By" AllowSorting="True" SortMode="Custom" FieldName="ModifiedBy" />
<dxg:GridColumn Header="Modified Date" AllowSorting="True" SortMode="Custom" FieldName="ModifiedOn" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView FocusedRow="{Binding SelectedJob, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" ShowFixedTotalSummary="True" AutoWidth="False" Name="JobView" AllowEditing="False" NavigationStyle="Row" EditorShowMode="MouseDownFocused" >
<!--<dxg:TableView ShowFixedTotalSummary="True" AutoWidth="False" Name="JobView" AllowEditing="False" FocusedRow="{Binding SelectedJob, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" NavigationStyle="Cell" EditorShowMode="MouseDownFocused" >-->
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseRightButtonUp">
<i:InvokeCommandAction Command="{Binding JobContextMenuCommand}" CommandParameter="{Binding ElementName=JobReportGrid}"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding SelectedJobCommand}" CommandParameter="{Binding ElementName=JobReportGrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<!--<dxg:TableView.RowStyle>
<Style TargetType="{x:Type dxg:RowControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Background" Value="LightGray" />
</DataTrigger>
</Style.Triggers>
<Setter Property="FontSize" Value="10"/>
</Style>
</dxg:TableView.RowStyle>-->
<dxg:TableView.RowStyle>
<Style TargetType="{x:Type dxg:RowControl}">
<Style.Triggers>
<Trigger Property="dxg:DataViewBase.IsFocusedRow" Value="True">
<Setter Property="Background" Value="LightGray" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
<Setter Property="FontSize" Value="10"/>
</Style>
</dxg:TableView.RowStyle>
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
//register the oracle event
public void GetTruSessionTblNotification()
{
using (var conn = new OracleConnection(this.TrekConnectionString))
{
try
{
using (var cmd = new OracleCommand("trek_projects.JOB_STATUS_NOTIFICATION", conn))
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OracleParameter("pv_result_o", OracleDbType.RefCursor, ParameterDirection.Output));
cmd.AddRowid = true;
var dep = new OracleDependency(cmd);
cmd.Notification.IsNotifiedOnce = false;
dep.OnChange += new OnChangeEventHandler(SessionTblDep_OnChange);
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
TrekLogger.Error("ProjectManager->GetProjectTblNotification", ex);
}
}
}
//getting notification
private void SessionTblDep_OnChange(object sender, OracleNotificationEventArgs eventArgs)
{
//string rowid = detailRow["Rowid"].ToString();
if (eventArgs.Info.ToString() == "Update")
{
this.eventAggregator.GetEvent<AfterSessionTableUpdate>().Publish(true);//raise te event
}
}
//in my code subscribe the event
this.eventAggregator.GetEvent<AfterSessionTableUpdate>().Subscribe(this.Refresh, true);
private void Refresh(bool value)
{
try
{
if (this.SelectedJob != null)
{
this.jobID = this.SelectedJob.ID;
GetTestRunJobsAfterNotify();
}
}
catch (Exception ex)
{
TrekLogger.Error("AutomatedTestJobViewModel->Refresh", ex);
}
}
//for hiting the database for fetching the gridcontrol data
private async void GetTestRunJobsAfterNotify()
{
try
{
await Task<bool>.Run(() => this.GetTestRunJobsFromDB(ApplicationContext.SelectedTestRunID)).ContinueWith(UpdateJobGridAfterNotify, TaskScheduler.Current);
}
catch (Exception ex)
{
TrekLogger.Error("TestCaseDescViewModel->GetTestRunJobsAfterNotify", ex);
}
finally
{
}
}
//after fetching trying to update the Gridcontrol UI
private void UpdateJobGridAfterNotify(Task<bool> tresult)
{
try
{
var result = tresult.Result;
if (result)
{
Dispatcher.CurrentDispatcher.Invoke((Action)(() =>
{
this.TestJobListFromDB = this.TestJobList;
if (jobID != 0)
{
var job = this.TestJobListFromDB.Where(id => id.ID == jobID).SingleOrDefault();
this.SelectedJob = job;
if (job != null && job.JobStatusID == Convert.ToDecimal(JobStatus.COMPLETED))
{
//here publish the event for updating the test case result not jobs.
this.eventAggregator.GetEvent<AfterResultImportOfJob>().Publish(true);
}
}
}));
}
}
catch (Exception ex)
{
TrekLogger.Error("TestCaseDescViewModel->UpdateJobGridAfterNotify", ex);
}
}