Posts

Showing posts from September, 2010

C# List sorting

DirectoryInfo dir = new DirectoryInfo(@"C:\temp"); List<FileInfo> files = new List<FileInfo>(dir.GetFiles()); files.Sort((x, y) => DateTime.Compare(x.LastWriteTime,y.LastWriteTime));

WPF Toolkit DataGrid & Chart example

Image
Download WPF ToolkitCreate new WPF Project Add References to WPFTookit, WPFTookit.Design (DataGrid) Add Reference to System.Windows.Controls.DataVisualization.Toolkit (Chart) This is XAML<Windowx:Class="WpfDataGrid.Window2"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"Title="WPF Toolkit DataGrid &amp; Chart"Height="357"Width="590"><DockPanelLastChildFill="True"><toolkit:DataGridItemsSource="{Binding Path=Data}"Height="118"AutoGenerateColumns="False"DockPanel.Dock="Top"><toolkit:DataGrid.Columns><toolkit:DataGridTextColumnBinding="{Binding Date}"Hea…

C# WCF sample with Callback

Image
Create new C# Library ProjectAdd Reference to System.ServiceModelDefine your service interfacenamespace PubSubLibrary { [ServiceContract( CallbackContract = typeof(IPubSubCallback), SessionMode=SessionMode.Required)] publicinterface IPubSubService { [OperationContract(IsOneWay = true)] void Subscribe(string clientId); [OperationContract(IsOneWay = true)] void Publish(string clientId, string message); } }Define your callback interfacenamespace PubSubLibrary { publicinterface IPubSubCallback { [OperationContract(IsOneWay = true)] void Broadcast(CallbackData callbackData); } [DataContract] publicclass CallbackData { [DataMember] publicstring ClientId { get; set; } [DataMember] publicstring Message { get; set; } } }Create Server C# Console ProjectAdd Reference to Library project and System.ServiceModelAdd App.config itemConfigure App.config (right click and select Edit WCF Configuration)<configuration><system.serviceModel><behaviors><serviceBehaviors><behaviorna…

Calling F# function from C# application

Download and install F#Create new Project Visual F# / F# LibraryCreate a sample Modulemodule MathLib let square x = x*x Create new C# Console ProjectAdd Reference to F# Library projectCall function from F# moduleclass Program { staticvoid Main(string[] args) { Console.WriteLine(MathLib.square(4)); Console.ReadLine(); } }