CloudIDSage50.cs
1 using Newtonsoft.Json;
2 using sage.ew.global;
3 using System;
4 using System.Collections.Generic;
5 using System.Diagnostics;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 
10 namespace sage.ew.functions.Clases
11 {
15  public static class CloudIDSage50
16  {
17  private static Sage.ES.S50.CloudId.AuthorizeSage50.LoginResultSage50 _loginData = null;
18 
19  private static string _lastError = "";
20 
21  #region Public methods
22 
27  public async static Task<bool> LoginCloudId(string prefilledEmail = "", string given_name = "", string family_name = "")
28  {
29  if (!FUNCTIONS.InternetOk())
30  {
31  _lastError = "Imposible conectar con los servidores de CloudId. Compruebe su conexión a Internet.";
32  return false;
33  }
34 
36  if (UseProductionServer())
37  sageIDEnvironment = Sage.ES.S50.CloudId.Auth0Sage50ClientOptions.SageIDEnvironment.Production;
38 
39  //_loginData = Sage.ES.S50.CloudId.AuthorizeSage50.Instance.LoginS50Async(prefilledEmail, given_name, family_name, sageIDEnvironment).Result;
40  _loginData = await Sage.ES.S50.CloudId.AuthorizeSage50.Instance.LoginS50Async(prefilledEmail, given_name, family_name, sageIDEnvironment);
41 
42  if (_loginData != null)
43  {
44  if (_loginData.Success)
45  _lastError = "";
46  else
47  _lastError = _loginData.AccessToken;
48 
49  return _loginData.Success;
50  }
51  else
52  {
53  _lastError = "Error indeterminado al intentar ejecutar el Login a CloudID. Revise los log de la aplicación";
54  return false;
55  }
56  }
57 
62  public async static Task<bool> RegisterCloudId(string prefilledEmail = "", string given_name = "", string family_name = "")
63  {
64  if (!FUNCTIONS.InternetOk())
65  {
66  _lastError = "Imposible conectar con los servidores de CloudId. Compruebe su conexión a Internet.";
67  return false;
68  }
69 
71  if (UseProductionServer())
72  sageIDEnvironment = Sage.ES.S50.CloudId.Auth0Sage50ClientOptions.SageIDEnvironment.Production;
73 
74  //_loginData = Sage.ES.S50.CloudId.AuthorizeSage50.Instance.RegisterS50Async(prefilledEmail, given_name, family_name, sageIDEnvironment).Result;
75  _loginData = await Sage.ES.S50.CloudId.AuthorizeSage50.Instance.RegisterS50Async(prefilledEmail, given_name, family_name, sageIDEnvironment);
76 
77  if (_loginData != null)
78  {
79  if (_loginData.Success)
80  _lastError = "";
81  else
82  _lastError = _loginData.AccessToken;
83 
84  return _loginData.Success;
85  }
86  else
87  {
88  _lastError = "Error indeterminado al intentar ejecutar el Login a CloudID. Revise los log de la aplicación";
89  return false;
90  }
91  }
92 
97  public async static Task<bool> LogoutCloudId()
98  {
99  if (!FUNCTIONS.InternetOk())
100  {
101  _lastError = "Imposible conectar con los servidores de CloudId. Compruebe su conexión a Internet.";
102  return false;
103  }
104 
105  //bool res = Sage.ES.S50.CloudId.AuthorizeSage50.Instance.LogoutS50Async().Result;
107 
108  if (res)
109  _lastError = "";
110  else
111  _lastError = "No fue posible cerrar sesión de CloudId";
112 
113  return res;
114  }
115 
120  public static string GetAccessToken()
121  {
122  return _loginData?.AccessToken;
123  }
124 
129  public static string GetRefreshToken()
130  {
131  return _loginData?.RefreshToken;
132  }
133 
138  public static DateTimeOffset? GetExpirationDate()
139  {
140  return _loginData?.ExpirationDate;
141  }
142 
147  public static string GetCustomerID()
148  {
149  return _loginData?.CustomerID;
150  }
151 
156  public static string GetEmail()
157  {
158  return _loginData?.Email;
159  }
160 
165  public static string GetIdentityToken()
166  {
167  return _loginData?.IdentityToken;
168  }
169 
174  public static string GetGivenName()
175  {
176  return _loginData?.GivenName;
177  }
178 
183  public static string GetFamilyName()
184  {
185  return _loginData?.FamilyName;
186  }
187 
192  public static string GetLastError()
193  {
194  return _lastError;
195  }
196  #endregion Public methods
197 
198  #region Private methods
199  private static bool UseProductionServer()
200  {
201 #if DEBUG
202  return false;
203 #endif
204  string pathInicio = Convert.ToString(EW_GLOBAL._GetVariable("wc_pathinicio"));
205 
206  bool defaultValue = true;//198763
207 
208  if (!string.IsNullOrWhiteSpace(pathInicio))
209  {
210  string lEntornoCloudID = FUNCTIONS.LeerConfigIni("[CLOUDID_SHADOW]", pathInicio, "config.ini");
211 
212  if (string.IsNullOrWhiteSpace(lEntornoCloudID))
213  return defaultValue;
214  else if (lEntornoCloudID.ToUpper() == "NO")
215  return true;
216  else if (lEntornoCloudID.ToUpper() == "SI")
217  return false;
218  else
219  return defaultValue;
220  }
221  else
222  {
223  return defaultValue;
224  }
225  }
226  #endregion Private methods
227  }
228 }
async Task< LoginResultSage50 > RegisterS50Async(string predefinedEmail, string predefinedGivenName, string predefinedFamilyName, Auth0Sage50ClientOptions.SageIDEnvironment _sageIDEnvironment)
Basic Asynchronous Registration
async Task< bool > LogoutS50Async()
Basic Asynchronous LogOut
static new AuthorizeSage50 Instance
async Task< LoginResultSage50 > LoginS50Async(string predefinedEmail, string predefinedGivenName, string predefinedFamilyName, Auth0Sage50ClientOptions.SageIDEnvironment _sageIDEnvironment)
Basic Asynchronous Login