/// <summary> /// Exports the supplied query /// </summary> /// <param name="q">The <see cref="StoredQuery"/> to export</param> /// <param name="filename">The name of the file to export it to.</param> /// <returns>True if the query was exported, false otherwise.</returns> private bool ExportQuery(StoredQuery q, string filename) { //overwrite file? if (File.Exists(filename)) { if (!Parameters.AskYesNo("The filename " + filename + " already exists, do you want to overwrite it?")) { return(false); } } if (q.QueryScope != QueryScope.Private) { return(true); } //Create item and serialize var wiq = new WorkItemQuery { Query = q.QueryText }; XmlSerializerUtil.SerializeToXmlFile(wiq, filename, new UTF8Encoding(false)); Console.WriteLine("Exported query " + q.Name + " to file " + filename); return(true); }
private static void FindAndReplaceInWiql(CopyQueryParameters parameters, WorkItemQuery sourceQuery) { if (parameters.QueryReplacements.QueryFindAndReplace != null && parameters.QueryReplacements.QueryFindAndReplace.Count > 0) { foreach (var item in parameters.QueryReplacements.QueryFindAndReplace) { if (!string.IsNullOrEmpty(item.Find) && !string.IsNullOrEmpty(item.Replace) && !item.Find.Equals(item.Replace, StringComparison.InvariantCultureIgnoreCase)) { var findIndex = sourceQuery.wiql.IndexOf(item.Find, StringComparison.InvariantCultureIgnoreCase); while (findIndex > -1) { sourceQuery.wiql = sourceQuery.wiql.Remove(findIndex, item.Find.Length); sourceQuery.wiql = sourceQuery.wiql.Insert(findIndex, item.Replace); findIndex = sourceQuery.wiql.IndexOf(item.Find, findIndex + item.Replace.Length, StringComparison.InvariantCultureIgnoreCase); } continue; } if (item.TryRemoveSource) { var newFind = item.Find.Replace("Source.", string.Empty); var newReplace = item.Replace.Replace("Source.", string.Empty); if (!string.IsNullOrEmpty(newFind) && !string.IsNullOrEmpty(newReplace) && !newFind.Equals(newReplace, StringComparison.InvariantCultureIgnoreCase)) { var findIndex = sourceQuery.wiql.IndexOf(newFind, StringComparison.InvariantCultureIgnoreCase); while (findIndex > -1) { sourceQuery.wiql = sourceQuery.wiql.Remove(findIndex, newFind.Length); sourceQuery.wiql = sourceQuery.wiql.Insert(findIndex, newReplace); findIndex = sourceQuery.wiql.IndexOf(newFind, findIndex + newReplace.Length, StringComparison.InvariantCultureIgnoreCase); } continue; } } if (item.TryRemoveTarget) { var newFind = item.Find.Replace("Target.", string.Empty); var newReplace = item.Replace.Replace("Target.", string.Empty); if (!string.IsNullOrEmpty(newFind) && !string.IsNullOrEmpty(newReplace) && !newFind.Equals(newReplace, StringComparison.InvariantCultureIgnoreCase)) { var findIndex = sourceQuery.wiql.IndexOf(newFind, StringComparison.InvariantCultureIgnoreCase); while (findIndex > -1) { sourceQuery.wiql = sourceQuery.wiql.Remove(findIndex, newFind.Length); sourceQuery.wiql = sourceQuery.wiql.Insert(findIndex, newReplace); findIndex = sourceQuery.wiql.IndexOf(newFind, findIndex + newReplace.Length, StringComparison.InvariantCultureIgnoreCase); } continue; } } } } }
private static TargetQueryInfo GetTargetQueryFolderId(WorkItemQuery sourceQuery, QueryReplacementParameters replacementParameters) { TargetQueryInfo targetQueryFolder = new TargetQueryInfo(); targetQueryFolder.FolderPath = sourceQuery.path; if (!string.IsNullOrEmpty(replacementParameters.PathFind) && !string.IsNullOrEmpty(replacementParameters.PathReplace) && !replacementParameters.PathFind.Equals(replacementParameters.PathReplace, StringComparison.InvariantCultureIgnoreCase)) { var findIndex = targetQueryFolder.FolderPath.IndexOf(replacementParameters.PathFind, StringComparison.InvariantCultureIgnoreCase); while (findIndex > -1) { targetQueryFolder.FolderPath = targetQueryFolder.FolderPath.Remove(findIndex, replacementParameters.PathFind.Length); targetQueryFolder.FolderPath = targetQueryFolder.FolderPath.Insert(findIndex, replacementParameters.PathReplace); findIndex = targetQueryFolder.FolderPath.IndexOf(replacementParameters.PathFind, findIndex + replacementParameters.PathReplace.Length, StringComparison.InvariantCultureIgnoreCase); } } targetQueryFolder.QueryName = targetQueryFolder.FolderPath.Remove(0, targetQueryFolder.FolderPath.LastIndexOf('/') + 1); targetQueryFolder.FolderPath = targetQueryFolder.FolderPath.Remove(targetQueryFolder.FolderPath.LastIndexOf('/')); try { targetQueryFolder.FolderId = TfsStatic.GetWorkItemQuery(false, targetQueryFolder.FolderPath, QueryExpand.minimal, 0).id; } catch { string pathLeft = targetQueryFolder.FolderPath; do { pathLeft = pathLeft.Remove(pathLeft.LastIndexOf('/')); try { targetQueryFolder.FolderId = TfsStatic.GetWorkItemQuery(false, pathLeft, QueryExpand.minimal, 0).id; break; } catch { } }while (string.IsNullOrEmpty(targetQueryFolder.FolderId)); do { var nextFolder = targetQueryFolder.FolderPath.Remove(0, pathLeft.Length + 1); if (nextFolder.IndexOf('/') > -1) { nextFolder = nextFolder.Remove(nextFolder.IndexOf('/')); } targetQueryFolder.FolderId = TfsStatic.CreateWorkItemQueryFolder(false, pathLeft, nextFolder).id; pathLeft = $"{pathLeft}/{nextFolder}"; }while (targetQueryFolder.FolderPath.Length != pathLeft.Length); } return(targetQueryFolder); }
/// <summary> /// Exports the supplied query /// </summary> /// <param name="q">The <see cref="StoredQuery"/> to export</param> /// <param name="filename">The name of the file to export it to.</param> /// <returns>True if the query was exported, false otherwise.</returns> private bool ExportQuery(StoredQuery q, string filename) { //overwrite file? if (File.Exists(filename)) if (!Parameters.AskYesNo("The filename " + filename + " already exists, do you want to overwrite it?")) return false; //Create item and serialize var wiq = new WorkItemQuery { Query = q.QueryText }; XmlSerializerUtil.SerializeToXmlFile(wiq, filename,new UTF8Encoding(false)); Console.WriteLine("Exported query " + q.Name + " to file " + filename); return true; }
private static void RemoveTeamAreaId(WorkItemQuery sourceQuery) { var pattern = @"\s<id:\w+-\w+-\w+-\w+-\w+>"; var regex = new Regex(pattern); var matches = regex.Matches(sourceQuery.wiql); for (int i = matches.Count - 1; i >= 0; i--) { Match match = matches[i]; if (match.Success) { sourceQuery.wiql = sourceQuery.wiql.Remove(match.Index, match.Length); } } }
private static WorkItemQuery TryWriteQuery(WorkItemQuery sourceQuery, TargetQueryInfo targetQueryInfo) { WorkItemQuery targetQuery; var queryExistsAlready = false; try { var targetFolder = TfsStatic.GetWorkItemQuery(true, targetQueryInfo.FolderId, QueryExpand.minimal, 1); if (targetFolder.hasChildren) { targetQuery = targetFolder.children.FirstOrDefault(o => o.name.Equals(targetQueryInfo.QueryName, StringComparison.InvariantCultureIgnoreCase)); if (targetQuery != null) { queryExistsAlready = true; sourceQuery.id = targetQuery.id; targetQuery = TfsStatic.UpdateWorkItemQuery(false, sourceQuery); } else { targetQuery = TfsStatic.CreateWorkItemQuery(false, targetQueryInfo.FolderId, sourceQuery); } } else { targetQuery = TfsStatic.CreateWorkItemQuery(false, targetQueryInfo.FolderId, sourceQuery); } } catch { if (queryExistsAlready) { throw; } targetQuery = TfsStatic.CreateWorkItemQuery(false, targetQueryInfo.FolderId, sourceQuery); } return(targetQuery); }
public ActionResult Index(string type, string processTitle, string actioner, string activityName, string status, string p) { ViewBag.ProcessTypes = this._managementApi.GetProcessTypes(); if (string.IsNullOrEmpty(type) && string.IsNullOrEmpty(processTitle) && string.IsNullOrEmpty(actioner) && string.IsNullOrEmpty(activityName) && string.IsNullOrEmpty(status) && string.IsNullOrEmpty(p)) { return(View()); } var statuses = string.IsNullOrEmpty(status) ? new Client.WorkItemStatus[] { } : new Client.WorkItemStatus[] { (Client.WorkItemStatus)Enum.Parse(typeof(Client.WorkItemStatus), status) }; var query = new WorkItemQuery() { ProcessTypeName = type, ProcessTitle = processTitle, Actioner = actioner, ActivityName = activityName, Status = statuses }; var result = this._managementApi.SearchWorkItems(query, Convert.ToInt32(p), 20); ViewBag.Total = result.Total; ViewBag.WorkItems = result.WorkItems; ViewBag.Type = type; ViewBag.ProcessTitle = processTitle; ViewBag.Actioner = actioner; ViewBag.ActivityName = activityName; ViewBag.Status = status; return(View()); }