Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta V1.1.5 #10

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/MailLobbyer/Data/CSVFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ namespace MailLobbyer.CSVFileClass
{
public class CSVFile
{
public Guid Id { get; }
public string Filename { get; set; }
public string Filepath { get; set; }
public byte[] Filecontents { get; set; }

public CSVFile (string filename, string filepath)
public CSVFile (Guid id, string filename, string filepath, byte[] filecontents)
{
Id = id;
Filename = filename;
Filepath = filepath;
Filecontents = filecontents;
}
}
}
43 changes: 39 additions & 4 deletions src/MailLobbyer/Hubs/CSVHub.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Microsoft.AspNetCore.SignalR;
using MailLobbyer.CSVFileClass;
using MailLobbyer.ContactClass;
using Microsoft.AspNetCore.Components.Forms;

namespace MailLobbyer.Server.Hubs;

public class CSVHub : Hub
{
private static List<CSVFile> csvfilesinmemory = new List<CSVFile>();
private static string[] filepaths;

public async Task CSVFileSeeker()
{
Expand All @@ -24,14 +26,47 @@ public async Task CSVFileSeeker()
}

// Later on change to use config values set by the user
string[] filepaths = Directory.GetFiles(directorypath);
filepaths = Directory.GetFiles(directorypath);

foreach (string filepath in filepaths)
{
CSVFile newcsvfile = new CSVFile(Path.GetFileNameWithoutExtension(filepath), filepath);
csvfilesinmemory.Add(newcsvfile);
System.Console.WriteLine(newcsvfile.Filename);

using (var ms = new MemoryStream())
{
using(FileStream fs = new FileStream(filepath, FileMode.Open,FileAccess.Read))
{
await fs.CopyToAsync(ms);
}

byte[] filecontents = ms.ToArray();
CSVFile newcsvfile = new CSVFile(Guid.NewGuid(),Path.GetFileNameWithoutExtension(filepath), filepath, filecontents);
csvfilesinmemory.Add(newcsvfile);
}

}
}

public async Task CSVFilesToUpload(IBrowserFile file)
{
string directorypath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "MailLobbyer");

using (FileStream fs = new FileStream(directorypath, FileMode.Create))
{
await file.OpenReadStream().CopyToAsync(fs);
}

}

public async Task RemoveCSVFile(string selectedcsvfilename)
{
foreach (string filepath in filepaths)
{
if(Path.GetFileNameWithoutExtension(filepath) == selectedcsvfilename)
{
File.Delete(filepath);
}
}

}


Expand Down
27 changes: 16 additions & 11 deletions src/MailLobbyer/Modules/CSVService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@ public class CSVService
{
public List<Contact> contacts = new List<Contact>();

public async Task CSVParser(string csvfilepath)
public async Task CSVParser(byte[] selectedcsvfilecontents)
{
await Task.Run(() =>
{
try
{
using (StreamReader reader = new StreamReader(csvfilepath))
using (MemoryStream ms = new MemoryStream(selectedcsvfilecontents))
{
string currentline;
using (StreamReader reader = new StreamReader(ms))
{
string currentline;

//Skip headers used for XLSX reference before conversion to CSV
reader.ReadLine();
//Skip headers used for XLSX reference before conversion to CSV
reader.ReadLine();

while((currentline = reader.ReadLine()) != null)
{
string[] substrings = currentline.Split(',');
while((currentline = reader.ReadLine()) != null)
{
string[] substrings = currentline.Split(',');

Contact newcontact = new Contact(substrings[0], substrings [1], substrings[2], substrings[3]);
contacts.Add(newcontact);
}
Contact newcontact = new Contact(substrings[0], substrings [1], substrings[2], substrings[3]);
contacts.Add(newcontact);
}

}

}

}
catch(Exception e)
{
Expand Down
19 changes: 13 additions & 6 deletions src/MailLobbyer/Pages/Email.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
{
<div class="form-group">
<label for="contactGroup">Contact Group:</label>
<select id="contactGroup" class="form-control" @bind="selectedgroup" required aria-label="Contact Group">
<select id="contactGroup" class="form-control" @bind="selectedcsvfileid" required aria-label="Contact Group">
<option value="">Select a group</option>
@foreach (CSVFile csvfile in csvfilesonserver)
{
<option value="@csvfile.Filepath" aria-label="@csvfile.Filename">@csvfile.Filename</option>
<option value="@csvfile.Id" aria-label="@csvfile.Filename">@csvfile.Filename</option>
}
</select>
</div>
Expand Down Expand Up @@ -119,7 +119,7 @@
private string subject;
private string body;
private List<IBrowserFile> selectedfiles = new List<IBrowserFile>();
private string selectedgroup;
private Guid selectedcsvfileid;
private string contactsearch = string.Empty;
private bool displaycontactsearch;
private bool istoggleselectallbuttondisabled;
Expand Down Expand Up @@ -231,14 +231,21 @@

private async Task EmailFormSubmitHandler()
{
if (string.IsNullOrEmpty(selectedgroup))
if (selectedcsvfileid == null)
{
// Replace with popup!
Console.WriteLine("Please select a group.");
return;
}

await csvserviceinstance.CSVParser(selectedgroup);
foreach (CSVFile csvfile in csvfilesonserver)
{
if (csvfile.Id == selectedcsvfileid)
{
await csvserviceinstance.CSVParser(csvfile.Filecontents);
}
}


displayform = false;

Expand Down Expand Up @@ -283,7 +290,7 @@
body = string.Empty;
selectedfiles = new List<IBrowserFile>();
csvserviceinstance.contacts.Clear();
selectedgroup = string.Empty;
selectedcsvfileid = Guid.Empty;
toggleselectallbuttonboolvalue = true;
toggleselectallbuttonstringvalue = "Select all";
displayform = true;
Expand Down
78 changes: 73 additions & 5 deletions src/MailLobbyer/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@using System.Text
@using FileHandlerComponent
@using MailLobbyer.SettingsProfilesClass
@using MailLobbyer.CSVFileClass
@using Microsoft.AspNetCore.SignalR.Client
@inject NavigationManager Navigation
@inject IJSRuntime JSRuntime
Expand Down Expand Up @@ -72,17 +73,52 @@
<div class="custom-inputfile">
<InputFile id="inputfiles" OnChange="@FileUploadHandler" multiple />
</div>
<div class="inputfile-form">
<input type="button" class="btn btn-primary"value="Browse..." onclick="document.getElementById('inputfiles').click();" />
@foreach (var file in selectedfiles)
{
<div class="selectedfile-container">
<button type="button" id="file" class="btn-selectedfile" @onclick="() => RemoveFile(file)">@file.Name X</button>
</div>

}
</div>
</div>

<button type="submit" class="btn btn-primary">Upload</button>
@if(selectedfiles.Count > 0)
{
<button type="submit" class="btn btn-primary">Upload</button>
}

</form>

<form class="input-form" @onsubmit="CSVFileRemoveSubmitHandler">
<div class="form-group">
<label for="inputfiles">Remove CSV files on server:</label>
<select id="contactGroup" class="form-control" @bind="selectedcsvfilename" required aria-label="Contact Group">
<option value="">Select a file</option>
@foreach (CSVFile csvfile in csvfilesonserver)
{
<option value="@csvfile.Filename" aria-label="@csvfile.Filename">@csvfile.Filename</option>
}
</select>
</div>

@if(selectedcsvfilename != null)
{
<button type="submit" class="btn btn-primary">Delete</button>
}
</form>

@code {
private HubConnection? settingshubconnection;
private HubConnection? csvhubconnection;
private List<CSVFile> csvfilesonserver = new List<CSVFile>();
private List<SettingsProfiles> settingsprofilesonserver = new List<SettingsProfiles>();
private List<IBrowserFile> selectedfiles = new List<IBrowserFile>();

private Guid selectedsettingsprofile;
private string selectedcsvfilename;
private string profilename;
private string sendername;
private string senderemail;
Expand All @@ -96,9 +132,14 @@
settingshubconnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/settingshub"))
.Build();

csvhubconnection = new HubConnectionBuilder()
.WithUrl(Navigation.ToAbsoluteUri("/csvhub"))
.Build();


await settingshubconnection.StartAsync();
await csvhubconnection.StartAsync();


if (settingshubconnection is not null)
Expand All @@ -109,6 +150,14 @@

settingsprofilesonserver = await settingshubconnection.InvokeAsync<List<SettingsProfiles>>("GetProfiles");
}

if (csvhubconnection is not null)
{
await csvhubconnection.SendAsync("CSVFileSeeker");


csvfilesonserver = await csvhubconnection.InvokeAsync<List<CSVFile>>("GetCSVFilesInMemory");
}
}

private void RemoveSelectedProfile()
Expand Down Expand Up @@ -137,14 +186,28 @@
selectedfiles = e.GetMultipleFiles().ToList();
}

private void RemoveFile(IBrowserFile file)
{
selectedfiles.Remove(file);

}

private async Task CSVFileFormSubmitHandler()
{
/*
FileHandler filehandlerinstance = new FileHandler();
foreach (IBrowserFile file in selectedfiles)
{
await csvhubconnection.SendAsync("CSVFilesToUpload", file);
}

await filehandlerinstance.ExtractUploadedFileContents(selectedfiles);
*/
await JSRuntime.InvokeVoidAsync("eval","location.reload(true)");

}

private async Task CSVFileRemoveSubmitHandler()
{
await csvhubconnection.SendAsync("RemoveCSVFile", selectedcsvfilename);

await JSRuntime.InvokeVoidAsync("eval","location.reload(true)");
}


Expand All @@ -155,6 +218,11 @@
await settingshubconnection.DisposeAsync();
settingsprofilesonserver.Clear();
}

if (csvhubconnection is not null)
{
await csvhubconnection.DisposeAsync();
}
}

}
11 changes: 2 additions & 9 deletions src/MailLobbyer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"SmtpClientSettings": {
"Sendername": "Test",
"Senderemail": "peterhamilton522@gmail.com",
"Host": "smtp.gmail.com",
"Password": "okakgvqorczjjllu",
"Port": "587",
"Username": "peterhamilton522@gmail.com"
}
"AllowedHosts": "*"

}
Binary file modified src/MailLobbyer/bin/Debug/net7.0/MailLobbyer.dll
Binary file not shown.
Binary file modified src/MailLobbyer/bin/Debug/net7.0/MailLobbyer.pdb
Binary file not shown.
6 changes: 6 additions & 0 deletions src/MailLobbyer/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ dotnet publish -c Release -r linux-x64 --self-contained true -o ./builds/ML-linu

# Zip the Linux version
zip -r ./builds/ML-linux-x64.zip ./builds/ML-linux-x64

# Publish for OSX
dotnet publish -c Release -r osx-x64 --self-contained true -o ./builds/ML-osx-x64

# Zip the OSX version
zip -r ./builds/ML-osx-x64.zip ./builds/ML-osx-x64
Binary file modified src/MailLobbyer/obj/Debug/net7.0/MailLobbyer.dll
Binary file not shown.
Binary file modified src/MailLobbyer/obj/Debug/net7.0/MailLobbyer.pdb
Binary file not shown.
Loading