Exemple #1
0
        public static string GetEnvironmentVariableValue(this IBag container, string variablename, bool throwifnotfound)
        {
            container.Logger.StartSection("GetEnvironmentVariableValue");
            container.Logger.Log($"Variable Name: {variablename}");
            var qe = new QueryExpression(Environmentvariabledefinition.EntityName);

            qe.ColumnSet.AddColumns(Environmentvariabledefinition.PrimaryName, Environmentvariabledefinition.Defaultvalue);
            qe.Criteria.AddCondition(Environmentvariabledefinition.PrimaryName, ConditionOperator.Equal, variablename);
            var ev = qe.AddLink(Environmentvariablevalue.EntityName, Environmentvariablevalue.EnvironmentvariabledefinitionId, Environmentvariabledefinition.PrimaryKey, JoinOperator.LeftOuter);

            ev.EntityAlias = "EV";
            ev.Columns.AddColumns(Environmentvariablevalue.Value);
            var variablevalues = container.RetrieveMultiple(qe);

            if (variablevalues.Entities.Count != 1)
            {
                if (throwifnotfound)
                {
                    throw new InvalidPluginExecutionException($"Found {variablevalues.Entities.Count} environment variables.");
                }
                return(string.Empty);
            }
            string result;

            if (variablevalues[0].GetAttributeValue <AliasedValue>("EV.value") is AliasedValue value)
            {
                //
                result = value.Value.ToString();
                container.Logger.Log($"Found Environment Variable value: {result}");
            }
            else
            {
                variablevalues[0].TryGetAttributeValue <string>(Environmentvariabledefinition.Defaultvalue, out result);
                container.Logger.Log($"Found Environment Variable default: {result}");
            }
            container.Logger.EndSection();
            return(result);
        }