Skip to content

Commit

Permalink
Merge pull request #3 from SyncfusionExamples/SampleChanges
Browse files Browse the repository at this point in the history
Online and Offline sample visibility fixed
  • Loading branch information
MuniappanSubramanian authored Nov 11, 2024
2 parents 1070e67 + df43602 commit b6ec048
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
17 changes: 15 additions & 2 deletions AIDataForm/AzureBaseService/SemanticKernelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
{
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
internal class SemanticKernelService
using System.ComponentModel;

internal class SemanticKernelService : INotifyPropertyChanged
{
#region Fields

Expand Down Expand Up @@ -56,6 +58,8 @@ internal class SemanticKernelService
/// </summary>
private Uri? uriResult;

public event PropertyChangedEventHandler? PropertyChanged;

#endregion

public SemanticKernelService()
Expand All @@ -69,7 +73,7 @@ public SemanticKernelService()
/// Gets or Set a value indicating whether an credentials are valid or not.
/// Returns <c>true</c> if the credentials are valid; otherwise, <c>false</c>.
/// </summary>
public static bool IsCredentialValid
public bool IsCredentialValid
{
get
{
Expand All @@ -78,6 +82,7 @@ public static bool IsCredentialValid
set
{
isCredentialValid = value;
RaisePropertyChanged(nameof(IsCredentialValid));
}
}

Expand Down Expand Up @@ -128,6 +133,14 @@ public Kernel? Kernel

#endregion

public void RaisePropertyChanged(string propName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}

/// <summary>
/// Validate Azure Credentials
/// </summary>
Expand Down
28 changes: 22 additions & 6 deletions AIDataForm/Behavior/DataFormAssistViewBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ protected override void OnAttachedTo(SfAIAssistView assistView)
this.assistView = assistView;
animation = new Animation();

UpdateVisibility();

if (this.assistView != null)
{
this.assistView.Request += this.OnAssistViewRequest;
Expand All @@ -149,13 +147,26 @@ protected override void OnAttachedTo(SfAIAssistView assistView)
this.AIActionButton.Clicked += this.OnAIActionButtonClicked;
this.StartAnimation();
}

if(semanticKernelService != null)
{
semanticKernelService.PropertyChanged += SemanticKernelService_PropertyChanged;
}
}

private void SemanticKernelService_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if(e.PropertyName == nameof(semanticKernelService.IsCredentialValid))
{
UpdateVisibility();
}
}

private void UpdateVisibility()
{
if (this.DataFormGeneratorModel != null)
{
if (SemanticKernelService.IsCredentialValid)
if (semanticKernelService.IsCredentialValid)
{
this.DataFormGeneratorModel.ShowInputView = true;
this.DataFormGeneratorModel.ShowDataForm = false;
Expand Down Expand Up @@ -194,7 +205,7 @@ private void RefreshButton_Clicked(object? sender, EventArgs e)
{
this.DataFormGeneratorModel.Messages.Clear();

if (!SemanticKernelService.IsCredentialValid)
if (!semanticKernelService.IsCredentialValid)
{
AssistItemSuggestion assistItemSuggestion = this.GetSubjectSuggestion();
AssistItem assistItem = new AssistItem() { Text = "You are in offline mode. Please select one of the forms below.", Suggestion = assistItemSuggestion, ShowAssistItemFooter = false };
Expand Down Expand Up @@ -251,6 +262,11 @@ protected override void OnDetachingFrom(SfAIAssistView assistView)
{
this.RefreshButton.Clicked -= RefreshButton_Clicked; ;
}

if (semanticKernelService != null)
{
semanticKernelService.PropertyChanged -= SemanticKernelService_PropertyChanged;
}
}

/// <summary>
Expand All @@ -262,7 +278,7 @@ private void OnCreateButtonClicked(object? sender, EventArgs e)
{
UpdateBusyIndicator(true);

if (SemanticKernelService.IsCredentialValid)
if (semanticKernelService.IsCredentialValid)
{
this.GetDataFormFromAI(this.Entry!.Text);
}
Expand All @@ -276,7 +292,7 @@ private void OnCreateButtonClicked(object? sender, EventArgs e)
private async void OnAssistViewRequest(object? sender, RequestEventArgs e)
{
string requestText = e.RequestItem.Text;
if (SemanticKernelService.IsCredentialValid && this.DataFormGeneratorModel != null)
if (semanticKernelService.IsCredentialValid && this.DataFormGeneratorModel != null)
{
this.DataFormGeneratorModel.ShowOfflineLabel = false;
this.GetDataFormFromAI(requestText);
Expand Down

0 comments on commit b6ec048

Please sign in to comment.