public async Task <IActionResult> Create() { try { MemoryStream stream = new MemoryStream(); await HttpContext.Request.Body.CopyToAsync(stream); stream.Position = 0; StreamReader reader = new StreamReader(stream); string profilejson = reader.ReadToEnd(); Profile profile = _profileJsonHelper.DeserializeObject(profilejson); var connection = _connectionFinder.GetPrimaryLITEConnection(profile); var manager = _connectionManagerFactory.GetManager(connection) as ILiteConnectionManager; await manager.RegisterLITE(profile); return(CreatedAtRoute("GetLITE", new { username = _connectionFinder.GetPrimaryLifeImageConnection(profile).username }, profile)); //return CreatedAtRoute("GetFile", new { boxUuid = paths[0], fileID = paths[0] }, paths); } catch (TaskCanceledException) { _logger.LogInformation($"Task was canceled."); return(StatusCode(503)); } catch (Exception e) { _logger.LogCritical($"{e.Message} {e.StackTrace}"); return(StatusCode(503)); } }
public Profile Load(string fileName) { _logger.Log(LogLevel.Information, $"Loading: {fileName}"); string json = File.ReadAllText(fileName); if (json == null || json == "" || !json.StartsWith("{")) { //BOUR-994 try to load the .backup json = File.ReadAllText(_util.GetTempFolder(fileName + ".backup")); if (json == null || json == "" || !json.StartsWith("{")) { throw new Exception("Local Profile is null or blank"); } else { _logger.Log(LogLevel.Critical, $"Profile was corrupt, recovered from backup!!"); } } return(_jsonHelper.DeserializeObject(json)); }
public async Task <Profile> GetAgentConfigurationFromCloud(LifeImageCloudConnection conn, string rowVersion, bool _overrideVersionAndModifiedDate) { var taskInfo = $"{conn.name}:"; string json = ""; var httpClient = _liteHttpClient.GetClient(conn); try { //set the URL string profileURL = conn.URL; if (rowVersion == null | _overrideVersionAndModifiedDate == true) { profileURL += CloudAgentConstants.AgentConfigurationUrl; } else { profileURL += $"{CloudAgentConstants.AgentConfigurationUrl}?version={rowVersion}"; } _logger.Log(LogLevel.Debug, $"{taskInfo} getProfileURL: {profileURL}"); var cookies = _liteHttpClient.GetCookies(profileURL); _logger.LogCookies(cookies, taskInfo); // issue the GET HttpResponseMessage httpResponse = await httpClient.GetAsync(profileURL); if (httpResponse.StatusCode == HttpStatusCode.NotModified) { return(null); } string response = await httpResponse.Content.ReadAsStringAsync(); _logger.Log(LogLevel.Debug, $"{taskInfo} response size: {response.Length}"); if (httpResponse.StatusCode == HttpStatusCode.OK && response != null && response.Length > 0) { // Cloud returns results in a map "configFile" -> value Dictionary <string, string> map = JsonHelper.DeserializeFromMap(response); map.TryGetValue("configFile", out string json64); // Convert back from base 64 (needed because json was getting munged) byte[] jsonBytes = Convert.FromBase64String(json64); json = System.Text.Encoding.Default.GetString(jsonBytes); _logger.Log(LogLevel.Debug, $"{taskInfo} Profile successfully downloaded from cloud."); _logger.Log(LogLevel.Debug, $"{taskInfo} Raw JSON: \n {json}"); map.TryGetValue("version", out rowVersion); } else { _logger.Log(LogLevel.Debug, $"{taskInfo} No profile update available from cloud."); } } catch (TaskCanceledException) { _logger.Log(LogLevel.Information, $"{taskInfo} Task Canceled"); } catch (HttpRequestException e) { _logger.Log(LogLevel.Warning, $"{taskInfo} Exception: {e.Message} {e.StackTrace}"); if (e.InnerException != null) { _logger.Log(LogLevel.Warning, $"Inner Exception: {e.InnerException}"); } _liteHttpClient.DumpHttpClientDetails(); } catch (Exception e) { _logger.LogFullException(e, $"{taskInfo} {e.Message}"); _liteHttpClient.DumpHttpClientDetails(); //throw e; //solves a perpetual state of unauthorized, now solved by inspection of response code in other liCloud calls } if (json == "") { return(null); } return(_jsonHelper.DeserializeObject(json)); }