예제 #1
0
        public static string FindTopFileInProjectDir(this BaseTask baseTask, string fileToFind)
        {
            string filePath = String.Empty;

            try
            {
                baseTask.LogVerbose($"Searching for config file {fileToFind}");
                var currentDirectoryInfo = new DirectoryInfo(baseTask.ProjectDir);
                if (currentDirectoryInfo == null)
                {
                    baseTask.Log.LogError($"Directory {baseTask.ProjectDir} is null");
                }
                do
                {
                    var fileExistenceToTest = Path.Combine(currentDirectoryInfo.FullName, fileToFind);
                    //baseTask.LogVerbose($"Testing for file {fileExistenceToTest}");
                    if (File.Exists(fileExistenceToTest))
                    {
                        //baseTask.LogVerbose($"File exists at {fileExistenceToTest}");
                        filePath = fileExistenceToTest;
                    }
                    if (currentDirectoryInfo.Parent == null)
                    {
                        break;
                    }
                    currentDirectoryInfo = currentDirectoryInfo.Parent;
                } while (currentDirectoryInfo != null);

                if (!String.IsNullOrEmpty(filePath))
                {
                    baseTask.LogInformation($"Selecting {fileToFind} from {filePath}");
                }
                else
                {
                    baseTask.LogDebug($"Did not find file {fileToFind} in path {baseTask.ProjectDir}");
                }
            } catch (Exception e) {
                baseTask.Log.LogError($"Exception reading files {e.Message}");
            }
            return(filePath);
        }
예제 #2
0
        /// <summary>
        /// Gets the tap config now stored in same json file as BuildConfigurations
        /// </summary>
        /// <returns>The tap config.</returns>
        /// <param name="baseTask">Base task.</param>
        public static ITaskItem GetTapSettings(this BaseTask baseTask)
        {
            try
            {
                var tapSettingsPath = baseTask.FindTopFileInProjectDir(Consts.TapSettingFile);

                if (String.IsNullOrEmpty(tapSettingsPath))
                {
                    var tapSettingTaskItem = new TaskItem(MetadataType.TapConfig);

                    tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, Consts.TapEndpoint);
                    tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, Consts.MediaEndpoint);
                    tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, LogLevelConsts.Information);

                    //baseTask.Log.LogMessage($"Tap log level set to {tapConfigTaskItem.GetMetadata(MetadataType.TapLogLevel)}");
                    return(tapSettingTaskItem);
                }
                else
                {
                    var json       = File.ReadAllText(tapSettingsPath);
                    var tapSetting = JsonConvert.DeserializeObject <TapSettingJson>(json);

                    var tapSettingTaskItem = new TaskItem(MetadataType.TapConfig);

                    if (!String.IsNullOrEmpty(tapSetting.LogLevel))
                    {
                        tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, tapSetting.LogLevel);
                    }
                    else
                    {
                        tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, LogLevelConsts.Information);
                    }

                    if (!String.IsNullOrEmpty(tapSetting.TapEndpoint))
                    {
                        tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, tapSetting.TapEndpoint);
                    }
                    else
                    {
                        tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, Consts.TapEndpoint);
                    }
                    if (!String.IsNullOrEmpty(tapSetting.MediaEndpoint))
                    {
                        tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, tapSetting.MediaEndpoint);
                    }
                    else
                    {
                        tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, Consts.MediaEndpoint);
                    }
                    baseTask.LogInformation($"Tap log level set to {tapSettingTaskItem.GetMetadata(MetadataType.TapLogLevel)}");
                    return(tapSettingTaskItem);
                }
            }
            catch
            {
                var tapSettingTaskItem = new TaskItem(MetadataType.TapConfig);

                tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, Consts.TapClientEndpoint);
                tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, Consts.MediaEndpoint);
                tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, LogLevelConsts.Information);
                baseTask.Log.LogWarning($"Error trying to read {Consts.TapSettingFile}, returning defaults");
                baseTask.LogInformation($"Tap log level set to {tapSettingTaskItem.GetMetadata(MetadataType.TapLogLevel)}");
                return(tapSettingTaskItem);
            }
        }