public async Task <bool> GetFunctionData() { _settings = await _functionSettings.GetFunctionSettings(); _localLogService.Log("Refreshing functions"); if (_settings == null) { _localLogService.LogError("Could not get function settings! Check the function key passed in with the 'k' parameter."); return(false); } _localLogService.LogInfo(" Functions in this site \r\n press (number) to run test data on live Azure Function. Press (r) to refresh function data from server."); var count = 1; foreach (var s in _settings) { var binding = s.config.bindings .FirstOrDefault(_ => _.direction == KsConstants.Functions.In && _.type.EndsWith(KsConstants.Functions.Trigger, StringComparison.Ordinal)); _localLogService.LogInfo($" ({count}) {s.name} [{binding?.type}]"); count++; } return(true); }
public async Task SendFile(string fullPath) { if (!File.Exists(fullPath)) { return; } byte[] data = null; try { data = File.ReadAllBytes(fullPath); } catch (Exception ex) { _localLogService.Log($"Error. Could not read {fullPath}. Probably locked or something like that. {ex.ToString()}"); return; } var baseDir = Directory.GetCurrentDirectory(); var offsetPath = fullPath.Replace(baseDir, ""); _siteSettings = _publishSettingsService.GetSettingsByPublishMethod(PublishMethods.MSDeploy); var offsetForUrl = offsetPath.Replace('\\', '/'); using (HttpClient httpClient = new HttpClient()) { httpClient.Timeout = TimeSpan.FromMilliseconds(10000); var requestUri = $"https://{_siteSettings.ApiUrl}/api/vfs/site/wwwroot{offsetForUrl}"; var request = new HttpRequestMessage(HttpMethod.Put, requestUri); request.Headers.Authorization = new AuthenticationHeaderValue("Basic", HttpHelpers.GetAuthenticationString(_siteSettings)); var content = new ByteArrayContent(data); request.Content = content; request.Headers.Add("If-Match", "*"); var result = await httpClient.SendAsync(request); if (result.IsSuccessStatusCode) { _localLogService.Log($"Sent {requestUri}"); } else { _localLogService.Log($"Failed {requestUri}, {result.ToString()}"); } } }
public (int, bool) Init(string[] args) { //check for publish settings file. _logService.Log(""); _logService.Log("Welcome to k-scratch. v0.1.5"); _logService.Log("Documentation and code @ https://github.com/jakkaj/k-scratch"); //just a couple of lines to space things out _logService.Log(""); var processor = _commandProcessorService.Process(args); return(processor); }
public async Task <bool> StartLog() { _localLogService.LogInfo("Starting logstream"); _siteSettings = _publishSettingsService.GetSettingsByPublishMethod(PublishMethods.MSDeploy); StopLog(); using (HttpClient httpClient = new HttpClient()) { httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); var requestUri = $"https://{_siteSettings.ApiUrl}/logstream/application"; var request = new HttpRequestMessage(HttpMethod.Get, requestUri); request.Headers.Authorization = new AuthenticationHeaderValue("Basic", HttpHelpers.GetAuthenticationString(_siteSettings)); var response = await httpClient.SendAsync( request, HttpCompletionOption.ResponseHeadersRead); if (!response.IsSuccessStatusCode) { return(false); } _currentStream = await response.Content.ReadAsStreamAsync(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { using (var reader = new StreamReader(_currentStream)) { var previous = new List <string>(); while (!reader.EndOfStream && _currentStream != null) { //We are ready to read the stream try { var currentLine = await reader.ReadLineAsync(); //it doubles up for some reason :/ if (previous.Contains(currentLine)) { continue; } previous.Add(currentLine); _localLogService.Log($" > {currentLine}"); } catch (Exception ex) { return; } } } StopLog(); StartLog(); }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(true); } }