Пример #1
0
        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);
        }
Пример #2
0
        public void Watch(string path, Func <string, Task> callback)
        {
            var baseDir = _fileRepo.PathOffset(path);

            _watcher = new FileSystemWatcher(baseDir);
            _watcher.IncludeSubdirectories = true;

            _watcher.Changed += _watcher_Changed;
            _watcher.Created += _watcher_Changed;

            _watcher.EnableRaisingEvents = true;

            _localLogService.LogInfo($"Monitoring {baseDir} for changes");

            _timer = new Timer(new TimerCallback(_monitorCallback), callback, 1000, 2000);
        }
Пример #3
0
        /// <summary>
        /// Discover the publish profile, load it and find/load the web deploy option
        /// </summary>
        /// <returns>True if discovery was successful. </returns>
        public KuduSiteSettings AutoLoadPublishProfile()
        {
            var discoveredProfile = DiscoverPublishProfile();

            if (discoveredProfile == null)
            {
                return(null);
            }

            _localLogService.LogInfo($"Profile settings: {discoveredProfile}");
            PublishData = LoadPublishProfile(discoveredProfile);

            if (PublishData == null)
            {
                return(null);
            }

            //find the web site settings and return

            var kuduSettings = GetSettingsByPublishMethod(PublishMethods.MSDeploy);

            return(kuduSettings);
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public (int, bool) Process(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                args = new[] { "-h" };
            }

            var monitor = false;
            var log     = false;
            var get     = false;
            var upload  = false;

            var path   = string.Empty;
            var folder = string.Empty;
            var key    = string.Empty;

            ArgumentSyntax.Parse(args, syntax =>
            {
                syntax.DefineOption("l|log", ref log, "Output the Kudulog stream to the console");
                syntax.DefineOption("m|monitor", ref monitor, "Monitor the path for changes and send them up");
                syntax.DefineOption("p|path", ref path, "The base path of your function (blank for current path)");
                syntax.DefineOption("g|get", ref get, "Download the Function app ready for editing locally");
                syntax.DefineOption("u|upload", ref upload, "Output the Kudulog stream to the console");
                syntax.DefineOption("f|folder", ref folder, "Sub folder to get or upload. If omitted it will get or send everything under wwwroot from Kudu");
                syntax.DefineOption("k|key", ref key, "Function key for use when calling test endpoints");
            });

            _paramService.Add("monitor", monitor.ToString());
            _paramService.Add("log", log.ToString());
            _paramService.Add("get", get.ToString());
            _paramService.Add("upload", upload.ToString());
            _paramService.Add("path", path);
            _paramService.Add("folder", folder);
            _paramService.Add("key", key);

            if (!string.IsNullOrEmpty(path))
            {
                _logService.LogInfo($"Base path: {path}");
                if (!Directory.Exists(path))
                {
                    _logService.LogError("Directory does not exist");
                    return(1, false);
                }
                Directory.SetCurrentDirectory(path);
            }

            var pubSettings = _publishSettingsService.AutoLoadPublishProfile();

            if (pubSettings == null)
            {
                _logService.LogError("Could not find publish settings file.");
                _logService.LogInfo("You can download a publish settings file from your Azure App Service settings.");
                _logService.LogInfo("Sample video: https://cloud.githubusercontent.com/assets/5225782/23344608/ac7c44d4-fcd3-11e6-90f2-0291a31f1522.gif");
                return(0, false);
            }

            if (key != string.Empty)
            {
                var result = _testService.GetFunctionData().Result;
            }

            if (get)
            {
                var filesResult = _fileService.GetFiles(folder).Result;

                if (!filesResult)
                {
                    return(1, false);
                }
            }
            else if (upload) //we probably don't want get and set!
            {
                var filesResult = _fileService.UploadFiles(folder).Result;

                if (!filesResult)
                {
                    return(1, false);
                }
            }

            if (log)
            {
                Task.Run(() =>
                {
                    _kuduLogService.StartLog();
                });
            }

            if (monitor)
            {
                Task.Run(() =>
                {
                    _fileService.Monitor();
                });
                return(0, true);
            }

            return(0, false);
        }