Hi,
Search bar glass in MAC is not working.
<HorizontalStackLayout Grid.Row="1" Grid.Column="0" Margin="10,10,0,5" HorizontalOptions="Start" WidthRequest="285">
<SearchBar x:Name="searchBar" WidthRequest="250" SearchCommand="{Binding PerformSearchCommand}"
Placeholder="Search in log file..." Text="{Binding SearchText, Mode=TwoWay}"/>
<ImageButton x:Name="cancelCommand" Source="cancel.png" WidthRequest="25" HeightRequest="25" Command="{Binding CancelSearchCommand}"
ToolTipProperties.Text="Cancel serach"/>
</HorizontalStackLayout>
LogsViewModel
public ICommand PerformSearchCommand { get; private set; }
public LogsViewModel()
{
try
{
PerformSearchCommand = new Command(PerformSearchCommandExcute);
}
catch (Exception ex)
{
_logger.Error("LogsViewModel", ex);
}
}
private async void PerformSearchCommandExcute(object searchTextObj)
{
if (string.IsNullOrEmpty(SearchText))
{
await LoadDataAsync(true, SearchText);
}
else
{
await LoadDataAsync(false, SearchText);
}
}
public async Task LoadDataAsync(bool fullSearch, string searchString)
{
try
{
BusyIndicatorIsBusy = true;
await System.Threading.Tasks.Task.Delay(500);
var clientFilePath = @"C:\GssdDesktopClient\Logs\GssdDesktopClient.log";
if (!File.Exists(clientFilePath))
{
var message = "Log file doesn't exist";
IsOpenPopup = true;
ErrorMessage = message;
_logger.Error(message);
BusyIndicatorIsBusy = false;
return;
}
var results = EncriptFile(clientFilePath, fullSearch, searchString);
LogText = results;
this.ScrollAction();// call the action
BusyIndicatorIsBusy = false;
}
catch (Exception ex)
{
var message = "There was a problem to load the log file.";
IsOpenPopup = true;
ErrorMessage = message;
_logger.Error("LoadDataAsync",ex);
BusyIndicatorIsBusy = false;
}
}
private string EncriptFile(string fileName, bool fullSearch, string searchString)
{
StringBuilder sb = new StringBuilder();
var lines = File.ReadAllLines(fileName);
int i = 0;
Stack<string> reverseStackStrings = new Stack<string>();
foreach (var line in lines.Reverse())
{
if (i > 500)
{
break;
}
reverseStackStrings.Push(line);
i++;
}
foreach (string line in reverseStackStrings)
{
//if (i > 500)
//{
// break;
//}
string[] spearator = { "GSSD" };
var splitedLine = line.Split(spearator, StringSplitOptions.RemoveEmptyEntries);
if (splitedLine != null && splitedLine.Length > 0)
{
string post = string.Empty;
string pre = splitedLine[0];
if (splitedLine.Length > 1)
{
post = splitedLine[1];
}
if (!string.IsNullOrEmpty(pre) && !string.IsNullOrEmpty(post))
{
var encriptedPost = AesHelper.Decrypt(post);
var concatValue = $"{pre}{encriptedPost}";
if (fullSearch)
{
sb.AppendLine(concatValue);
}
else
{
if(concatValue.ToUpper().Contains(searchString.ToUpper()))
{
sb.AppendLine(concatValue);
}
}
}
else
{
if (fullSearch)
{
sb.AppendLine(line);
}
else
{
if(line.ToUpper().Contains(searchString.ToUpper()))
{
sb.AppendLine(line);
}
}
}
}
}
return sb.ToString();
}