I developed a simple C# windows application to help me when I have to merge changesets from a source branch to another.
I was also trying to implement multiple merge by selecting more changesets and merging them inside an iteration.
It's basically working ( the files in the destination branch are correctly updated ) but when I get the updated list of Merge Candidates from the source branch It still gives me those changesets. This doens't happen when I merge a single Changeset.
Do you know if there are better ways to make multiple merges?
Here I report some code for you:
Workspace ws = versionControl.GetWorkspace(config.WorkingFolder);
foreach(string changesetId in candidates){
ChangesetVersionSpec csvs = new ChangesetVersionSpec(changesetId);
GetStatus gs = ws.Merge(config.SourceBranchPath, config.DestinationBranchPath, csvs, csvs, LockLevel.None, RecursionType.Full, MergeOptions.None);
}
Related
I just encountered strange behavior from my VSTO Outlook add-in. I am trying to delete all distribution lists stored in an Outlook folder.
Here is how I do that:
public Outlook.MAPIFolder ListsFolder;
foreach (DistListItem distList in ListsFolder.Items.OfType<DistListItem>())
{
distList.Delete();
}
It deletes a whole lot of lists, but strangely not all of them. A few always remain. As far as I can see, there's nothing special about those. All of the lists in this folder have been programmatically created by the same add-in, like this:
myList = ListsFolder.Items.Add(Outlook.OlItemType.olDistributionListItem) as Outlook.DistListItem;
Any ideas on what I might be doing wrong?
Firstly, never loop through all items in a folder - you wouldn't execute a SELECT SQL statement without a WHERE clause, would you? Use Items.Find/FindNext or Items.Restrict - let the store provider do the filtering. In your case, the search query would be [MessageClass] = 'IPM.DistList'.
Secondly, you are deleting items from a collection thus changing it - that is why some items are always skipped. You need to either use a down loop from Count to 1, or store all entry ids in a string list and then loop though that list opening each item using Namespace.GetItemfromID.
Is is possible to get files that is ordered same as in Windows Explorer
I know "natural sort", but it's not what I need, I need to get the file list ordered by the same attribute in Windows Explorer, for example:
If I ordered a directory by the attribute "create date", then I will get a file list as below:
name create date file size
1.txt 2012/1/1 125Kb
2.tab 2012/3/2 15Kb
3.bmp 2013/5/5 26Kb
If my windows explorer order file list with the attribute "file size", the the file list would be:
name create date file size
2.tab 2012/3/2 15Kb
3.bmp 2013/5/5 26Kb
1.txt 2012/1/1 125Kb
Could anyone help?
I think this is going to be a lot more complex than you expect. Folder settings are stored in the registry in two places:
HKCU\Software\Microsoft\Windows\Shell\BagMRU
HKCU\Software\Microsoft\Windows\Shell\Bags
The first path contains a structure which reflects the structure of the file system, and the second path contains details about those items, including a REG_BINARY value called "Sort" which records the sort order used for that folder.
See Willi Balenthin's website for details on the structure, including sample code (in Python)
Here's how to get a list of files sorted by their name:
var path = #"C:\windows"; // obviously change this to whatever you want
var files = System.IO.Directory.GetFiles (path).ToList ();
file.Sort();
And that's it!
Here's how you would do it per your given code sample:
var temperaturePressureSignalFilesList = Directory.GetFiles(TemperaturePressureSignalDirectory, "*.txt", SearchOption.TopDirectoryOnly).ToList();
temperaturePressureSignalFilesList.Sort();
using System.Linq;
DirectoryInfo info = new DirectoryInfo(""); FileInfo[] files =
info.GetFiles().OrderBy(p => p.CreationTime).ToArray(); foreach
(FileInfo file in files) {
// DO Something... }
here is the sample code for get files in directory by creation time.
You can get files by size same way.
I guess you are talking about viewing pane in Windows Explorer (it's essentially a Windows File Manager but also known under different name). Some clarification is needed. You can apply your custom sorting on various columns; moreover, you can have multiple viewing panes (windows) open sorted on different columns. Thus, the problem definition is a bit unclear.
Assuming that you know the sorting order in your viewing panes, then you can use System.IO.DirectoryInfo and derived FileSystemInfo[] objects; the latter has files.OrderBy method.
Hope this will help. My best, Alex
If you want natural sort order, you should either P/Invoke StrCmpLogicalW (http://msdn.microsoft.com/en-us/library/bb759947.aspx) or find a managed natural sort algorithm. There is no built-in natural sort in .NET Framework.
I think you cannot know which is the order in the pane (by size, name or whatever), you must read the list and then sort it the way you want or prompt the user to select a sorting attribute.
As Kenny posted Sorting Directory.GetFiles() here is an approach, anyway I still thinking there is no possibly way to know which is the sorting order that user selected in the viewing pane.
I think you would have to write a shell extension for windows explorer that captures sort events on columns and writes that metadata to disk in some structured way. You may have multiple explorer windows open so might be an idea to apply timestamp or id so you know which explorer window you are dealing with. Then in your app read that metadata to get the sort order and apply accordingly. Not easy but doable.
I'm using Ektron CMS version 8.5 SP2.
I have some items in a taxonomy. Some are actual pages, some are library items (documents like Word files and PDFs).
Let's say there are 3 pages and 2 library items for a total of 5 items in my taxonomy.
I use the following code...
ContentManager cManager = new Ektron.Cms.Framework.Content.ContentManager();
Ektron.Cms.Content.ContentTaxonomyCriteria ctCriteria = new Ektron.Cms.Content.ContentTaxonomyCriteria();
ctCriteria.AddFilter(1707, true); // hard coded taxonomy ID
List<ContentData> list = cManager.GetList(ctCriteria);
Label1.Text = list.Count.ToString();
When this code runs, the count of items in the list is 3. If I output the actual list, I can see it's only the pages in the taxonomy, not the 2 library items.
It seems that the ContentManager.getList() function does not get library items, even when those items have been added to the taxonomy. I can confirm that in the admin workarea, the library items are visible in the taxonomy.
For clarification, this is a problem with retrieving items that have already been added to the taxonomy.
Does anyone know how I can retirieve a list of all items in a taxonomy, including any library items in there.
Note: If I add the files to the Document Managment System instead of the library, it works perfectly. But in the live system, I have hundreds of items in the library and I'm hoping theres' a way to view them via a taxonomy without having to move them all into the DMS.
I have posted this question on the Ektron developers forum as well, but I've had no reply. I'm hoping somebody here can help.
Cheers.
A follow up to my comment from the other day on #nedlud's answer, I felt like this deserved its own answer though.
According to the Framework API docs:
If intent is to retrieve CMS items that have been categorized in Taxonomies, use TaxonomyItemManager.
But as already noted in the comments, the TaxonomyItemData objects returned by this API have a number of empty properties such as QuickLink and Html. I've found that using the TaxonomyManager, one can successfully query for items assigned to particular taxonomy categories.
Here's a brief snippet using the Framework API (version >= 8.5); this feels reminiscent of working with the older (version <= 8.0) taxonomy API wherein one would create a TaxonomyRequest and get an object structure back that encapsulated not only the taxonomy iteself, but the items categorized into that taxonomy:
//e.g. for a single-level taxonomy
long taxRoot = 1707; //from OP's question
TaxonomyManager taxManager = new TaxonomyManager();
//GetTree overload supplying includeItems parameter
TaxonomyData taxTree = taxManager.GetTree(taxRoot, includeItems: true);
foreach(TaxonomyItemData taxItem in taxTree.TaxonomyItems)
{
//these should print true
Response.Write(!String.IsNullOrEmpty(taxItem.QuickLink));
Response.Write(!String.IsNullOrEmpty(taxItem.Html));
}
I'm currently refactoring some version 8.0 code into version 8.6 and converting to the Framework API. Until Ektron fixes the (bug?) of TaxonomyItemManager returning TaxonomyItemData with null properties, I'll be using the above method + LINQ for the sorting/filtering/etc.
I would look at the TaxonomyItemManager rather than the ContentManager.
Thanks to #maddoxej suggestion of using the TaxonomyItemManager, I have working solution code...
TaxonomyItemCriteria criteria = new TaxonomyItemCriteria();
criteria.AddFilter(TaxonomyItemProperty.TaxonomyId, CriteriaFilterOperator.EqualTo, 1707);
TaxonomyItemManager taxonomyItemManager = new TaxonomyItemManager();
List<TaxonomyItemData> taxonomyItemList = taxonomyItemManager.GetList(criteria);
Label1.Text = taxonomyItemList.Count.ToString();
This code now shows the expected count of "5", and I can display all the itmes :)
So many "manager" classes in Ektron.
I have produced a solution in a C# web app that runs a report which returns a DataSet containing 9 Datatables.
The tables are linked with many-to-many relationships, and the purpose of the report is to produce a snapshot of the progress on records contained in the tables for anyone point in time.
This dictates that all 9 tables are queried at once, as querying the tables individually at different times will mean that the results dont match up between tables.
I was returning the 9 csv files in a zip file, which worked fine in development. However, in the organisation I am working for a lot of user's machines are very limited and we cannot rely on them having winzip or some other archiving software, and as such I have been told to find an alternative solution.
So far, the problems I have come up against are:
All 9 datatables must be produced from the same query, which rules out giving users the option to run the report against tables individually as the results may not match up if they are run at different times of the day.
I can only return one file at a time to the browser, which stops me returning the collection of csv files unzipped.
I did think about returning the data as separate tabs on an excel workbook, however some of the results have leading zeros, which will be trimmed off when they are loading into the worksheet.
It would be great if anyone knew of an obvious solution I'm missing?
Using DotNetZip, you can zip and unzip files like so:
using Ionic.Zip;
namespace ConsoleApplication23
{
class Program
{
static void Main(string[] args)
{
//Zip your files like so
ZipFile x = new ZipFile();
x.AddFile(#"C:\myFile");
x.AddFile(#"C:\mySecondFile");
x.Save(#"c:\myZipFile.zip");
//Unzip like so
ZipFile y = ZipFile.Read(#"c:\myZipFile.zip");
foreach (ZipEntry e in y)
{
e.Extract(#"c:\test", ExtractExistingFileAction.OverwriteSilently);
}
}
}
}
Given a particular path of folder in tfs, I need to recursively find all files and folders within the folder for a given changeset. In other words, i need to get the transitive closure of a path in tfs for a given changeset. The problem I'm facing in doing so is listing the contents of a particular folder within tfs..
How would this be possible in C# ?
I'm assuming you want 'folder contents as of changeset X' and not 'folder contents that were part of changeset X'
GetItems is the right call to use, just pass in a version spec for the changeset you're interested in.
http://msdn.microsoft.com/en-US/library/bb138911.aspx
so, assuming you already have a reference to the VersionControlServer instance:
var myFolderAtChangeset17 = versionControlServer.GetItems("$/MyFolder", new ChangesetVersionSpec(17), RecursionType.Full);
If I misunderstood and you happen to want to 'folder contents that were part of changeset X', there's a few different ways of doing it, but getting the changeset with GetChangeset and just filtering the Changes is pretty simple.
Something like this might be more what you're looking for. This gets all changes in a changeset and iterates through them, identifying the ones in the given path. This could be shortened with a linq query, but I'm leaving it a bit more expanded to give the gist of what I'm trying to say:
TeamFoundationServer tfs = new TeamFoundationServer("http://tfs:8080");
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
Changeset cs = vcs.GetChangeset(6284868);
foreach (Change change in cs.Changes)
{
if (change.Item.ServerItem.StartsWith("$/Application Common/Dev/src"))
{
System.Diagnostics.Debug.WriteLine(string.Format("Changeset {0}, file {1}, changes {2}",
cs.ChangesetId, change.Item.ServerItem, change.ChangeType.ToString()));
}
}
I think something like this would work..
TeamFoundationServer tfs = new TeamFoundationServer("http://tfs:8080");
VersionControlServer vcs = tfs.GetService();
ItemSet items;
items = vcs.GetItems(tfsPath, RecursionType.Full);
If you have any other ideas, please post them..
You can use the changeset webservice to get an XML document that contains all of the changed items for a particular changeset. Then just loop through the list of changed items and see if they are in the path you are looking for.
Here's the URL to the changeset webservice:
http://your_tfs_server/VersionControl/Changeset.aspx?artifactMoniker=your_changeset_number&webView=true