/// <summary>
        /// Performs the Import operation
        /// </summary>
        public override void PerformOperation()
        {
            int nrOfImportedQueries = 0;
            foreach (KeyValuePair<string, FileInfo> pair in _filesToImport) {

                FileInfo file = pair.Value;
                string queryName = pair.Key;
            //Read file
            var wiq = XmlSerializerUtil.DeserializeFromXmlFile<WorkItemQuery>(file.FullName);

            //see if query already exists
            StoredQuery q = GetStoredQuery(queryName);

            //update existing?
            if (q != null) {
                if (!Parameters.AskYesNo("The StoredQuery " + queryName + " already exists, do you want to overwrite it?"))
                    continue;
                q.QueryText = wiq.Query;
                q.Update();
            } else {

                //create new
                q = new StoredQuery(Parameters.QueryScope, queryName, wiq.Query, Parameters.QueryDescription);
                Project.StoredQueries.Add(q);
            }
            Console.WriteLine("Imported file "+file.Name+ " as query " + queryName);
                nrOfImportedQueries++;
            }
            if(nrOfImportedQueries>1)
                Console.WriteLine("Imported "+nrOfImportedQueries+" queries.");
        }
        /// <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;
        }
Beispiel #3
0
 public TfsQuery(StoredQuery query)
 {
     Query = query;
     Name = query.Name;
 }
Beispiel #4
0
 public TfsQuery(StoredQuery query)
 {
     Query = query;
     Name  = query.Name;
 }