Ejemplo n.º 1
0
        /// <summary>
        /// Populate this container with AcLock objects on streams in \e depots.
        /// </summary>
        /// <param name="depots">Limit the list of locks to those on streams in \e depots only. Depot names in \e depots
        /// must match their respective AccuRev depot name exactly.</param>
        /// <returns>\e true if initialization succeeded, \e false otherwise.</returns>
        /// <exception cref="AcUtilsException">caught and [logged](@ref AcUtils#AcDebug#initAcLogging)
        /// in <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\<prog_name\>-YYYY-MM-DD.log</tt> on \c show command failure.</exception>
        /// <exception cref="Exception">caught and logged in same on failure to handle a range of exceptions.</exception>
        /*! \sa [AcLocks constructor](@ref AcUtils#AcLocks#AcLocks), initAsync(AcDepot), initAsync(StreamsCollection) */
        /*! \show_ <tt>show -fx locks</tt> */
        public async Task <bool> initAsync(DepotsCollection depots)
        {
            AcDepots dlist = new AcDepots();

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

            bool ret = false; // assume failure

            try
            {
                AcResult r = await AcCommand.runAsync("show -fx locks").ConfigureAwait(false);

                if (r != null && r.RetVal == 0)
                {
                    bool     result = true;
                    XElement xml    = XElement.Parse(r.CmdResult);
                    for (int ii = 0; ii < dlist.Count && result; ii++)
                    {
                        AcDepot depot = dlist[ii];
                        IEnumerable <XElement> query = from e in xml.Elements("Element")
                                                       join AcStream s in depot.Streams on(string) e.Attribute("Name") equals s.Name
                                                       select e;

                        result = initList(query);
                    }

                    ret = result;
                }
            }

            catch (AcUtilsException ecx)
            {
                AcDebug.Log($"AcUtilsException caught and logged in AcLocks.initAsync(DepotsCollection){Environment.NewLine}{ecx.Message}");
            }

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

            return(ret);
        }
        /// <summary>
        /// Populate this container with AcRule objects for all streams in \e depotsCol
        /// as per [constructor parameter](@ref AcUtils#AcRules#AcRules) \e explicitOnly.
        /// </summary>
        /// <param name="depotsCol">The list of depots to query for rules.</param>
        /// <param name="progress">Optionally report progress back to the caller.</param>
        /// <returns>\e true if no failure occurred and list was initialized successfully, \e false otherwise.</returns>
        /// <exception cref="Exception">caught and [logged](@ref AcUtils#AcDebug#initAcLogging) in
        /// <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\<prog_name\>-YYYY-MM-DD.log</tt> on failure to handle a range of exceptions.</exception>
        public async Task <bool> initAsync(DepotsCollection depotsCol, IProgress <int> progress = null)
        {
            bool ret = false; // assume failure

            try
            {
                AcDepots depots = new AcDepots();
                if (!(await depots.initAsync(depotsCol, progress).ConfigureAwait(false)))
                {
                    return(false);
                }
                int num = 0; // get number of streams for tasks list
                foreach (AcDepot depot in depots)
                {
                    num += depot.Streams.Count();
                }
                List <Task <bool> >      tasks = new List <Task <bool> >(num);
                Func <Task <bool>, bool> cf    = t =>
                {
                    bool res = t.Result;
                    if (res && progress != null)
                    {
                        progress.Report(Interlocked.Increment(ref _counter));
                    }
                    return(res);
                };

                foreach (AcStream stream in depots.SelectMany(d => d.Streams))
                {
                    Task <bool> t = initAsync(stream).ContinueWith(cf);
                    tasks.Add(t);
                }

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

                ret = (arr != null && arr.All(n => n == true));
            }

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

            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Populate this container with AcDepot objects as per [constructor parameters](@ref AcUtils#AcDepots#AcDepots).
        /// </summary>
        /// <param name="depotsCol">List of depots to create, otherwise \e null for all depots.</param>
        /// <param name="progress">Optionally report progress back to the caller.</param>
        /// <returns>\e true if initialization succeeded, \e false otherwise.</returns>
        /// <exception cref="AcUtilsException">caught and [logged](@ref AcUtils#AcDebug#initAcLogging) in
        /// <tt>\%LOCALAPPDATA\%\\AcTools\\Logs\\<prog_name\>-YYYY-MM-DD.log</tt> on \c show command failure.</exception>
        /// <exception cref="Exception">caught and logged in same on failure to handle a range of exceptions.</exception>

        /*! \code
         *  DepotsSection ds = ConfigurationManager.GetSection("Depots") as DepotsSection;
         *  DepotsCollection _dcol = ds.Depots; // list of depots from FooApp.exe.config
         *  ...
         *  private async Task<bool> initComboBoxDepotsAsync()
         *  {
         *      bool ret = false; // assume failure
         *      try
         *      {
         *          toolStripStatusLabel.Text = "Initializing...";
         *          toolStripProgressBar.Visible = true;
         *          toolStripProgressBar.Maximum = _dcol.Count;
         *          Progress<int> progress = new Progress<int>(i => toolStripProgressBar.Value = i);
         *
         *          AcDepots depots = new AcDepots(dynamicOnly: true);
         *          if (await depots.initAsync(_dcol, progress)) // if initialization succeeds
         *          {
         *              foreach (AcDepot depot in depots)
         *                  toolStripComboBoxDepot.Items.Add(depot); // a ToolStripComboBox control
         *              ret = true; // operation succeeded
         *          }
         *          else
         *          {
         *              AcDebug.Log("Failure in FooApp.initComboBoxDepotsAsync");
         *              MessageBox.Show($"Depots list initialization failed. See log file:{Environment.NewLine}{AcDebug.getLogFile()}",
         *                  "FooApp", MessageBoxButtons.OK, MessageBoxIcon.Hand);
         *          }
         *      }
         *
         *      catch (Exception ecx)
         *      {
         *          AcDebug.Log($"Exception caught and logged in FooApp.initComboBoxDepotsAsync{Environment.NewLine}{ecx.Message}");
         *      }
         *
         *      finally
         *      {
         *          toolStripStatusLabel.Text = "Ready";
         *          toolStripProgressBar.Visible = false;
         *      }
         *
         *      return ret;
         *  }
         *  \endcode */
        /*! \sa [AcDepots constructor](@ref AcUtils#AcDepots#AcDepots), DepotsCollection, AcGroups.initAsync */
        /*! \show_ <tt>show -fx depots</tt> */

        /*! \accunote_ The XML attribute \e locWidth from <tt>show -fx depots</tt> is obsolete.
         *  It's an AccuRev 4.x artifact and should be removed. RPI defect 1112042, SupportLine AR3325. */
        public async Task <bool> initAsync(DepotsCollection depotsCol = null, IProgress <int> progress = null)
        {
            bool ret = false; // assume failure

            try
            {
                AcResult r = await AcCommand.runAsync("show -fx depots").ConfigureAwait(false);

                if (r != null && r.RetVal == 0)
                {
                    XElement xml = XElement.Parse(r.CmdResult);
                    IEnumerable <XElement> query = null;
                    if (depotsCol == null)
                    {
                        query = from e in xml.Elements("Element") select e;
                    }
                    else
                    {
                        query = from e in xml.Elements("Element")
                                where depotsCol.OfType <DepotElement>().Any(de => de.Depot == (string)e.Attribute("Name"))
                                select e;
                    }

                    int num = query.Count();
                    List <Task <bool> >      tasks = new List <Task <bool> >(num);
                    Func <Task <bool>, bool> cf    = t =>
                    {
                        bool res = t.Result;
                        if (res && progress != null)
                        {
                            progress.Report(Interlocked.Increment(ref _counter));
                        }
                        return(res);
                    };

                    foreach (XElement e in query)
                    {
                        AcDepot depot = new AcDepot(_dynamicOnly, _includeHidden);
                        depot.ID               = (int)e.Attribute("Number");
                        depot.Name             = (string)e.Attribute("Name");
                        depot.Slice            = (int)e.Attribute("Slice");
                        depot.ExclusiveLocking = (bool)e.Attribute("exclusiveLocking");
                        string temp = (string)e.Attribute("case");
                        depot.Case     = (CaseSensitivity)Enum.Parse(typeof(CaseSensitivity), temp);
                        depot._streams = new AcStreams(_dynamicOnly, _includeHidden);
                        lock (_locker) { Add(depot); }
                        Task <bool> t = depot._streams.initAsync(depot, depot.listFile()).ContinueWith(cf);
                        tasks.Add(t);
                    }

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

                    ret = (arr != null && arr.All(n => n == true)); // true if all succeeded
                }
            }

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

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

            return(ret);
        }