Dynamic Language Programming with Python – Sample Implementation

DLR is a great invention by Microsoft .NET 4.0 along with Dynamic Typing

The Dynamic Language Runtime (DLR) is piece of technology that unifies dynamic programming on the .NET platform, the same way the Common Language Runtime (CLR) has been a common platform for statically typed languages. CLR always has dynamic capabilities ,DLR is on top of CLR.

Currently IronPython and IronRuby is supported , below is an example of how to consume a python class in C#.

You may need to download the IronPython Library from the below link and install , include those references to your project.

http://ironpython.codeplex.com/

Assume you have python class like below

Calc.py

class Calculator:

   def add(self, argA, argB):

      return argA+argB

   def sub(self, argA, argB):

      return argA-argB

The above said class can be accessed in C# like below

using IronPython.Hosting;

static void Main(string[] args)

{

var enginePY = Python.CreateEngine();

  dynamic calcPYObject = enginePY.ExecuteFile(@”C:\Uday\DynamicPY – Demo Application\DynamicPY – Demo Application\calc.py”);

dynamic calc = calcPYObject.Calculator();

Console.WriteLine(calc.__class__.__name__);

//write ‘Calculator’

double X = 25;

double Y = 10;

double result;

result = calc.add(X, Y);

Console.WriteLine(“{0} + {1} = {2}”, X, Y, result);

 result = calc.sub(X, Y);

Console.WriteLine(“{0} – {1} = {2}”, X, Y, result);

Console.WriteLine(“Press any key to close the application…”);

Console.Read();

        }

    }

Advertisements

WCF – Configuring Instance Management

Instance management refers to the way a service handles a request from a client. Instance management is set of techniques WCF uses to bind client request to service instance, governing which service instance handles which client request.
 
It is necessary because application will differ in their need for scalability, performance, durability, transaction and queued calls.
 
There are three instance modes in WCF:
  1. Per-Call instance mode
  2. Per-Session instance mode
  3. Singleton Instance Mode
 
Configuration:
−Instance mode can be configured using ServiceBehavior attribute. This can be specified at implementing the service contract as shown below.
 
[ServiceContract()]
public interface IPayRollService
{
[OperationContract]
double ProcessSalary();
 }
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class PayRollService:IPayRollService
{
public double ProcessSalary()
{
//Do something
}
}

Sample MVVM Driven WPF Application

WPF has a very powerful data binding feature, that provides an easy one-way or two-way synchronization of properties.

The model-view-viewmodel is a typically WPF pattern. It consists of a view, that gets all the user input and forwards it to the viewmodel, typically by using commands.
 
This is a pattern created by by John Gossman from WPF team.
Below is the sample application which shows up how to implement the WPF PropertyChanged trigger.
 
 XAML implementation

    <DockPanel Margin=”10″>
        <StackPanel DockPanel.Dock=”Right” Margin=”10,0,0,0″>
            <Button Name=”btnAddUser” Click=”btnAddUser_Click”>Add Employee</Button>
            <Button Name=”btnChangeUser” Click=”btnChangeUser_Click” Margin=”0,5″>Change Employee</Button>
            <Button Name=”btnDeleteUser” Click=”btnDeleteUser_Click”>Delete Employee</Button>
        </StackPanel>
        <ListBox Name=”lbUsers” DisplayMemberPath=”Age”></ListBox>
    </DockPanel>

CodeBehind Implementation

 public partial class MainWindow : Window     {      

        private ObservableCollection<Employee> employees = new ObservableCollection<Employee>();

 

        public  MainWindow()                 {

                    InitializeComponent();                        employees.Add(new Employee() { Name = “Aieshwanth Deepak ” ,Age =18});                        employees.Add(new Employee() { Name = “Sharika Shivani”, Age = 19 });                        employees.Add(new Employee() { Name = “Jeeva Rekha”, Age = 28 });

                        lbUsers.ItemsSource = employees;                 }

                private void btnAddEmployee_Click(object sender, RoutedEventArgs e)                 {                         employees.Add(new Employee() { Name = “New Employee” ,Age=25});                 }

                private void btnChangeEmployee_Click(object sender, RoutedEventArgs e)                 {                         if(lbUsers.SelectedItem != null)                         {                                 (lbUsers.SelectedItem as Employee).Name = “Raymond Schenk”;                                 (lbUsers.SelectedItem as Employee).Age = 48;                         }

                }

                private void btnDeleteEmployee_Click(object sender, RoutedEventArgs e)                 {                         if(lbUsers.SelectedItem != null)                                 employees.Remove(lbUsers.SelectedItem as Employee);                 }         }

        public class Employee : INotifyPropertyChanged         {                 private string name;                 public string Name {                         get { return this.name; }                         set                         {                                 if(this.name != value)                                 {                                         this.name = value;                                         this.NotifyPropertyChanged(“Name”);                                 }                         }                 }

                public event PropertyChangedEventHandler PropertyChanged;

                public int _age;

                public int Age                 {                     get { return this._age; }                     set                     {                         if (this._age != value)                         {                             this._age = value;                             this.NotifyPropertyChanged(“Age”);                         }                     }                 }                 public void NotifyPropertyChanged(string propName)                 {                         if(this.PropertyChanged != null)                                 this.PropertyChanged(this, new PropertyChangedEventArgs(propName));                 }         }

 

Hope this helps

Windows 8.1 Preview Released

Microsoft has announced today the release of Windows 8.1 Preview  during Build 2013 conference, great news for Windows app community.

its a free update to Windows 8 coming later this year, and a prerelease version is available now for you to try. Windows 8.1 has new ways to personalize PC and includes a wave of awesome new apps and services.

One can download from the below link.

http://windows.microsoft.com/en-us/windows-8/preview

Lots of cool features Built in Cloud Storage , you can boot now directly to desktop..etc

 

 

 

VS.NET 2013 & Windows 8.1 Preview Released today during Build 2013

Absolutely its a day to remember after looking into the things happening  today at Microsoft side especially releasing several products. One side we have VS.NET 2012 Update 3 which is cumulative update to the existing  VS.NET 2012 and the other side we have VS.NET 2013 preview release , Excellent. Build 2013 conference at San Francisco rocks.

Simple Things to understand what went different on SharePoint 2010

Hope you all guys are rushing towards migration of your products to SP2010 from MOSS 2007. Gudos to SP 2010 team and thier real good work. Okay here is something to understand which is really some basics.

I hope you all guys remember my post of MOSS six pillars and I want to write this post based on that.

Collaboration —> Communities

Business Intelligence — > Insights

Portal —> Compositions

Content Management —> Content

Platform Services —> Sites

The left side is MOSS and obviously your right side is SP 2010

Will post more going forward….

Here we go : Microsoft TechEd 2010

The much awaited tech ed 2010 is going to happen in bangalore by this month April 12-14. A wonderful event  for professionals who want to go ahead.

You can watch the twitter.

http://www.microsoftteched.in/

I am going to take a part and I would request all of you to make use of such wonderful opportunity which occurs only every year.