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 Toolkit Create new WPF Project Add References to WPFTookit, WPFTookit.Design (DataGrid) Add Reference to System.Windows.Controls.DataVisualization.Toolkit (Chart) This is XAML < Window x : 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" > < DockPanel LastChildFill = "True" > < toolkit : DataGrid ItemsSource = "{Binding Path=Data}" Height = "118" AutoGenerateColumns

C# WCF sample with Callback

Image
Create new C# Library Project Add Reference to System.ServiceModel Define your service interface namespace PubSubLibrary { [ServiceContract( CallbackContract = typeof (IPubSubCallback), SessionMode=SessionMode.Required)] public interface IPubSubService { [OperationContract(IsOneWay = true )] void Subscribe( string clientId); [OperationContract(IsOneWay = true )] void Publish( string clientId, string message); } } Define your callback interface namespace PubSubLibrary { public interface IPubSubCallback { [OperationContract(IsOneWay = true )] void Broadcast(CallbackData callbackData); } [DataContract] public class CallbackData { [DataMember] public string ClientId { get ; set ; } [DataMember] public string Message { get ; set ; } } } Create Server C# Console Project Add Reference to Library project and System.ServiceModel Add App.config item Configure App.config (right click and select Edit WCF Configuration) < configuration > < system.serviceModel >

Calling F# function from C# application

Download and install F# Create new Project Visual F# / F# Library Create a sample Module module MathLib let square x = x*x Create new C# Console Project Add Reference to F# Library project Call function from F# module class Program { static void Main( string [] args) { Console.WriteLine(MathLib.square(4)); Console.ReadLine(); } }