среда, 24 августа 2011 г.

How to convert TFS folder to branch programmatically by TFS API (Convert to Branch operation in VS2010))


How to convert TFS folder to branch programmatically by TFS API (Convert to Branch operation in VS2010))

First you need create instance of VersionControlServer object. Then use CreateBranchObject method. serverTrunkPath="C:\myWorkspace\trunk" - target folder you want to make branch.

versionControlServer.CreateBranchObject(new BranchProperties(new ItemIdentifier(serverTrunkPath)));

вторник, 10 мая 2011 г.

Working Example of Web.config for WCF-Service IIS hosted for Silverlight with Windows Authentication


<?xml version="1.0" encoding="UTF-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <customErrors mode="RemoteOnly" />
        <authentication mode="Windows" />
      </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <services>
            <service name="web4.TsService">
              <endpoint address="" binding="basicHttpBinding" bindingConfiguration="web4.TsService.customBinding0" contract="web4.TsService">
                  <identity>
                    <dns value="MyDomainName" />
                  </identity>
                  </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
              <host>
                <baseAddresses>
                  <add baseAddress="http://MyServerName.MyDomainName:8080/tfs/web4/"/>
                </baseAddresses>
              </host>
            </service>
        </services>
        <bindings>
            <basicHttpBinding>
                <binding name="web4.TsService.customBinding0">
                  <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Ntlm"></transport>
                  </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client />
    </system.serviceModel>
</configuration>

среда, 4 мая 2011 г.

Silverlight 3 HierarchicalDataTemplate


I was able to get it work!

1) First treaky thing : You must find where HierarchicalDataTemplate is living
xmlns:xctrl="clr-namespace:System.Windows;assembly=System.Windows.Controls"

2) In silverlight you should explicitly point thе template. While in WPF the way you move is type recognition in hierarhy. There is DataType property for HierarchicalDataTemplate in WPF.
Here in silverlight ItemTemplate for ChildTemplate. For child use DataTemplate or HierarhicalDataTemplate




<UserControl x:Class="TestSilverlight5.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:xctrl="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    mc:Ignorable="d"
    d:DesignHeight="337" d:DesignWidth="591" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Loaded="UserControl_Loaded">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <xctrl:HierarchicalDataTemplate x:Key="ChildTemplate">
                <CheckBox Content="{Binding Path=Name}"  IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"></CheckBox>
            </xctrl:HierarchicalDataTemplate>
            <xctrl:HierarchicalDataTemplate x:Key="ParentTemplate" ItemsSource="{Binding Path=Users, Mode=TwoWay}" ItemTemplate="{StaticResource ChildTemplate}">
                <CheckBox FontStyle="Italic" Content="{Binding Path=Name}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"></CheckBox>
            </xctrl:HierarchicalDataTemplate>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="12" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <data:DataGrid AutoGenerateColumns="False" Name="dataGrid1" Grid.Column="2">
            <data:DataGrid.Columns>
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
                <data:DataGridCheckBoxColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" />
            </data:DataGrid.Columns>
        </data:DataGrid>
        <controls:GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" Grid.Row="0" Name="gridSplitter1" Width="12" Cursor="SizeWE">
            <controls:GridSplitter.Background>
                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    <GradientStop Color="#FFBCF1F1" Offset="0" />
                    <GradientStop Color="#FFC8CDCD" Offset="1" />
                    <GradientStop Color="#FFEBFBFB" Offset="0.325" />
                    <GradientStop Color="#FFA3B3B3" Offset="0.797" />
                </LinearGradientBrush>
            </controls:GridSplitter.Background>
        </controls:GridSplitter>
        <Button Content="View" HorizontalAlignment="Left" Margin="7,0,0,5" Name="buttonView" Width="65" Height="23" VerticalAlignment="Bottom" />
        <controls:TreeView Name="treeView" ItemTemplate="{StaticResource ParentTemplate}">

        </controls:TreeView>
    </Grid>
</UserControl>

вторник, 22 марта 2011 г.

Select filename from file path


To get file name from file path by Regex:

string file = Regex.Match(FilePath, @"(?<=([\\/]))([^\\/])*?$").Value;

Example:
FilePath="/UI/Pages/WorkItems/QueryExplorer.aspx"
file="QueryExplorer.aspx"

четверг, 10 февраля 2011 г.

Convert files from Dos to Unix and back.


        private void Unix2Dos(string fileName)
        {
            const byte CR = 0x0D;
            const byte LF = 0x0A;
            byte[] DOS_LINE_ENDING = new byte[] { CR, LF };
            byte[] data = File.ReadAllBytes(fileName);
            using (FileStream fileStream = File.OpenWrite(fileName))
            {
                BinaryWriter bw = new BinaryWriter(fileStream);
                int position = 0;
                int index = 0;
                do
                {
                    index = Array.IndexOf<byte>(data, LF, position);
                    if (index >= 0)
                    {
                        if ( ( index > 0 ) && (data[index - 1] == CR ))
                        {
                            // already dos ending
                            bw.Write(data, position, index - position + 1);
                        }
                        else
                        {
                            bw.Write(data, position, index - position);
                            bw.Write(DOS_LINE_ENDING);
                        }
                        position = index + 1;
                    }
                }
                while (index > 0);
                bw.Write(data, position, data.Length - position);
               fileStream.SetLength(fileStream.Position);
            }
        }

        private void Dos2Unix(string fileName)
        {
            const byte CR = 0x0D;
            const byte LF = 0x0A;
            byte[] data = File.ReadAllBytes(fileName);
            using (FileStream fileStream = File.OpenWrite(fileName))
            {
                BinaryWriter bw = new BinaryWriter(fileStream);
                int position = 0;
                int index = 0;
                do
                {
                    index = Array.IndexOf<byte>(data, CR, position);
                    if ((index >= 0) && (data[index + 1] == LF))
                    {
                        // Write before the CR
                        bw.Write(data, position, index - position);
                        // from LF
                        position = index + 1;
                    }
                }
                while (index > 0);
                bw.Write(data, position, data.Length - position);
                fileStream.SetLength(fileStream.Position);
            }
        }

воскресенье, 6 февраля 2011 г.

DataGrid groupping snippet


What we should get:



XAML:
&lt;Window x:Class="WpfDataGrid1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"&gt;
    &lt;Grid&gt;
        &lt;DataGrid AutoGenerateColumns="False" Margin="15,40,14,12" Name="dataGrid1"&gt;
            &lt;DataGrid.GroupStyle&gt;
                &lt;GroupStyle&gt;
                    &lt;GroupStyle.ContainerStyle&gt;
                        &lt;Style  TargetType="{x:Type GroupItem}"&gt;
                        &lt;Setter Property="Template"&gt;
                            &lt;Setter.Value&gt;
                                &lt;ControlTemplate&gt;
                                    &lt;Expander x:Name="exp" IsExpanded="True"
                                            Background="White"
                                            Foreground="Black"&gt;
                                        &lt;Expander.Header&gt;
                                            &lt;TextBlock Text="{Binding Name}"/&gt;
                                        Expander.Header&gt;
                                        &lt;ItemsPresenter /&gt;
                                    Expander&gt;
                                ControlTemplate&gt;
                            Setter.Value&gt;
                        Setter&gt;
                        Style&gt;
                    GroupStyle.ContainerStyle&gt;
                    &lt;GroupStyle.Panel&gt;
                        &lt;ItemsPanelTemplate&gt;
                            &lt;DataGridRowsPresenter/&gt;
                        ItemsPanelTemplate&gt;
                    GroupStyle.Panel&gt;
                GroupStyle&gt;
            DataGrid.GroupStyle&gt;
            &lt;DataGrid.Columns&gt;
                &lt;DataGridTextColumn Header="Data2" Binding="{Binding Path=MyItemValue}" Width="*"&gt;DataGridTextColumn&gt;
            DataGrid.Columns&gt;
        DataGrid&gt;
    Grid&gt;
Window&gt;

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfDataGrid1
{
    ///

    /// Interaction logic for MainWindow.xaml
    ///
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            List&lt;MyItem&gt; MyItems = new List&lt;MyItem&gt;
                {
                    new MyItem{ MyItemName= "US", MyItemValue=77 },
                    new MyItem{ MyItemName= "US", MyItemValue=778 },
                    new MyItem{ MyItemName= "US", MyItemValue=78 },
                    new MyItem{ MyItemName= "UK", MyItemValue=7 },
                    new MyItem{ MyItemName= "Israel", MyItemValue=9 },
                    new MyItem{ MyItemName= "Turkey", MyItemValue=98 },
                    new MyItem{ MyItemName= "Turkey", MyItemValue=4 }
                };

            CollectionViewSource collection = new CollectionViewSource();
            collection.Source = MyItems;
            PropertyGroupDescription propertyGroupDescription = new PropertyGroupDescription("MyItemName");
            collection.GroupDescriptions.Add(propertyGroupDescription);
            dataGrid1.ItemsSource = collection.View;
        }
    }
}