Exemple #1
0
        // Get the stranded elements along with the list of status types found and the total count for each type.
        // Returns true if the operation completed successfully, false otherwise. Exception caught and logged
        // in %LOCALAPPDATA%\AcTools\Logs\Stranded-YYYY-MM-DD.log on failure to handle a range of exceptions.
        private static async Task <bool> getStrandedAsync()
        {
            bool ret = false; // assume failure

            try
            {
                AcDepots depots = new AcDepots(dynamicOnly: true); // dynamic streams only
                if (!(await depots.initAsync()))
                {
                    return(false);
                }

                List <Task <bool> > tasks = new List <Task <bool> >();
                // select all depots except those from Stranded.exe.config that should be ignored
                IEnumerable <AcDepot> filter = from d in depots
                                               where !_excludeList.OfType <DepotElement>().Any(de => de.Depot == d.Name)
                                               select d;

                foreach (AcStream stream in filter.SelectMany(d => d.Streams))
                {
                    tasks.Add(runStatCommandAsync(stream));
                }

                bool[] arr = await Task.WhenAll(tasks);         // finish running stat commands in parallel

                ret = (arr != null && arr.All(n => n == true)); // true if all succeeded or if no tasks were run
            }

            catch (Exception ecx)
            {
                AcDebug.Log($"Exception caught and logged in Program.getStrandedAsync{Environment.NewLine}{ecx.Message}");
            }

            return(ret);
        }
        private static readonly object _locker = new object();                     // token for lock keyword scope
        #endregion

        // Returns zero (0) if program ran successfully, otherwise
        // one (1) in the event of an exception or program initialization failure.
        static int Main()
        {
            // general program startup initialization
            if (!init())
            {
                return(1);
            }

            // if a TwinsExcludeFile was specified in EvilTwins.exe.config,
            // validate that it exists and retrieve its content
            if (!String.IsNullOrEmpty(_twinsExcludeFile))
            {
                if (!File.Exists(_twinsExcludeFile))
                {
                    AcDebug.Log($"TwinsExcludeFile {_twinsExcludeFile} specified in EvilTwins.exe.config not found");
                    return(1);
                }
                else
                {
                    _excludeList = getTwinsExcludeList();
                }
            }

            // all stream types in order to include workspace streams, include hidden (removed) streams
            AcDepots    depots = new AcDepots(dynamicOnly: false, includeHidden: true);
            Task <bool> dini   = depots.initAsync(_selDepots);

            if (!dini.Result)
            {
                return(1);
            }

            _tcompare = new TwinEqualityComparer();
            _map      = new Dictionary <AcDepot, HashSet <Tuple <string, int> > >();
            List <Task <bool> > tasks = new List <Task <bool> >(depots.Count);

            foreach (AcDepot depot in depots)
            {
                tasks.Add(initMapAsync(depot));
            }

            Task <bool[]> arr = Task.WhenAll(tasks); // finish running stat commands and initialization in parallel

            if (arr == null || arr.Result.Any(n => n == false))
            {
                return(1);                                                // check log file
            }
            Task <bool> r = reportAsync();

            return((r.Result) ? 0 : 1);
        }
Exemple #3
0
        public static async Task <bool> streamWkspaceMismatchAsync()
        {
            bool ret = false; // assume failure

            try
            {
                // all streams and not just dynamic, include hidden streams
                AcDepots depots = new AcDepots(dynamicOnly: false, includeHidden: true);
                if (!(await depots.initAsync()))
                {
                    return(false);
                }

                // all workspaces (not just the script user), include hidden workspaces
                AcWorkspaces wkspaces = new AcWorkspaces(depots, allWSpaces: true, includeHidden: true);
                if (!(await wkspaces.initAsync()))
                {
                    return(false);
                }

                foreach (AcDepot depot in depots.OrderBy(n => n))
                {
                    var query = from AcStream s in depot.Streams
                                join AcWorkspace w in wkspaces on s.Depot equals w.Depot
                                where w.ID == s.ID && !string.Equals(s.Name, w.Name) // stream ID's equal but names don't
                                orderby w.Name
                                select new
                    {
                        Hidden        = w.Hidden,
                        WorkspaceName = w.Name,
                        StreamName    = s.Name
                    };

                    foreach (var f in query)
                    {
                        Console.WriteLine($"{(f.Hidden ? "Hidden" : "Visible")} wspace: {f.WorkspaceName}, stream: {f.StreamName}");
                    }
                }

                ret = true; // operation succeeded
            }

            catch (Exception ecx)
            {
                Console.WriteLine($"Exception caught and logged in Program.streamWkspaceMismatchAsync{Environment.NewLine}{ecx.Message}");
            }

            return(ret);
        }
Exemple #4
0
        public static async Task <bool> listDynStreamsAsync()
        {
            // true for dynamic streams only
            AcDepots depots = new AcDepots(dynamicOnly: true); // typical two-part object construction

            if (!(await depots.initAsync()))                   // ..
            {
                return(false);                                 // initialization failure
            }
            foreach (AcStream stream in depots.SelectMany(d => d.Streams)
                     .OrderBy(s => s.Depot).ThenBy(s => s))
            {
                Console.WriteLine(stream);
            }

            return(true);
        }
Exemple #5
0
        // General program startup initialization.
        private static bool init()
        {
            // initialize our logging support so we can log errors
            if (!AcDebug.initAcLogging())
            {
                Console.WriteLine("Logging support initialization failed.");
                return(false);
            }

            // save an unhandled exception in log file before program terminates
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AcDebug.unhandledException);

            // ensure we're logged into AccuRev
            Task <string> prncpl = AcQuery.getPrincipalAsync();

            if (String.IsNullOrEmpty(prncpl.Result))
            {
                AcDebug.Log($"Not logged into AccuRev.{Environment.NewLine}Please login and try again.");
                return(false);
            }

            // initialize our class variables from LatestPromotions.exe.config
            if (!initAppConfigData())
            {
                return(false);
            }

            // dynamic streams only in select depots
            _depots = new AcDepots(dynamicOnly: true);
            Task <bool> dini = _depots.initAsync(_selDepots);

            // no group membership initialization, include deactivated users
            _users = new AcUsers(_domains, _properties, includeGroupsList: false, includeDeactivated: true);
            Task <bool> uini = _users.initAsync();

            Task <bool[]> all = Task.WhenAll(dini, uini); // finish initializing both lists in parallel

            if (all == null || all.Result.Any(n => n == false))
            {
                return(false);
            }

            return(true);
        }
Exemple #6
0
        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);
        }
        // Initialize our workspaces list class variable.
        // Returns true if initialization was successful, false otherwise.
        private static async Task <bool> initWSListAsync()
        {
            // fully initialized depots list is required for workspaces list construction below
            AcDepots depots = new AcDepots();

            if (!(await depots.initAsync(_selDepots)))
            {
                return(false);
            }

            // include all workspaces (not just the script user), include only workspaces that are active
            _wspaces = new AcWorkspaces(depots, allWSpaces: true, includeHidden: false);
            if (!(await _wspaces.initAsync()))
            {
                return(false);
            }

            return(true);
        }
        // General program startup initialization. Returns true if initialization succeeded, false otherwise.
        private static bool init()
        {
            // initialize our logging support so we can log errors
            if (!AcDebug.initAcLogging())
            {
                Console.WriteLine("Logging support initialization failed.");
                return(false);
            }

            // in the event of an unhandled exception, save it to our log file before the program terminates
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AcDebug.unhandledException);

            // ensure we're logged into AccuRev
            Task <string> prncpl = AcQuery.getPrincipalAsync();

            if (String.IsNullOrEmpty(prncpl.Result))
            {
                AcDebug.Log($"Not logged into AccuRev.{Environment.NewLine}Please login and try again.");
                return(false);
            }

            // initialize our class variables from PromoCount.exe.config
            if (!initAppConfigData())
            {
                return(false);
            }
            // initialize our logging support for program results
            if (!initPromoCountResultsLogging())
            {
                return(false);
            }

            _users  = new AcUsers(_domains, null, includeGroupsList: false, includeDeactivated: true);
            _depots = new AcDepots(dynamicOnly: true);
            Task <bool[]> lists = Task.WhenAll(_depots.initAsync(_selDepots), _users.initAsync());

            if (lists == null || lists.Result.Any(n => n == false))
            {
                return(false);
            }

            return(true);
        }
        // Initialize Stat with all versions in the repository with overlap or underlap status.
        private static async Task <bool> initStatAsync()
        {
            AcDepots depots = new AcDepots(dynamicOnly: true); // dynamic streams only

            if (!(await depots.initAsync()))
            {
                return(false);
            }

            List <Task <bool> > tasks = new List <Task <bool> >();

            foreach (AcStream stream in depots.SelectMany(d => d.Streams).Where(s => s.HasDefaultGroup))
            {
                tasks.Add(runStatCommandAsync($@"stat -s ""{stream}"" -o -B -fx"));
            }

            bool[] arr = await Task.WhenAll(tasks);         // continue running stat commands in parallel

            return(arr != null && arr.All(n => n == true)); // true if all succeeded
        }
        public static async Task <bool> showActiveWSpacesAsync()
        {
            AcDepots depots = new AcDepots();

            if (!(await depots.initAsync(_selDepots)))
            {
                return(false);
            }

            var filter = from s in depots.SelectMany(d => d.Streams)
                         where s.Name.Contains("DEV3") && s.HasDefaultGroup &&
                         s.Type == StreamType.workspace
                         select s;

            foreach (AcStream s in filter.OrderBy(n => n.Depot).ThenBy(n => n))
            {
                Console.WriteLine(s.ToString("lv"));
            }

            return(true);
        }
        // General program startup initialization.
        private static bool init()
        {
            // initialize our logging support so we can log errors
            if (!AcDebug.initAcLogging())
            {
                Console.WriteLine("Logging support initialization failed.");
                return(false);
            }

            // in the event of an unhandled exception, save it to our log file before the program terminates
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AcDebug.unhandledException);

            // ensure we're logged into AccuRev
            Task <string> prncpl = AcQuery.getPrincipalAsync();

            if (String.IsNullOrEmpty(prncpl.Result))
            {
                AcDebug.Log($"Not logged into AccuRev.{Environment.NewLine}Please login and try again.");
                return(false);
            }

            // initialize our ElementType array class variable from XLinked.exe.config
            if (!initAppConfigData())
            {
                return(false);
            }

            _depots = new AcDepots(dynamicOnly: true); // dynamic streams only
            Task <bool> dini = _depots.initAsync();

            if (!dini.Result)
            {
                AcDebug.Log($"Depots list initialization failed. See log file:{Environment.NewLine}" +
                            $"{AcDebug.getLogFile()}");
                return(false);
            }

            return(true);
        }
        public static async Task <bool> permissionsAsync()
        {
            // since the default is the list of depots the script user can view,
            // this is typically run by an admin so that all depots are in the list
            AcDepots    depots = new AcDepots(dynamicOnly: true); // dynamic streams only
            Task <bool> dini   = depots.initAsync();

            // include group membership initialization for each user (slower, but it's required here)
            AcUsers     users = new AcUsers(_domains, null, includeGroupsList: true);
            Task <bool> uini  = users.initAsync();

            // initialize both lists in parallel
            bool[] lists = await Task.WhenAll(dini, uini);

            if (lists == null || lists.Any(n => n == false))
            {
                return(false);
            }

            // show depots for these users only
            var arr = new[] { "thomas", "barnyrd", "madhuri", "robert" };
            IEnumerable <AcUser> filter = users.Where(n => arr.Any(user => n.Principal.Name == user));

            // list depots each user has permission to access
            // default order comparer sorts by display name from LDAP if available, otherwise principal name
            foreach (AcUser user in filter.OrderBy(n => n))
            {
                string availDepots = await depots.canViewAsync(user);

                if (!String.IsNullOrEmpty(availDepots))
                {
                    Console.WriteLine($"{user}{Environment.NewLine}{availDepots}{Environment.NewLine}");
                }
            }

            return(true);
        }
        public static async Task <bool> showRulesAsync(string user)
        {
            List <AcRules> rules = new List <AcRules>();
            Func <AcStream, Task <bool> > init = (s) =>
            {
                AcRules r = new AcRules(explicitOnly: true); // explicitly-set rules only
                lock (_locker) { rules.Add(r); }
                return(r.initAsync(s));
            };

            AcDepots depots = new AcDepots();

            if (!(await depots.initAsync()))
            {
                return(false);
            }

            var tasks = from s in depots.SelectMany(d => d.Streams)
                        where s.Type == StreamType.workspace &&
                        !s.Hidden && s.Name.EndsWith(user) // workspace names have principal name appended
                        select init(s);

            bool[] arr = await Task.WhenAll(tasks);

            if (arr == null || arr.Any(n => n == false))
            {
                return(false);
            }

            foreach (AcRule rule in rules.SelectMany(n => n).OrderBy(n => n))
            {
                Console.WriteLine(rule);
            }

            return(true);
        }