-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Cootz/dev
Dev merge for version update
- Loading branch information
Showing
29 changed files
with
352 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,35 @@ | ||
using System.Data; | ||
using System.Data.SqlServerCe; | ||
using Microsoft.EntityFrameworkCore; | ||
using PasswordManager.Model.DB.Schema; | ||
using PasswordManager.Model.IO; | ||
using System.Data; | ||
|
||
namespace PasswordManager.Model.DB | ||
{ | ||
public class DBController : IController | ||
{ | ||
private static readonly string DBName = PasswordController.Path + @"\PswDB.sdf"; | ||
private static readonly string Com = $"DataSource=\"{DBName}\"; Password=\"scpassw1\""; | ||
private SqlCeEngine _engine; | ||
private SqlCeConnection _connection; | ||
private SqlCeCommand _cmd; | ||
|
||
private async Task OpenCon() | ||
{ | ||
_connection = new SqlCeConnection(Com); | ||
await _connection.OpenAsync(); | ||
} | ||
|
||
private async Task<DataSet> CreateCommand(string command) | ||
{ | ||
_cmd = new SqlCeCommand(command, _connection); | ||
await _cmd.ExecuteNonQueryAsync(); | ||
SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(_cmd); | ||
DataSet dataSet = new DataSet(); | ||
dataAdapter.Fill(dataSet); | ||
return dataSet; | ||
} | ||
namespace PasswordManager.Model.DB; | ||
|
||
public async Task Initialize() | ||
{ | ||
File.Delete(DBName); | ||
|
||
if (!File.Exists(DBName)) | ||
{ | ||
try | ||
{ | ||
_engine = new SqlCeEngine(Com); | ||
_engine.CreateDatabase(); | ||
} | ||
catch { } | ||
|
||
await OpenCon(); | ||
|
||
try | ||
{ | ||
await CreateCommand("CREATE TABLE Profiles " + | ||
"(ProfileID int IDENTITY(1,1) PRIMARY KEY," + | ||
"Service nvarchar(4000) NOT NULL," + | ||
"Email nvarchar(4000) NOT NULL," + | ||
"Password nvarchar(4000) NOT NULL," + | ||
"Username nvarchar(4000));"); | ||
_engine.Upgrade(); | ||
} | ||
catch { } | ||
} | ||
else | ||
{ | ||
await OpenCon(); | ||
} | ||
public class DBController : DbContext, IController | ||
{ | ||
private static readonly string DBPath = Path.Combine(AppDirectoryManager.AppData, "Psw.db"); | ||
private static readonly string Connection = $"Filename=\"{DBPath}\""; | ||
|
||
private DbSet<Profile> Profiles { get; set; } | ||
|
||
} | ||
public async Task Initialize() | ||
{ | ||
await Database.EnsureCreatedAsync(); | ||
} | ||
|
||
public async Task Add(Profile profile) | ||
{ | ||
await CreateCommand("INSERT INTO Profiles (Service, Email, Password, Username)" + | ||
$"VALUES (\'{profile.Service}\',\'{profile.Email.Adress}\',\'{profile.Password}\',\'{profile.Username}\')"); | ||
} | ||
public async Task Add(Profile profile) | ||
{ | ||
await Profiles.AddAsync(profile); | ||
await SaveChangesAsync(); | ||
} | ||
|
||
public async Task<DataSet> Select(string condition) | ||
{ | ||
DataSet dataSet = await CreateCommand("SELECT * FROM Profiles " + | ||
"WHERE " + condition + ";"); | ||
public IEnumerable<Profile> Select(Func<Profile, bool> predicate) | ||
{ | ||
return Profiles.Where(predicate); | ||
} | ||
|
||
return dataSet; | ||
} | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
optionsBuilder.UseSqlite(Connection); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
using PasswordManager.Model.DB.Schema; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PasswordManager.Model.DB | ||
namespace PasswordManager.Model.DB; | ||
|
||
internal interface IController | ||
{ | ||
internal interface IController | ||
{ | ||
public Task Initialize(); | ||
public Task<DataSet> Select(string condition); | ||
public Task Add(Profile profile); | ||
} | ||
public Task Initialize(); | ||
public IEnumerable<Profile> Select(Func<Profile, bool> predicate); | ||
public Task Add(Profile profile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,23 @@ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Data; | ||
using System.Threading.Tasks; | ||
using PasswordManager.Model.DB.Schema; | ||
using PasswordManager.Model.DB.Schema; | ||
|
||
namespace PasswordManager.Model.DB | ||
{ | ||
public static class PasswordController | ||
{ | ||
private static IController DB = new DBController(); | ||
public static string Path = @"\Passwords"; | ||
|
||
public static async Task Initialize() | ||
{ | ||
Path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path; | ||
|
||
if (!Directory.Exists(Path)) | ||
{ | ||
Directory.CreateDirectory(Path); | ||
} | ||
namespace PasswordManager.Model.DB; | ||
|
||
await DB.Initialize(); | ||
} | ||
public static class PasswordController | ||
{ | ||
private static IController DB = new DBController(); | ||
|
||
public static async void SavePasswords(Profile[] data) | ||
{ | ||
foreach (Profile prof in data) | ||
{ | ||
await DB.Add(prof); | ||
} | ||
} | ||
public static async Task Initialize() | ||
{ | ||
await DB.Initialize(); | ||
} | ||
|
||
public static async Task<List<Profile>> SearhProfiles(string keyWord) | ||
public static async void SavePasswords(Profile[] data) | ||
{ | ||
foreach (Profile prof in data) | ||
{ | ||
List<Profile> profiles = new List<Profile>(); | ||
|
||
DataSet data = await DB.Select(keyWord); | ||
|
||
DataRowCollection dataRows = data.Tables[0].Rows; | ||
|
||
foreach (DataRow row in dataRows) | ||
{ | ||
object[] items = row.ItemArray; | ||
|
||
Profile profile = new Profile(); | ||
|
||
profile.Service = (string)items[1]; | ||
profile.Email = new EMail() { Adress = (string)items[2] }; | ||
profile.Password = (string)items[3]; | ||
profile.Username = (string)items[4]; | ||
|
||
profiles.Add(profile); | ||
} | ||
|
||
return profiles; | ||
await DB.Add(prof); | ||
} | ||
} | ||
|
||
public static List<Profile> SearhProfiles(Func<Profile, bool> predicate) => DB.Select(predicate).ToList(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace PasswordManager.Model.DB.Schema | ||
namespace PasswordManager.Model.DB.Schema; | ||
|
||
public abstract class AProfile : IEquatable<Profile> | ||
{ | ||
public abstract class AProfile : IEquatable<Profile> | ||
{ | ||
protected string username; | ||
protected string password; | ||
protected EMail eMail; | ||
protected string service; | ||
protected string username; | ||
protected string password; | ||
protected string service; | ||
|
||
public abstract bool Equals([AllowNull] Profile other); | ||
} | ||
public abstract bool Equals([AllowNull] Profile other); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
namespace PasswordManager.Model.DB.Schema; | ||
|
||
namespace PasswordManager.Model.DB.Schema | ||
public class EMail | ||
{ | ||
public class EMail | ||
{ | ||
private const char SplitChar = '@'; | ||
private char SplitChar = '@'; | ||
|
||
public int ID { get; set; } | ||
|
||
public string Adress | ||
public string Adress | ||
{ | ||
get | ||
{ | ||
get | ||
{ | ||
return _adr + SplitChar + _postfix; | ||
} | ||
set | ||
{ | ||
Parse(value); | ||
} | ||
return _adr + SplitChar + _postfix; | ||
} | ||
set | ||
{ | ||
Parse(value); | ||
} | ||
} | ||
|
||
private string _adr; | ||
private string _postfix; | ||
private string _adr; | ||
private string _postfix; | ||
|
||
public EMail() { } | ||
public EMail() { } | ||
|
||
public EMail(string adress, string postfix) | ||
{ | ||
_adr = adress; | ||
_postfix = postfix; | ||
} | ||
public EMail(string adress, string postfix) | ||
{ | ||
_adr = adress; | ||
_postfix = postfix; | ||
} | ||
|
||
private void Parse(string email) | ||
{ | ||
string[] parsed = email.Split(SplitChar); | ||
public EMail(string fullAdress) | ||
{ | ||
Adress = fullAdress; | ||
} | ||
|
||
private void Parse(string email) | ||
{ | ||
string[] parsed = email.Split(SplitChar); | ||
|
||
_adr = parsed[0]; | ||
_postfix = parsed[1]; | ||
_adr = parsed[0]; | ||
_postfix = parsed[1]; | ||
|
||
} | ||
} | ||
|
||
public static bool operator !=(EMail left, EMail right) => left.Adress != right.Adress; | ||
public static bool operator ==(EMail left, EMail right) => left.Adress == right.Adress; | ||
public static bool operator !=(EMail left, EMail right) => left.Adress != right.Adress; | ||
public static bool operator ==(EMail left, EMail right) => left.Adress == right.Adress; | ||
|
||
public override bool Equals(object obj) | ||
public override bool Equals(object obj) | ||
{ | ||
try | ||
{ | ||
return this == (EMail)obj; | ||
} | ||
catch | ||
{ | ||
try | ||
{ | ||
return this == (EMail)obj; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
public override int GetHashCode() => base.GetHashCode(); | ||
public override int GetHashCode() => base.GetHashCode(); | ||
|
||
public override string ToString() => Adress; | ||
} | ||
public override string ToString() => Adress; | ||
} |
Oops, something went wrong.