Abbozzato gestione auth

This commit is contained in:
Samuele E. Locatelli
2020-09-01 18:02:19 +02:00
parent 745205093c
commit 8fb844e83d
6 changed files with 158 additions and 56 deletions
+1
View File
@@ -55,6 +55,7 @@
<Compile Include="eSetup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="sysdiagram.cs" />
<Compile Include="Utils.cs" />
<Compile Include="v_dimensDistinct.cs" />
</ItemGroup>
<ItemGroup>
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AppData
{
public class Utils
{
/// <summary>
/// Setup file std
/// </summary>
public static string setupFile = "active.set";
public static string confDir
{
get
{
//string basePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
return $"{Directory.GetCurrentDirectory()}\\CONF\\";
}
}
}
}
+33 -1
View File
@@ -13,9 +13,41 @@ namespace AppData
/// </summary>
public string name { get; set; } = "";
/// <summary>
/// Imposto
/// </summary>
public bool SSIP { get; set; } = false;
/// <summary>
/// SQL server instance
/// </summary>
public string sqlServer { get; set; } = "";
/// <summary>
/// User SQL
/// </summary>
public string userName { get; set; } = "";
/// <summary>
/// PAsswd SQL
/// </summary>
public string passwd { get; set; } = "";
/// <summary>
/// Conn string di base
/// </summary>
public string connString { get; set; } = "";
public string connString
{
get
{
string answ = "";
if (SSIP)
{
answ = $"data source={sqlServer};initial catalog=Elmah;persist security info=True;Integrated Security=SSPI;MultipleActiveResultSets=True;App=EntityFramework";
}
else
{
answ = $"data source={sqlServer};initial catalog=Elmah;persist security info=True;user id={userName};password={passwd};MultipleActiveResultSets=True;App=EntityFramework";
}
return answ;
}
}
/// <summary>
/// URL di base x recupero ELMAH da sito
/// </summary>
+30 -28
View File
@@ -31,6 +31,7 @@
this.label1 = new System.Windows.Forms.Label();
this.txtServerName = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.txtPasswd = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtUser = new System.Windows.Forms.TextBox();
@@ -39,15 +40,14 @@
this.txtBaseUrl = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.txtAppBasePath = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.btnApply = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.txtAppBasePath = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.menuStrip1.SuspendLayout();
@@ -85,6 +85,16 @@
this.groupBox1.TabStop = false;
this.groupBox1.Text = "SQL Server";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(281, 20);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(73, 17);
this.checkBox1.TabIndex = 6;
this.checkBox1.Text = "integ auth";
this.checkBox1.UseVisualStyleBackColor = true;
//
// txtPasswd
//
this.txtPasswd.Location = new System.Drawing.Point(70, 81);
@@ -157,15 +167,22 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "IIS Server";
//
// checkBox1
// txtAppBasePath
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(281, 20);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(73, 17);
this.checkBox1.TabIndex = 6;
this.checkBox1.Text = "integ auth";
this.checkBox1.UseVisualStyleBackColor = true;
this.txtAppBasePath.Location = new System.Drawing.Point(70, 59);
this.txtAppBasePath.Name = "txtAppBasePath";
this.txtAppBasePath.Size = new System.Drawing.Size(306, 20);
this.txtAppBasePath.TabIndex = 23;
this.txtAppBasePath.Text = "--";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(8, 59);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(51, 13);
this.label6.TabIndex = 22;
this.label6.Text = "App Path";
//
// btnApply
//
@@ -213,29 +230,14 @@
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
this.loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.loadToolStripMenuItem.Text = "&Load";
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
//
// saveToolStripMenuItem
//
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveToolStripMenuItem.Text = "&Save";
//
// txtAppBasePath
//
this.txtAppBasePath.Location = new System.Drawing.Point(70, 59);
this.txtAppBasePath.Name = "txtAppBasePath";
this.txtAppBasePath.Size = new System.Drawing.Size(306, 20);
this.txtAppBasePath.TabIndex = 23;
this.txtAppBasePath.Text = "--";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(8, 59);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(51, 13);
this.label6.TabIndex = 22;
this.label6.Text = "App Path";
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
//
// ConfigMan
//
+61 -10
View File
@@ -1,9 +1,11 @@
using AppData;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -30,16 +32,6 @@ namespace ELMA
txtAppBasePath.Text = currSetup.appBasePath;
}
private void btnLoad_Click(object sender, EventArgs e)
{
}
private void btnSave_Click(object sender, EventArgs e)
{
}
private void btnApply_Click(object sender, EventArgs e)
{
((LogAnalyzer)this.Owner).activeSetup = currSetup;
@@ -51,5 +43,64 @@ namespace ELMA
currSetup=((LogAnalyzer)this.Owner).activeSetup;
doUpdate();
}
/// <summary>
/// Carica la conf corrente
/// </summary>
/// <param name="filePath"></param>
private void loadConf(string filePath)
{
if (File.Exists(filePath))
{
try
{
currSetup = JsonConvert.DeserializeObject<eSetup>(File.ReadAllText(filePath));
}
catch
{ }
}
}
/// <summary>
/// Salva conf corrente sul file indicato
/// </summary>
/// <param name="filePath"></param>
private void saveConf(string filePath)
{
// .. e lo salvo...
string rawData = JsonConvert.SerializeObject(currSetup, Formatting.Indented);
File.WriteAllText(filePath, rawData);
}
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
// salvo la conf corrente...
OpenFileDialog oFileDialog = new OpenFileDialog();
oFileDialog.DefaultExt = "jset";
oFileDialog.Filter = "Conf files (*.jset)|*.jset|All files (*.*)|*.*";
oFileDialog.InitialDirectory = Utils.confDir;
oFileDialog.RestoreDirectory = true;
if (oFileDialog.ShowDialog() == DialogResult.OK)
{
// carico
loadConf(oFileDialog.FileName);
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
// salvo la conf corrente...
SaveFileDialog sFileDialog = new SaveFileDialog();
sFileDialog.DefaultExt = "jset";
sFileDialog.Filter = "Conf files (*.jset)|*.jset|All files (*.*)|*.*";
sFileDialog.InitialDirectory = Utils.confDir;
sFileDialog.RestoreDirectory = true;
if (sFileDialog.ShowDialog() == DialogResult.OK)
{
// salvo!
string rawData = JsonConvert.SerializeObject(currSetup, Formatting.Indented);
saveConf(sFileDialog.FileName);
}
}
}
}
+7 -17
View File
@@ -27,26 +27,13 @@ namespace ELMA
/// </summary>
public eSetup activeSetup = new eSetup();
/// <summary>
/// Setup file std
/// </summary>
protected string setupFile = "active.set";
protected string confDir
{
get
{
//string basePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
return $"{Directory.GetCurrentDirectory()}\\CONF\\";
}
}
/// <summary>
/// Setup configurazione da std file
/// </summary>
private void setupConfig()
{
// cerco il file json di config
string filePath = $"{confDir}\\{setupFile}";
string filePath = $"{Utils.confDir}\\{Utils.setupFile}";
loadConf(filePath);
if (string.IsNullOrEmpty(activeSetup.name))
{
@@ -54,7 +41,10 @@ namespace ELMA
activeSetup = new eSetup()
{
name = "standard",
connString = "data source=SQL2016DEV;initial catalog=Elmah;persist security info=True;user id=sa;password=keyhammer16;MultipleActiveResultSets=True;App=EntityFramework",
userName="sa",
passwd="keyhammer16",
SSIP=false,
sqlServer= "SQL2016DEV",
appBasePath = "/LM/W3SVC/1/ROOT",
baseUrl = "https://localhost:44388"
};
@@ -104,7 +94,7 @@ namespace ELMA
OpenFileDialog oFileDialog = new OpenFileDialog();
oFileDialog.DefaultExt = "jset";
oFileDialog.Filter = "Conf files (*.jset)|*.jset|All files (*.*)|*.*";
oFileDialog.InitialDirectory = confDir;
oFileDialog.InitialDirectory = Utils.confDir;
oFileDialog.RestoreDirectory = true;
if (oFileDialog.ShowDialog() == DialogResult.OK)
{
@@ -119,7 +109,7 @@ namespace ELMA
SaveFileDialog sFileDialog = new SaveFileDialog();
sFileDialog.DefaultExt= "jset";
sFileDialog.Filter = "Conf files (*.jset)|*.jset|All files (*.*)|*.*";
sFileDialog.InitialDirectory = confDir;
sFileDialog.InitialDirectory = Utils.confDir;
sFileDialog.RestoreDirectory = true;
if (sFileDialog.ShowDialog() == DialogResult.OK)
{