コード例 #1
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);
        }
        // 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
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        // Initialize our history and stat lists for each stream listed in the LatestPromotions.exe.config Streams section.
        // AcUtilsException caught and logged in %LOCALAPPDATA%\AcTools\Logs\LatestPromotions-YYYY-MM-DD.log on hist or stat
        // command failure. Exception caught and logged in same on failure to handle a range of exceptions.
        private static async Task <bool> initListsAsync(DateTime past)
        {
            bool ret = false; // assume failure

            try
            {
                string timeHrsAgo = AcDateTime.DateTime2AcDate(past); // get date in string format suitable for AccuRev CLI
                List <Task <AcResult> >[] tasks = new List <Task <AcResult> > [2];
                tasks[0] = new List <Task <AcResult> >();             // for hist results
                tasks[1] = new List <Task <AcResult> >();             // for stat results

                // Alternatively change Equals() to Contains() and modify LatestPromotions.exe.config stream values
                // accordingly to filter on stream name subsets, e.g. <add stream="DEV"/> for all streams with DEV in their name.
                foreach (AcStream stream in _depots.SelectMany(d => d.Streams
                                                               .Where(s => _selStreams.OfType <StreamElement>().Any(se => s.Name.Equals(se.Stream)))))
                {
                    Task <AcResult> hr = AcCommand.runAsync($@"hist -k promote -s ""{stream}"" -t now-""{timeHrsAgo}"" -fx");
                    tasks[0].Add(hr);
                    Task <AcResult> sr = AcCommand.runAsync($@"stat -s ""{stream}"" -d -fx"); // stream's default group
                    tasks[1].Add(sr);
                }

                _hist = new List <XElement>(tasks[0].Count);
                while (tasks[0].Count > 0) // process hist results
                {
                    Task <AcResult> r = await Task.WhenAny(tasks[0]);

                    tasks[0].Remove(r);
                    if (r == null || r.Result.RetVal != 0)
                    {
                        return(false);
                    }
                    XElement xml = XElement.Parse(r.Result.CmdResult);
                    _hist.Add(xml);
                }

                while (tasks[1].Count > 0) // process stat results
                {
                    Task <AcResult> r = await Task.WhenAny(tasks[1]);

                    tasks[1].Remove(r);
                    if (r == null || r.Result.RetVal != 0)
                    {
                        return(false);
                    }
                    if (!Stat.init(r.Result.CmdResult))
                    {
                        return(false);
                    }
                }

                ret = true; // if we're here then all completed successfully
            }

            catch (AcUtilsException exc)
            {
                AcDebug.Log($"AcUtilsException caught and logged in Program.initListsAsync{Environment.NewLine}{exc.Message}");
            }

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

            return(ret);
        }
コード例 #6
0
        // Run the AccuRev hist command for all streams in PromoCount.exe.config, generate the results and send it
        // to the daily log file PromoCountResults-YYYY-MM-DD.log created (or updated) in the same folder where
        // PromoCount.exe resides. Returns true if the operation succeeded, false otherwise. AcUtilsException
        // caught and logged in %LOCALAPPDATA%\AcTools\Logs\PromoCount-YYYY-MM-DD.log on hist command failure.
        // Exception caught and logged in same for a range of exceptions.
        private static async Task <bool> promoCountAsync()
        {
            bool ret = false; // assume failure

            try
            {
                Dictionary <AcStream, Task <AcResult> > map = new Dictionary <AcStream, Task <AcResult> >(_selStreams.Count);
                Func <AcStream, Task <AcResult> >       run = (stream) =>
                {
                    // start-end times reversed as workaround for AccuRev issue 15780
                    Task <AcResult> result = AcCommand.runAsync(
                        $@"hist -fx -k promote -s ""{stream}"" -t ""{_endTime} - {_startTime}""");
                    lock (_locker) { map.Add(stream, result); }
                    return(result);
                };

                var tasks = from s in _depots.SelectMany(d => d.Streams)
                            where _selStreams.OfType <StreamElement>().Any(se => se.Stream == s.Name)
                            select run(s);

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

                if (arr == null || arr.Any(r => r.RetVal != 0))
                {
                    return(false);
                }

                log($"Promotions to select streams from {_startTime} to {_endTime}.{Environment.NewLine}");
                int tgrandtot = 0; int vgrandtot = 0;
                foreach (var ii in map.OrderBy(n => n.Key))
                {
                    log($"{ii.Key} {{{$"promotions\\versions"}}}:"); // key is stream
                    AcResult r   = ii.Value.Result;
                    XElement xml = XElement.Parse(r.CmdResult);
                    ILookup <string, XElement> look = xml.Elements("transaction")
                                                      .ToLookup(n => (string)n.Attribute("user"), n => n);
                    int tsubtot = 0; int vsubtot = 0;
                    foreach (var jj in look.OrderBy(n => _users.getUser(n.Key)))
                    {
                        AcUser user = _users.getUser(jj.Key);
                        int    tnum = jj.Count();
                        int    vnum = jj.Elements("version").Count();
                        string val  = $"{{{tnum}\\{vnum}}}";
                        log($"\t{user.ToString().PadRight(40, '.')}{val.PadLeft(13, '.')}");
                        tsubtot += tnum; tgrandtot += tnum;
                        vsubtot += vnum; vgrandtot += vnum;
                    }

                    log($"\tTotal {tsubtot} promotions and {vsubtot} versions.{Environment.NewLine}");
                }

                log($"Grand total of {tgrandtot} promotions and {vgrandtot} versions.");
                ret = true;
            }

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

            return(ret);
        }