17 using System.Collections.Generic;
18 using System.Configuration;
20 using System.Globalization;
55 if (r != null && r.
RetVal == 0)
57 using (StringReader reader =
new StringReader(r.
CmdResult))
61 char[] sep =
new char[] {
':' };
62 while ((line = reader.ReadLine()) != null && login == null)
64 string[] arr = line.Split(sep);
67 if (String.Equals(arr[0],
"Principal"))
69 string temp = arr[1].Replace(
"\t",
"");
70 if (String.Equals(temp,
"(not logged in)"))
86 AcDebug.
Log($
"AcUtilsException caught and logged in AcQuery.getPrincipalAsync{Environment.NewLine}{ecx.Message}");
91 AcDebug.
Log($
"Exception caught and logged in AcQuery.getPrincipalAsync{Environment.NewLine}{ecx.Message}");
121 string tmpFile = null;
125 .ConfigureAwait(
false);
126 if (r != null && r.
RetVal == 0)
128 tmpFile = Path.GetTempFileName();
129 using (StreamWriter streamWriter =
new StreamWriter(tmpFile))
138 AcDebug.
Log($
"AcUtilsException caught and logged in AcQuery.getCatFileAsync{Environment.NewLine}{ecx.Message}");
141 catch (Exception ecx)
143 AcDebug.
Log($
"Exception caught and logged in AcQuery.getCatFileAsync{Environment.NewLine}{ecx.Message}");
173 .ConfigureAwait(
false);
174 if (r != null && r.
RetVal < 2)
176 XElement xml = XElement.Parse(r.
CmdResult);
177 XElement stream2 = xml.Descendants().Where(n => n.Name ==
"Stream2").SingleOrDefault();
180 XAttribute version = stream2.Attributes(
"Version").SingleOrDefault();
183 string temp = (string)version;
184 string[] a = temp.Split(
'/');
185 int realStreamNumber = Int32.Parse(a[0], NumberStyles.Integer);
186 int realVersionNumber = Int32.Parse(a[1], NumberStyles.Integer);
187 arr =
new int[] { realStreamNumber, realVersionNumber };
193 catch (AcUtilsException ecx)
195 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getBackedVersionAsync{Environment.NewLine}{ecx.Message}");
198 catch (Exception ecx)
200 AcDebug.Log($
"Exception caught and logged in AcQuery.getBackedVersionAsync{Environment.NewLine}{ecx.Message}");
235 Tuple<string, int> ret = null;
239 if (r != null && r.
RetVal == 0)
241 XElement xml = XElement.Parse(r.
CmdResult);
242 string location = (string)xml.Element(
"element").Attribute(
"location");
243 int parent_id = (int)xml.Element(
"element").Attribute(
"parent_id");
244 ret = Tuple.Create(location, parent_id);
250 AcDebug.
Log($
"AcUtilsException caught and logged in AcQuery.getElementNameAsync{Environment.NewLine}{ecx.Message}");
253 catch (Exception ecx)
255 AcDebug.
Log($
"Exception caught and logged in AcQuery.getElementNameAsync{Environment.NewLine}{ecx.Message}");
270 var value = ConfigurationManager.AppSettings[key];
271 return (T)
System.Convert.ChangeType(value, typeof(T),
272 CultureInfo.InvariantCulture);
296 string tempFile = null;
299 tempFile = Path.GetTempFileName();
300 using (StreamWriter streamWriter =
new StreamWriter(tempFile))
302 streamWriter.Write(
@"<serverInfo/>");
306 if (r != null && r.
RetVal == 0)
308 using (StringReader reader =
new StringReader(r.
CmdResult))
310 XElement doc = XElement.Load(reader);
311 XElement sv = doc.Element(
"serverVersion");
312 int major = (int)sv.Attribute(
"major");
313 int minor = (int)sv.Attribute(
"minor");
314 int patch = (int)sv.Attribute(
"patch");
315 arr =
new int[] { major, minor, patch };
322 AcDebug.
Log($
"AcUtilsException caught and logged in AcQuery.getAccuRevVersionAsync{Environment.NewLine}{ecx.Message}");
325 catch (Exception ecx)
327 AcDebug.
Log($
"Exception caught and logged in AcQuery.getAccuRevVersionAsync{Environment.NewLine}{ecx.Message}");
332 if (tempFile != null)
333 File.Delete(tempFile);
354 if (r != null && r.
RetVal == 0)
356 XElement t = XElement.Parse(r.
CmdResult);
357 count = t.Elements(
"Element").Count();
361 catch (AcUtilsException ecx)
363 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getUsersCountAsync{Environment.NewLine}{ecx.Message}");
366 catch (Exception ecx)
368 AcDebug.Log($
"Exception caught and logged in AcQuery.getUsersCountAsync{Environment.NewLine}{ecx.Message}");
387 AcResult r = await AcCommand.runAsync(
"show -fx depots").ConfigureAwait(
false);
388 if (r != null && r.RetVal == 0)
390 XElement t = XElement.Parse(r.CmdResult);
391 count = t.Elements(
"Element").Count();
395 catch (AcUtilsException ecx)
397 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getDepotsCountAsync{Environment.NewLine}{ecx.Message}");
400 catch (Exception ecx)
402 AcDebug.Log($
"Exception caught and logged in AcQuery.getDepotsCountAsync{Environment.NewLine}{ecx.Message}");
421 AcResult r = await AcCommand.runAsync(
"show -fx -d streams").ConfigureAwait(
false);
422 if (r != null && r.RetVal == 0)
424 XElement s = XElement.Parse(r.CmdResult);
425 count = (
from d in s.Elements(
"stream") where d.Attribute(
"isDynamic").Value ==
"true" select d).Count();
429 catch (AcUtilsException ecx)
431 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getDynStreamsCountAsync{Environment.NewLine}{ecx.Message}");
434 catch (Exception ecx)
436 AcDebug.Log($
"Exception caught and logged in AcQuery.getDynStreamsCountAsync{Environment.NewLine}{ecx.Message}");
455 AcResult r = await AcCommand.runAsync(
"show -fix streams").ConfigureAwait(
false);
456 if (r != null && r.RetVal == 0)
458 XElement t = XElement.Parse(r.CmdResult);
459 count = t.Elements(
"stream").Count();
463 catch (AcUtilsException ecx)
465 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getTotalStreamsCountAsync{Environment.NewLine}{ecx.Message}");
468 catch (Exception ecx)
470 AcDebug.Log($
"Exception caught and logged in AcQuery.getTotalStreamsCountAsync{Environment.NewLine}{ecx.Message}");
489 AcResult r = await AcCommand.runAsync(
"show -fx -d streams").ConfigureAwait(
false);
490 if (r != null && r.RetVal == 0)
492 XElement t = XElement.Parse(r.CmdResult);
493 count = t.Elements(
"stream").Count();
497 catch (AcUtilsException ecx)
499 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getStreamsWithDefaultGroupCountAsync{Environment.NewLine}{ecx.Message}");
502 catch (Exception ecx)
504 AcDebug.Log($
"Exception caught and logged in AcQuery.getStreamsWithDefaultGroupCountAsync{Environment.NewLine}{ecx.Message}");
523 AcResult r = await AcCommand.runAsync(
"show -fix -a wspaces").ConfigureAwait(
false);
524 if (r != null && r.RetVal == 0)
526 XElement t = XElement.Parse(r.CmdResult);
527 count = t.Elements(
"Element").Count();
531 catch (AcUtilsException ecx)
533 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getTotalWorkspaceCountAsync{Environment.NewLine}{ecx.Message}");
536 catch (Exception ecx)
538 AcDebug.Log($
"Exception caught and logged in AcQuery.getTotalWorkspaceCountAsync{Environment.NewLine}{ecx.Message}");
555 string temp = String.Empty;
558 using (Process process =
new Process())
560 process.StartInfo.RedirectStandardOutput =
true;
561 process.StartInfo.CreateNoWindow =
true;
562 process.StartInfo.UseShellExecute =
false;
563 process.StartInfo.Arguments =
"acgui.exe";
564 process.StartInfo.FileName =
"where";
566 temp = process.StandardOutput.ReadToEnd();
567 process.WaitForExit();
571 catch (Exception ecx)
573 AcDebug.
Log($
"Exception caught and logged in AcQuery.getAcGUIpath{Environment.NewLine}{ecx.Message}");
577 bool result = (!error && !String.IsNullOrEmpty(temp));
579 path = temp.Substring(0, temp.IndexOf(
'\r'));
596 string dir = Path.GetDirectoryName(temp);
597 path = Path.Combine(dir,
"acclient.cnf");
614 FileStream fs = null;
620 fs =
new FileStream(cnfFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
621 using (StreamReader sr =
new StreamReader(fs))
623 string line = sr.ReadLine();
624 string[] arr = line.Split(
'=');
625 server = arr[1].Trim();
632 catch (Exception ecx)
634 AcDebug.
Log($
"Exception caught and logged in AcQuery.getServerFromAcClientCnf{Environment.NewLine}{ecx.Message}");
639 if (fs != null) fs.Dispose();
654 List<string> depots = null;
656 try { result = await
AcCommand.
runAsync(
"show -fx depots").ConfigureAwait(
false); }
658 catch (AcUtilsException ecx)
660 AcDebug.Log($
"AcUtilsException caught and logged in AcQuery.getDepotNameListAsync{Environment.NewLine}{ecx.Message}");
663 if (result != null && result.
RetVal == 0)
665 XElement xml = XElement.Parse(result.
CmdResult);
666 IEnumerable<XElement> query =
from e in xml.Elements(
"Element")
668 int num = query.Count();
669 depots =
new List<string>(num);
670 foreach (XElement n
in query)
671 depots.Add((
string)n.Attribute(
"Name"));
static async Task< string > getPrincipalAsync()
Determines if the current user is logged into AccuRev and, if so, retrieves their principal name...
static async Task< int > getTotalStreamsCountAsync()
Get the total number of streams (including workspace streams) in the repository including those that ...
AccuRev program return value and command result.
static async Task< int > getDepotsCountAsync()
Get the number of active depots in the repository.
static bool getAcGUIpath(out string path)
Determine if acgui.exe is found in the Path and thus can be spawned.
static bool getAcClientCnfPath(out string path)
Helper function for getServerFromAcClientCnf returns the full path to acclient.cnf on the host machin...
static async Task< int > getUsersCountAsync(bool includeDeactivated=false)
Get the number of active users.
static async Task< int[]> getBackedVersionAsync(string realverspec, AcDepot depot, string depotrelpath)
For the real version specified in the argument list, get the real stream/version for the version in t...
A depot object that defines the attributes of an AccuRev depot.
static async Task< int > getTotalWorkspaceCountAsync()
Get the total number of workspaces in the repository including those that are hidden.
static async Task< int > getStreamsWithDefaultGroupCountAsync()
Get the number of streams (including workspace streams) in the repository that have a default group...
string CmdResult
The command result (usually XML) emitted by AccuRev.
int RetVal
The AccuRev program return value for the command, otherwise minus one (-1) on error.
static void Log(string message, bool formatting=true)
Write the message text to STDOUT, to weekly log files located in %LOCALAPPDATA%\AcTools\Logs, and to trigger.log in the AccuRev server's ..storage\site_slice\logs folder in the case of triggers.
static T getAppConfigSetting< T >(string key)
Type safe way to retrieve values from
.exe.config files.
static bool getServerFromAcClientCnf(out string server)
Get the default AccuRev server from acclient.cnf. The default server is the first line in the file...
Exception thrown when an AccuRev command fails. The AccuRev program return value is zero (0) on succe...
static async Task< string > getCatFileAsync(int eid, AcDepot depot, string ver_spec)
Use to retrieve the contents of a text file under version control.
static async Task< int > getDynStreamsCountAsync()
Get the number of dynamic streams in the repository that have a default group.
static async Task< Tuple< string, int > > getElementNameAsync(string stream, int EID)
Get the depot-relative path for the element in stream with EID. Also returns the element's parent fol...
AccuRev command processing.
static async Task< AcResult > runAsync(string command, ICmdValidate validator=null)
Run the AccuRev command asynchronously with non-blocking I/O.
Use to log and display error and general purpose text messages, and to save the XML param data sent b...
static async Task< int[]> getAccuRevVersionAsync()
Retrieves the AccuRev program major, minor and patch version numbers.
Miscellaneous stuff that didn't fit in elsewhere.
static async Task< List< string > > getDepotNameListAsync()
Get the list of depot names in sorted order.