本文整理汇总了C#中VariableDictionary.Get方法的典型用法代码示例。如果您正苦于以下问题:C# VariableDictionary.Get方法的具体用法?C# VariableDictionary.Get怎么用?C# VariableDictionary.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableDictionary
的用法示例。
在下文中一共展示了VariableDictionary.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateConfigurationSettings
static void UpdateConfigurationSettings(XContainer configurationFile, VariableDictionary variables)
{
Log.Verbose("Updating configuration settings...");
var foundSettings = false;
WithConfigurationSettings(configurationFile, (roleName, settingName, settingValueAttribute) =>
{
var setting = variables.Get(roleName + "/" + settingName) ??
variables.Get(roleName + "\\" + settingName) ??
variables.Get(settingName) ??
(variables.GetNames().Contains(settingName) ? "" : null);
if (setting != null)
{
foundSettings = true;
Log.Info("Updating setting for role {0}: {1} = {2}", roleName, settingName, setting);
settingValueAttribute.Value = setting;
}
});
if (!foundSettings)
{
Log.Info("No settings that match provided variables were found.");
}
}
示例2: UpdateConfigurationWithCurrentInstanceCount
void UpdateConfigurationWithCurrentInstanceCount(XContainer localConfigurationFile, string configurationFileName, VariableDictionary variables)
{
if (!variables.GetFlag(SpecialVariables.Action.Azure.UseCurrentInstanceCount))
return;
var serviceName = variables.Get(SpecialVariables.Action.Azure.CloudServiceName);
var slot = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), variables.Get(SpecialVariables.Action.Azure.Slot));
var remoteConfigurationFile = configurationRetriever.GetConfiguration(
credentialsFactory.GetCredentials(variables.Get(SpecialVariables.Action.Azure.SubscriptionId),
variables.Get(SpecialVariables.Action.Azure.CertificateThumbprint),
variables.Get(SpecialVariables.Action.Azure.CertificateBytes)),
serviceName,
slot);
if (remoteConfigurationFile == null)
{
Log.Info("There is no current deployment of service '{0}' in slot '{1}', so existing instance counts will not be imported.", serviceName, slot);
return;
}
var rolesByCount = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Log.Verbose("Local instance counts (from " + Path.GetFileName(configurationFileName) + "): ");
WithInstanceCounts(localConfigurationFile, (roleName, attribute) =>
{
Log.Verbose(" - " + roleName + " = " + attribute.Value);
string value;
if (rolesByCount.TryGetValue(roleName, out value))
{
attribute.SetValue(value);
}
});
Log.Verbose("Remote instance counts: ");
WithInstanceCounts(remoteConfigurationFile, (roleName, attribute) =>
{
rolesByCount[roleName] = attribute.Value;
Log.Verbose(" - " + roleName + " = " + attribute.Value);
});
Log.Verbose("Replacing local instance count settings with remote settings: ");
WithInstanceCounts(localConfigurationFile, (roleName, attribute) =>
{
string value;
if (!rolesByCount.TryGetValue(roleName, out value))
return;
attribute.SetValue(value);
Log.Verbose(" - " + roleName + " = " + attribute.Value);
});
}
示例3: CreateAzureCertificate
private string CreateAzureCertificate(string workingDirectory, VariableDictionary variables)
{
var certificateFilePath = Path.Combine(workingDirectory, CertificateFileName);
var certificatePassword = GenerateCertificatePassword();
var azureCertificate = certificateStore.GetOrAdd(
variables.Get(SpecialVariables.Action.Azure.CertificateThumbprint),
variables.Get(SpecialVariables.Action.Azure.CertificateBytes),
StoreName.My);
variables.Set("OctopusAzureCertificateFileName", certificateFilePath);
variables.Set("OctopusAzureCertificatePassword", certificatePassword);
fileSystem.WriteAllBytes(certificateFilePath, azureCertificate.Export(X509ContentType.Pfx, certificatePassword));
return certificateFilePath;
}
示例4: ReplaceAppSettingOrConnectionString
static IEnumerable<string> ReplaceAppSettingOrConnectionString(XNode document, string xpath, string keyAttributeName, string keyAttributeValue, string valueAttributeName, VariableDictionary variables)
{
var changes = new List<string>();
var settings = (
from element in document.XPathSelectElements(xpath)
let keyAttribute = element.Attribute(keyAttributeName)
where keyAttribute != null
where string.Equals(keyAttribute.Value, keyAttributeValue, StringComparison.InvariantCultureIgnoreCase)
select element).ToList();
if (settings.Count == 0)
return changes;
var value = variables.Get(keyAttributeValue) ?? string.Empty;
foreach (var setting in settings)
{
changes.Add(string.Format("Setting '{0}' = '{1}'", keyAttributeValue, value));
var valueAttribute = setting.Attribute(valueAttributeName);
if (valueAttribute == null)
{
setting.Add(new XAttribute(valueAttributeName, value));
}
else
{
valueAttribute.SetValue(value);
}
}
return changes;
}
示例5: SetOutputVariable
void SetOutputVariable(string name, string value, VariableDictionary variables)
{
if (variables.Get(name) != value)
{
Log.SetOutputVariable(name, value, variables);
}
}
示例6: BuildPath
private static string BuildPath(string site, VariableDictionary variables)
{
var relativePath = (variables.Get(SpecialVariables.Action.Azure.PhysicalPath) ?? "").TrimStart('\\');
return relativePath != ""
? site + "\\" + relativePath
: site;
}
示例7: AppendEnvironmentNameIfProvided
string AppendEnvironmentNameIfProvided(VariableDictionary variables, string root)
{
var environment = variables.Get(SpecialVariables.Environment.Name);
if (!string.IsNullOrWhiteSpace(environment))
{
environment = fileSystem.RemoveInvalidFileNameChars(environment);
root = Path.Combine(root, environment);
}
return root;
}
示例8: GetApplicationDirectoryPath
string GetApplicationDirectoryPath (VariableDictionary variables)
{
const string windowsRoot = "env:SystemDrive";
const string linuxRoot = "env:HOME";
var root = variables.Get(SpecialVariables.Tentacle.Agent.ApplicationDirectoryPath);
if (root != null)
return root;
root = variables.Get(windowsRoot);
if (root == null)
{
root = variables.Get(linuxRoot);
if (root == null)
{
throw new Exception(string.Format("Unable to determine the ApplicationRootDirectory. Please provide the {0} variable", SpecialVariables.Tentacle.Agent.ApplicationDirectoryPath));
}
}
return string.Format("{0}{1}Applications", root, Path.DirectorySeparatorChar);
}
示例9: ShouldSetVariables
public void ShouldSetVariables()
{
var variables = new VariableDictionary();
var output = Invoke(Calamari()
.Action("run-script")
.Argument("script", GetFixtureResouce("Scripts", "CanSetVariable.ps1")), variables);
output.AssertZero();
output.AssertOutput("##octopus[setVariable name='VGVzdEE=' value='V29ybGQh']");
Assert.AreEqual("World!", variables.Get("TestA"));
}
示例10: EnsureCertificateFileExists
bool EnsureCertificateFileExists(string workingDirectory, VariableDictionary variables)
{
var certificateFilePath = Path.Combine(workingDirectory, certificateFileName);
if (fileSystem.FileExists(certificateFileName))
return true;
var azureCertificate = certificateStore.GetOrAdd(
variables.Get(SpecialVariables.Action.Azure.CertificateThumbprint),
variables.Get(SpecialVariables.Action.Azure.CertificateBytes),
StoreName.My);
var certificatePassword = GenerateCertificatePassword();
fileSystem.WriteAllBytes(certificateFilePath, azureCertificate.Export(X509ContentType.Pfx, certificatePassword));
Log.SetOutputVariable(SpecialVariables.Action.Azure.Output.CertificateFileName, certificateFilePath, variables);
Log.SetOutputVariable(SpecialVariables.Action.Azure.Output.CertificatePassword, certificatePassword, variables);
return false;
}
示例11: Execute
public CommandResult Execute(string scriptFile, VariableDictionary variables, ICommandLineRunner commandLineRunner)
{
var scriptType = Path.GetExtension(scriptFile).TrimStart('.').ToScriptType();
var engine = GetSpecificScriptEngine(scriptType);
// When running Powershell against an Azure target, we load the Azure Powershell modules,
// and set the Azure subscription
if (scriptType == ScriptType.Powershell &&
variables.Get(SpecialVariables.Account.AccountType) == "AzureSubscription")
{
var azureContextScriptFile = azurePowershellContext.CreateAzureContextScript(scriptFile, variables);
return engine.Execute(azureContextScriptFile, variables, commandLineRunner);
}
return engine.Execute(scriptFile, variables, commandLineRunner);
}
示例12: Generate
public void Generate(string appSettingsFilePath, VariableDictionary variables)
{
var root = LoadJson(appSettingsFilePath);
var names = variables.GetNames();
names.Sort(StringComparer.OrdinalIgnoreCase);
foreach (var name in names)
{
if (name.StartsWith("Octopus", StringComparison.OrdinalIgnoreCase))
continue;
SetValueRecursive(root, name, name, variables.Get(name));
}
SaveJson(appSettingsFilePath, root);
}
示例13: GetEncoding
private Encoding GetEncoding(string sourceFile, VariableDictionary variables)
{
var requestedEncoding = variables.Get(SpecialVariables.Package.SubstituteInFilesOutputEncoding);
if (requestedEncoding == null)
{
return fileSystem.GetFileEncoding(sourceFile);
}
try
{
return Encoding.GetEncoding(requestedEncoding);
}
catch (ArgumentException)
{
return fileSystem.GetFileEncoding(sourceFile);
}
}
示例14: WriteVariableDictionary
static void WriteVariableDictionary(VariableDictionary variables, StringBuilder output)
{
output.AppendLine("$OctopusParameters = New-Object 'System.Collections.Generic.Dictionary[String,String]' (,[System.StringComparer]::OrdinalIgnoreCase)");
foreach (var variableName in variables.GetNames().Where(name => !SpecialVariables.IsLibraryScriptModule(name)))
{
output.Append("$OctopusParameters[").Append(EncodeValue(variableName)).Append("] = ").AppendLine(EncodeValue(variables.Get(variableName)));
}
}
示例15: WriteVariableDictionary
static string WriteVariableDictionary(VariableDictionary variables)
{
var builder = new StringBuilder();
foreach (var variable in variables.GetNames())
{
builder.AppendLine(" this[" + EncodeValue(variable) + "] = " + EncodeValue(variables.Get(variable)) + ";");
}
return builder.ToString();
}