Skip to content

Commit

Permalink
overlay entry configuration with Json persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
DevTechProfile committed Dec 30, 2019
1 parent a934d76 commit db7839e
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
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
2 changes: 2 additions & 0 deletions source/CapFrameX.Contracts/Overlay/IOverlayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ public interface IOverlayService
void ResetHistory();

void AddRunToHistory(List<string> captureData);

void UpdateOverlayEntries();
}
}
8 changes: 8 additions & 0 deletions source/CapFrameX.Overlay/CapFrameX.Overlay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Prism, Version=7.0.0.396, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
Expand Down Expand Up @@ -81,6 +84,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="OverlayEntryPersistence.cs" />
<Compile Include="OverlayEntryProvider.cs" />
<Compile Include="OverlayEntryWrapper.cs" />
<Compile Include="OverlayService.cs" />
Expand Down Expand Up @@ -110,7 +114,11 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<Content Include="OverlayConfiguration\OverlayEntryConfiguration.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
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": ""
}
]
}
10 changes: 10 additions & 0 deletions source/CapFrameX.Overlay/OverlayEntryPersistence.cs
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; }
}
}
117 changes: 109 additions & 8 deletions source/CapFrameX.Overlay/OverlayEntryProvider.cs
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);
}
}
}
}
2 changes: 2 additions & 0 deletions source/CapFrameX.Overlay/OverlayEntryWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CapFrameX.Contracts.Overlay;
using Newtonsoft.Json;
using Prism.Mvvm;

namespace CapFrameX.Overlay
Expand All @@ -14,6 +15,7 @@ public class OverlayEntryWrapper : BindableBase, IOverlayEntry

public string Identifier { get; }

[JsonIgnore]
public string FormattedValue
=> _valueFormat == null ? Value.ToString()
: string.Format(_valueFormat, Value);
Expand Down
8 changes: 5 additions & 3 deletions source/CapFrameX.Overlay/OverlayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void StartCountdown(int seconds)
SetCaptureTimerValue((int)t);

if (t == 0)
OnCountdownFinished();
SetShowCaptureTimer(false);
});
}

Expand Down Expand Up @@ -170,9 +170,11 @@ public void AddRunToHistory(List<string> captureData)
_pauseRefreshHeartBeat = false;
}

private void OnCountdownFinished()
public void UpdateOverlayEntries()
{
SetShowCaptureTimer(false);
_pauseRefreshHeartBeat = true;
SetOverlayEntries(_overlayEntryProvider?.GetOverlayEntries());
_pauseRefreshHeartBeat = false;
}

private void SetShowCaptureTimer(bool show)
Expand Down
1 change: 1 addition & 0 deletions source/CapFrameX.Overlay/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net472" />
<package id="Prism.Core" version="7.0.0.396" targetFramework="net472" />
<package id="System.Reactive" version="4.0.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net472" />
Expand Down
15 changes: 15 additions & 0 deletions source/CapFrameX.Test/CapFrameX.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Data\FileRecordInfoTest.cs" />
<Compile Include="Extensions\ObservableExtensionsTest.cs" />
<Compile Include="Extensions\StringExtensionsTest.cs" />
<Compile Include="Overlay\OverlayEntryPersistenceTest.cs" />
<Compile Include="PresentMonInterface\SystemInfoTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestHelper.cs" />
Expand Down Expand Up @@ -101,6 +102,10 @@
<Project>{a4559b99-7fcb-40ef-bf97-d293a2b7d6d3}</Project>
<Name>CapFrameX.Extensions</Name>
</ProjectReference>
<ProjectReference Include="..\CapFrameX.Overlay\CapFrameX.Overlay.csproj">
<Project>{624777C2-6AF6-46D5-A019-1285F699B8A7}</Project>
<Name>CapFrameX.Overlay</Name>
</ProjectReference>
<ProjectReference Include="..\CapFrameX.PresentMonInterface\CapFrameX.PresentMonInterface.csproj">
<Project>{adfbaece-b74f-4a80-87d1-84bc990527b0}</Project>
<Name>CapFrameX.PresentMonInterface</Name>
Expand All @@ -125,11 +130,21 @@
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.2.0.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Prism, Version=7.0.0.396, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59, processorArchitecture=MSIL">
<HintPath>..\..\packages\Prism.Core.7.0.0.396\lib\net45\Prism.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Reactive, Version=4.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reactive.4.0.0\lib\net46\System.Reactive.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
Expand Down
Loading

0 comments on commit db7839e

Please sign in to comment.