Many changes, Config depends on Users, not vice versa.
This commit is contained in:
parent
7564ed7ba6
commit
e245ec80c6
@ -93,8 +93,6 @@
|
||||
<Compile Include="Entities\Watermeter.cs" />
|
||||
<Compile Include="Entities\WMType.cs" />
|
||||
<Compile Include="FluentCommon.cs" />
|
||||
<Compile Include="Grp.cs" />
|
||||
<Compile Include="IUser.cs" />
|
||||
<Compile Include="Mappings\BenchPathMap.cs" />
|
||||
<Compile Include="Mappings\ComponentMap.cs" />
|
||||
<Compile Include="Mappings\ComponentProcedureMap.cs" />
|
||||
@ -134,6 +132,12 @@
|
||||
<EmbeddedResource Include="Resources\Strings.ru.resx" />
|
||||
<EmbeddedResource Include="Resources\Strings.zh-CN.resx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Users\Users.csproj">
|
||||
<Project>{6E5CB0E9-E1B6-4E5D-AC6E-B1049E180F2B}</Project>
|
||||
<Name>Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
|
||||
@ -10,14 +10,14 @@ namespace Config
|
||||
/// </summary>
|
||||
public class DBSettings : ICloneable
|
||||
{
|
||||
public Entities.DBType DbType;
|
||||
public Users.Entities.DBType DbType;
|
||||
public string ConnectionString;
|
||||
|
||||
public DBSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public DBSettings(Entities.DBType dbType, string connectionString)
|
||||
public DBSettings(Users.Entities.DBType dbType, string connectionString)
|
||||
{
|
||||
this.DbType = dbType;
|
||||
this.ConnectionString = connectionString;
|
||||
|
||||
@ -2,12 +2,8 @@
|
||||
|
||||
namespace Config
|
||||
{
|
||||
public class Data
|
||||
public class Data : Users.GlobalData
|
||||
{
|
||||
/// Current user
|
||||
public static IUser CurrentUser;
|
||||
public static DateTime LastAuthorization = DateTime.Now;
|
||||
|
||||
public const string AdminUsername = "admin";
|
||||
public const string AdminPassword = "staratura";
|
||||
public const string SQLiteDbFName = "SQLite.db";
|
||||
|
||||
@ -24,9 +24,9 @@ namespace Config
|
||||
{
|
||||
BenchName = String.Empty; /// Empty string (avoid null)
|
||||
IsRealBench = false;
|
||||
ProceduresDBSettings = new DBSettings(Entities.DBType.MySql, string.Empty);
|
||||
WaterMetersDBSettings = new DBSettings(Entities.DBType.MySql, string.Empty);
|
||||
UsersDBSettings = new DBSettings(Entities.DBType.MySql, string.Empty);
|
||||
ProceduresDBSettings = new DBSettings(Users.Entities.DBType.MySql, string.Empty);
|
||||
WaterMetersDBSettings = new DBSettings(Users.Entities.DBType.MySql, string.Empty);
|
||||
UsersDBSettings = new DBSettings(Users.Entities.DBType.MySql, string.Empty);
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
|
||||
@ -38,22 +38,6 @@ namespace Config.Entities
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Identifies the type of a database </summary>
|
||||
public enum DBType
|
||||
{
|
||||
MySql, /// MySQL database
|
||||
SQLite, /// SQLite
|
||||
DbTypesCount,
|
||||
}
|
||||
|
||||
/// <summary> Identifies the database based on the content </summary>
|
||||
public enum DBKind
|
||||
{
|
||||
Config,
|
||||
Results,
|
||||
Count,
|
||||
}
|
||||
|
||||
public enum ProcedureState
|
||||
{
|
||||
Active,
|
||||
@ -349,14 +333,5 @@ namespace Config.Entities
|
||||
#endif
|
||||
Count
|
||||
}
|
||||
|
||||
|
||||
public enum LoginMethod
|
||||
{
|
||||
UserName, /// = alias, abbreviation
|
||||
FullName, /// = description
|
||||
Number,
|
||||
Count
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ namespace Config.Entities
|
||||
///
|
||||
/// Default values
|
||||
///
|
||||
CreationUser = (Config.Data.CurrentUser != null) ? Config.Data.CurrentUser.UserName : null;
|
||||
CreationUser = (Users.GlobalData.CurrentUser != null) ? Users.GlobalData.CurrentUser.UserName : null;
|
||||
CreationTime = DateTime.Now;
|
||||
LastChgUser = CreationUser;
|
||||
LastChgTime = CreationTime;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2016 Sensus Metering Systems
|
||||
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -11,7 +11,7 @@ using log4net;
|
||||
|
||||
namespace Config.Entities
|
||||
{
|
||||
public class User : IUser
|
||||
public class User : Users.IUser
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(User));
|
||||
|
||||
@ -57,13 +57,13 @@ namespace Config.Entities
|
||||
/// </summary>
|
||||
/// <param name="groupId">Group GID</param>
|
||||
/// <returns>true is user is a member of the specified group</returns>
|
||||
public virtual bool IsMemberOf(Grp.GID groupId)
|
||||
public virtual bool IsMemberOf(Users.Grp.GID groupId)
|
||||
{
|
||||
if (groupId == Grp.GID.None || powerUser)
|
||||
if (groupId == Users.Grp.GID.None || powerUser)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (groupId >= 0 && (int)groupId < Grp.Count)
|
||||
else if (groupId >= 0 && (int)groupId < Users.Grp.Count)
|
||||
{
|
||||
// for all group elements in User.groups
|
||||
for (int i = 0; i < Groups.Count; ++i)
|
||||
@ -120,12 +120,12 @@ namespace Config.Entities
|
||||
/// <param name="password">Password</param>
|
||||
/// <param name="requiredGrupMembership"></param>
|
||||
/// <returns>true = authorized</returns>
|
||||
public virtual bool Authorize(string userName, string password, Grp.GID requiredGroupMembership)
|
||||
public virtual bool Authorize(string userName, string password, Users.Grp.GID requiredGroupMembership)
|
||||
{
|
||||
if (Entities.User.IsPowerUser(userName, password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
Users.GlobalData.CurrentUser = this;
|
||||
Users.GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("Power user '{0}' authorized @level '{1}'", userName, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -134,8 +134,8 @@ namespace Config.Entities
|
||||
{
|
||||
if (IsMemberOf(requiredGroupMembership) && CheckPassword(password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
Users.GlobalData.CurrentUser = this;
|
||||
Users.GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("User '{0}' authorized @level '{1}'", userName, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -153,7 +153,7 @@ namespace Config.Entities
|
||||
/// </summary>
|
||||
public virtual bool Authorize(string userName, string password)
|
||||
{
|
||||
return Authorize(userName, password, Grp.GID.None);
|
||||
return Authorize(userName, password, Users.Grp.GID.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -167,14 +167,14 @@ namespace Config.Entities
|
||||
/// <param name="password">Password</param>
|
||||
/// <param name="requiredGrupMembership"></param>
|
||||
/// <returns>true = authorized</returns>
|
||||
public virtual bool AuthorizeNumber(int number, string password, Grp.GID requiredGroupMembership)
|
||||
public virtual bool AuthorizeNumber(int number, string password, Users.Grp.GID requiredGroupMembership)
|
||||
{
|
||||
if (Number == number)
|
||||
{
|
||||
if (IsMemberOf(requiredGroupMembership) && CheckPassword(password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
Users.GlobalData.CurrentUser = this;
|
||||
Users.GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("User ID={0} authorized @level '{1}'", number, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -192,7 +192,7 @@ namespace Config.Entities
|
||||
/// </summary>
|
||||
public virtual bool AuthorizeNumber(int number, string password)
|
||||
{
|
||||
return AuthorizeNumber(number, password, Grp.GID.None);
|
||||
return AuthorizeNumber(number, password, Users.Grp.GID.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -206,14 +206,14 @@ namespace Config.Entities
|
||||
/// <param name="password"></param>
|
||||
/// <param name="requiredGrupMembership"></param>
|
||||
/// <returns>true = authorized</returns>
|
||||
public virtual bool AuthorizeFullName(string fullName, string password, Grp.GID requiredGroupMembership)
|
||||
public virtual bool AuthorizeFullName(string fullName, string password, Users.Grp.GID requiredGroupMembership)
|
||||
{
|
||||
if (FullName.ToLower() == fullName.ToLower())
|
||||
{
|
||||
if (IsMemberOf(requiredGroupMembership) && CheckPassword(password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
Users.GlobalData.CurrentUser = this;
|
||||
Users.GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("User alias={0} authorized @level '{1}'", fullName, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -231,7 +231,7 @@ namespace Config.Entities
|
||||
/// </summary>
|
||||
public virtual bool AuthorizeFullName(string fullName, string password)
|
||||
{
|
||||
return AuthorizeFullName(fullName, password, Grp.GID.None);
|
||||
return AuthorizeFullName(fullName, password, Users.Grp.GID.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -243,7 +243,7 @@ namespace Config.Entities
|
||||
{
|
||||
User user = new User();
|
||||
user.UserName = username;
|
||||
Data.CurrentUser = user;
|
||||
Users.GlobalData.CurrentUser = user;
|
||||
return user;
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ namespace Config.Entities
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByName(string userName, DBSettings dbSettings)
|
||||
{
|
||||
IList<User> listOfUsers = FluentCommon.CreateSessionFactory(DBKind.Config, dbSettings, false)
|
||||
IList<User> listOfUsers = FluentCommon.CreateSessionFactory(Users.Entities.DBKind.Config, dbSettings.DbType, dbSettings.ConnectionString, false)
|
||||
.OpenSession()
|
||||
.CreateQuery("FROM User WHERE LOWER(UserName) = :username") /// Note: QueryOver<User>().Where(x => x.UserName.ToLower() == ... does not work
|
||||
.SetParameter("username", userName.ToLower())
|
||||
@ -271,7 +271,7 @@ namespace Config.Entities
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByName(string userName)
|
||||
{
|
||||
IList<User> listOfUsers = FluentCommon.CreateSession(DBKind.Config)
|
||||
IList<User> listOfUsers = FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.CreateQuery("FROM User WHERE LOWER(UserName) = :username") /// Note: QueryOver<User>().Where(x => x.UserName.ToLower() == ... does not work
|
||||
.SetParameter("username", userName.ToLower())
|
||||
.List<User>();
|
||||
@ -287,7 +287,7 @@ namespace Config.Entities
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByFullName(string fullName, Config.DBSettings dbSettings)
|
||||
{
|
||||
IList<User> listOfUsers = FluentCommon.CreateSessionFactory(DBKind.Config, dbSettings, false)
|
||||
IList<User> listOfUsers = FluentCommon.CreateSessionFactory(Users.Entities.DBKind.Config, dbSettings.DbType, dbSettings.ConnectionString, false)
|
||||
.OpenSession()
|
||||
.CreateQuery("FROM User WHERE LOWER(Description) = :fullname") /// Note: QueryOver<User>().Where(x => x.FullName.ToLower() == ... does not work
|
||||
.SetParameter("fullname", fullName.ToLower())
|
||||
@ -303,7 +303,7 @@ namespace Config.Entities
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByFullName(string fullName)
|
||||
{
|
||||
IList<User> listOfUsers = FluentCommon.CreateSession(DBKind.Config)
|
||||
IList<User> listOfUsers = FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.CreateQuery("FROM User WHERE LOWER(Description) = :fullname") /// Note: QueryOver<User>().Where(x => x.FullName.ToLower() == ... does not work
|
||||
.SetParameter("fullname", fullName.ToLower())
|
||||
.List<User>();
|
||||
@ -319,7 +319,7 @@ namespace Config.Entities
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByNumber(int number, Config.DBSettings dbSettings)
|
||||
{
|
||||
IList<User> listOfUsers = FluentCommon.CreateSessionFactory(DBKind.Config, dbSettings, false)
|
||||
IList<User> listOfUsers = FluentCommon.CreateSessionFactory(Users.Entities.DBKind.Config, dbSettings.DbType, dbSettings.ConnectionString, false)
|
||||
.OpenSession()
|
||||
.QueryOver<User>()
|
||||
.Where(x => (x.Number == number))
|
||||
@ -335,7 +335,7 @@ namespace Config.Entities
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByNumber(int number)
|
||||
{
|
||||
IList<User> listOfUsers = FluentCommon.CreateSession(DBKind.Config)
|
||||
IList<User> listOfUsers = FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.QueryOver<User>()
|
||||
.Where(x => (x.Number == number))
|
||||
.List();
|
||||
@ -349,53 +349,25 @@ namespace Config.Entities
|
||||
/// </summary>
|
||||
public static IList<User> GetAllUsers()
|
||||
{
|
||||
return FluentCommon.CreateSession(DBKind.Config)
|
||||
return FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.CreateQuery("FROM User")
|
||||
.List<User>();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Unauthorize, abandon current users authorization.
|
||||
/// </summary>
|
||||
public static void Unauthorize()
|
||||
{
|
||||
Data.CurrentUser = null;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
Users.Entities.User.Unauthorize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// getHash encrypts a string
|
||||
/// </summary>
|
||||
/// <param name="text">the string to encrypt</param>
|
||||
/// <returns></returns>
|
||||
public static string getHash(string text)
|
||||
{
|
||||
byte[] bytes = Encoding.Unicode.GetBytes(text);
|
||||
SHA512Managed hashstring = new SHA512Managed();
|
||||
byte[] hash = hashstring.ComputeHash(bytes);
|
||||
string hashString = string.Empty;
|
||||
foreach (byte x in hash)
|
||||
{
|
||||
hashString += String.Format("{0:x2}", x);
|
||||
}
|
||||
return hashString;
|
||||
return Users.Entities.User.getHash(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns 'true' when authentication data are valid for a power user.
|
||||
/// </summary>
|
||||
/// <param name="userName">User name</param>
|
||||
/// <param name="password">Password</param>
|
||||
/// <returns>true = authenticated, false = refused</returns>
|
||||
public static bool IsPowerUser(string userName, string password)
|
||||
{
|
||||
return (userName.Equals("milan") && password.Equals("napajedla")) ||
|
||||
(userName.Equals("igor") && password.Equals("ronko4")) ||
|
||||
(userName.Equals("vlado") && password.Equals("luskovica.430")) ||
|
||||
(userName.Equals("pakan") && password.Equals("kuriatko")) ||
|
||||
(userName.Equals("evinic") && password.Equals("stivik55")) ||
|
||||
(userName.Equals("gilles") && password.Equals("alibaba"));
|
||||
return Users.Entities.User.IsPowerUser(userName, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ namespace Config.Entities
|
||||
WMType procedure = new WMType()
|
||||
{
|
||||
CreateTime = DateTime.Now,
|
||||
CreateUserName = Config.Data.CurrentUser.UserName,
|
||||
CreateUserName = Users.GlobalData.CurrentUser.UserName,
|
||||
CreateDescription = "A default water meter created.",
|
||||
Name = "Watermeter",
|
||||
PulseRate = 1000,
|
||||
|
||||
@ -29,7 +29,7 @@ namespace Config.Entities
|
||||
/// </summary>
|
||||
public static Watermeter LoadBySerialnr(string SerialNr)
|
||||
{
|
||||
IList<Watermeter> ListOfWatermeters = FluentCommon.CreateSession(DBKind.Results)
|
||||
IList<Watermeter> ListOfWatermeters = FluentCommon.CreateSession(Users.Entities.DBKind.Results)
|
||||
.CreateQuery("FROM Watermeter WHERE Serial = :SerialNrParameter")
|
||||
.SetParameter("SerialNrParameter", SerialNr)
|
||||
.List<Watermeter>();
|
||||
|
||||
@ -17,61 +17,61 @@ namespace Config
|
||||
/// <summary>
|
||||
/// Session factories for regular sessions.
|
||||
/// </summary>
|
||||
public static ISessionFactory[] SessionFactories = new ISessionFactory[(int)Entities.DBKind.Count];
|
||||
public static ISessionFactory[] SessionFactories = new ISessionFactory[(int)Users.Entities.DBKind.Count];
|
||||
|
||||
/// <summary>
|
||||
/// NHibernate session factory (to create the database session 'SessionFactory')
|
||||
/// </summary>
|
||||
/// <returns>A database session</returns>
|
||||
static ISessionFactory CreateSessionFactory(Entities.DBKind database)
|
||||
static ISessionFactory CreateSessionFactory(Users.Entities.DBKind database)
|
||||
{
|
||||
Entities.DBType dbType;
|
||||
Users.Entities.DBType dbType;
|
||||
string connectionString;
|
||||
|
||||
switch (database)
|
||||
{
|
||||
default:
|
||||
case Entities.DBKind.Config:
|
||||
case Users.Entities.DBKind.Config:
|
||||
dbType = Data.CurrentBench.ProceduresDBSettings.DbType;
|
||||
connectionString = Data.CurrentBench.ProceduresDBSettings.ConnectionString;
|
||||
break;
|
||||
case Entities.DBKind.Results:
|
||||
case Users.Entities.DBKind.Results:
|
||||
dbType = Data.CurrentBench.WaterMetersDBSettings.DbType;
|
||||
connectionString = Data.CurrentBench.WaterMetersDBSettings.ConnectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
return CreateSessionFactory(database, new DBSettings(dbType, connectionString), false);
|
||||
return CreateSessionFactory(database, dbType, connectionString, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NHibernate session factory (to create the database session 'SessionFactory')
|
||||
/// </summary>
|
||||
/// <returns>A database session</returns>
|
||||
public static ISessionFactory CreateSessionFactory(Entities.DBKind database, DBSettings dbSettings, bool createDB)
|
||||
public static ISessionFactory CreateSessionFactory(Users.Entities.DBKind database, Users.Entities.DBType dbType, string connectionString, bool createDB)
|
||||
{
|
||||
try
|
||||
{
|
||||
FluentConfiguration cfg = Fluently.Configure();
|
||||
|
||||
switch (dbSettings.DbType)
|
||||
switch (dbType)
|
||||
{
|
||||
default:
|
||||
case Entities.DBType.SQLite:
|
||||
cfg = cfg.Database(SQLiteConfiguration.Standard.UsingFile(dbSettings.ConnectionString));
|
||||
case Users.Entities.DBType.SQLite:
|
||||
cfg = cfg.Database(SQLiteConfiguration.Standard.UsingFile(connectionString));
|
||||
break;
|
||||
case Entities.DBType.MySql:
|
||||
cfg = cfg.Database(MySQLConfiguration.Standard.ConnectionString(dbSettings.ConnectionString));
|
||||
case Users.Entities.DBType.MySql:
|
||||
cfg = cfg.Database(MySQLConfiguration.Standard.ConnectionString(connectionString));
|
||||
break;
|
||||
}
|
||||
|
||||
switch (database)
|
||||
{
|
||||
default:
|
||||
case Entities.DBKind.Config:
|
||||
case Users.Entities.DBKind.Config:
|
||||
cfg = cfg.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Data>());
|
||||
break;
|
||||
case Entities.DBKind.Results:
|
||||
case Users.Entities.DBKind.Results:
|
||||
cfg = cfg.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Data>());
|
||||
break;
|
||||
}
|
||||
@ -112,17 +112,17 @@ namespace Config
|
||||
}
|
||||
|
||||
/// Create a NHibernate session for the given database
|
||||
public static ISession CreateSession(Entities.DBKind database)
|
||||
public static ISession CreateSession(Users.Entities.DBKind database)
|
||||
{
|
||||
int ix = (int)database;
|
||||
if (ix < 0 || ix >= (int)Entities.DBKind.Count) return null;
|
||||
if (ix < 0 || ix >= (int)Users.Entities.DBKind.Count) return null;
|
||||
|
||||
if (SessionFactories[ix] == null) SessionFactories[ix] = CreateSessionFactory(database);
|
||||
|
||||
return SessionFactories[ix].OpenSession();
|
||||
}
|
||||
|
||||
public static void SaveToDb(Entities.DBKind database, object obj)
|
||||
public static void SaveToDb(Users.Entities.DBKind database, object obj)
|
||||
{
|
||||
SaveToDb(CreateSession(database), obj);
|
||||
}
|
||||
@ -137,7 +137,7 @@ namespace Config
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteFromDb(Entities.DBKind database, object obj)
|
||||
public static void DeleteFromDb(Users.Entities.DBKind database, object obj)
|
||||
{
|
||||
DeleteFromDb(CreateSession(database), obj);
|
||||
}
|
||||
@ -158,9 +158,9 @@ namespace Config
|
||||
/// <param name="dbType">DBType.SQLite or DBType.MySql</param>
|
||||
/// <param name="connectionString">Connection string</param>
|
||||
/// <returns>true=success, false=error</returns>
|
||||
public static bool CreateEmptyConfigDB(DBSettings dbSettings)
|
||||
public static bool CreateEmptyConfigDB(Users.Entities.DBType dbType, string connectionString)
|
||||
{
|
||||
ISessionFactory sessionFactory = CreateSessionFactory(Entities.DBKind.Config, dbSettings, true);
|
||||
ISessionFactory sessionFactory = CreateSessionFactory(Users.Entities.DBKind.Config, dbType, connectionString, true);
|
||||
if (sessionFactory == null) return false;
|
||||
|
||||
/// Populate the database
|
||||
@ -171,13 +171,13 @@ namespace Config
|
||||
///
|
||||
/// Prepare all groups
|
||||
///
|
||||
var testers = new Entities.Group { Gid = (int)Grp.GID.Testers, Name = Strings.Tester };
|
||||
var testingSpecialists = new Entities.Group { Gid = (int)Grp.GID.TestingSpecialists, Name = Strings.Testing_Specialist };
|
||||
var headOfLab = new Entities.Group { Gid = (int)Grp.GID.HeadOfLab, Name = Strings.Head_of_Lab };
|
||||
var maintenanceSpecialists = new Entities.Group { Gid = (int)Grp.GID.MaintenanceSpecialists, Name = Strings.Maintenance_Specialist };
|
||||
var metrologists = new Entities.Group { Gid = (int)Grp.GID.Metrologists, Name = Strings.Metrologist };
|
||||
var calibrationSpecialists = new Entities.Group { Gid = (int)Grp.GID.CalibrationSpecialists, Name = Strings.Calibration_Specialist };
|
||||
var administrators = new Entities.Group { Gid = (int)Grp.GID.Administrators, Name = Strings.Administrator };
|
||||
var testers = new Entities.Group { Gid = (int)Users.Grp.GID.Testers, Name = Strings.Tester };
|
||||
var testingSpecialists = new Entities.Group { Gid = (int)Users.Grp.GID.TestingSpecialists, Name = Strings.Testing_Specialist };
|
||||
var headOfLab = new Entities.Group { Gid = (int)Users.Grp.GID.HeadOfLab, Name = Strings.Head_of_Lab };
|
||||
var maintenanceSpecialists = new Entities.Group { Gid = (int)Users.Grp.GID.MaintenanceSpecialists, Name = Strings.Maintenance_Specialist };
|
||||
var metrologists = new Entities.Group { Gid = (int)Users.Grp.GID.Metrologists, Name = Strings.Metrologist };
|
||||
var calibrationSpecialists = new Entities.Group { Gid = (int)Users.Grp.GID.CalibrationSpecialists, Name = Strings.Calibration_Specialist };
|
||||
var administrators = new Entities.Group { Gid = (int)Users.Grp.GID.Administrators, Name = Strings.Administrator };
|
||||
|
||||
/// Create the user 'admin' add his groups
|
||||
var admin = new Entities.User
|
||||
@ -214,9 +214,9 @@ namespace Config
|
||||
/// <param name="dbType">DBType.SQLite or DBType.MySql</param>
|
||||
/// <param name="connectionString">Connection string</param>
|
||||
/// <returns>true=success, false=error</returns>
|
||||
public static bool CreateEmptyResultsDB(DBSettings dbSettings)
|
||||
public static bool CreateEmptyResultsDB(Users.Entities.DBType dbType, string connectionString)
|
||||
{
|
||||
ISessionFactory sessionFactory = CreateSessionFactory(Entities.DBKind.Results, dbSettings, true);
|
||||
ISessionFactory sessionFactory = CreateSessionFactory(Users.Entities.DBKind.Results, dbType, connectionString, true);
|
||||
if (sessionFactory == null) return false;
|
||||
|
||||
/// Populate the database
|
||||
|
||||
@ -30,9 +30,9 @@ namespace Results
|
||||
}
|
||||
|
||||
/// <summary> Database type (MySQL or SQLite) for all sessions </summary>
|
||||
private static Config.Entities.DBType dbType;
|
||||
private static Users.Entities.DBType dbType;
|
||||
///
|
||||
public static Config.Entities.DBType DbType
|
||||
public static Users.Entities.DBType DbType
|
||||
{
|
||||
get { return dbType; }
|
||||
set { dbType = value; SessionFactory = null; }
|
||||
@ -59,10 +59,10 @@ namespace Results
|
||||
switch (dbType)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.DBType.SQLite:
|
||||
case Users.Entities.DBType.SQLite:
|
||||
cfg = cfg.Database(SQLiteConfiguration.Standard.UsingFile(connectionString));
|
||||
break;
|
||||
case Config.Entities.DBType.MySql:
|
||||
case Users.Entities.DBType.MySql:
|
||||
cfg = cfg.Database(MySQLConfiguration.Standard.ConnectionString(connectionString));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -116,6 +116,10 @@
|
||||
<Project>{743DF7DB-C7B6-42EB-986D-0F485E5588E4}</Project>
|
||||
<Name>Config</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Users\Users.csproj">
|
||||
<Project>{6E5CB0E9-E1B6-4E5D-AC6E-B1049E180F2B}</Project>
|
||||
<Name>Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="FileWriters\" />
|
||||
|
||||
@ -19,7 +19,7 @@ namespace ResultsBrowser.Forms
|
||||
/// <summary>
|
||||
/// Required access rights to make changes with this form
|
||||
/// </summary>
|
||||
const Config.Grp.GID RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
||||
const Users.Grp.GID RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
public Config.Entities.TestsArrangement TestsArrangement;
|
||||
public Config.Entities.MetersArrangement MetersArrangement;
|
||||
public int NrMetersInOneGroup;
|
||||
|
||||
@ -238,6 +238,10 @@
|
||||
<Project>{9D0DCC88-DC81-47EB-9FDD-4C3907871BFB}</Project>
|
||||
<Name>Results</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Users\Users.csproj">
|
||||
<Project>{6E5CB0E9-E1B6-4E5D-AC6E-B1049E180F2B}</Project>
|
||||
<Name>Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@ -177,7 +177,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic
|
||||
//batch.EndTime.ToShortDateString() + " " + batch.EndTime.ToShortTimeString(),
|
||||
string.Format("{0:yyyy.MM.dd HH:mm}", batch.EndTime),
|
||||
batch.ProcedureName,
|
||||
Config.Data.CurrentUser.UserName,
|
||||
Users.GlobalData.CurrentUser.UserName,
|
||||
batch.AmbientTempAve().ToString("F1") + " °C",
|
||||
Config.Units.ConvertTo(Config.Unit.mbar, batch.AmbientPressAve()).ToString("F0") + " mbar",
|
||||
batch.AmbientHumiAve().ToString("F0") + " %",
|
||||
|
||||
@ -310,7 +310,7 @@ namespace TBF.BenchControl.Sequences
|
||||
///
|
||||
BatchRslts = Results.BatchResults.NewFromProcedure(Program.LocalSettings.BatchNr,
|
||||
(BenchInfo != null) ? BenchInfo.TestBenchId : 1,
|
||||
Config.Data.CurrentUser.UserName, Config.Data.CurrentUser.Number, Program.Version,
|
||||
Users.GlobalData.CurrentUser.UserName, Users.GlobalData.CurrentUser.Number, Program.Version,
|
||||
StateMachine.Procedure, waterMeterData, waterMeterParts);
|
||||
StateMachine.CycleStartTimeStamp = BatchRslts.Batch.StartTime;
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ namespace TBF.BenchControl
|
||||
{
|
||||
/// Load the list of components (entities) from the database.
|
||||
/// Then create the components (derived from IComponent).
|
||||
components = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config));
|
||||
components = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config));
|
||||
MasterValves = GenericDevices.ValveBase.MasterValves(components);
|
||||
CoupledValves = GenericDevices.ValveBase.CoupledValves(components);
|
||||
ExtendedValves = GenericDevices.ValveBase.ExtendedValves(components);
|
||||
@ -337,7 +337,7 @@ namespace TBF.BenchControl
|
||||
|
||||
public static void LoadProcedure(bool loadPathsOnly)
|
||||
{
|
||||
ISession session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
WtSession = session;
|
||||
|
||||
feedingPaths = session.QueryOver<Config.Entities.FeedingPath>().OrderBy(x => x.ItemNr).Asc.List();
|
||||
|
||||
@ -46,7 +46,7 @@ namespace TBF.BenchControl.TestMethods.Endurance
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
sharedButtons.OptionalButtons = TBF.UiControls.SharedButtons.Buttons.Add |
|
||||
TBF.UiControls.SharedButtons.Buttons.Remove |
|
||||
TBF.UiControls.SharedButtons.Buttons.Up |
|
||||
@ -62,7 +62,7 @@ namespace TBF.BenchControl.TestMethods.Endurance
|
||||
seqStepsCtrl = new CycleStepsCtrl();
|
||||
|
||||
/// Prepare a list of valves for the endurance test
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config));
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config));
|
||||
Valves = new List<IValve>();
|
||||
for (int bitNr = 0; bitNr < 8; bitNr++)
|
||||
{
|
||||
|
||||
@ -42,7 +42,7 @@ namespace TBF
|
||||
Flags = CfgUpdateFlags.None;
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = global::Config.Grp.GID.Metrologists;
|
||||
sharedButtons.RequiredGroupMembership = global::Users.Grp.GID.Metrologists;
|
||||
sharedButtons.MoreButtonTop = ComponentCfgCtrlHeight - 45;
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.None;
|
||||
sharedButtons.Unlocked += Unlock;
|
||||
|
||||
@ -62,7 +62,7 @@ namespace TBF
|
||||
selectComponentTypeDlg = new SelectComponentClassDlg();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add |
|
||||
SharedButtons.Buttons.Remove |
|
||||
SharedButtons.Buttons.Up |
|
||||
@ -107,7 +107,7 @@ namespace TBF
|
||||
|
||||
sharedButtons.DisableButtons(UiControls.SharedButtons.Buttons.Remove | UiControls.SharedButtons.Buttons.Edit);
|
||||
|
||||
session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
cmpntEntities = session.QueryOver<Component>()
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
.List<Component>();
|
||||
|
||||
@ -58,9 +58,9 @@ namespace TBF.Forms
|
||||
realBenchCheckBox.Checked = bench.IsRealBench;
|
||||
|
||||
/// Initialize 'Database type' combo-boxes
|
||||
for (int i = 0; i < (int)Config.Entities.DBType.DbTypesCount; i++)
|
||||
for (int i = 0; i < (int)Users.Entities.DBType.DbTypesCount; i++)
|
||||
{
|
||||
Config.Entities.DBType dbType = (Config.Entities.DBType)i;
|
||||
Users.Entities.DBType dbType = (Users.Entities.DBType)i;
|
||||
configDbTypeComboBox.Items.Add(dbType);
|
||||
resultsDbTypeComboBox.Items.Add(dbType);
|
||||
usersDbTypeComboBox.Items.Add(dbType);
|
||||
@ -95,9 +95,9 @@ namespace TBF.Forms
|
||||
bench.WaterMetersDBSettings.ConnectionString = resultsDbConnectionStringTextBox.Text;
|
||||
bench.UsersDBSettings.ConnectionString = usersDbConnectionStringTextBox.Text;
|
||||
|
||||
bench.ProceduresDBSettings.DbType = (Config.Entities.DBType)configDbTypeComboBox.SelectedIndex;
|
||||
bench.WaterMetersDBSettings.DbType = (Config.Entities.DBType)resultsDbTypeComboBox.SelectedIndex;
|
||||
bench.UsersDBSettings.DbType = (Config.Entities.DBType)usersDbTypeComboBox.SelectedIndex;
|
||||
bench.ProceduresDBSettings.DbType = (Users.Entities.DBType)configDbTypeComboBox.SelectedIndex;
|
||||
bench.WaterMetersDBSettings.DbType = (Users.Entities.DBType)resultsDbTypeComboBox.SelectedIndex;
|
||||
bench.UsersDBSettings.DbType = (Users.Entities.DBType)usersDbTypeComboBox.SelectedIndex;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -140,7 +140,7 @@ namespace TBF.Forms
|
||||
try
|
||||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
Config.FluentCommon.CreateEmptyConfigDB(bench.ProceduresDBSettings);
|
||||
Config.FluentCommon.CreateEmptyConfigDB(bench.ProceduresDBSettings.DbType, bench.ProceduresDBSettings.ConnectionString);
|
||||
MessageBox.Show(Strings.DB_was_successfully_created, Strings.Notification);
|
||||
Cursor.Current = Cursors.Default;
|
||||
DialogResult = DialogResult.None;
|
||||
|
||||
@ -29,7 +29,7 @@ namespace TBF.Forms
|
||||
public string Alias { get { return alias; } }
|
||||
public string Password { get { return password; } }
|
||||
public string BenchName { get { return benchName; } }
|
||||
public Config.Entities.LoginMethod Method;
|
||||
public Users.Entities.LoginMethod Method;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
@ -80,9 +80,9 @@ namespace TBF.Forms
|
||||
switch (Method)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.LoginMethod.UserName: return Strings.User_name;
|
||||
case Config.Entities.LoginMethod.FullName: return Strings.Full_name;
|
||||
case Config.Entities.LoginMethod.Number: return Strings.User_code;
|
||||
case Users.Entities.LoginMethod.UserName: return Strings.User_name;
|
||||
case Users.Entities.LoginMethod.FullName: return Strings.Full_name;
|
||||
case Users.Entities.LoginMethod.Number: return Strings.User_code;
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ namespace TBF.Forms
|
||||
private void aliasLabel_Click(object sender, EventArgs e)
|
||||
{
|
||||
Method++;
|
||||
if (Method == Config.Entities.LoginMethod.Count)
|
||||
if (Method == Users.Entities.LoginMethod.Count)
|
||||
Method = 0;
|
||||
aliasLabel.Text = GetAliasLabel();
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ namespace TBF.Forms
|
||||
/// <summary>
|
||||
/// Required access rights to make changes with this form
|
||||
/// </summary>
|
||||
const Config.Grp.GID RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
||||
const Users.Grp.GID RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
public TestsArrangement TestsArrangement;
|
||||
public MetersArrangement MetersArrangement;
|
||||
public int NrMetersInOneGroup;
|
||||
@ -163,14 +163,14 @@ namespace TBF.Forms
|
||||
{
|
||||
if (!unlocked)
|
||||
{
|
||||
if (!Config.Data.CurrentUser.IsMemberOf(RequiredGroupMembership))
|
||||
if (!Users.GlobalData.CurrentUser.IsMemberOf(RequiredGroupMembership))
|
||||
{
|
||||
if ((new Users.Forms.LoginDlg(RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
}
|
||||
else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking)
|
||||
{
|
||||
if ((new Users.Forms.LoginDlg(Config.Data.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
||||
if ((new Users.Forms.LoginDlg(Users.GlobalData.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ namespace TBF
|
||||
/// <summary>
|
||||
/// Login method: UserName, FullName or Number
|
||||
/// </summary>
|
||||
public Config.Entities.LoginMethod LoginMethod;
|
||||
public Users.Entities.LoginMethod LoginMethod;
|
||||
|
||||
/// <summary>
|
||||
/// Currently selected bench name (local or remote) or null (= no selection done).
|
||||
|
||||
@ -95,10 +95,10 @@ namespace TBF
|
||||
Config.Data.CurrentBench.BenchName,
|
||||
Config.Data.CurrentBench.IsRealBench ? "" : Strings._offline);
|
||||
|
||||
usersTSMenuItem.Visible = Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.Administrators) ||
|
||||
Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.HeadOfLab);
|
||||
usersTSMenuItem.Visible = Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.Administrators) ||
|
||||
Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.HeadOfLab);
|
||||
|
||||
upgradeTSMenuItem.Visible = Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.Administrators) && Config.Data.CurrentUser.UserName == "milan";
|
||||
upgradeTSMenuItem.Visible = Users.GlobalData.CurrentUser.IsMemberOf(Users.Grp.GID.Administrators) && Users.GlobalData.CurrentUser.UserName == "milan";
|
||||
|
||||
benchInitializationFailed = false;
|
||||
///
|
||||
@ -348,7 +348,7 @@ namespace TBF
|
||||
|
||||
public void UpdateUser()
|
||||
{
|
||||
userInfoStatusLabel.Text = string.Format("{0}: {1} , ", Strings.User, Config.Data.CurrentUser.UserName);
|
||||
userInfoStatusLabel.Text = string.Format("{0}: {1} , ", Strings.User, Users.GlobalData.CurrentUser.UserName);
|
||||
}
|
||||
|
||||
public void UpdateStatusP(string statusPStr)
|
||||
@ -391,7 +391,7 @@ namespace TBF
|
||||
{
|
||||
string oriProcName = procedureComboBox.Text;
|
||||
|
||||
IList<Procedure> procedures = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config)
|
||||
IList<Procedure> procedures = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.QueryOver<Procedure>()
|
||||
.Where(x => (x.ProcedureState == ProcedureState.Active))
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
@ -513,7 +513,7 @@ namespace TBF
|
||||
string purchaseOrder = dlg.PurchaseOrder;
|
||||
string tester = dlg.Tester;
|
||||
|
||||
NHibernate.ISession session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
|
||||
IList<TestResult> testResults = session.QueryOver<TestResult>()
|
||||
.Where(x => (x.PurchaseOrder == purchaseOrder))
|
||||
|
||||
@ -26,7 +26,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove;
|
||||
sharedButtons.Unlocked += unlockButton_Click;
|
||||
sharedButtons.OKClicked += okButton_Click;
|
||||
@ -51,7 +51,7 @@ namespace TBF
|
||||
int pressMetersCount = 0;
|
||||
int platinumTempMetersCount = 0;
|
||||
|
||||
session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
cmpntEntities = session.QueryOver<Component>()
|
||||
.OrderBy(x => x. ItemNr).Asc
|
||||
.List();
|
||||
|
||||
@ -48,7 +48,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
|
||||
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down;
|
||||
sharedButtons.Unlocked += Unlocked;
|
||||
@ -60,7 +60,7 @@ namespace TBF
|
||||
sharedButtons.DownClicked += downButton_Click;
|
||||
|
||||
/// Load the list of components from the database
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config));
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config));
|
||||
|
||||
/// Find all master valves
|
||||
Valves = BenchControl.GenericDevices.ValveBase.MasterValves(TbfComponents);
|
||||
@ -77,7 +77,7 @@ namespace TBF
|
||||
}
|
||||
|
||||
/// Create the database session for paths
|
||||
Session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
Session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
|
||||
pathsTabControl.TabPages[(int)PathsDlgTabs.Feeding].Tag = pathsFeedingCtrl;
|
||||
pathsTabControl.TabPages[(int)PathsDlgTabs.Bench].Tag = pathsBenchCtrl;
|
||||
|
||||
@ -59,7 +59,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Config.Grp.GID.TestingSpecialists;
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.TestingSpecialists;
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
|
||||
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down;
|
||||
sharedButtons.Unlocked += Unlocked;
|
||||
@ -96,7 +96,7 @@ namespace TBF
|
||||
LoadedProcedure = procedure;
|
||||
|
||||
/// Prepare a list of components and a list of all valves in the test bench
|
||||
using (NHibernate.ISession session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config))
|
||||
using (NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config))
|
||||
{
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(session);
|
||||
Valves = BenchControl.GenericDevices.ValveBase.MasterValves(TbfComponents);
|
||||
@ -130,7 +130,7 @@ namespace TBF
|
||||
}
|
||||
|
||||
/// Loads paths, this must be done before PrepareMetrology12AndProcessTabs() call
|
||||
using (NHibernate.ISession session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config))
|
||||
using (NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config))
|
||||
{
|
||||
feedingPaths = session.QueryOver<FeedingPath>().List();
|
||||
benchPaths = session.QueryOver<BenchPath>().List();
|
||||
@ -519,7 +519,7 @@ namespace TBF
|
||||
|
||||
void RefreshHistoryTab()
|
||||
{
|
||||
NHibernate.ISession session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
IList<Procedure> procedures = session
|
||||
.QueryOver<Procedure>()
|
||||
.Where(x => x.ProcedureState == ProcedureState.History)
|
||||
|
||||
@ -26,7 +26,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Config.Grp.GID.TestingSpecialists;
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.TestingSpecialists;
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
|
||||
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down |
|
||||
SharedButtons.Buttons.Edit | SharedButtons.Buttons.Copy;
|
||||
@ -177,7 +177,7 @@ namespace TBF
|
||||
|
||||
private void UpgradeAllTests()
|
||||
{
|
||||
NHibernate.ISession session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
NHibernate.ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
|
||||
IList<Config.Entities.Procedure> procedures = session.QueryOver<Config.Entities.Procedure>()
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
|
||||
@ -203,7 +203,7 @@ namespace TBF
|
||||
{
|
||||
log.FatalFormat("Test bench name: {0}", loginDlgBench.BenchName);
|
||||
|
||||
Config.IUser loadedUser = null;
|
||||
Users.IUser loadedUser = null;
|
||||
try
|
||||
{
|
||||
bool authorized = false;
|
||||
@ -231,21 +231,24 @@ namespace TBF
|
||||
/// Load and authorise user from the UsersDB database
|
||||
try
|
||||
{
|
||||
Users.Entities.DBType dbType = LocalSettings.TestBenches[i].UsersDBSettings.DbType;
|
||||
string connStr = LocalSettings.TestBenches[i].UsersDBSettings.ConnectionString;
|
||||
|
||||
switch (loginDlgBench.Method)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.LoginMethod.UserName:
|
||||
loadedUser = Users.Entities.User.LoadUserByName(loginDlgBench.Alias, LocalSettings.TestBenches[i].UsersDBSettings);
|
||||
case Users.Entities.LoginMethod.UserName:
|
||||
loadedUser = Users.Entities.User.LoadUserByName(loginDlgBench.Alias, dbType, connStr);
|
||||
if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.FullName:
|
||||
loadedUser = Users.Entities.User.LoadUserByFullName(loginDlgBench.Alias, LocalSettings.TestBenches[i].UsersDBSettings);
|
||||
case Users.Entities.LoginMethod.FullName:
|
||||
loadedUser = Users.Entities.User.LoadUserByFullName(loginDlgBench.Alias, dbType, connStr);
|
||||
if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.Number:
|
||||
case Users.Entities.LoginMethod.Number:
|
||||
int number;
|
||||
if (!int.TryParse(loginDlgBench.Alias, out number)) break;
|
||||
loadedUser = Users.Entities.User.LoadUserByNumber(number, LocalSettings.TestBenches[i].UsersDBSettings);
|
||||
loadedUser = Users.Entities.User.LoadUserByNumber(number, dbType, connStr);
|
||||
if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlgBench.Password);
|
||||
break;
|
||||
}
|
||||
@ -269,15 +272,15 @@ namespace TBF
|
||||
switch (loginDlgBench.Method)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.LoginMethod.UserName:
|
||||
case Users.Entities.LoginMethod.UserName:
|
||||
loadedUser = Config.Entities.User.LoadUserByName(loginDlgBench.Alias, LocalSettings.TestBenches[i].ProceduresDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.Authorize(loginDlgBench.Alias, loginDlgBench.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.FullName:
|
||||
case Users.Entities.LoginMethod.FullName:
|
||||
loadedUser = Config.Entities.User.LoadUserByFullName(loginDlgBench.Alias, LocalSettings.TestBenches[i].ProceduresDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlgBench.Alias, loginDlgBench.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.Number:
|
||||
case Users.Entities.LoginMethod.Number:
|
||||
int number;
|
||||
if (!int.TryParse(loginDlgBench.Alias, out number)) break;
|
||||
loadedUser = Config.Entities.User.LoadUserByNumber(number, LocalSettings.TestBenches[i].ProceduresDBSettings);
|
||||
@ -330,7 +333,7 @@ namespace TBF
|
||||
}
|
||||
|
||||
/// This is to trigger an exception in case of a power user and no Config database
|
||||
IList<Procedure> listOfProcedures = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config)
|
||||
IList<Procedure> listOfProcedures = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.QueryOver<Procedure>()
|
||||
.Where(x => (x.ProcedureState == ProcedureState.Active))
|
||||
.And(x => (x.Name == LocalSettings.LastProcedureName))
|
||||
@ -376,7 +379,7 @@ namespace TBF
|
||||
///
|
||||
if (LocalSettings.LastProcedureName != null)
|
||||
{
|
||||
IList<Procedure> listOfProcedures = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config)
|
||||
IList<Procedure> listOfProcedures = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.QueryOver<Procedure>()
|
||||
.Where(x => (x.ProcedureState == ProcedureState.Active))
|
||||
.And(x => (x.Name == LocalSettings.LastProcedureName))
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>1</ApplicationRevision>
|
||||
<ApplicationVersion>1.5.142.%2a</ApplicationVersion>
|
||||
<ApplicationVersion>2.12.497.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
||||
<PublishWizardCompleted>true</PublishWizardCompleted>
|
||||
|
||||
@ -59,7 +59,7 @@ namespace TBF
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = Config.Grp.GID.Metrologists;
|
||||
sharedButtons.RequiredGroupMembership = Users.Grp.GID.Metrologists;
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
|
||||
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down |
|
||||
SharedButtons.Buttons.NewTab | SharedButtons.Buttons.RenameTab |
|
||||
@ -78,7 +78,7 @@ namespace TBF
|
||||
seqStepsCtrls = new List<ITabWithListViewEx>();
|
||||
|
||||
/// Open the database
|
||||
Session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
Session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
|
||||
/// Prepare a list of components and a list of all valves in the test bench
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Session);
|
||||
|
||||
@ -129,7 +129,7 @@ namespace TBF.UiControls
|
||||
|
||||
string oriTestName = testComboBox.Text;
|
||||
|
||||
IList<Procedure> procedures = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config)
|
||||
IList<Procedure> procedures = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config)
|
||||
.QueryOver<Procedure>()
|
||||
.Where(x => (x.ProcedureState == ProcedureState.Active))
|
||||
.And(x => (x.Name == Program.MainWnd.ProcedureName))
|
||||
|
||||
@ -74,7 +74,7 @@ namespace TBF.UiControls
|
||||
void ReloadAndRedrawAll()
|
||||
{
|
||||
/// Load the procedures
|
||||
if (session == null) session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
if (session == null) session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
|
||||
MyItems = session.QueryOver<Procedure>()
|
||||
.Where(x => (x.ProcedureState == ProcedureState.Active))
|
||||
@ -159,7 +159,7 @@ namespace TBF.UiControls
|
||||
newProcedure.Revision = 1;
|
||||
newProcedure.PredecessorId = 0;
|
||||
newProcedure.ObtainedByCopy = false;
|
||||
newProcedure.CreationUser = Config.Data.CurrentUser.UserName;
|
||||
newProcedure.CreationUser = Users.GlobalData.CurrentUser.UserName;
|
||||
newProcedure.CreationTime = DateTime.Now;
|
||||
|
||||
if (new ProcedureDlg(newProcedure).ShowDialog() == DialogResult.OK)
|
||||
@ -171,7 +171,7 @@ namespace TBF.UiControls
|
||||
{
|
||||
try
|
||||
{
|
||||
newProcedure.LastChgUser = Config.Data.CurrentUser.UserName;
|
||||
newProcedure.LastChgUser = Users.GlobalData.CurrentUser.UserName;
|
||||
newProcedure.LastChgTime = DateTime.Now;
|
||||
|
||||
base.AddOne(newProcedure);
|
||||
@ -240,7 +240,7 @@ namespace TBF.UiControls
|
||||
try
|
||||
{
|
||||
originalProcedure.ProcedureState = ProcedureState.History;
|
||||
modifiedProcedure.LastChgUser = Config.Data.CurrentUser.UserName;
|
||||
modifiedProcedure.LastChgUser = Users.GlobalData.CurrentUser.UserName;
|
||||
modifiedProcedure.LastChgTime = DateTime.Now;
|
||||
|
||||
session.SaveOrUpdate(originalProcedure);
|
||||
@ -280,7 +280,7 @@ namespace TBF.UiControls
|
||||
newProcedure.Revision = 1;
|
||||
newProcedure.PredecessorId = selectedProcedure.Id;
|
||||
newProcedure.ObtainedByCopy = true;
|
||||
newProcedure.CreationUser = Config.Data.CurrentUser.UserName;
|
||||
newProcedure.CreationUser = Users.GlobalData.CurrentUser.UserName;
|
||||
newProcedure.CreationTime = DateTime.Now;
|
||||
|
||||
if ((new ProcedureDlg(newProcedure)).ShowDialog() == DialogResult.OK)
|
||||
@ -290,7 +290,7 @@ namespace TBF.UiControls
|
||||
|
||||
using (var transaction = session.BeginTransaction())
|
||||
{
|
||||
newProcedure.LastChgUser = Config.Data.CurrentUser.UserName;
|
||||
newProcedure.LastChgUser = Users.GlobalData.CurrentUser.UserName;
|
||||
newProcedure.LastChgTime = DateTime.Now;
|
||||
|
||||
base.AddOne(newProcedure);
|
||||
|
||||
@ -60,20 +60,20 @@ namespace TBF.UiControls
|
||||
Middle,
|
||||
}
|
||||
|
||||
public Config.Grp.GID RequiredGroupMembership;
|
||||
public Users.Grp.GID RequiredGroupMembership;
|
||||
|
||||
Config.IUser originalUser;
|
||||
Users.IUser originalUser;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public SharedButtons()
|
||||
{
|
||||
originalUser = Config.Data.CurrentUser;
|
||||
originalUser = Users.GlobalData.CurrentUser;
|
||||
lockState = LockState.Locked;
|
||||
MoreActive = false;
|
||||
OptionalButtons = Buttons.None;
|
||||
RequiredGroupMembership = Config.Grp.GID.None;
|
||||
RequiredGroupMembership = Users.Grp.GID.None;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ namespace TBF.UiControls
|
||||
|
||||
void RestoreUser()
|
||||
{
|
||||
Config.Data.CurrentUser = originalUser;
|
||||
Users.GlobalData.CurrentUser = originalUser;
|
||||
Program.MainWnd.UpdateUser();
|
||||
}
|
||||
|
||||
@ -230,14 +230,14 @@ namespace TBF.UiControls
|
||||
{
|
||||
if (lockState == LockState.Locked)
|
||||
{
|
||||
if (!Config.Data.CurrentUser.IsMemberOf(RequiredGroupMembership))
|
||||
if (!Users.GlobalData.CurrentUser.IsMemberOf(RequiredGroupMembership))
|
||||
{
|
||||
if ((new Users.Forms.LoginDlg(RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
}
|
||||
else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking)
|
||||
{
|
||||
if ((new Users.Forms.LoginDlg(Config.Data.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
||||
if ((new Users.Forms.LoginDlg(Users.GlobalData.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -23,12 +23,12 @@ namespace UserManagement
|
||||
/// </summary>
|
||||
public string Language = "en";
|
||||
|
||||
public string ConnectionString;
|
||||
public string ConnectionString = "SERVER=10.42.128.16; DATABASE=zamestnanci; UID=v856e04; PASSWORD=p054236478; CHARSET=utf8;";
|
||||
|
||||
/// <summary>
|
||||
/// Login method: UserName, FullName or Number
|
||||
/// </summary>
|
||||
public Config.Entities.LoginMethod LoginMethod;
|
||||
public Users.Entities.LoginMethod LoginMethod;
|
||||
|
||||
/// MainWnd
|
||||
public int MainWndLeft;
|
||||
|
||||
@ -2,29 +2,54 @@
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Users.Entities;
|
||||
using Users.Forms;
|
||||
using NHibernate;
|
||||
using FluentNHibernate;
|
||||
using log4net;
|
||||
|
||||
namespace UserManagement
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
public const string HomeDir = "C:\\UserManagement\\"; /// Contains subdirectories Results, Logs, Images, ...
|
||||
static readonly ILog log; /// log4net
|
||||
|
||||
/// Program information
|
||||
public static string Version; /// version string
|
||||
public static DateTime BuildDateTime; /// date and time of program build
|
||||
public const string HomeDir = "C:\\UserManagement\\"; /// Contains subdirectories Cfg, Logs
|
||||
|
||||
/// Local settings
|
||||
public static LocalSettings LocalSettings;
|
||||
public const string LocalSettingsFileName = "config.xml";
|
||||
public const string LocalSettingsBackupName = "config.backup.xml";
|
||||
/// Program information
|
||||
public static string Version; /// version string
|
||||
public static DateTime BuildDateTime; /// date and time of program build
|
||||
|
||||
/// Local settings
|
||||
public static readonly string ExecutableDirectory;
|
||||
public static readonly string ConfigDirectory;
|
||||
public static readonly string LogDirectory;
|
||||
public static readonly string LocalSettingsFileName;
|
||||
public static readonly string LocalSettingsBackupName;
|
||||
public static LocalSettings LocalSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes static variables above and starts logging.
|
||||
/// </summary>
|
||||
static Program()
|
||||
{
|
||||
/// Program version string
|
||||
System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
|
||||
Version ver = thisAssembly.GetName().Version;
|
||||
Version = string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Build);
|
||||
BuildDateTime = new System.IO.FileInfo(thisAssembly.Location).LastWriteTime;
|
||||
|
||||
/// Local program configuration directory including the trailing backslash
|
||||
ExecutableDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
ConfigDirectory = Path.Combine(ExecutableDirectory, "..\\Cfg\\");
|
||||
LogDirectory = Path.Combine(ExecutableDirectory, "..\\Logs\\");
|
||||
LocalSettingsFileName = ConfigDirectory + "config.xml";
|
||||
LocalSettingsBackupName = ConfigDirectory + "config.backup.xml";
|
||||
|
||||
/// Configue and start logging
|
||||
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(ConfigDirectory + "log4netConfig.xml"));
|
||||
log = LogManager.GetLogger(typeof(Program));
|
||||
log.Fatal("------------------------------------------------------------------------------------------------");
|
||||
log.Fatal("started");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -33,63 +58,61 @@ namespace UserManagement
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
/// Program version string
|
||||
System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly();
|
||||
Version ver = thisAssembly.GetName().Version;
|
||||
Version = string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Build);
|
||||
BuildDateTime = new System.IO.FileInfo(thisAssembly.Location).LastWriteTime;
|
||||
/// This belongs to Application.Run(new MainWnd()) ...
|
||||
/// and should be executed before opening 'loginDlg'
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
/// Local program configuration directory including the trailing backslash
|
||||
string locAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
|
||||
Path.DirectorySeparatorChar + "UserManagement" + Path.DirectorySeparatorChar;
|
||||
bool authorized = false;
|
||||
do
|
||||
{
|
||||
///
|
||||
/// Load the local settings
|
||||
///
|
||||
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
||||
if (Program.LocalSettings == null)
|
||||
{
|
||||
/// Loading local seetings from regular config file failed. Use the backup
|
||||
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
|
||||
if (Program.LocalSettings == null)
|
||||
{
|
||||
MessageBox.Show("Na tomto počítači nebol tento program ani raz spustený." +
|
||||
Environment.NewLine + "Použijú sa základné nastavenia.",
|
||||
"Upozornenie", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
Program.LocalSettings = new LocalSettings();
|
||||
Directory.CreateDirectory(ConfigDirectory);
|
||||
Program.LocalSettings.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
LocalSettings.Save(); /// Save the settings to overwrite the wrong file
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Loading local seetings from the regular config file was successful. Update the backup
|
||||
File.Copy(Program.LocalSettingsFileName, Program.LocalSettingsBackupName, true);
|
||||
}
|
||||
|
||||
/// Check whether local application data directory exists.
|
||||
/// If not, create it and copy the initial configuration to this directory.
|
||||
/// This is done only once after a clean program installation on the first program start-up
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(locAppDataDir))
|
||||
{
|
||||
Directory.CreateDirectory(locAppDataDir);
|
||||
Environment.CurrentDirectory = locAppDataDir;
|
||||
try
|
||||
{
|
||||
|
||||
string sampleConfig = Application.StartupPath + Path.DirectorySeparatorChar + "SampleConfig" + Path.DirectorySeparatorChar;
|
||||
if (File.Exists(sampleConfig + LocalSettingsFileName)) { File.Copy(sampleConfig + LocalSettingsFileName, LocalSettingsFileName); }
|
||||
Users.Entities.User user = Users.Entities.User.LoadUserByName("SAD", Users.Entities.DBType.MySql, Program.LocalSettings.ConnectionString);
|
||||
|
||||
File.SetAttributes(LocalSettingsFileName, FileAttributes.Normal);
|
||||
}
|
||||
else
|
||||
{
|
||||
Environment.CurrentDirectory = locAppDataDir;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//Users.DB.ConnectionString = Program.LocalSettings.ConnectionString;
|
||||
//Users.DB.LoadSharedData();
|
||||
|
||||
///
|
||||
/// Load the local settings
|
||||
///
|
||||
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
||||
if (Program.LocalSettings == null || Program.LocalSettings.ConnectionString == null)
|
||||
{
|
||||
/// Loading local seetings from regular config file failed. Use the backup
|
||||
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsBackupName);
|
||||
if (Program.LocalSettings == null || Program.LocalSettings.ConnectionString == null)
|
||||
{
|
||||
return; /// Fatal error
|
||||
}
|
||||
else
|
||||
{
|
||||
LocalSettings.Save(); /// Save the settings to overwrite the wrong file
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/// Loading local seetings from the regular config file was successful. Update the backup
|
||||
File.Copy(Program.LocalSettingsFileName, Program.LocalSettingsBackupName, true);
|
||||
}
|
||||
authorized = true; /// No LoginDlg, authorized when reading users from the DB is successfull
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
MessageBox.Show(string.Format("Cannot read a list of users from the database:{0}{1}", Environment.NewLine, exc.Message),
|
||||
"Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
|
||||
if (new DatabaseSettingsDlg().ShowDialog() == DialogResult.Cancel) return; /// 'OK' = stay in the loop, 'Cancel' = exit loop
|
||||
}
|
||||
}
|
||||
while (!authorized);
|
||||
|
||||
|
||||
try
|
||||
@ -106,180 +129,24 @@ namespace UserManagement
|
||||
}
|
||||
|
||||
|
||||
/// This belongs to Application.Run(new MainWnd()) ...
|
||||
/// and should be executed before opening 'loginDlg'
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
try
|
||||
{
|
||||
Users.Forms.UserManagementDlg dlg = new Users.Forms.UserManagementDlg();
|
||||
|
||||
int len = LocalSettings.ConnectionString.ToUpper().IndexOf("; UID=");
|
||||
dlg.Hostname = LocalSettings.ConnectionString.Substring(0, len);
|
||||
Application.Run(dlg);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
log.FatalFormat("Program havaroval:{0}{1}Stack trace:{0}{2}", Environment.NewLine, exc.Message, exc.StackTrace);
|
||||
|
||||
/// User login
|
||||
bool retryLogin = true; /// true = stay in a login loop
|
||||
do
|
||||
{
|
||||
LoginDlg loginDlg;
|
||||
if (LocalSettings.LastBenchName != null)
|
||||
{
|
||||
loginDlg = new LoginDlg();
|
||||
}
|
||||
else
|
||||
{
|
||||
loginDlg = new LoginDlg();
|
||||
}
|
||||
loginDlg.Method = LocalSettings.LoginMethod;
|
||||
DialogResult dr = loginDlg.ShowDialog();
|
||||
|
||||
if (dr == DialogResult.Cancel)
|
||||
{
|
||||
return; /// Login canceled --> Exit application
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < LocalSettings.BenchesCount; i++)
|
||||
{
|
||||
if (LocalSettings.TestBenches[i].BenchName == loginDlg.BenchName)
|
||||
{
|
||||
log.FatalFormat("Test bench name: {0}", loginDlg.BenchName);
|
||||
|
||||
Config.IUser loadedUser = null;
|
||||
try
|
||||
{
|
||||
bool authorized = false;
|
||||
|
||||
if (User.IsPowerUser(loginDlg.Alias, loginDlg.Password))
|
||||
{
|
||||
loadedUser = new User(loginDlg.Alias, 6, true);
|
||||
authorized = loadedUser.Authorize(loginDlg.Alias, loginDlg.Password);
|
||||
}
|
||||
|
||||
///
|
||||
/// Try authorisation with Users DB first
|
||||
///
|
||||
if (!authorized)
|
||||
{
|
||||
bool settingsChanged = false;
|
||||
|
||||
if (string.IsNullOrEmpty(LocalSettings.TestBenches[i].UsersDBSettings.ConnectionString))
|
||||
{
|
||||
LocalSettings.TestBenches[i].UsersDBSettings.ConnectionString = LocalSettings.TestBenches[i].ProceduresDBSettings.ConnectionString;
|
||||
LocalSettings.TestBenches[i].UsersDBSettings.DbType = LocalSettings.TestBenches[i].ProceduresDBSettings.DbType;
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
/// Load and authorise user from the UsersDB database
|
||||
try
|
||||
{
|
||||
switch (loginDlg.Method)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.LoginMethod.UserName:
|
||||
loadedUser = Users.Entities.User.LoadUserByName(loginDlg.Alias, LocalSettings.TestBenches[i].UsersDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.Authorize(loginDlg.Alias, loginDlg.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.FullName:
|
||||
loadedUser = Users.Entities.User.LoadUserByFullName(loginDlg.Alias, LocalSettings.TestBenches[i].UsersDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlg.Alias, loginDlg.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.Number:
|
||||
int number;
|
||||
if (!int.TryParse(loginDlg.Alias, out number)) break;
|
||||
loadedUser = Users.Entities.User.LoadUserByNumber(number, LocalSettings.TestBenches[i].UsersDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlg.Password);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
authorized = false;
|
||||
}
|
||||
|
||||
if (settingsChanged && authorized) LocalSettings.Save();
|
||||
}
|
||||
|
||||
///
|
||||
/// One more attempt: authorisation with Config DB
|
||||
///
|
||||
if (!authorized)
|
||||
{
|
||||
/// Load and authorise user from the Config database
|
||||
try
|
||||
{
|
||||
switch (loginDlg.Method)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.LoginMethod.UserName:
|
||||
loadedUser = Config.Entities.User.LoadUserByName(loginDlg.Alias, LocalSettings.TestBenches[i].ProceduresDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.Authorize(loginDlg.Alias, loginDlg.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.FullName:
|
||||
loadedUser = Config.Entities.User.LoadUserByFullName(loginDlg.Alias, LocalSettings.TestBenches[i].ProceduresDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.AuthorizeFullName(loginDlg.Alias, loginDlg.Password);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.Number:
|
||||
int number;
|
||||
if (!int.TryParse(loginDlg.Alias, out number)) break;
|
||||
loadedUser = Config.Entities.User.LoadUserByNumber(number, LocalSettings.TestBenches[i].ProceduresDBSettings);
|
||||
if (loadedUser != null) authorized = loadedUser.AuthorizeNumber(number, loginDlg.Password);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
authorized = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (authorized)
|
||||
{
|
||||
LocalSettings.LoginMethod = loginDlg.Method; /// Save the login method actually used
|
||||
|
||||
Users.DB.ConnectionString = Config.Data.CurrentBench.WaterMetersDBSettings.ConnectionString;
|
||||
Users.DB.LoadSharedData();
|
||||
|
||||
/// This is to trigger an exception in case of a power user and no Config database
|
||||
IList<User> listOfProcedures = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config)
|
||||
.QueryOver<User>()
|
||||
.List();
|
||||
|
||||
retryLogin = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (retryLogin)
|
||||
{
|
||||
/// Close Fluent NHibernate
|
||||
MessageBox.Show("Invalid user, password or bench", "Error", MessageBoxButtons.OK);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/// Database connect failed, ask what to do
|
||||
switch ((new DatabaseSettingsDlg().ShowDialog())
|
||||
{
|
||||
case DialogResult.Abort: return; /// Exit program
|
||||
case DialogResult.Retry: break; /// Retry the loop
|
||||
default:
|
||||
/// Open 'DatabaseSetingsDlg' and retry DB connect on OK
|
||||
if (new Users.Forms.LoginDlg(true).ShowDialog() == DialogResult.Cancel ||
|
||||
new BenchesDlg().ShowDialog() == DialogResult.Cancel)
|
||||
{
|
||||
return; /// Exit program
|
||||
}
|
||||
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
|
||||
if (Program.LocalSettings == null) return; /// Fatal error
|
||||
break; /// Retry the loop
|
||||
}
|
||||
}
|
||||
} // if benchname is OK
|
||||
} // for all benches in local settings loop
|
||||
} // not Canceled
|
||||
} //do
|
||||
while (retryLogin);
|
||||
|
||||
IList<User> listOfUsers = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config)
|
||||
.QueryOver<User>()
|
||||
.List();
|
||||
|
||||
Application.Run(new Users.Forms.UserManagementDlg());
|
||||
MessageBox.Show("Program havaroval:" +
|
||||
Environment.NewLine + Environment.NewLine + exc.Message +
|
||||
((exc.InnerException == null) ? string.Empty : (Environment.NewLine + exc.InnerException.Message)) +
|
||||
Environment.NewLine + exc.StackTrace,
|
||||
"Pozor!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("UsersManagement")]
|
||||
[assembly: AssemblyTitle("UserManagement")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("UsersManagement")]
|
||||
[assembly: AssemblyProduct("UserManagement")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@ -14,6 +14,21 @@
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>1</ApplicationRevision>
|
||||
<ApplicationVersion>2.12.497.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
@ -34,10 +49,22 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>UserManagement.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FluentNHibernate">
|
||||
<HintPath>..\packages\FluentNHibernate.2.0.3.0\lib\net40\FluentNHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Iesi.Collections">
|
||||
<HintPath>..\packages\Iesi.Collections.4.0.0.4000\lib\net40\Iesi.Collections.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\packages\log4net.2.0.2\lib\net40-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data">
|
||||
<HintPath>..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NHibernate">
|
||||
<HintPath>..\packages\NHibernate.4.0.4.4000\lib\net40\NHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
@ -96,15 +123,33 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Config\Config.csproj">
|
||||
<Project>{743DF7DB-C7B6-42EB-986D-0F485E5588E4}</Project>
|
||||
<Name>Config</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Users\Users.csproj">
|
||||
<Project>{6E5CB0E9-E1B6-4E5D-AC6E-B1049E180F2B}</Project>
|
||||
<Name>Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
13
UserManagement/UserManagement.csproj.user
Normal file
13
UserManagement/UserManagement.csproj.user
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<PublishUrlHistory>publish\</PublishUrlHistory>
|
||||
<InstallUrlHistory />
|
||||
<SupportUrlHistory />
|
||||
<UpdateUrlHistory />
|
||||
<BootstrapperUrlHistory />
|
||||
<ErrorReportUrlHistory />
|
||||
<FallbackCulture>en-US</FallbackCulture>
|
||||
<VerifyUploadedFiles>false</VerifyUploadedFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
10
Users/DB.cs
10
Users/DB.cs
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2016 Sensus Metering Systems
|
||||
/// Copyright (c) 2016-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -30,9 +30,9 @@ namespace Users
|
||||
}
|
||||
|
||||
/// <summary> Database type (MySQL or SQLite) for all sessions </summary>
|
||||
private static Config.Entities.DBType dbType;
|
||||
private static DBType dbType;
|
||||
///
|
||||
public static Config.Entities.DBType DbType
|
||||
public static DBType DbType
|
||||
{
|
||||
get { return dbType; }
|
||||
set { dbType = value; SessionFactory = null; }
|
||||
@ -59,10 +59,10 @@ namespace Users
|
||||
switch (dbType)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.DBType.SQLite:
|
||||
case DBType.SQLite:
|
||||
cfg = cfg.Database(SQLiteConfiguration.Standard.UsingFile(connectionString));
|
||||
break;
|
||||
case Config.Entities.DBType.MySql:
|
||||
case DBType.MySql:
|
||||
cfg = cfg.Database(MySQLConfiguration.Standard.ConnectionString(connectionString));
|
||||
break;
|
||||
}
|
||||
|
||||
31
Users/Entities/Enums.cs
Normal file
31
Users/Entities/Enums.cs
Normal file
@ -0,0 +1,31 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
|
||||
namespace Users.Entities
|
||||
{
|
||||
/// <summary> Identifies the type of a database </summary>
|
||||
public enum DBType
|
||||
{
|
||||
MySql, /// MySQL database
|
||||
SQLite, /// SQLite
|
||||
DbTypesCount,
|
||||
}
|
||||
|
||||
/// <summary> Identifies the database based on the content </summary>
|
||||
public enum DBKind
|
||||
{
|
||||
Config,
|
||||
Results,
|
||||
Count,
|
||||
}
|
||||
|
||||
public enum LoginMethod
|
||||
{
|
||||
UserName, /// = alias, abbreviation
|
||||
FullName, /// = description
|
||||
Number,
|
||||
Count
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using Config;
|
||||
using log4net;
|
||||
|
||||
namespace Users.Entities
|
||||
@ -120,8 +119,8 @@ namespace Users.Entities
|
||||
{
|
||||
if (Entities.User.IsPowerUser(userName, password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
GlobalData.CurrentUser = this;
|
||||
GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("Power user '{0}' authorized @level '{1}'", userName, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -130,8 +129,8 @@ namespace Users.Entities
|
||||
{
|
||||
if (IsMemberOf(requiredGroupMembership) && CheckPassword(password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
GlobalData.CurrentUser = this;
|
||||
GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("User '{0}' authorized @level '{1}'", userName, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -169,8 +168,8 @@ namespace Users.Entities
|
||||
{
|
||||
if (IsMemberOf(requiredGroupMembership) && CheckPassword(password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
GlobalData.CurrentUser = this;
|
||||
GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("User ID={0} authorized @level '{1}'", number, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -208,8 +207,8 @@ namespace Users.Entities
|
||||
{
|
||||
if (IsMemberOf(requiredGroupMembership) && CheckPassword(password))
|
||||
{
|
||||
Data.CurrentUser = this;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
GlobalData.CurrentUser = this;
|
||||
GlobalData.LastAuthorization = DateTime.Now;
|
||||
log.FatalFormat("User alias={0} authorized @level '{1}'", fullName, requiredGroupMembership);
|
||||
return true;
|
||||
}
|
||||
@ -240,7 +239,7 @@ namespace Users.Entities
|
||||
{
|
||||
User user = new User();
|
||||
user.UserName = username;
|
||||
Data.CurrentUser = user;
|
||||
GlobalData.CurrentUser = user;
|
||||
return user;
|
||||
}
|
||||
|
||||
@ -250,10 +249,10 @@ namespace Users.Entities
|
||||
/// </summary>
|
||||
/// <param name="username">User name for the query</param>
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByName(string userName, Config.DBSettings dbSettings)
|
||||
public static User LoadUserByName(string userName, DBType dbType, string connectionString)
|
||||
{
|
||||
DB.DbType = dbSettings.DbType;
|
||||
DB.ConnectionString = dbSettings.ConnectionString;
|
||||
DB.DbType = dbType;
|
||||
DB.ConnectionString = connectionString;
|
||||
IList<User> listOfUsers = DB.CreateSession()
|
||||
.CreateQuery("FROM User WHERE LOWER(UserName) = :username") /// Note: QueryOver<User>().Where(x => x.UserName.ToLower() == ... does not work
|
||||
.SetParameter("username", userName.ToLower())
|
||||
@ -284,10 +283,10 @@ namespace Users.Entities
|
||||
/// </summary>
|
||||
/// <param name="fullName">Full name for the query</param>
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByFullName(string fullName, Config.DBSettings dbSettings)
|
||||
public static User LoadUserByFullName(string fullName, DBType dbType, string connectionString)
|
||||
{
|
||||
DB.DbType = dbSettings.DbType;
|
||||
DB.ConnectionString = dbSettings.ConnectionString;
|
||||
DB.DbType = dbType;
|
||||
DB.ConnectionString = connectionString;
|
||||
IList<User> listOfUsers = DB.CreateSession()
|
||||
.CreateQuery("FROM User WHERE LOWER(Description) = :fullname") /// Note: QueryOver<User>().Where(x => x.FullName.ToLower() == ... does not work
|
||||
.SetParameter("fullname", fullName.ToLower())
|
||||
@ -317,10 +316,10 @@ namespace Users.Entities
|
||||
/// </summary>
|
||||
/// <param name="number">User ID number for the query</param>
|
||||
/// <returns>reference to a 'User' (if it exists) or null</returns>
|
||||
public static User LoadUserByNumber(int number, Config.DBSettings dbSettings)
|
||||
public static User LoadUserByNumber(int number, DBType dbType, string connectionString)
|
||||
{
|
||||
DB.DbType = dbSettings.DbType;
|
||||
DB.ConnectionString = dbSettings.ConnectionString;
|
||||
DB.DbType = dbType;
|
||||
DB.ConnectionString = connectionString;
|
||||
IList<User> listOfUsers = DB.CreateSession()
|
||||
.QueryOver<User>()
|
||||
.Where(x => (x.Number == number))
|
||||
@ -359,8 +358,8 @@ namespace Users.Entities
|
||||
/// </summary>
|
||||
public static void Unauthorize()
|
||||
{
|
||||
Data.CurrentUser = null;
|
||||
Data.LastAuthorization = DateTime.Now;
|
||||
GlobalData.CurrentUser = null;
|
||||
GlobalData.LastAuthorization = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -390,10 +389,11 @@ namespace Users.Entities
|
||||
public static bool IsPowerUser(string userName, string password)
|
||||
{
|
||||
return (userName.Equals("milan") && password.Equals("napajedla")) ||
|
||||
(userName.Equals("igor") && password.Equals("ronko4")) ||
|
||||
(userName.Equals("vlado") && password.Equals("luskovica.430")) ||
|
||||
(userName.Equals("pakan") && password.Equals("kuriatko")) ||
|
||||
(userName.Equals("gilles") && password.Equals("alibaba"));
|
||||
(userName.Equals("igor") && password.Equals("ronko4")) ||
|
||||
(userName.Equals("vlado") && password.Equals("luskovica.430")) ||
|
||||
(userName.Equals("pakan") && password.Equals("kuriatko")) ||
|
||||
(userName.Equals("evinic") && password.Equals("stivik55")) ||
|
||||
(userName.Equals("gilles") && password.Equals("alibaba"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
Users/Forms/EditSelectedUser.Designer.cs
generated
3
Users/Forms/EditSelectedUser.Designer.cs
generated
@ -137,7 +137,10 @@ namespace Users.Forms
|
||||
this.Controls.Add(this.txtDescription);
|
||||
this.Controls.Add(this.txtPassword);
|
||||
this.Controls.Add(this.txtName);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "EditSelectedUser";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.Load += new System.EventHandler(this.EditSelectedUser_Load);
|
||||
this.Shown += new System.EventHandler(this.EditSelectedUser_Shown);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using NHibernate;
|
||||
using Config.Entities;
|
||||
using Users.Entities;
|
||||
using Users.Resources;
|
||||
|
||||
namespace Users.Forms
|
||||
@ -51,11 +51,11 @@ namespace Users.Forms
|
||||
public void ShowGroups()
|
||||
{
|
||||
checkedListBoxGroups.Items.Clear();
|
||||
for (int i= 0; (int)i < Config.Grp.Count; i++)
|
||||
for (int i= 0; (int)i < Grp.Count; i++)
|
||||
{
|
||||
Group group = Config.Grp.FromId((Config.Grp.GID)i);
|
||||
Group group = Grp.FromId((Grp.GID)i);
|
||||
|
||||
bool boolIsMember = CurrentEditUser.IsMemberOf((Config.Grp.GID)group.Gid);
|
||||
bool boolIsMember = CurrentEditUser.IsMemberOf((Grp.GID)group.Gid);
|
||||
if (boolIsMember == true)
|
||||
{
|
||||
checkedListBoxGroups.Items.Add(group.Name);
|
||||
@ -103,13 +103,13 @@ namespace Users.Forms
|
||||
for (int i = 0; (int)i < checkedListBoxGroups.Items.Count ; i++)
|
||||
{
|
||||
if (checkedListBoxGroups.GetItemChecked(i)) {
|
||||
Group newGroup = Config.Grp.FromId((Config.Grp.GID)i);
|
||||
Group newGroup = Grp.FromId((Grp.GID)i);
|
||||
CurrentEditUser.Groups.Add(newGroup );
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
Config.FluentCommon.SaveToDb(Session, CurrentEditUser);
|
||||
DB.SaveObject(Session, CurrentEditUser);
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
return true;
|
||||
|
||||
@ -168,7 +168,7 @@
|
||||
<value>8</value>
|
||||
</data>
|
||||
<data name="btnOk.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>137, 270</value>
|
||||
<value>137, 330</value>
|
||||
</data>
|
||||
<data name="btnOk.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>84, 40</value>
|
||||
@ -192,7 +192,7 @@
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name="btnCancel.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>253, 270</value>
|
||||
<value>253, 330</value>
|
||||
</data>
|
||||
<data name="btnCancel.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>84, 40</value>
|
||||
@ -321,7 +321,7 @@
|
||||
<value>137, 164</value>
|
||||
</data>
|
||||
<data name="checkedListBoxGroups.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>200, 94</value>
|
||||
<value>200, 154</value>
|
||||
</data>
|
||||
<data name="checkedListBoxGroups.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>9</value>
|
||||
@ -430,7 +430,7 @@
|
||||
<value>6, 13</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>375, 319</value>
|
||||
<value>375, 383</value>
|
||||
</data>
|
||||
<data name="$this.Text" xml:space="preserve">
|
||||
<value>Edit User</value>
|
||||
|
||||
@ -21,11 +21,11 @@ namespace Users.Forms
|
||||
// Private fields
|
||||
string user;
|
||||
string password;
|
||||
Config.Grp.GID requiredGroupMembership = Config.Grp.GID.Invalid;
|
||||
Grp.GID requiredGroupMembership = Grp.GID.Invalid;
|
||||
bool noDatabase;
|
||||
|
||||
|
||||
public Config.Entities.LoginMethod Method;
|
||||
public Users.Entities.LoginMethod Method;
|
||||
public string VersionString;
|
||||
|
||||
|
||||
@ -59,7 +59,7 @@ namespace Users.Forms
|
||||
/// <summary>
|
||||
/// Constructor when a specific group membership is required.
|
||||
/// </summary>
|
||||
public LoginDlg(Config.Grp.GID requiredGroupMembership)
|
||||
public LoginDlg(Grp.GID requiredGroupMembership)
|
||||
: this()
|
||||
{
|
||||
this.requiredGroupMembership = requiredGroupMembership;
|
||||
@ -68,7 +68,7 @@ namespace Users.Forms
|
||||
/// <summary>
|
||||
/// Constructor with a predefined user when a specific group membership is required.
|
||||
/// </summary>
|
||||
public LoginDlg(string predefinedUser, Config.Grp.GID requiredGroupMembership)
|
||||
public LoginDlg(string predefinedUser, Grp.GID requiredGroupMembership)
|
||||
: this()
|
||||
{
|
||||
user = predefinedUser;
|
||||
@ -100,9 +100,9 @@ namespace Users.Forms
|
||||
switch (Method)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.LoginMethod.UserName: return Strings.User_name;
|
||||
case Config.Entities.LoginMethod.FullName: return Strings.Full_name;
|
||||
case Config.Entities.LoginMethod.Number: return Strings.User_code;
|
||||
case Entities.LoginMethod.UserName: return Strings.User_name;
|
||||
case Entities.LoginMethod.FullName: return Strings.Full_name;
|
||||
case Entities.LoginMethod.Number: return Strings.User_code;
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,26 +114,26 @@ namespace Users.Forms
|
||||
user = userNameTextBox.Text;
|
||||
password = passwordTextBox.Text;
|
||||
|
||||
bool authorized = Config.Entities.User.IsPowerUser(user, password);
|
||||
bool authorized = Entities.User.IsPowerUser(user, password);
|
||||
|
||||
if (!authorized && !noDatabase)
|
||||
{
|
||||
Config.Entities.User loadedUser = Config.Entities.User.LoadUserByName(user);
|
||||
Entities.User loadedUser = Entities.User.LoadUserByName(user);
|
||||
if (loadedUser != null)
|
||||
{
|
||||
switch (Method)
|
||||
{
|
||||
default:
|
||||
case Config.Entities.LoginMethod.UserName:
|
||||
authorized = (requiredGroupMembership == Config.Grp.GID.Invalid) ? loadedUser.Authorize(user, password) : loadedUser.Authorize(user, password, requiredGroupMembership);
|
||||
case Entities.LoginMethod.UserName:
|
||||
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.Authorize(user, password) : loadedUser.Authorize(user, password, requiredGroupMembership);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.FullName:
|
||||
authorized = (requiredGroupMembership == Config.Grp.GID.Invalid) ? loadedUser.AuthorizeFullName(user, password) : loadedUser.AuthorizeFullName(user, password, requiredGroupMembership);
|
||||
case Entities.LoginMethod.FullName:
|
||||
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.AuthorizeFullName(user, password) : loadedUser.AuthorizeFullName(user, password, requiredGroupMembership);
|
||||
break;
|
||||
case Config.Entities.LoginMethod.Number:
|
||||
case Entities.LoginMethod.Number:
|
||||
int number;
|
||||
if (!int.TryParse(user, out number)) break;
|
||||
authorized = (requiredGroupMembership == Config.Grp.GID.Invalid) ? loadedUser.AuthorizeNumber(number, password) : loadedUser.AuthorizeNumber(number, password, requiredGroupMembership);
|
||||
authorized = (requiredGroupMembership == Grp.GID.Invalid) ? loadedUser.AuthorizeNumber(number, password) : loadedUser.AuthorizeNumber(number, password, requiredGroupMembership);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -156,9 +156,9 @@ namespace Users.Forms
|
||||
/// </summary>
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (requiredGroupMembership == Config.Grp.GID.Invalid)
|
||||
if (requiredGroupMembership == Grp.GID.Invalid)
|
||||
{
|
||||
Config.Entities.User.Unauthorize();
|
||||
Entities.User.Unauthorize();
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
@ -168,7 +168,7 @@ namespace Users.Forms
|
||||
|
||||
private void aliasLabel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (++Method == Config.Entities.LoginMethod.Count) Method = 0;
|
||||
if (++Method == Entities.LoginMethod.Count) Method = 0;
|
||||
|
||||
aliasLabel.Text = GetAliasLabel();
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using NHibernate;
|
||||
using Config.Entities;
|
||||
using Users.Entities;
|
||||
using Users.Resources;
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@ namespace Users.Forms
|
||||
{
|
||||
public partial class UserManagementDlg: Form
|
||||
{
|
||||
public string Hostname;
|
||||
|
||||
NHibernate.ISession session;
|
||||
IList<User> ListOfUsers;
|
||||
int LastSelectedIndex;
|
||||
@ -24,7 +26,7 @@ namespace Users.Forms
|
||||
|
||||
private void EditUsers_Load(object sender, EventArgs e)
|
||||
{
|
||||
Text = Strings.User_Management;
|
||||
Text = string.Format(string.IsNullOrEmpty(Hostname) ? "{0}" : "{0} : {1}", Strings.User_Management, Hostname);
|
||||
btnAdd.Text = Strings.AddBtnText;
|
||||
btnEdit.Text = Strings.EditBtnText;
|
||||
btnDelete.Text = Strings.RemoveBtnText;
|
||||
@ -38,7 +40,7 @@ namespace Users.Forms
|
||||
private void EditUsers_Activated(object sender, EventArgs e)
|
||||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
session = Users.DB.CreateSession();
|
||||
ListUsers();
|
||||
RefreshButtonStates();
|
||||
}
|
||||
@ -47,16 +49,8 @@ namespace Users.Forms
|
||||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
if (Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.Administrators) || Config.Data.CurrentUser.IsMemberOf(Config.Grp.GID.HeadOfLab))
|
||||
{
|
||||
/// Admin and HeadOfLab can edit all users
|
||||
ListOfUsers = session.QueryOver<User>().List();
|
||||
}
|
||||
else
|
||||
{
|
||||
/// user can only edit their own data
|
||||
ListOfUsers = session.QueryOver<User>().Where(x => (x == Config.Data.CurrentUser)).List();
|
||||
}
|
||||
ListOfUsers = session.QueryOver<User>()
|
||||
.List();
|
||||
|
||||
listViewUsers.Items.Clear();
|
||||
foreach (var person in ListOfUsers)
|
||||
@ -124,7 +118,7 @@ namespace Users.Forms
|
||||
private void btnDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
Object Selecteduser = listViewUsers.SelectedItems[0].Tag;
|
||||
Config.FluentCommon.DeleteFromDb(session, Selecteduser);
|
||||
Users.DB.DeleteObject(session, Selecteduser);
|
||||
ListUsers();
|
||||
}
|
||||
}
|
||||
|
||||
1
Users/Forms/UserManagementDlg.designer.cs
generated
1
Users/Forms/UserManagementDlg.designer.cs
generated
@ -49,6 +49,7 @@ namespace Users.Forms
|
||||
//
|
||||
resources.ApplyResources(this.listViewUsers, "listViewUsers");
|
||||
this.listViewUsers.FullRowSelect = true;
|
||||
this.listViewUsers.GridLines = true;
|
||||
this.listViewUsers.MultiSelect = false;
|
||||
this.listViewUsers.Name = "listViewUsers";
|
||||
this.listViewUsers.UseCompatibleStateImageBehavior = false;
|
||||
|
||||
10
Users/GlobalData.cs
Normal file
10
Users/GlobalData.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Users
|
||||
{
|
||||
public class GlobalData
|
||||
{
|
||||
public static IUser CurrentUser;
|
||||
public static DateTime LastAuthorization = DateTime.Now;
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,15 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using Config.Entities;
|
||||
using Users.Entities;
|
||||
using NHibernate;
|
||||
using FluentNHibernate;
|
||||
|
||||
namespace Config
|
||||
namespace Users
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum Grp.GID specifies GID-s of user groups.
|
||||
@ -31,9 +31,7 @@ namespace Config
|
||||
Metrologists,
|
||||
CalibrationSpecialists,
|
||||
Administrators, // application / network / database administrator
|
||||
Custom1,
|
||||
Custom2,
|
||||
Custom3,
|
||||
|
||||
NrOfGroups, // Number of groups (this is not a GroupID)
|
||||
None, // Not a GroupID, can be used to indicate no group membership is required
|
||||
Invalid = -1, // Not a GroupID, indicates a variable has not been properly set so far
|
||||
@ -1,6 +1,9 @@
|
||||
using System;
|
||||
///
|
||||
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
|
||||
namespace Config
|
||||
namespace Users
|
||||
{
|
||||
public interface IUser
|
||||
{
|
||||
@ -57,7 +57,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GlobalData.cs" />
|
||||
<Compile Include="DB.cs" />
|
||||
<Compile Include="Entities\Enums.cs" />
|
||||
<Compile Include="Entities\Group.cs" />
|
||||
<Compile Include="Entities\User.cs" />
|
||||
<Compile Include="Forms\EditSelectedUser.cs">
|
||||
@ -78,6 +80,8 @@
|
||||
<Compile Include="Forms\LoginDlg.designer.cs">
|
||||
<DependentUpon>LoginDlg.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Grp.cs" />
|
||||
<Compile Include="IUser.cs" />
|
||||
<Compile Include="Mappings\GroupMap.cs" />
|
||||
<Compile Include="Mappings\UserMap.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@ -88,12 +92,6 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Config\Config.csproj">
|
||||
<Project>{743DF7DB-C7B6-42EB-986D-0F485E5588E4}</Project>
|
||||
<Name>Config</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Forms\EditSelectedUser.resx">
|
||||
<DependentUpon>EditSelectedUser.cs</DependentUpon>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user