Skip to content

Commit

Permalink
small bug fixes and first run experience
Browse files Browse the repository at this point in the history
  • Loading branch information
Kvikku committed Feb 6, 2024
1 parent 89ab2f6 commit 0719247
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 15 deletions.
Binary file modified .vs/IntuneAssignments/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/IntuneAssignments/v17/.suo
Binary file not shown.
6 changes: 3 additions & 3 deletions FormUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void WriteSystemSummaryToLog()
// This method will be used to write a summary of the system to the log file

// Create a new instance of the StreamWriter class
System.IO.StreamWriter sw = new System.IO.StreamWriter(GlobalVariables.MainLogFile, true);
System.IO.StreamWriter sw = new System.IO.StreamWriter(GlobalVariables.primaryLogFile, true);

// Write the data to the log file
sw.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - Beginning system summary");
Expand All @@ -75,7 +75,7 @@ public static void WriteToLog(string data)


// Read the last ten lines from the log file
List<string> lastTenLines = ReadLastLines(GlobalVariables.MainLogFile, 5);
List<string> lastTenLines = ReadLastLines(GlobalVariables.primaryLogFile, 5);

// Check if any of the last ten lines are identical to the new data
if (lastTenLines.Any(line => line.Contains(data)))
Expand All @@ -88,7 +88,7 @@ public static void WriteToLog(string data)


// Use the using statement to ensure proper disposal of StreamWriter
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(GlobalVariables.MainLogFile, true))
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(GlobalVariables.primaryLogFile, true))
{
// Write the data to the log file
sw.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {data}");
Expand Down
17 changes: 17 additions & 0 deletions GlobalVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ public class GlobalVariables
public static string configurationFolder = @"C:\ProgramData\IntuneAssignments";
public static string AppSettingsFile = @"C:\ProgramData\IntuneAssignments" + @"\AppSettings.json";
public static string MainLogFile = @"C:\ProgramData\IntuneAssignments" + @"\Primary Logfile.log";



public static string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
public static string appFolderName = "IntuneAssignments";
public static string appDataFolder = Path.Combine(appDataPath, appFolderName);

public static string logFileName = "IntuneAssignments.log";
public static string appSettingsFileName = "AppSettings.json";
public static string primaryLogFile = Path.Combine(appDataPath,appFolderName,logFileName);
public static string appSettingsFile = Path.Combine(appDataPath, appFolderName, appSettingsFileName);






public static string graphAssembly = "Microsoft.Graph.Beta";
public string graphClassNamePrefix = "Microsoft.Graph.Beta.Models.";

Expand Down
56 changes: 48 additions & 8 deletions HomePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using static IntuneAssignments.GraphServiceClientCreator;
using Microsoft.IdentityModel.Logging;
using Microsoft.Graph.Beta;
using System.Text.Json;

namespace IntuneAssignments
{
Expand All @@ -37,7 +38,7 @@ private void HomePage_Load(object sender, EventArgs e)

createConfigurationFolder();

createConfigurationFiles();
createAppSettingsFile();

ShowWarningOnStatusLabels();

Expand Down Expand Up @@ -86,12 +87,13 @@ private void createConfigurationFolder()


// Check if the folder in configurationFolder variable exists
if (!System.IO.Directory.Exists(configurationFolder))
if (!System.IO.Directory.Exists(appDataFolder))
{
// If it does not exist, create it
System.IO.Directory.CreateDirectory(configurationFolder);
System.IO.Directory.CreateDirectory(appDataFolder);


// Must also create log file here
createPrimaryLogFile();

WriteToLog("");
WriteToLog("");
Expand All @@ -101,7 +103,7 @@ private void createConfigurationFolder()
WriteToLog("Configuration folder created");

}
else if (!System.IO.File.Exists(MainLogFile))
else if (!System.IO.File.Exists(primaryLogFile))
{
// Create configuration files

Expand All @@ -124,20 +126,58 @@ private void createConfigurationFolder()

private void createPrimaryLogFile()
{

using (FileStream fs = File.Create(MainLogFile))
if (!System.IO.File.Exists(primaryLogFile))
{
// Do nothing
using (FileStream fs = File.Create(primaryLogFile))
{
// Do nothing
WriteToLog("The log file is missing. It may have been deleted or it is the first time the app is running on the system");
WriteToLog("Creating the log file");
}
}
else
{
WriteToLog("The log file already exists. No need to create");
}


// release the file
}

private void createAppSettingsFile()
{
if (!System.IO.File.Exists(appSettingsFile))
{
using (FileStream fs = File.Create(appSettingsFile))
{
// Do nothing
WriteToLog("The configuration file is missing. It may have been deleted or it is the first time the app is running on the system");
WriteToLog("Creating the configuration file");


// FIX CREATION OF THE FILE WITH JSON CONTENT

}
}
else
{
WriteToLog("The configuration file already exists. No need to create");
}


}

private void createConfigurationFiles()
{
// TO BE DELETED
// Create configuration files in the configuration folder

using (FileStream fs = File.Create(appSettingsFile))
{
// Do nothing
}


// check if the configuration file already exists
if (!System.IO.File.Exists(AppSettingsFile))
{
Expand Down
2 changes: 1 addition & 1 deletion Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void Settings_Load(object sender, EventArgs e)

// Retrieve data from appsettings.json and populate labels

string path = AppSettingsFile; //@"C:\ProgramData\IntuneAssignments" + @"\AppSettings.json";
string path = appSettingsFile; //@"C:\ProgramData\IntuneAssignments" + @"\AppSettings.json";

IConfigurationRoot configuration = new ConfigurationBuilder()
//.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
Expand Down
Binary file modified bin/Release/net6.0-windows10.0.22621.0/IntuneAssignments.dll
Binary file not shown.
Binary file modified bin/Release/net6.0-windows10.0.22621.0/IntuneAssignments.exe
Binary file not shown.
Binary file modified bin/Release/net6.0-windows10.0.22621.0/IntuneAssignments.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("IntuneAssignments")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1527565d29bef2efe6f8b2e96f4d2abf300c7f48")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+89ab2f619c87447a795b9232eeef26fc0885f8b7")]
[assembly: System.Reflection.AssemblyProductAttribute("IntuneAssignments")]
[assembly: System.Reflection.AssemblyTitleAttribute("IntuneAssignments")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7a2ab3fccd884a74ec6a57caebc4c788d2c107f7545eb5661b0392ac54a61dc8
ac4dfce9013c563f70f78831f8dc195c70481709cf35e50faed809d5427263b1
Binary file modified obj/Release/net6.0-windows10.0.22621.0/IntuneAssignments.dll
Binary file not shown.
Binary file modified obj/Release/net6.0-windows10.0.22621.0/IntuneAssignments.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"C:\\Github\\IntuneAssignments\\*":"https://raw.githubusercontent.com/Kvikku/IntuneAssignments/1527565d29bef2efe6f8b2e96f4d2abf300c7f48/*"}}
{"documents":{"C:\\Github\\IntuneAssignments\\*":"https://raw.githubusercontent.com/Kvikku/IntuneAssignments/89ab2f619c87447a795b9232eeef26fc0885f8b7/*"}}
Binary file modified obj/Release/net6.0-windows10.0.22621.0/apphost.exe
Binary file not shown.
Binary file modified obj/Release/net6.0-windows10.0.22621.0/ref/IntuneAssignments.dll
Binary file not shown.
Binary file not shown.

0 comments on commit 0719247

Please sign in to comment.