-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
330 additions
and
38 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using LiteDB; | ||
|
||
namespace SnackTime.Core.Database | ||
{ | ||
public class DatabaseFactory | ||
{ | ||
private const string ConnectionString = "MediaDb"; | ||
|
||
public LiteDatabase CreateDatabase() | ||
{ | ||
return new LiteDatabase(ConnectionString); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SnackTime.Core.Process | ||
{ | ||
public interface IProcessManager | ||
{ | ||
void StartProcess(string path, string[] args = null); | ||
bool IsProcessRunning(string path); | ||
void StopProcess(string path); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace SnackTime.Core.Process | ||
{ | ||
public class ProcessManager : IProcessManager | ||
{ | ||
private readonly Dictionary<string, System.Diagnostics.Process> _process; | ||
|
||
public ProcessManager() | ||
{ | ||
_process = new Dictionary<string, System.Diagnostics.Process>(); | ||
} | ||
|
||
|
||
public void StartProcess(string path, string[] args = null) | ||
{ | ||
if (IsProcessRunning(path)) return; | ||
|
||
var process = System.Diagnostics.Process.Start(path, string.Join(" ", args)); | ||
_process.Add(path, process); | ||
} | ||
|
||
public bool IsProcessRunning(string path) | ||
{ | ||
if (!_process.ContainsKey(path)) | ||
return false; | ||
|
||
if (!_process[path].HasExited) return true; | ||
|
||
_process.Remove(path); | ||
return false; | ||
} | ||
|
||
public void StopProcess(string path) | ||
{ | ||
if (IsProcessRunning(path)) | ||
_process[path].Kill(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Linq; | ||
using SnackTime.Core.Database; | ||
|
||
namespace SnackTime.Core.Settings | ||
{ | ||
public class SettingsService | ||
{ | ||
private readonly SettingsRepo _settingsRepo; | ||
|
||
public SettingsService(SettingsRepo settingsRepo) | ||
{ | ||
_settingsRepo = settingsRepo; | ||
} | ||
|
||
public void Save(Settings settings) | ||
{ | ||
_settingsRepo.Save(settings); | ||
} | ||
|
||
public Settings Get() | ||
{ | ||
return _settingsRepo.Get() ?? new Settings(); | ||
} | ||
} | ||
|
||
public class SettingsRepo | ||
{ | ||
private const string CollectionName = "settxigns"; | ||
|
||
private readonly DatabaseFactory _databaseFactory; | ||
|
||
public SettingsRepo(DatabaseFactory databaseFactory) | ||
{ | ||
_databaseFactory = databaseFactory; | ||
} | ||
|
||
public void Save(Settings settings) | ||
{ | ||
settings.Id = 1; | ||
using (var db = _databaseFactory.CreateDatabase()) | ||
{ | ||
var collection = db.GetCollection<Settings>(CollectionName); | ||
collection.Upsert(settings); | ||
} | ||
} | ||
|
||
public Settings Get() | ||
{ | ||
using (var db = _databaseFactory.CreateDatabase()) | ||
{ | ||
var collection = db.GetCollection<Settings>(CollectionName); | ||
return collection.FindAll().FirstOrDefault(); | ||
} | ||
} | ||
} | ||
|
||
|
||
public class Settings : DbEntity | ||
{ | ||
public string MpvPath { get; set; } | ||
public string SvpPath { get; set; } | ||
|
||
public string SonarrAddress { get; set; } | ||
public string RadarrAddress { get; set; } | ||
} | ||
|
||
public abstract class DbEntity | ||
{ | ||
public int Id { get; set; } | ||
} | ||
} |
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
Oops, something went wrong.