Lock promotions to select streams across multiple depots for all except those in the specified group.
- Warning
- Be careful with this one since it changes the repository!
- See also
- AcLocks constructor, Locks.cs, PromoRights.cs
- LockStreams.exe.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Depots" type="AcUtils.DepotsSection, AcUtils, Version=1.6.4.0, Culture=neutral, PublicKeyToken=26470c2daf5c2e2f, processorArchitecture=MSIL" />
</configSections>
<Depots>
<depots>
</depots>
</Depots>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
using System.Collections.Generic;
namespace LockStreams
{
class Program
{
private static DepotsCollection _selDepots;
static int Main()
{
bool ret = false;
DepotsSection depotsConfigSection = ConfigurationManager.GetSection("Depots") as DepotsSection;
if (depotsConfigSection == null)
Console.WriteLine("Error creating DepotsSection");
else
{
_selDepots = depotsConfigSection.Depots;
Task<bool> init = lockStreamsAsync();
ret = init.Result;
}
return (ret) ? 0 : 1;
}
public static async Task<bool> lockStreamsAsync()
{
var selStreams = new[] { "DEV2", "UAT" };
AcGroups groups = new AcGroups();
if (!(await groups.initAsync())) return false;
AcPrincipal
group = groups.getPrincipal(
"DEV_LEAD");
if (group == null) return false;
AcDepots depots = new AcDepots(dynamicOnly: true);
if (!(await depots.initAsync(_selDepots))) return false;
foreach (AcDepot
depot in depots.OrderBy(n => n))
{
AcLocks locks = new AcLocks();
if (!(await locks.initAsync(depot))) return false;
IEnumerable<AcStream> filter = depot.Streams.Where(n => selStreams.Any(s => n.Name.Contains(s)));
foreach (AcStream
stream in filter.OrderBy(n => n))
{
bool ret = await locks.lockAsync(stream.Name,
"Authorized users only",
LockKind.to,
group);
Console.WriteLine($@"{stream} ""{LockKind.to}"" lock {(ret ? "succeeded" : "failed")}");
}
}
return true;
}
}
}