forked from JoseFuentesDevAp/CRMWebApiExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientConfiguration.cs
More file actions
35 lines (31 loc) · 1.1 KB
/
ClientConfiguration.cs
File metadata and controls
35 lines (31 loc) · 1.1 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
using System.Diagnostics;
using System.Xml.Serialization;
public class ClientConfiguration
{
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string TenantId { get; set; }
public string User { get; set; }
public string Password { get; set; }
public string Resource { get; set; }
public static ClientConfiguration LoadFromXml(string filePath)
{
if (!File.Exists(filePath))
{
throw new FileNotFoundException($"El archivo de configuración no existe: {filePath}");
}
try
{
XmlSerializer serializer = new XmlSerializer(typeof(ClientConfiguration));
using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
ClientConfiguration config = (ClientConfiguration)serializer.Deserialize(fileStream);
return config;
}
}
catch (Exception ex)
{
throw new Exception($"Error al cargar la configuración desde XML: {ex.Message}", ex);
}
}
}