-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAwpProfileService.cs
More file actions
47 lines (41 loc) · 1.6 KB
/
Copy pathAwpProfileService.cs
File metadata and controls
47 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.IO;
using System.Web.Script.Serialization;
namespace AutisAnalytics.NavisworksAtributos
{
internal static class AwpProfileService
{
private static readonly JavaScriptSerializer Serializer = new JavaScriptSerializer();
public static string DefaultFolder
{
get
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Autis4D",
"Navisworks",
"AWP Profiles");
}
}
public static void Save(string path, AwpProjectProfile profile)
{
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("Choose a valid profile path.", nameof(path));
if (profile == null)
throw new ArgumentNullException(nameof(profile));
var folder = Path.GetDirectoryName(path);
if (!string.IsNullOrWhiteSpace(folder))
Directory.CreateDirectory(folder);
File.WriteAllText(path, Serializer.Serialize(profile));
}
public static AwpProjectProfile Load(string path)
{
if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
throw new FileNotFoundException("AWP profile not found.", path);
var result = Serializer.Deserialize<AwpProjectProfile>(File.ReadAllText(path));
if (result == null)
throw new InvalidDataException("The selected AWP profile is invalid.");
return result;
}
}
}