コード例 #1
0
        public void SaveSettings(RunnerSettings settings)
        {
            Trace.Info("Saving runner settings.");
            if (File.Exists(_configFilePath))
            {
                // Delete existing runner settings file first, since the file is hidden and not able to overwrite.
                Trace.Info("Delete exist runner settings file.");
                IOUtil.DeleteFile(_configFilePath);
            }

            IOUtil.SaveObject(settings, _configFilePath);
            Trace.Info("Settings Saved.");
            File.SetAttributes(_configFilePath, File.GetAttributes(_configFilePath) | FileAttributes.Hidden);
        }
コード例 #2
0
        public RunnerSettings GetSettings()
        {
            if (_settings == null)
            {
                RunnerSettings configuredSettings = null;
                if (File.Exists(_configFilePath))
                {
                    string json = File.ReadAllText(_configFilePath, Encoding.UTF8);
                    Trace.Info($"Read setting file: {json.Length} chars");
                    configuredSettings = StringUtil.ConvertFromJson <RunnerSettings>(json);
                }

                ArgUtil.NotNull(configuredSettings, nameof(configuredSettings));
                _settings = configuredSettings;
            }

            return(_settings);
        }
コード例 #3
0
        public string GetDirectory(WellKnownDirectory directory)
        {
            string path;

            switch (directory)
            {
            case WellKnownDirectory.Bin:
                path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                break;

            case WellKnownDirectory.Diag:
                path = Path.Combine(
                    GetDirectory(WellKnownDirectory.Root),
                    Constants.Path.DiagDirectory);
                break;

            case WellKnownDirectory.Externals:
                path = Path.Combine(
                    GetDirectory(WellKnownDirectory.Root),
                    Constants.Path.ExternalsDirectory);
                break;

            case WellKnownDirectory.Root:
                path = new DirectoryInfo(GetDirectory(WellKnownDirectory.Bin)).Parent.FullName;
                break;

            case WellKnownDirectory.Temp:
                path = Path.Combine(
                    GetDirectory(WellKnownDirectory.Work),
                    Constants.Path.TempDirectory);
                break;

            case WellKnownDirectory.Actions:
                path = Path.Combine(
                    GetDirectory(WellKnownDirectory.Work),
                    Constants.Path.ActionsDirectory);
                break;

            case WellKnownDirectory.Tools:
                // TODO: Coallesce to just check RUNNER_TOOL_CACHE when images stabilize
                path = Environment.GetEnvironmentVariable("RUNNER_TOOL_CACHE") ?? Environment.GetEnvironmentVariable("RUNNER_TOOLSDIRECTORY") ?? Environment.GetEnvironmentVariable("AGENT_TOOLSDIRECTORY") ?? Environment.GetEnvironmentVariable(Constants.Variables.Agent.ToolsDirectory);

                if (string.IsNullOrEmpty(path))
                {
                    path = Path.Combine(
                        GetDirectory(WellKnownDirectory.Work),
                        Constants.Path.ToolDirectory);
                }
                break;

            case WellKnownDirectory.Update:
                path = Path.Combine(
                    GetDirectory(WellKnownDirectory.Work),
                    Constants.Path.UpdateDirectory);
                break;

            case WellKnownDirectory.Work:
                var            configurationStore = GetService <IConfigurationStore>();
                RunnerSettings settings           = configurationStore.GetSettings();
                ArgUtil.NotNull(settings, nameof(settings));
                ArgUtil.NotNullOrEmpty(settings.WorkFolder, nameof(settings.WorkFolder));
                path = Path.GetFullPath(Path.Combine(
                                            GetDirectory(WellKnownDirectory.Root),
                                            settings.WorkFolder));
                break;

            default:
                throw new NotSupportedException($"Unexpected well known directory: '{directory}'");
            }

            _trace.Info($"Well known directory '{directory}': '{path}'");
            return(path);
        }