-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from 8T4/fix/load-c4-files
Fix/load c4 files
- Loading branch information
Showing
11 changed files
with
117 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using C4Sharp.Models.Plantuml; | ||
|
||
namespace C4Sharp.Extensions | ||
{ | ||
internal static class ResourceMethods | ||
{ | ||
public static Stream GetPlantumlResource() | ||
{ | ||
try | ||
{ | ||
return Assembly | ||
.GetExecutingAssembly() | ||
.GetManifestResourceStream($"C4Sharp.bin.plantuml.jar"); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new PlantumlException($"{nameof(PlantumlException)}: Could not get resource.", e); | ||
} | ||
} | ||
|
||
public static string GetResource(string name) | ||
{ | ||
try | ||
{ | ||
var assembly = Assembly.GetExecutingAssembly(); | ||
var resourceName = $"C4Sharp.bin.{name}"; | ||
|
||
using var stream = assembly.GetManifestResourceStream(resourceName); | ||
using var reader = new StreamReader(stream); | ||
return reader.ReadToEnd(); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new PlantumlException($"{nameof(PlantumlException)}: Could not get resource.", e); | ||
} | ||
} | ||
} | ||
} |
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,38 @@ | ||
using System.IO; | ||
using C4Sharp.Extensions; | ||
using C4Sharp.Models.Diagrams; | ||
|
||
namespace C4Sharp.FileSystem | ||
{ | ||
internal static class C4Directory | ||
{ | ||
public static string DirectoryName => "c4"; | ||
public static string ResourcesFolderName => "resources"; | ||
private static string ResourcesPath => Path.Join(DirectoryName, ResourcesFolderName); | ||
|
||
public static void LoadResources(Diagram diagram) | ||
{ | ||
LoadBaseResourceFile(); | ||
var path = Path.Join(ResourcesPath, $"{diagram.Name}.puml"); | ||
|
||
if (File.Exists(path)) | ||
return; | ||
|
||
var stream = ResourceMethods.GetResource($"{diagram.Name}.puml"); | ||
Directory.CreateDirectory(ResourcesPath); | ||
File.WriteAllText(path, stream); | ||
} | ||
|
||
private static void LoadBaseResourceFile() | ||
{ | ||
var path = Path.Join(ResourcesPath, $"C4.puml"); | ||
|
||
if (File.Exists(path)) | ||
return; | ||
|
||
var stream = ResourceMethods.GetResource($"C4.puml"); | ||
Directory.CreateDirectory(ResourcesPath); | ||
File.WriteAllText(path, stream); | ||
} | ||
} | ||
} |
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,17 @@ | ||
using System; | ||
|
||
namespace C4Sharp.FileSystem | ||
{ | ||
public class C4FileException: Exception | ||
{ | ||
public C4FileException(string message):base(message) | ||
{ | ||
|
||
} | ||
|
||
public C4FileException(string message, Exception innerException):base(message, innerException) | ||
{ | ||
|
||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Binary file not shown.