-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overlay entry configuration with Json persistence
- Loading branch information
DevTechProfile
committed
Dec 30, 2019
1 parent
a934d76
commit db7839e
Showing
12 changed files
with
280 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
|
||
# CA1031: Do not catch general exception types | ||
dotnet_diagnostic.CA1031.severity = none |
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
44 changes: 44 additions & 0 deletions
44
source/CapFrameX.Overlay/OverlayConfiguration/OverlayEntryConfiguration.json
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,44 @@ | ||
{ | ||
"OverlayEntries": [ | ||
{ | ||
"Identifier": "CaptureServiceStatus", | ||
"ShowOnOverlay": true, | ||
"GroupName": "", | ||
"Value": "Capture service ready...", | ||
"ShowGraph": false, | ||
"Color": "" | ||
}, | ||
{ | ||
"Identifier": "RunHistory", | ||
"ShowOnOverlay": true, | ||
"GroupName": "", | ||
"Value": null, | ||
"ShowGraph": false, | ||
"Color": "" | ||
}, | ||
{ | ||
"Identifier": "CaptureTimer", | ||
"ShowOnOverlay": true, | ||
"GroupName": "Timer: ", | ||
"Value": "0", | ||
"ShowGraph": false, | ||
"Color": "" | ||
}, | ||
{ | ||
"Identifier": "Framerate", | ||
"ShowOnOverlay": true, | ||
"GroupName": "<APP>", | ||
"Value": 0.0, | ||
"ShowGraph": false, | ||
"Color": "" | ||
}, | ||
{ | ||
"Identifier": "Frametime", | ||
"ShowOnOverlay": true, | ||
"GroupName": "<APP>", | ||
"Value": 0.0, | ||
"ShowGraph": true, | ||
"Color": "" | ||
} | ||
] | ||
} |
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,10 @@ | ||
using CapFrameX.Contracts.Overlay; | ||
using System.Collections.Generic; | ||
|
||
namespace CapFrameX.Overlay | ||
{ | ||
public class OverlayEntryPersistence | ||
{ | ||
public List<IOverlayEntry> OverlayEntries { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,133 @@ | ||
using CapFrameX.Contracts.Overlay; | ||
using System; | ||
using CapFrameX.Extensions; | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.IO; | ||
|
||
namespace CapFrameX.Overlay | ||
{ | ||
public class OverlayEntryProvider : IOverlayEntryProvider | ||
{ | ||
private readonly Dictionary<string, IOverlayEntry> _identifierOverlayEntryDict | ||
= new Dictionary<string, IOverlayEntry>(); | ||
private List<IOverlayEntry> _overlayEntries; | ||
|
||
public OverlayEntryProvider() | ||
{ | ||
|
||
try | ||
{ | ||
LoadOverlayEntriesFromJson(); | ||
} | ||
catch | ||
{ | ||
SetOverlayEntryDefaults(); | ||
} | ||
} | ||
|
||
public IOverlayEntry[] GetOverlayEntries() | ||
{ | ||
throw new NotImplementedException(); | ||
return _overlayEntries.ToArray(); | ||
} | ||
|
||
public IOverlayEntry GetOverlayEntry(string identifier) | ||
{ | ||
throw new NotImplementedException(); | ||
return _identifierOverlayEntryDict[identifier]; | ||
} | ||
|
||
public void MoveEntry(int sourceIndex, int targetIndex) | ||
{ | ||
throw new NotImplementedException(); | ||
_overlayEntries.Move(sourceIndex, targetIndex); | ||
} | ||
|
||
public bool SaveOverlayEntriesToJson() | ||
{ | ||
try | ||
{ | ||
var persistence = new OverlayEntryPersistence() | ||
{ | ||
OverlayEntries = _overlayEntries | ||
}; | ||
|
||
var json = JsonConvert.SerializeObject(persistence); | ||
File.WriteAllText(@"OverlayConfiguration\OverlayEntryConfiguration.json", json); | ||
|
||
return true; | ||
} | ||
catch { return false; } | ||
} | ||
|
||
private void LoadOverlayEntriesFromJson() | ||
{ | ||
string json = File.ReadAllText(@"OverlayConfiguration\OverlayEntryConfiguration.json"); | ||
_overlayEntries = new List<IOverlayEntry>(JsonConvert.DeserializeObject<OverlayEntryPersistence>(json).OverlayEntries); | ||
|
||
foreach (var entry in _overlayEntries) | ||
{ | ||
_identifierOverlayEntryDict.Add(entry.Identifier, entry); | ||
} | ||
} | ||
|
||
private void SetOverlayEntryDefaults() | ||
{ | ||
_overlayEntries = new List<IOverlayEntry> | ||
{ | ||
// CX | ||
// CaptureServiceStatus | ||
new OverlayEntryWrapper("CaptureServiceStatus") | ||
{ | ||
ShowOnOverlay = true, | ||
GroupName = string.Empty, | ||
Value = "Capture service ready...", | ||
ShowGraph = false, | ||
Color = string.Empty | ||
}, | ||
|
||
// RunHistory | ||
new OverlayEntryWrapper("RunHistory") | ||
{ | ||
ShowOnOverlay = true, | ||
GroupName = string.Empty, | ||
Value = default(object), | ||
ShowGraph = false, | ||
Color = string.Empty | ||
}, | ||
|
||
// RunHistory | ||
new OverlayEntryWrapper("CaptureTimer") | ||
{ | ||
ShowOnOverlay = true, | ||
GroupName = "Timer: ", | ||
Value = "0", | ||
ShowGraph = false, | ||
Color = string.Empty | ||
}, | ||
|
||
// RTSS | ||
// Framerate | ||
new OverlayEntryWrapper("Framerate") | ||
{ | ||
ShowOnOverlay = true, | ||
GroupName = "<APP>", | ||
Value = 0d, | ||
ShowGraph = false, | ||
Color = string.Empty | ||
}, | ||
|
||
// Frametime | ||
new OverlayEntryWrapper("Frametime") | ||
{ | ||
ShowOnOverlay = true, | ||
GroupName = "<APP>", | ||
Value = 0d, | ||
ShowGraph = true, | ||
Color = string.Empty | ||
} | ||
}; | ||
|
||
foreach (var entry in _overlayEntries) | ||
{ | ||
_identifierOverlayEntryDict.Add(entry.Identifier, entry); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.