AcUtils
A high performance abstraction layer for AccuRev
LockStreams.cs

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>
<add depot="JUPITER" />
<add depot="MARS" />
<add depot="VENUS" />
<add depot="NEPTUNE" />
</depots>
</Depots>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
/* Copyright (C) 2016-2018 Verizon. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
// Required references: AcUtils.dll, System.configuration
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using AcUtils;
namespace LockStreams
{
class Program
{
private static DepotsCollection _selDepots;
static int Main()
{
bool ret = false; // assume failure
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()
{
// set 'To' lock on dynamic streams in select depots that have these strings in their name
var selStreams = new[] { "DEV2", "UAT" };
// lock for all except those in DEV_LEAD group
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); // dynamic streams only in select depots
if (!(await depots.initAsync(_selDepots))) return false;
foreach (AcDepot depot in depots.OrderBy(n => n)) // use default sort ordering
{
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;
}
}
}