I'm looking to see if the SQL Database behind TFS2015 (or any version of TFS, in this case 2015 or 2010) stores the full file path for a file. There is information that we include in the Project folder (namely the version number) and while I realize there are better ways to track this information, we have a lot of legacy data that only has the version stored within this path. I want to pull the data into Crystal Reports to strip off the information and then use it.
You want to get a list of folders in TFS Source Control, instead of querying in database, we recommend to achieve it programmatically. The blog below and the sample code associated with it will do what you want:
http://blogs.microsoft.co.il/blogs/shair/archive/2009/02/26/tfs-api-part-16-mapping-source-control-using-versioncontrolserver.aspx
Also, check the code snippet in this case, which should help you:
ICommonStructureService structureService = (ICommonStructureService)Tfscollection.GetService(typeof(ICommonStructureService));
ProjectInfo[] projects = structureService.ListAllProjects();
//combo_projects.ItemsSource = projects;
////Create VersionControlServer object from TFS
//sourceControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
RecursionType recursion = RecursionType.OneLevel;
Item[] items = null;
string path = "$/" + projects[0].Name;//"$/TescoPOC/FetchStoryfromTFS";
ItemSet itemSet = versionControl.GetItems(path, recursion);
items = itemSet.Items;
//Dictionary<string, int> FolderListName = new Dictionary<string, int>();
List<string> FolderListName = new List<string>();
foreach (Item keyItem in items)
{
char[] charSeparators = new char[] { '/' };
//Using split to isolated the Project Name and the File Name
string[] ss = keyItem.ServerItem.Split(charSeparators, StringSplitOptions.None);
if (keyItem != items[0])
{
string filename = keyItem.ServerItem.Replace(path + "/", string.Empty);
if (filename != "BuildProcessTemplates")
{
FolderListName.Add(filename);
//if (FolderListName.ContainsKey(filename))
// FolderListName[filename] = FolderListName[filename] + 1;
//else
// FolderListName.Add(filename, 1);
}
}
}
I am using WPF Flowdocument to print content in a Table with Header and Footer.
However, when the data occupies only couple of rows in the table, footer section still reflects at the last of the page and the whole page gets printed, leaving half of the page blank.
Can I expect the content (Header + Content + Footer) to occupy only half of the page if the data is less and one full page (A4/Letter page) if the data is more than half page? And if the data is more than a full page, it should span to the second page too.
Thanks..
I am able to solve this by overriding OnPrintCommand for DocumentViewer
public class CustomDocumentViewer : DocumentViewer
{
protected override void OnPrintCommand()
{
// get a print dialog, defaulted to default printer and default printer's preferences.
PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;
// get a reference to the FixedDocumentSequence for the viewer.
FixedDocumentSequence docSeq = this.Document as FixedDocumentSequence;
if (Globals.PRINT_COMMAND_PAGEHEIGHT == "FULL")
printDialog.PrintTicket.PageMediaSize = new PageMediaSize(960, 1152);
else
printDialog.PrintTicket.PageMediaSize = new PageMediaSize(960, 576);
if (printDialog.ShowDialog() == true)
{
// set the print ticket for the document sequence and write it to the printer.
docSeq.PrintTicket = printDialog.PrintTicket;
XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
writer.WriteAsync(docSeq, printDialog.PrintTicket);
}
}
}
Window_Activated function:
//Set Page Height and Width dynamically
MemoryStream mem = new MemoryStream();
byte[] buf = Encoding.UTF8.GetBytes(strXmlData);
mem.Write(buf, 0, buf.Length);
mem.Position = 0;
FlowDocument res = XamlReader.Load(mem) as FlowDocument;
//1152 = 12in * 96 DPI
if (Utils.GetPageHeight(strOrderNo.Substring(0, 2)) == "FULL")
{
res.PageHeight = Globals.FULL_PAGE_HEIGHT;
Globals.PRINT_COMMAND_PAGEHEIGHT = "FULL";
}
else
{
res.PageHeight = Globals.HALF_PAGE_HEIGHT;
Globals.PRINT_COMMAND_PAGEHEIGHT = "HALF";
}
res.PageWidth = Globals.PAGE_WIDTH;
reportDocument.XamlData = XamlWriter.Save(res);
in the DocumentViewer xaml file:
<Grid>
<spu:CustomDocumentViewer x:Name="documentViewer" />
</Grid>
and in the Flowdocument Template:
PageHeight="0.0cm" PageWidth="0.0cm" ColumnWidth="21.0cm"
Thanks,
~ Ravi
I have a wpf staff creation window in which I can create basic information like first name, last name etc this creates the staff in my REST web service. An example:
Client side:
private void CreateStaffMember_Click(object sender, RoutedEventArgs e)
{
string uri = "http://localhost:8001/Service/Staff";
StringBuilder sb = new StringBuilder();
sb.Append("<Staff>");
sb.AppendLine("<FirstName>" + this.textBox1.Text + "</FirstName>");
sb.AppendLine("<LastName>" + this.textBox2.Text + "</LastName>");
sb.AppendLine("<Password>" + this.passwordBox1.Password + "</Password>");
sb.AppendLine("</Staff>");
string NewStudent = sb.ToString();
byte[] arr = Encoding.UTF8.GetBytes(NewStudent);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "application/xml";
req.ContentLength = arr.Length;
Stream reqStrm = req.GetRequestStream();
reqStrm.Write(arr, 0, arr.Length);
reqStrm.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
MessageBox.Show("Staff Creation: Status " + resp.StatusDescription);
reqStrm.Close();
resp.Close();
}
Web Service side:
#region POST
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/Staff")]
void AddStaff(Staff staff);
#endregion
public void AddStaff(Staff staff)
{
staff.StaffID = (++eCount).ToString();
staff.Salt = GenerateSalt();
byte[] passwordHash = Hash(staff.Password, staff.Salt);
staff.Password = Convert.ToBase64String(passwordHash);
staffmembers.Add(staff);
}
All fine on that side, but Im looking to "import" the staff details from an excel spreadsheet, not sure if import is the correct word but I want to take the first names and last names contained in such n such spreadsheet and add them to the web service from the client side wpf application.
How would I go about it? I have my open file dialog:
private void Import_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dlg.FileName;
}
}
So I open my excel spread sheet then how would I go about taking the inner contents and sending it to the web service? Really stuck on the code or how to go about it :/
Just looking for an automated way of adding staff members rather than manually typing the names, but seeing as the staff excel doc could be named anything I wanted the open file dialog box. The structure inside will always be the same first name then last name.
First, here is my test Excel file that contains the Staff you want to import:
(Column 'A' if first name, column 'B' is last name and column 'C' is the password...)
Ok, so assuming that your code calling your web service works, here is my version of the Import_Click method (and a generic method to save new staff):
private void Import_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dlg.FileName;
Microsoft.Office.Interop.Excel.Application vExcelObj = new Microsoft.Office.Interop.Excel.Application();
try
{
Workbook theWorkbook = vExcelObj.Workbooks.Open(filename, Type.Missing, true);
Worksheet sheet = theWorkbook.Worksheets[1]; // This is assuming that the list of staff is in the first worksheet
string vFirstName = "temp";
string vLastName = "temp";
string vPassword = "temp";
int vIndex = 1;
while (vFirstName != "")
{
// Change the letters of the appropriate columns here!
// In my example, 'A' is first name, 'B' is last name and 'C' is the password
vFirstName = sheet.get_Range("A" + vIndex.ToString()).Value.ToString();
vLastName = sheet.get_Range("B" + vIndex.ToString()).Value.ToString();
vPassword = sheet.get_Range("C" + vIndex.ToString()).Value.ToString();
this.SaveNewStaff(vFirstName, vLastName, vPassword);
vIndex++;
}
}
catch (Exception ex)
{
MessageBox.Show("Error processing excel file : " + ex.Message);
}
finally {
vExcelObj.Quit();
}
}
}
private void SaveNewStaff(string firstName, string lastName, string password) {
string uri = "http://localhost:8001/Service/Staff";
StringBuilder sb = new StringBuilder();
sb.Append("<Staff>");
sb.AppendLine("<FirstName>" + firstName + "</FirstName>");
sb.AppendLine("<LastName>" + lastName + "</LastName>");
sb.AppendLine("<Password>" + password + "</Password>");
sb.AppendLine("</Staff>");
string NewStudent = sb.ToString();
byte[] arr = Encoding.UTF8.GetBytes(NewStudent);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "application/xml";
req.ContentLength = arr.Length;
Stream reqStrm = req.GetRequestStream();
reqStrm.Write(arr, 0, arr.Length);
reqStrm.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
//MessageBox.Show("Staff Creation: Status " + resp.StatusDescription);
reqStrm.Close();
resp.Close();
}
Note: I have REMed out the MessageBox in the call to the web service to make sure you are not annoyed by it if the list is long, but you are free to "unREM" it if you need confirmation for every staff creation. In the same line of taught, there is not validation that the creation has occurred successfully. I would need more details to create a decent validation process.
Also VERY important, this does not validate if the staff you are saving already exists in the list. If you re-run this import procedure multiple times, it may (and probably will) create duplicate entries.
Cheers
Is there any way to render a Silverlight text to a path or graphics object at runtime? I know this can be done using the design tools, but I want to be able to do this on the fly.
I've seen an example that calls a webservice which uses WPF constructs to convert a WPF FormattedText object to a PathGeometry, but those objects aren't available in Silverlight.
I'm pretty sure this just isn't supported in Silverlight, but thought it was worth asking.
As you suspected, you'd have to do it server-side to convert the text to a PathGeometry which is supported in Silverlight.
What are you trying to achieve?
Here is the code for creating a SilverLight path Geometry dynamically.
or creating a SilverLight path from a string.
Just paste below method in a new class or in existing class and it will be ready to use.
you can find a sample code to use this functions at bottom of the method.
/// Method tested with SilverLight 2.0
// this method will generates path with the data string
public PathGeometry getPathGeometry(string data)
{
PathGeometry pg = new PathGeometry();
PathSegmentCollection psc = new PathSegmentCollection();
PathFigure pf = new PathFigure();
PathFigureCollection pfc = new PathFigureCollection();
data= data.Replace("M "," M").Replace("C "," C").Replace("L "," L");
string[] str = data.Split(' ');
for (int i = 0; i < str.Length; i++)
{
if (str[i].StartsWith("C") || str[i].StartsWith("c"))
{
string[] item = str[i].Split(',');
string[] item1 = str[i + 1].Split(',');
string[] item2 = str[i + 2].Split(',');
BezierSegment bs = new BezierSegment();
bs.Point1 = new Point(double.Parse(item[0].Substring(1)), double.Parse(item[1]));
bs.Point2 = new Point(double.Parse(item1[0]), double.Parse(item1[1]));
bs.Point3 = new Point(double.Parse(item2[0]), double.Parse(item2[1]));
i += 2;
psc.Add(bs);
}
else if (str[i].StartsWith("L") || str[i].StartsWith("l"))
{
string[] item = str[i].Split(',');
LineSegment ls = new LineSegment();
ls.Point = new Point(double.Parse(item[0].Substring(1)), double.Parse(item[1]));
psc.Add(ls);
}
else if (str[i].StartsWith("M") || str[i].StartsWith("m"))
{
string[] item = str[i].Split(',');
pf.StartPoint = new Point(double.Parse(item[0].Substring(1)), double.Parse(item[1]));
}
else if (str[i].StartsWith("z") || str[i].StartsWith("Z"))
{
pf.IsClosed = true;
}
}
pf.Segments = psc;
pfc.Add(pf);
pg.Figures = pfc;
return pg;
}
///// End of Method
Sample Code for calling method
Path path = new Path();
string str = " F1 M 933.291,430.505C 924.367,415.673 923.007,387.822 922.503,370.604C 921.343,331.31 944.994,317.76 975.999,296.994L 949.334,299.957C 938.729,302.545 930.572,309.925 920.255,313.368C 901.85,319.521 886.504,313.062 870.896,303.53C 850.12,290.842 831.457,270.65 815.107,251.462C 806.279,241.101 798.257,221.598 781.986,226.017C 767.327,229.99 760.199,246.869 743.058,244.012C 737.559,227.262 741.368,204.78 739.591,187.029C 738.108,172.136 733.986,158.933 733.996,143.736C 734.003,128.417 734.091,113.088 733.996,97.7689C 733.909,83.5475 730.302,82.6582 716.114,86.0475C 687.558,92.8796 663.68,115.232 634.418,119.337C 622.391,121.028 598.323,121.184 603.745,103.642C 603.745,103.642 547.667,116.478 522.623,101.969L 397.73,43.1915C 374.54,33.5875 352.799,21.5236 330.186,10.7568C 315.067,3.55951 298.84,3.50623 282.684,6.54358C 268.628,9.18353 252.14,8.36884 238.73,13.0222C 227.932,16.7648 225.711,27.0569 220.839,35.6369C 204.622,64.1582 184.474,89.9609 163.49,115.642C 143.3,140.356 124.747,161.949 100.268,182.977C 76.4618,203.437 58.0045,230.722 39.6698,256.062C 27.9845,272.228 10.5298,295.73 5.62447,315.546C 1.21381,333.368 7.65381,345.95 16.7778,360.225C 30.9738,382.42 52.4365,394.917 74.4578,408.658C 108.356,429.826 144.964,432.43 182.619,439.202C 194.226,441.284 201.93,444.466 212.456,450.234C 228.9,459.261 246.18,466.181 262.031,476.002C 277.378,485.518 288.175,498.328 306.771,498.502C 331.423,498.729 342.159,498.364 359.554,517.221C 368.632,527.06 372.859,537.585 380.38,548.114C 395.159,568.82 409.076,590.689 426.295,609.442C 440.326,624.728 467.967,633.601 487.652,636.902C 505.622,639.908 521.979,632.736 535.859,620.806C 545.402,612.606 552.478,602.246 557.978,591.161C 561.915,583.213 564.966,568.085 572.399,564.296C 578.046,561.41 595.117,563.91 601.338,564.312C 612.171,565.009 621.722,568.994 632.552,569.976C 651.071,571.65 654.679,567.992 668.187,558.989C 681.275,550.254 697.746,547.268 711.451,538.109C 733.726,523.208 751.861,501.273 773.035,484.254C 795.099,466.53 815.65,437.337 845.207,434.924C 871.813,432.754 933.291,430.505 933.291,430.505 Z";
path.Data = getPathGeometry(str);
I'm building a demo app in WPF, which is new to me. I'm currently displaying text in a FlowDocument, and need to print it.
The code I'm using looks like this:
PrintDialog pd = new PrintDialog();
fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = pd.PrintableAreaWidth;
IDocumentPaginatorSource dps = fd;
pd.PrintDocument(dps.DocumentPaginator, "flow doc");
fd is my FlowDocument, and for now I'm using the default printer instead of allowing the user to specify print options. It works OK, except that after the document prints, the FlowDocument displayed on screen has changed to to use the settings I specified for printing.
I can fix this by manually resetting everything after I print, but is this the best way? Should I make a copy of the FlowDocument before I print it? Or is there another approach I should consider?
yes, make a copy of the FlowDocument before printing it. This is because the pagination and margins will be different. This works for me.
private void DoThePrint(System.Windows.Documents.FlowDocument document)
{
// Clone the source document's content into a new FlowDocument.
// This is because the pagination for the printer needs to be
// done differently than the pagination for the displayed page.
// We print the copy, rather that the original FlowDocument.
System.IO.MemoryStream s = new System.IO.MemoryStream();
TextRange source = new TextRange(document.ContentStart, document.ContentEnd);
source.Save(s, DataFormats.Xaml);
FlowDocument copy = new FlowDocument();
TextRange dest = new TextRange(copy.ContentStart, copy.ContentEnd);
dest.Load(s, DataFormats.Xaml);
// Create a XpsDocumentWriter object, implicitly opening a Windows common print dialog,
// and allowing the user to select a printer.
// get information about the dimensions of the seleted printer+media.
System.Printing.PrintDocumentImageableArea ia = null;
System.Windows.Xps.XpsDocumentWriter docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia);
if (docWriter != null && ia != null)
{
DocumentPaginator paginator = ((IDocumentPaginatorSource)copy).DocumentPaginator;
// Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
Thickness t = new Thickness(72); // copy.PagePadding;
copy.PagePadding = new Thickness(
Math.Max(ia.OriginWidth, t.Left),
Math.Max(ia.OriginHeight, t.Top),
Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right),
Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom));
copy.ColumnWidth = double.PositiveInfinity;
//copy.PageWidth = 528; // allow the page to be the natural with of the output device
// Send content to the printer.
docWriter.Write(paginator);
}
}
You can use the code from the URL below, it wraps the flow document in a fixed document and prints that, the big advantage is that you can use it to add margin, headers and footers.
https://web.archive.org/web/20150502085246/http://blogs.msdn.com:80/b/fyuan/archive/2007/03/10/convert-xaml-flow-document-to-xps-with-style-multiple-page-page-size-header-margin.aspx
The following works with both text and non-text visuals:
//Clone the source document
var str = XamlWriter.Save(FlowDoc);
var stringReader = new System.IO.StringReader(str);
var xmlReader = XmlReader.Create(stringReader);
var CloneDoc = XamlReader.Load(xmlReader) as FlowDocument;
//Now print using PrintDialog
var pd = new PrintDialog();
if (pd.ShowDialog().Value)
{
CloneDoc.PageHeight = pd.PrintableAreaHeight;
CloneDoc.PageWidth = pd.PrintableAreaWidth;
IDocumentPaginatorSource idocument = CloneDoc as IDocumentPaginatorSource;
pd.PrintDocument(idocument.DocumentPaginator, "Printing FlowDocument");
}
I am also generating a WPF report off a Flow document, but I am purposely using the flow document as a print preview screen. I there for want the margins to be the same. You can read about how I did this here.
In your scenario I'm thinking why not just make a copy of your settings, instead of the entire flow document. You can then re-apply the settings if you wish to return the document back to it's original state.