Fixing Repositories to work on first run

This commit is contained in:
Terry MacDonald
2020-08-07 15:59:23 +12:00
parent 41c03c30b5
commit b95e7bbd39
4 changed files with 31 additions and 21 deletions

View File

@ -32,7 +32,8 @@ namespace HeliosPlus.Shared
{ {
#region Class Variables #region Class Variables
// Common items to the class // Common items to the class
private static List<ProfileItem> _allProfiles = null; private static List<ProfileItem> _allProfiles = new List<ProfileItem>();
private static bool _profilesLoaded = false;
public static Version Version = new Version(1, 0, 0); public static Version Version = new Version(1, 0, 0);
// Other constants that are useful // Other constants that are useful
public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus"); public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
@ -72,7 +73,7 @@ namespace HeliosPlus.Shared
{ {
get get
{ {
if (_allProfiles == null) if (!_profilesLoaded)
// Load the Profiles from storage if they need to be // Load the Profiles from storage if they need to be
LoadProfiles(); LoadProfiles();
return _allProfiles; return _allProfiles;
@ -102,9 +103,11 @@ namespace HeliosPlus.Shared
{ {
get get
{ {
if (_allProfiles == null) if (!_profilesLoaded)
// Load the Profiles from storage if they need to be // Load the Profiles from storage if they need to be
LoadProfiles(); LoadProfiles();
return _allProfiles.Count; return _allProfiles.Count;
} }
} }
@ -364,15 +367,17 @@ namespace HeliosPlus.Shared
ProfileBitmap = _currentProfile.ProfileIcon.ToBitmap(256, 256) ProfileBitmap = _currentProfile.ProfileIcon.ToBitmap(256, 256)
}; };
foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles) if (ProfileRepository.ProfileCount > 0)
{ {
if (activeProfile.Equals(loadedProfile)) foreach (ProfileItem loadedProfile in ProfileRepository.AllProfiles)
{ {
_currentProfile = loadedProfile; if (activeProfile.Equals(loadedProfile))
return; {
_currentProfile = loadedProfile;
return;
}
} }
} }
_currentProfile = activeProfile; _currentProfile = activeProfile;
} }
@ -468,6 +473,7 @@ namespace HeliosPlus.Shared
_currentProfile.ProfileIcon = new ProfileIcon(_currentProfile); _currentProfile.ProfileIcon = new ProfileIcon(_currentProfile);
_currentProfile.ProfileBitmap = _currentProfile.ProfileIcon.ToBitmap(256, 256); _currentProfile.ProfileBitmap = _currentProfile.ProfileIcon.ToBitmap(256, 256);
} }
_profilesLoaded = true;
return true; return true;
} }

View File

@ -68,6 +68,9 @@
<Compile Include="Shield.cs" /> <Compile Include="Shield.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="EDIDParser">
<Version>1.2.0.1</Version>
</PackageReference>
<PackageReference Include="ServerRegistrationManager"> <PackageReference Include="ServerRegistrationManager">
<Version>2.7.2</Version> <Version>2.7.2</Version>
</PackageReference> </PackageReference>

View File

@ -185,8 +185,11 @@
<PackageReference Include="CircularProgressBar"> <PackageReference Include="CircularProgressBar">
<Version>2.8.0.16</Version> <Version>2.8.0.16</Version>
</PackageReference> </PackageReference>
<PackageReference Include="EDIDParser">
<Version>1.2.0.1</Version>
</PackageReference>
<PackageReference Include="HtmlAgilityPack"> <PackageReference Include="HtmlAgilityPack">
<Version>1.11.23</Version> <Version>1.11.24</Version>
</PackageReference> </PackageReference>
<PackageReference Include="IconExtractor.dll"> <PackageReference Include="IconExtractor.dll">
<Version>1.0.2.1-beta</Version> <Version>1.0.2.1-beta</Version>
@ -204,7 +207,7 @@
<Version>3.0.0</Version> <Version>3.0.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers"> <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>3.0.0</Version> <Version>3.3.0-beta2.final</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>

View File

@ -24,7 +24,8 @@ namespace HeliosPlus
{ {
#region Class Variables #region Class Variables
// Common items to the class // Common items to the class
private static List<ShortcutItem> _allShortcuts = null; private static List<ShortcutItem> _allShortcuts = new List<ShortcutItem>();
private static bool _shortcutsLoaded = false;
// Other constants that are useful // Other constants that are useful
private static string _shortcutStorageJsonPath = Path.Combine(Program.AppDataPath, $"Shortcuts"); private static string _shortcutStorageJsonPath = Path.Combine(Program.AppDataPath, $"Shortcuts");
private static string _shortcutStorageJsonFileName = Path.Combine(_shortcutStorageJsonPath, $"Shortcuts_{Version.ToString(2)}.json"); private static string _shortcutStorageJsonFileName = Path.Combine(_shortcutStorageJsonPath, $"Shortcuts_{Version.ToString(2)}.json");
@ -45,18 +46,10 @@ namespace HeliosPlus
{ {
get get
{ {
if (_allShortcuts == null) if (!_shortcutsLoaded)
// Load the Shortcuts from storage // Load the Shortcuts from storage
LoadShortcuts(); LoadShortcuts();
/* if (LoadShortcuts() && ShortcutCount > 0)
{
// Work out the starting NextShortcutId value
long max = _allShortcuts.Max<ShortcutItem>(item => item.Id);
_lastShortcutId = Convert.ToUInt32(max);
}
else
_lastShortcutId = 0;
*/
return _allShortcuts; return _allShortcuts;
} }
} }
@ -66,6 +59,10 @@ namespace HeliosPlus
{ {
get get
{ {
if (!_shortcutsLoaded)
// Load the Shortcuts from storage
LoadShortcuts();
return _allShortcuts.Count; return _allShortcuts.Count;
} }
} }
@ -336,6 +333,7 @@ namespace HeliosPlus
} }
} }
} }
_shortcutsLoaded = true;
return true; return true;
} }