Skip to content

Commit

Permalink
Added Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ergen35 committed Jun 23, 2021
1 parent d62b19a commit 760d998
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 51 deletions.
11 changes: 9 additions & 2 deletions PoliceOp.API/Controllers/AgentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using PoliceOp.API.Data;
using PoliceOp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -21,12 +23,13 @@ public class AgentsController : ControllerBase
private readonly PoliceOpAPIContext _context;
private readonly IConfiguration configuration;
private readonly Services.JWTServices jWTService;
private readonly ILogger<AgentsController> logger;


public AgentsController(PoliceOpAPIContext context, IConfiguration configuration)
public AgentsController(PoliceOpAPIContext context, IConfiguration configuration, ILogger<AgentsController> logger)
{
_context = context;
this.configuration = configuration;
this.logger = logger;
jWTService = new Services.JWTServices(this.configuration);
}

Expand Down Expand Up @@ -55,9 +58,13 @@ public async Task<ActionResult<IEnumerable<Agent>>> GetAgents()
return NotFound();
}


await _context.Entry(agent).Reference(a => a.Residence).LoadAsync();
await _context.Entry(agent).Reference(a => a.Biometrie).LoadAsync();


logger.LogInformation($"Agent @{agent.Matricule} Connecté ::{HttpContext.Connection.RemotePort}, {DateTime.Now.ToShortDateString()}");

return agent;
}

Expand Down
2 changes: 1 addition & 1 deletion PoliceOp.API/Controllers/AvisRechercheController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<ActionResult<IEnumerable<AvisRecherche>>> GetAvisRecherches()

foreach (var item in liar)
{
await _context.Entry(item).Reference(r => r.PersonneRecherchee).LoadAsync();
item.PersonneRecherchee = await _context.Personnes.FindAsync(item.PersonneRechercheeId);
}
return liar;
}
Expand Down
22 changes: 16 additions & 6 deletions PoliceOp.API/Controllers/ZeroController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ public async Task<IActionResult> GetToken()
{
var token = jWTService.TokenizeID("89898598", "77a8zeea87", "Session", Models.Issuers.PoliceOpAPI, Models.Audiences.TerminalDesktop);

await GenerateData(1500, 450);
//await GenerateData(1500, 450, 22);

await ctx.SaveChangesAsync();
//await ctx.SaveChangesAsync();
//EraseData();
Console.WriteLine("Done!");
//Console.WriteLine("Done!");

int totalA = ctx.Agents.Count();
int totalP = ctx.Personnes.Count();

//return NoContent();

List<Models.Agent> LA = ctx.Agents.Take(2).AsEnumerable().ToList();
List<Models.Agent> LA = ctx.Agents.Skip(Faker.RandomNumber.Next(1, 400)).Take(2).AsEnumerable().ToList();

return Json(new { token = token, totalAgents = totalA, totalPersonnes = totalP, Agebtx2 = LA });
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public ActionResult<string> Post([FromHeader] String value)

}

public async Task GenerateData(long totalPersonnes, long totalAgents)
public async Task GenerateData(long totalPersonnes, long totalAgents, int totalAvis)
{
DataGenerator generator = new DataGenerator();

Expand All @@ -125,9 +125,19 @@ public async Task GenerateData(long totalPersonnes, long totalAgents)
Console.Write("|");
}

Console.WriteLine("Fin Agents");
Console.WriteLine("Fin Agents\n");


Console.Write("[");
for (int i = 0; i < totalAvis; i++)
{
await ctx.AvisRecherches.AddAsync(await generator.GenerateAvis());

Console.Write("|");
}

Console.WriteLine("Fin Avis");

ctx.SaveChanges();

}
Expand Down
13 changes: 13 additions & 0 deletions PoliceOp.API/DataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,18 @@ public async Task<Agent> GenerateAgent()

return A;
}

public async Task<AvisRecherche> GenerateAvis()
{
AvisRecherche avis = new AvisRecherche()
{
DateEmission = Faker.Identification.DateOfBirth(),
Informations = Faker.Lorem.Sentence(5),
PersonneRechercheeId = Faker.RandomNumber.Next(1, 1400),
StatutRecherche = "Actif"
};

return avis;
}
}
}
4 changes: 2 additions & 2 deletions PoliceOp.API/Migrations/20210623170714_InitialMigration001.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
using System;

namespace PoliceOp.API.Migrations
{
Expand Down
2 changes: 2 additions & 0 deletions PoliceOp.API/PoliceOp.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.15" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.15" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Contracts" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Core" Version="3.1.5" />
Expand Down
2 changes: 1 addition & 1 deletion PoliceOp.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace PoliceOp.API
{
public class Program
{

public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
Expand All @@ -17,6 +18,5 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
webBuilder.UseStartup<Startup>();

});

}
}
1 change: 1 addition & 0 deletions PoliceOp.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down
4 changes: 2 additions & 2 deletions PoliceOp.Models/Agent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;


namespace PoliceOp.Models
Expand Down
1 change: 0 additions & 1 deletion PoliceOp.Models/AvisRecherche.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.Design;

namespace PoliceOp.Models
{
Expand Down
2 changes: 0 additions & 2 deletions PoliceOp.Models/Personne.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PoliceOp.Models
{
Expand Down
25 changes: 10 additions & 15 deletions PoliceOp.OpCenter/Dialogs/NewWantedNoticeDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using RestSharp;
using RestSharp.Authenticators;

namespace PoliceOp.OpCenter.Dialogs
{
Expand All @@ -27,17 +22,17 @@ public NewWantedNoticeDialog()

private async void DetailsBtn_Click(object sender, RoutedEventArgs e)
{

}

private async void SendAvisBtn_Click(object sender, RoutedEventArgs e)
{
this.SendAvisBtn.IsEnabled = false;
SendAvisBtn.IsEnabled = false;

if (this.PersonnesListView.SelectedIndex < 0 || this.StatutCbbx.SelectedIndex < 0)
if (PersonnesListView.SelectedIndex < 0 || StatutCbbx.SelectedIndex < 0)
{
MessageBox.Show("Veuillez Renseigner tous les champs néccessaires");
this.SendAvisBtn.IsEnabled = false;
SendAvisBtn.IsEnabled = false;
return;
}

Expand All @@ -46,8 +41,8 @@ private async void SendAvisBtn_Click(object sender, RoutedEventArgs e)
Models.AvisRecherche avis = new Models.AvisRecherche()
{
DateEmission = DateTime.Now,
Informations = this.InfosTxtb.Text,
PersonneRecherchee = (this.PersonnesListView.SelectedItem as Models.Personne),
Informations = InfosTxtb.Text,
PersonneRechercheeId = (PersonnesListView.SelectedItem as Models.Personne).PersonneId,
StatutRecherche = StatutCbbx.SelectedItem.ToString(),
};

Expand All @@ -67,7 +62,7 @@ private async void SendAvisBtn_Click(object sender, RoutedEventArgs e)
else
{
AppLevel.NotificationManagers.ShowNotification(response.ResponseStatus.ToString(), "Info", AppLevel.NotificationLevel.Error);
this.SendAvisBtn.IsEnabled = true;
SendAvisBtn.IsEnabled = true;
}

LoadingInd.Visibility = Visibility.Collapsed;
Expand Down
12 changes: 5 additions & 7 deletions PoliceOp.OpCenter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using ControlzEx.Theming;
using Enterwell.Clients.Wpf.Notifications;
using LazyCache;
using PoliceOp.OpCenter.Services;
using RestSharp;
using System;
Expand Down Expand Up @@ -197,9 +195,9 @@ private async void SideMenu_ItemSelected(object sender, RoutedEventArgs e)
DrawerLeft.IsOpen = false;
LoadingIndicator.Visibility = Visibility.Visible;
await System.Threading.Tasks.Task.Delay(new TimeSpan(0, 0, 5));

ContentFrame.Navigate(new Pages.NoticesListPage());

LoadingIndicator.Visibility = Visibility.Collapsed;
}

Expand Down Expand Up @@ -230,7 +228,7 @@ private async void SideMenu_ItemSelected(object sender, RoutedEventArgs e)

LoadingIndicator.Visibility = Visibility.Collapsed;
}

if (((sender as HandyControl.Controls.SideMenuItem).Header as string).ToLower().Contains("diffusions"))
{
DrawerLeft.IsOpen = false;
Expand All @@ -241,7 +239,7 @@ private async void SideMenu_ItemSelected(object sender, RoutedEventArgs e)

LoadingIndicator.Visibility = Visibility.Collapsed;
}

if (((sender as HandyControl.Controls.SideMenuItem).Header as string).ToLower().Contains("admin"))
{
DrawerLeft.IsOpen = false;
Expand All @@ -252,7 +250,7 @@ private async void SideMenu_ItemSelected(object sender, RoutedEventArgs e)

LoadingIndicator.Visibility = Visibility.Collapsed;
}

if (((sender as HandyControl.Controls.SideMenuItem).Header as string).ToLower().Contains("center"))
{
DrawerLeft.IsOpen = false;
Expand Down
15 changes: 7 additions & 8 deletions PoliceOp.OpCenter/Pages/AgentsManagementPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Windows.Controls;
using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using RestSharp;
using RestSharp.Authenticators;
using System.Windows.Controls;

namespace PoliceOp.OpCenter.Pages
{
Expand All @@ -20,7 +19,7 @@ public partial class AgentsManagementPage : Page
public AgentsManagementPage()
{
AList = new List<Models.Agent>();

InitializeComponent();

Loaded += AgentsManagementPage_Loaded;
Expand Down Expand Up @@ -73,7 +72,7 @@ private async void SearchWdgt_SearchStarted(object sender, HandyControl.Data.Fun

SearchLoadingLine.Visibility = Visibility.Collapsed;
}


}
}
6 changes: 3 additions & 3 deletions PoliceOp.OpCenter/Pages/NoticesListPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using RestSharp;
using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;
using System.Windows.Controls;

Expand Down Expand Up @@ -99,7 +99,7 @@ private async void FetchData()
if (response.IsSuccessful)
{
ListWanted = response.Data;
this.WantedListView.ItemsSource = ListWanted;
WantedListView.ItemsSource = ListWanted;
}
else
{
Expand Down
1 change: 0 additions & 1 deletion PoliceOp.OpCenter/Pages/SearchPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using RestSharp.Authenticators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

Expand Down
Binary file added PoliceOp.OpCenter/Resources/images/Wanted.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 760d998

Please sign in to comment.