Skip to content

Commit

Permalink
the solution json now contains the project unique name
Browse files Browse the repository at this point in the history
it is used if the guid does not match any exisiting project
  • Loading branch information
Irame committed Jul 29, 2024
1 parent 6501427 commit bc00191
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ namespace SmartCmdArgs.DataSerialization
{
class SolutionDataSerializer : DataSerializer
{
public static SolutionDataJson Serialize(TreeViewModel vm, Stream stream)
public static void Serialize(SolutionDataJson data, Stream stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));

var data = Serialize(vm);

string jsonStr = JsonConvert.SerializeObject(data, Formatting.Indented);

StreamWriter sw = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
sw.Write(jsonStr);
sw.Flush();

return data;
}

public static SolutionDataJson Serialize(TreeViewModel vm)
Expand Down
18 changes: 16 additions & 2 deletions SmartCmdArgs/SmartCmdArgs.Shared/Services/FileStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ public ProjectDataJson ReadDataForProject(IVsHierarchyWrapper project)
}
else
{
Guid projectGui = project.GetGuid();
string jsonFilename = FullFilenameForSolutionJsonFile();

if (File.Exists(jsonFilename))
Expand All @@ -240,7 +239,14 @@ public ProjectDataJson ReadDataForProject(IVsHierarchyWrapper project)
{
SolutionDataJson slnData = SolutionDataSerializer.Deserialize(fileStream);

Guid projectGui = project.GetGuid();
result = slnData.ProjectArguments.FirstOrDefault(p => p.Id == projectGui);

if (result == null)
{
string projectFullName = vsHelper.GetUniqueName(project);
result = slnData.ProjectArguments.FirstOrDefault(p => p.Command == projectFullName);
}
}
Logger.Info($"Read {result?.Items?.Count} commands for project '{project.GetName()}' from json-file '{jsonFilename}'.");
}
Expand Down Expand Up @@ -344,7 +350,15 @@ private void SaveJsonForSolution()
{
using (Stream fileStream = File.Open(jsonFilename, FileMode.Create, FileAccess.Write))
{
SolutionDataSerializer.Serialize(treeViewModel, fileStream);
var solutionData = SolutionDataSerializer.Serialize(treeViewModel);

foreach(var projectData in solutionData.ProjectArguments)
{
var project = vsHelper.HierarchyForProjectGuid(projectData.Id);
projectData.Command = vsHelper.GetUniqueName(project);
}

SolutionDataSerializer.Serialize(solutionData, fileStream);
}
}
catch (Exception e)
Expand Down

0 comments on commit bc00191

Please sign in to comment.