I have the following situation.
I programmatically create a temporary workspace using TFS. I then map it to a spot on my local machine so that I can be able to checkin/checkout files. Since the mapping to the local drive through the workspace is what creates the file structure. What is the way to delete the mapping through the workspace object that I created?
Ive tried the following.
WorkingFolder tempFolder = workspace.getWorkingFolderForServerItem(serverItem);
workspace.DeleteMapping(tempFolder);
Stepping through in debug mode, the tempFolder Object I make holds the correct local mapping as well as the correct server mapping. I cant seem to get it to delete the local content though. Is this mostly correct or do you suggest something completely different?
In TFS, the trick to deleting files locally and telling the server that you do not have them anymore is to get the files at Changeset 1 (i.e. before they existed). In code that would be something like:
workspace.Get(
new string[] {"C:\\LocalPath"},
new ChangesetVersionSpec(1),
RecursionType.Full,
GetOptions.None);
See the following blog post where I explain this concept some more:
TFS Top Tip #11 - Removing source control files from your local file system
That said, if the workspace is just temporary and you do not need it anymore then doing a workspace.Delete() followed by a traditional file delete is a perfectly good way of doing things. If you were trying to keep the workspace around you could get into trouble though (because TFS thinks those files are still in your local workspace unless you tell it that they are not)
Since the mapping to the local drive through the workspace is what creates the file structure.
I think you have this wrong. The local folders (and files) are created only when you perform the get after the mapping is created (whether from the Team Explorer GUI, "tf.exe get", or otherwise).
After deleting the workspace mapping, you will need to create code to delete the files and folders yourself.
Thanks to Richard, I decided to not try and delete the file through the workspace.
Given:
WorkingFolder tempFolder = workspace.getWorkingFolderForServerItem(serverItem);
I ended up doing:
File.setAttributes(tempFolder.LocalItem, FileAttributes.normal)//Get rid of read-only
File.Delete(tempFolder.LocalItem);
Thanks for the help!
Related
My application refers to a bunch of xsd files which are used for xml validation. Currently, they are stored in my local directory and I refer it by giving a path to the primary xsd like "C:\TestFolder\TestFile.xsd". This path is stored in the mongo database. I am not sure where do I store the files once I host this application on the Cloud(Azure). And how do I refer that path in mongo? Since there would be many instances of this application running on the cloud, I am not sure what is the best way to solve this problem.
One way could be to store the files in the project and refer them but I don't think that is the best way.
Can someone point me in the right direction?
The xsd files are not changed by the application, they are just used for validation.
Solution 1 (Simple). Make sure you are using the Relative Path and not the Absolute Path when dealing with the files. Also, make sure to import the files into the project and set the “Copy to Output Directory” property to “Copy Always” so that it can be accessed at run time.
Solution 2. You could store your static files as Blob files on Azure and then reference them (there are many tutorials available out there on how to do it). This way, should you accidentally delete your application, those files will not be lost.
Running my C# application from Visual studio works fine (in this respect)
But when installing the application in my system (win7, .NET 4.0) I get problems with the cache.
These are the errors I get:
LogMessageCallback. Message:20:43:03.988 E [playlist:1978] Unable to save file: playlist.bnk
LogMessageCallback. Message:20:43:03.988 E [social-mgr:830] Unable to save file: social_stream.bnk
LogMessageCallback. Message:20:46:31.034 E [user_cache:107] Unable to save file: user-cache.bnk
LogMessageCallback. Message:20:43:04.988 I [c:/Users/spotify-buildagent/BuildAgent/work/1e0ce8a77adfb2dc/client/core/protocol/file_streamer_simple.cpp:769] Request for file 57a6ab34bad26645e2345a610ae652fe77f82afb complete (code: 0)
I have tried to deleted the entire cache library and it gets recreated when I start the app, so it can't be a matter of file privilege.
Since the cache does not seem to be valid my playlists are not accessible to me at startup.
I do log out properly.
Any explanation/workaround?
I think I've got it...
I search for the playlist.bnk file on my disk and found one under Spotify\bin\Debug\cache_location\Users\bes51659-user, that is from where I run my project with visual studio. "cache_location" in the path directed me to the settings_location argument in the config struct when creating the session. I had set it to const string "cache_location". I must have understood the explanation wrong:
https://developer.spotify.com/docs/libspotify/12.1.51/structsp__session__config.html#a342532432040d476aaaf73f10893d23b
The location where Spotify will write setting files and per-user cache items. This includes playlists, track metadata, etc. 'settings_location' may be the same path as 'cache_location'. 'settings_location' folder will not be created (unlike 'cache_location'), if you don't want to create the folder yourself, you can set 'settings_location' to 'cache_location'.
(a bit contradictory that the "cache_location" catalog was actually created under debug!)
The comment must mean that if I reuse the same location for setting_location as for cache_location I do not have to create it as it has already been created!
I do not know if libspotify did not have permissions to create the catalog "cache_location" under "program files", or if it expected it to be there and did not find it. But it does not matter. I have now changed both the locations to "c:\mySpotify" in the config struct and problem solved...
My only excuse is that google tells me that I'm not the first to have fallen into this pithole.
I am trying to create a custom build activity in C# that gets the list of files in the changesets from a build that was triggered by a check-in action in TFS 2010 and move those files from the SourcesDirectory to another location. The question is whether it is possible to retrieve the list of files that the user checks in to TFS 2010 that triggers a build so that I can loop through the files and move them to another location? So far, I have no luck.
Thanks much for any answers or help!
Thanks Loïc Faure-Lacroix for the comments. I guess my question was too broad so nobody answered my question.
It took me a while to get to where I am now and here’s what I’ve managed to do so far. I got the idea from the following links to take the Changesets as a parameter for my custom activity. I also took the SourcesDirectory as a param which I could obtain from inside the “Run On Agent” sequence.
http://blogs.msdn.com/b/codejunkie/archive/2010/09/02/custom-build-activity-for-tfs-2010-to-send-email-with-build-details-part-1.aspx
http://blogs.msdn.com/b/codejunkie/archive/2010/09/15/custom-build-activity-for-tfs-2010-to-send-email-with-build-details-part-2.aspx
[RequiredArgument]
[Browsable(true)]
public InArgument<IList<Changeset>> Changesets { get; set; }
[RequiredArgument] // The source directory to copy the files from
public InArgument<string> SourcesDirectory { get; set; }
I then needed to loop through the changeset to get the list of items that were checked in to TFS. However, the items I got from the changeset contain the server path, namely, something like “$/MainProj/SubProj/contactus/contact.htm” so I needed a way similar to the ConvertWorkspaceItem activity that can convert the server path to the real local build path on the build server. Does anyone know how the ConvertWorkspaceItem actually work? The SourcesDirectory has the path similar to this (which I am not sure whether always has the same format or will change based on projects or how build server was configured.): C:\Builds\1\SubProj\Sources\contactus
Since I could not find a proper way to convert the paths so I used an ugly way of basic substring search and replacement…
Once I looped through the changset, converted the server path to local source path, I was able to copy those files just checked in to TFS to another location such as a folder on our development server.
Then I ran into one big obstacle. I got the access denied error from the build when I tested with creating a new folder with a few new files in it and checking those in to trigger the build. It seemed that some process or thread that created the new folder in TFS and checked the files in still lock the folder when the build started to run, which I assumed is another thread… If the checked in files were in an existing folder, everything worked fine… Could anyone please share some insights?
Thanks!
I keep having a situation where gets annoying (with TFS). I searched for "TFS" and "Recursive folder/files" but didn't find something similar in SOF and then good it but not exactly what I need.
I have checked out a project from TFS (#1) on my local machine and then after some modifications did update them on a new TFS (#2). Later noticed on TFS #2 have:
Solution folder
folder 1/folder 2/files
folder 2
folder 3/folder 3/files
I checked back on TFS #1 things were OK however, for a reason when it gets to my local drive it can get recursive. Anybody knows what I have done wrong? or any settings are involved?
One thing is that folders which go recursive are other developers projects.
Thank you!
I've put 3 especially large SQL queries within my Visual Studio project, under a folder "Queries" that is in the project directory (not the solution). Is there an eloquent way to access these files? I was hoping that something like #"Queries/firstSqlQuery.sql would work.
Specifying the full path, like with #"C:\\Users\John\Documents\VisualStudio2010\Projects\MySolution\MyProject\Queries\firstSqlQuery.sql
is something I'd really rather not do, since it requires me to go back into code and fix the path, should the application move.
EDIT: For some reason, the page is looking for the files in C:\\Program Files(x86)\Common Files\Microsoft Shared\DevServer\Queries\firstSqlQuery.sql. Why is it looking in this location, when the executable directory is different?
You can do something like this... if it's outside of project. (When I intitially read this-- I misread and thought it was in the solution directory which I was assuming contained the project)--
var pathToBin = Assembly.GetExecutingAssembly().Location;
var directoryInfoOfBin = new DirectoryInfo(pathToBin);
var solutionDirectory = directory.Parent().Parent();
var pathToSolution = solutionDirectory.FullName;
but this is much simpler if it's in the project
System.Web.HttpContext.Current.Server.MapPath("~/Queries/firstSqlQuery");
There are a number of ways to handle this, but there is a fundamental understanding you must gather first. Issuing something like #"Queries/..." isn't, by itself, isn't going to do anything. You need to leverage the System.IO namespace to perform IO operations.
With that part of the foundation, let's lay some more, when you issue a command like this:
File.ReadAllText("firstSqlQuery.sql");
the path that is implied is the Working Directory of the assembly that's executing the code. When debugging an application in Visual Studio, especially and ASP.NET Application, that's the bin directory that resides under the project directory, by default. So, if you did want to access the Queries folder, you would have to do something like this:
File.ReadAllText(#"..\Queries\firstSqlQuery.sql");
so, that's one way of handling it.
Another way of handling it would be to copy the file over into the bin folder every time the project is built by looking at the file properties (e.g. create a Post Build Event), but that's more work than I think you're looking for.
Again, the key here is to understand what directory you're starting in.
Finally, one thing worth noting, if you leverage the directory structure you'll need to ensure that the Queries folder gets deployed to the live site. That probably goes without saying, but I've seen people run into that exact problem before.
You could make sure your query files are copy to the output directory when you do a build and read the files from there without having to set a path.