Projet de stage 2021

This commit is contained in:
2021-06-18 10:37:33 +02:00
commit eb522143cf
314 changed files with 202141 additions and 0 deletions

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace key4intranet.Api.Docs {
public enum Departement {
OPERATIONNEL,
COMMERCIAL,
ADMISTRATIF,
DEV,
DIRECTION,
ERR //only for errors
}
}

View File

@ -0,0 +1,44 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.IO;
namespace key4intranet.Api.Docs {
[Serializable]
public class Document {
public String id {get;}
[JsonIgnore]
private FileInfo file; //for back-end usage
public String fileName {get;} //for front-end usage
public String extension {get;}
[JsonConverter(typeof(StringEnumConverter))]
public Departement group {get;}
public int permissionLevel {get;}
public Document(String i_d, FileInfo f, Departement depart, int permission_level) {
this.id = i_d;
this.file = f;
this.fileName = f.Name.Split(".")[0].Substring(6);
this.extension = f.Extension.Substring(1);
this.group = depart;
this.permissionLevel = permission_level;
}
public Document() {
}
public String getId() {
return this.id;
}
public String getPath() {
return this.file.FullName;
}
public Departement getGroup() {
return this.group;
}
}
}

View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace key4intranet.Api.Docs {
public interface IDocumentLibrary{
void resetLibrary();
Document GetDocumentFromLibrary(String fileId);
Boolean HasFile(String fileId);
void addToLibrary(Document d);
List<Document> GetAllDocuments();
List<Document> GetAllDocumentsFromGroup(Departement departement);
Boolean isEmpty();
}
public class DocumentLibrary: IDocumentLibrary
{
private List<Document> library;
public DocumentLibrary() {
library = new List<Document>();
}
public void resetLibrary() {
this.library.Clear();
}
public Document GetDocumentFromLibrary(String fileId) {
Document r;
if(this.HasFile(fileId)) {
int iterator = 0;
int index = -1;
foreach(Document d in library) {
if(d.getId().ToUpper().Equals(fileId.ToUpper())) {
index = iterator;
}
++iterator;
}
r = library[index];
} else {
r = new Document();
}
return r;
}
public Boolean HasFile(String fileId) {
Boolean r = false;
foreach(Document d in library) {
if(d.getId().ToUpper().Equals(fileId.ToUpper())) {
return true;
}
}
return r;
}
public void addToLibrary(Document d) {
library.Add(d);
}
public List<Document> GetAllDocuments() {
return this.library;
}
public List<Document> GetAllDocumentsFromGroup(Departement departement) {
List<Document> rl = new List<Document>();
List<Document> library = this.GetAllDocuments();
foreach(Document doc in library) {
if(doc.getGroup().Equals(departement)) {
rl.Add(doc);
}
}
return rl;
}
public Boolean isEmpty() {
return (this.library.Count == 0);
}
}
}

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace key4intranet.Api.Docs
{
public interface IDocumentManager
{
public DocumentLibrary dl { get; set; }
public void KnowAllDocuments();
public Departement GetDepartement(String file);
}
public class DocumentManager : IDocumentManager
{
private readonly IDocumentPathManager _documentPathManager;
public DocumentLibrary dl { get; set; }
public DocumentManager(IDocumentPathManager documentPathManager)
{
_documentPathManager = documentPathManager ?? throw new ArgumentNullException(nameof(documentPathManager));
this.dl = new DocumentLibrary();
KnowAllDocuments();
}
public void KnowAllDocuments()
{
DirectoryInfo d = new DirectoryInfo(_documentPathManager.KnowFolder());
List<FileInfo> files = new List<FileInfo>(d.GetFiles("*.*", SearchOption.AllDirectories));
if (!dl.isEmpty())
{
dl.resetLibrary();
}
foreach (FileInfo file in files)
{
if (!(file.Name.ToLower().Contains(".git")))
{
dl.addToLibrary(new Document(GenerateID(file.Name), file, GetDepartement(file.Name), 1));
}
}
}
public Departement GetDepartement(String file)
{
String check;
if (file.Length >= 3)
{
check = file.Substring(0, 3).ToUpper();
}
else
{
check = "ERR";
}
switch (check)
{
case "OPE":
return Departement.OPERATIONNEL;
case "COM":
return Departement.COMMERCIAL;
case "ADM":
return Departement.ADMISTRATIF;
case "DEV":
return Departement.DEV;
case "DIR":
return Departement.DIRECTION;
default:
return Departement.ERR;
}
}
private String GenerateID(String file)
{
return file.Substring(0, 3).ToUpper() + file.Substring(3, 3);
}
}
}

View File

@ -0,0 +1,41 @@
using Microsoft.Extensions.Configuration;
using System;
namespace key4intranet.Api.Docs{
public interface IDocumentPathManager
{
String BuildFullPathToFile(String fileName, String format);
public String BuildFullPathToFile(String subFolderPath, String fileName, String format);
public String KnowFolder();
}
public class DocumentPathManager : IDocumentPathManager
{
private readonly String sourceFolderPath;
private readonly String ressourcesPath;
public DocumentPathManager(IConfiguration config)
{
sourceFolderPath = config.GetSection("Settings:sourceFolderPath").Value;
ressourcesPath = config.GetSection("Settings:ressourcesPath").Value;
}
private String BuildFileName(String fileName, String format) {
return fileName + "." + format.ToLower();
}
public String BuildFullPathToFile(String fileName, String format) {
return BuildFullPathToFile("", fileName, format);
}
public String BuildFullPathToFile(String subFolderPath, String fileName, String format) {
return sourceFolderPath + ressourcesPath + subFolderPath + BuildFileName(fileName, format);
}
public String KnowFolder() {
return sourceFolderPath + ressourcesPath;
}
}
}