Im not sure if this is even possible but I am looking to be able to create an app (VB or C#) that will essentially replicate the behaviour of the 'View history' of a selected TFS Project. I will want to be able to browse the Changeset, select one and download the solution into a specified location.
I have not had a chance to take a proper look yet, but I assume it is straight forward to get the ChangeSet history from the SQL database, but I am not sure where to look next to be able to download the associated solution/project. Is it something similar to Filestream?
If anyone has covered this in the past, I would love to hear about how you got the project files.
Try with following code (I assume you are using TFVC version control):
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace API {
class Program
{
static void Main(string[] args)
{
string vsuri = "http://xxx.xxx.xxx.xxx";
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(vsuri));
tpc.EnsureAuthenticated();
VersionControlServer vcs = tpc.GetService<VersionControlServer>();
Workspace ws = vcs.CreateWorkspace("NewWorkSpace");
ws.Map("$/ProjectName","C:\\LocationPath");
int changesetversiontoget = 111;
ChangesetVersionSpec cvs = new ChangesetVersionSpec(changesetversiontoget);
ws.Get(cvs,GetOptions.GetAll);
}
} }
The code will create a work space and then get all the files with a specified version like you get a version from Team Explorer\Source Control.
Just as Daniel mentioned, the best way to achieve what you need is through TFS API.
You can follow below links:
Using TFS API - how to get previous version of a file given a Changeset
Get Changeset and all it's changes on TFS using c#
If you want to download solution files for a given changeset, this could be achieved through web portal, detailed steps please check below link:
Download code of a specific changeset in TFVC
Related
Edit: I just read that Microsoft products often delete and create a new file when saving, so we may need a completely different solution than below...
I'm writing some code to track file and folder changes on both Windows and Mac while my app is running, but it also needs to detect changes if it's not running.
I'm able to do this on Windows by obtaining folder and file ID's using the following post:
Getting a Folder ID C#
Now I need a solution for Mac, but after searching I've come up a bit empty. I can't find anything regarding a system-wide folder/file ID. The closest I came to a solution was using some sort of bookmark that could track the file as described below, but I haven't started yet:
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW10
Seems I would have to store these bookmarks as Alias files to recall when the program starts back up.
Are there any other options for getting a global file/folder ID on Mac using C#?
You can use NSFileManager.GetAttributes to obtain an "inode" of the file (as Jason's comment calls out)
Note: Of course inodes change if moved across volumes, if a program that edits a file performs a delete and recreate vs. a replace, etc...
Example:
var ns = NSFileManager.DefaultManager;
var attribs = ns.GetAttributes("/Users/sushi/Desktop/foo.txt");
Console.WriteLine(attribs.SystemFileNumber);
File.Move("/Users/sushi/Desktop/foo.txt", "/Users/sushi/Desktop/foo2.txt");
var attribs2 = ns.GetAttributes("/Users/sushi/Desktop/foo2.txt");
Console.WriteLine(attribs2.SystemFileNumber);
I'm trying to use SharpSvn to read the contents of two revisions of a file. When I run the following code the fileVersions collection only contains one item..
var svnClient = new SvnClient();
var revisionInfo = new SvnFileVersionsArgs
{
Start = 80092,
End = 80093
};
Collection<SvnFileVersionEventArgs> fileVersions;
svnClient.GetFileVersions(
new SvnUriTarget("https://DbDiff.svn.codeplex.com/svn/DbDiffCommon/DataAccess/SqlCommand11.xml"),
revisionInfo,
out fileVersions);
However I would expect it to include two items. Using TortoiseSVN I can see that the file changed in revision 80088, so I would expect to get this version when I use Start = 80092..
Using Start = 80091 doesn't help either..
The problem is not in your code but in the SvnBridge software used by codeplex. (They store the data in TFS and provide access via the bridge instead of using a real Subversion backend).
The bridge software doesn't implement this api properly. (I added an issue on it years ago, but as far as I can tell it was never fixed).
Subversion itself only uses this api for 'svn blame' (/praise/annotate), so I think the SvnBridge developers didn't care enough to fix this.
In AnkhSVN I detect the case of just receiving one file and then use SvnClient.Write() to obtain the file the slow way :(
I was wondering if anyone knew of a good site showing examples of using TFS 2010's API.
I would like to develop a project that would allow a team to see which files/items other team members had checked out. It simply a system users could see which projects developers are currently working on. Does any one have any experience with this that could give advise to get started?
I would be developing in .NET (C# OR VB) and the application would ride on a SQL Server 2008 database.
As Alex mentions, TFS Sidekicks from Attrice has this functionality.
In addition, the TFS Power Tools allows you to use "Find in Source Control" to see what files are checked out by any (or all) users.
However, if you did want to roll your own solution, you could do so pretty easily using the TFS SDK. I'll let the documentation speak for itself, but you'll probably want to do something along the lines of:
TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(new Uri("http://tfs.mycompany.com:8080/tfs/DefaultCollection"));
VersionControlServer vc = projectCollection.GetService<VersionControlServer>();
/* Get all pending changesets for all items (note, you can filter the items in the first arg.) */
PendingSet[] pendingSets = vc.GetPendingSets(null, RecursionType.Full);
foreach(PendingSet set in pendingSets)
{
/* Get each item in the pending changeset */
foreach(PendingChange pc in set.PendingChanges)
{
Console.WriteLine(pc.ServerItem + " is checked out by " + set.OwnerName);
}
}
(Note: totally untested)
But again, I'd recommend you check out those two existing projects to see if they fit your needs.
TFS Sidekicks by Attrice already does this and a lot more. Plus, it's free
TFS Sidekicks
I think it is simple to do this but i dont know how to start? I want to get layer name or label name in the autocad file using c#. I search the forums but i really find anything valuable. I found the ObjectARX and AutoLisp, but i dont find any tutorial about theese API's. So, i want to simple example about the reach autocad file.
If you downloaded the ObjectARX SDK from the official site it contains many sample projects to get you started. You will need to have some AutoCAD knowledge to understand the structure of the .dwg database as exposed by the API. Be prepared to invest significant time in the project.
If you just are looking for a simple one time dump of the data in a .dwg file ask your local drafter as there is a command in the AutoCAD UI for doing this known as the Data Extraction Wizard.
Another answer on stackoverflow recommend this book chapter as a way to understand the AutoCAD database connection features.
It's simple as follows:
[CommandMethod("LayerIterator")]
public static void LayerIterator_Method()
{
Database database = HostApplicationServices.WorkingDatabase;
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
SymbolTable symTable = (SymbolTable)transaction.GetObject(database.LayerTableId, OpenMode.ForRead);
foreach (ObjectId id in symTable)
{
LayerTableRecord symbol = (LayerTableRecord)transaction.GetObject(id, OpenMode.ForRead);
//TODO: Access to the symbol
MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nName: {0}", symbol.Name));
}
transaction.Commit();
}
}
Details can be found from http://spiderinnet1.typepad.com/blog/2012/06/autocad-net-iterate-through-layer-table.html
We have a report generator. Daily, it writes its data into a excel file.
For reasons of version controlling and file data safety, we need to alter this file, and commit the changes into a repository.
Do you recommend any .net SVN API you've used?
You should take a look at the SharpSvn .NET library. You will probably need checkout and commit commands:
Checking out:
string wcPath = "c:\\my working copy";
using (SvnClient client = new SvnClient())
{
client.CheckOut(new Uri("http://server/path/to/repos"), wcPath);
}
Committing:
string wcPath = "c:\\my working copy";
SvnCommitArgs a = new SvnCommitArgs();
a.LogMessage = "My log message";
using (SvnClient client = new SvnClient())
{
client.Commit(wcPath, a);
}
You might be able to turn on Autoversioning for your repository. Since it uses WebDAV, you can treat the repository just like a network drive (Web Folder). And you can treat the file as a normal file, just open, modify, and save.
If it were me , I would create a new repository for the excel data files. I don't think I'd like my code being autoversioned :)
We are using tool that actually searching for installed TortoiseSVN in predefined locations and using it command-line api. If that is for Windows and it's for not redistribution - it might be easier to do.
Helpful code for cmd:
#echo off
if exist "%ProgramW6432%\TortoiseSVN\bin\TortoiseProc.exe" set patht=%ProgramW6432%
if exist "%ProgramFiles%\TortoiseSVN\bin\TortoiseProc.exe" set patht=%ProgramFiles%
if exist "%ProgramFiles(x86)%\TortoiseSVN\bin\TortoiseProc.exe" set patht=%ProgramFiles(x86)%
echo Placing SVN Commit
"%patht%\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:"%CD%" /notempfile
If you still want to do that task from code - SharpSVN http://sharpsvn.open.collab.net is better choiŃe
The simplest would be to spawn a process and call SVN.exe
to commit your changes.
Here is a similiar question that was asked.
Does anyone know of a good C# API for Subversion?
Here is another resource
SVN Libraries for .NET?