Beispiel #1
0
		public static List<string> GetChildItems(VersionControlServer server)
		{
			/*var path = "$/Main/PartnerAccess/PALibraries/PAUdb/.nuget";
			var items = server.GetItems(path, new ChangesetVersionSpec(2538), RecursionType.OneLevel);*/
			var path = "$/Main/PartnerAccess/PALibraries/PAUdb/udbcodegen";
			//var items = server.GetItems(path, new ChangesetVersionSpec(2538), RecursionType.OneLevel);
			var items = server.GetItems(path, RecursionType.OneLevel);
			return items
				.Items
				.Select(i => i.ServerItem)
				.Where(i => i != path)
				.ToList();
		}
Beispiel #2
0
        public void Item_DownloadFile()
        {
            // need TFS_ envvars for this test
            // this test also assumes the $TFS_PROJECT contains at least one file in
            // the top level directory which is non-zero in length

            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            string   itemPath = String.Format("$/{0}/*", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            ItemSpec itemSpec = new ItemSpec(itemPath, RecursionType.OneLevel);

            ItemSet itemSet = vcs.GetItems(itemSpec, VersionSpec.Latest,
                                           DeletedState.NonDeleted, ItemType.File, true);

            int i = 0;

            Item[] items = itemSet.Items;
            foreach (Item item in items)
            {
                if (item.ContentLength == 0)
                {
                    continue;
                }
                i++;

                string fname = Path.GetTempFileName();
                item.DownloadFile(fname);

                FileInfo fileInfo = new FileInfo(fname);
                Assert.IsTrue(fileInfo.Length > 0);
                File.Delete(fname);

                // limit how many files we pull here
                if (i == 3)
                {
                    break;
                }
            }
        }
        public void Workspace_GetItems2()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
            string  itemPath         = String.Format("$/{0}/*", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            ItemSet itemSet          = vcs.GetItems(itemPath, RecursionType.OneLevel);

            Item[] items = itemSet.Items;
            foreach (Item item in items)
            {
                Assert.IsNotNull(item.ServerItem);
            }
        }
        public IEnumerable <IItem> GetItems(string path, Version version)
        {
            var itemSet = _versionControlServer.GetItems(path, version.Spec(), tfs.RecursionType.Full);

            return(itemSet.Items.Select(i => new Item(i)));
        }
Beispiel #5
0
    public static void ShowChangeset(VersionControlServer vcs, 
																	 ChangesetVersionSpec versionSpec, 
																	 bool brief, DiffOptions diffOpts)
    {
        int changesetId = versionSpec.ChangesetId;
        Changeset changeset = vcs.GetChangeset(changesetId, true, true);

        // fetch all items in one fell swoop
        List<int> ids = new List<int>();
        foreach (Change change in changeset.Changes)
            ids.Add(change.Item.ItemId);

        // find items in prior changeset
        Item[] items = vcs.GetItems(ids.ToArray(), changesetId-1, true);
        SortedList<int, Item> itemList = new SortedList<int, Item>();
        foreach (Item item in items)
            {
                // itemId of 0 means a null item, IOW file was added in this changeset
                // and missing in prior changeset
                if (item.ItemId == 0) continue;
                itemList.Add(item.ItemId, item);
            }

        foreach (Change change in changeset.Changes)
            {
                // skip folders
                if (change.Item.ItemType == ItemType.Folder) continue;
                string p = change.Item.ServerItem.Substring(2);

                if (brief)
                    {
                        Console.WriteLine(p);
                        continue;
                    }

                IDiffItem a = new DiffItemNull();
                IDiffItem b = new DiffItemNull();

                string tnameA = null;
                string tnameB = null;

                if (((change.ChangeType & ChangeType.Add) != ChangeType.Add) &&
                        (itemList.ContainsKey(change.Item.ItemId)))
                    {
                        Item itemA = itemList[change.Item.ItemId];

                        tnameA = Path.GetTempFileName();
                        itemA.DownloadFile(tnameA);

                        a = new DiffItemLocalFile(tnameA, itemA.Encoding,
                                                                            changeset.CreationDate, true);
                    }

                if ((change.ChangeType & ChangeType.Delete) != ChangeType.Delete)
                    {
                        tnameB = Path.GetTempFileName();
                        change.Item.DownloadFile(tnameB);

                        b = new DiffItemLocalFile(tnameB, change.Item.Encoding,
                                                                            changeset.CreationDate, true);
                    }

                diffOpts.TargetLabel = versionSpec.DisplayString;
                Difference.DiffFiles(vcs, a, b, diffOpts, p, true);

                if (!String.IsNullOrEmpty(tnameA))
                    File.Delete(tnameA);

                if (!String.IsNullOrEmpty(tnameB))
                    File.Delete(tnameB);
            }
    }
        private void RunForItemSpec(VersionControlServer versionControl, string itemSpec)
        {
            _logger.Info(string.Format("Starting for ItemSpec: {0}", itemSpec));

            try
            {
                DateTime startTime = DateTime.UtcNow;

                // Retrieving list of items

                _logger.Info("Retrieving list of items...");

                var items = versionControl.GetItems(itemSpec, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.File, true);

                DateTime finishTimeGetItems = DateTime.UtcNow;
                TimeSpan elapsedTimeGetItems = finishTimeGetItems - startTime;

                _logger.Info("Retrieved {0} items to warm up. Retrieval time: {1}", items.Items.Length, elapsedTimeGetItems);

                if (elapsedTimeGetItems > TimeSpan.FromMinutes(MAX_MINUTES_FOR_GETITEMS))
                {
                    _logger.Warn("Retrieval of items for the ItemSpec took more than {0} minutes, actual time: {1}. Consider reconfiguration of ItemSpecs for the Project Collection.",
                        MAX_MINUTES_FOR_GETITEMS, elapsedTimeGetItems);
                }

                // Processing retrieved items

                _logger.Info("Downloading items...");

                foreach (var item in items.Items)
                {
                    try
                    {
                        // Extracting file ID from the item's download URL to avoid downloading of already warmed up files
                        // during this session

                        int fileId = item.GetFileId();

                        if (!_alreadyDownloadedFileIds.Contains(fileId))
                        {
                            // Requesting file and closing stream, because we don't need the file itself

                            item.DownloadFile().Dispose();

                            _logger.Debug("Downloaded: {0}:{1}", item.ServerItem, item.ChangesetId);

                            // Marking the file as downloaded during this session

                            _alreadyDownloadedFileIds.Add(fileId);
                        }
                        else
                            _logger.Debug("Skipped (already downloaded): {0}:{1}", item.ServerItem, item.ChangesetId);
                    }
                    catch (Exception ex)
                    {
                        _logger.WarnException(string.Format("Failed to process item: {0}:{1}", item.ServerItem, item.ChangesetId), ex);
                    }
                }

                // Calculating elapsed time

                DateTime finishTime = DateTime.UtcNow;
                TimeSpan elapsedTime = finishTime - startTime;

                _logger.Info("Warm up for the ItemSpec done. Elapsed time: {0}", elapsedTime);
            }
            catch (Exception ex)
            {
                _logger.ErrorException(string.Format("Warm up for the ItemSpec failed with error: {0}", ex.Message), ex);
            }
        }