Thursday, January 19, 2012

Ironpython hosting in SilverLight

Here is one of the simplest sample i could make to illustrate.
The only issue i encoutered was adding a reference to 'Microsoft.CSharp'

using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Scripting.Silverlight;


///
/// script.py => def Adder (x, y) : return x + y
///


namespace DLRSilverlight
{
    public partial class MainPage : UserControl
    {
        dynamic runtime = DynamicEngine.CreateRuntime().UseFile("script.py");
               
        public MainPage()
        {
            InitializeComponent();                  
        }
       
        private void button1_Click(object sender, RoutedEventArgs e)
        {            
            dynamic result = runtime.Adder(Convert.ToDouble(this.N1.Text), Convert.ToDouble(this.N2.Text));
            MessageBox.Show(String.Format("{0}", result));
        }        
    }
}

Active Directory with IronPython

Here is a little snippet

import clr
clr.AddReference("System.DirectoryServices")
from System.DirectoryServices import DirectorySearcher

class ADHelper(object):

    def __init__(self, strLDAP = "LDAP://******"):
        self.searcher  =  DirectorySearcher(strLDAP)

    def searchUserByLogin(self,user,*prop):
        """        
        searchUserByLogin("alogin","cn","sn",'SAMAccountName')
        """        
        str = ""
        self.searcher.Filter = "(sAMAccountName=%s)"%user
        self.searcher.PropertiesToLoad.Add("cn")
        self.searcher.PropertiesToLoad.Add("SAMAccountName")
        self.searcher.PropertiesToLoad.Add("givenName")
        self.searcher.PropertiesToLoad.Add("sn")   
        result = self.searcher.FindOne()
        for option in prop:
            str +=  (option + " : " + result.Properties[option][0] + " ")
        return str
    
ad = ADHelper()
print ad.searchUserByLogin("alogin","cn","sn",'SAMAccountName')

Wednesday, January 18, 2012

C# 4.0 First Look :: Dynamic Keyword and Calling Python from C#

C# 4.0 First Look :: Dynamic Keyword and Calling Python from C# « AbdulMoniem's Thoughts

Dynamic keyword, Ironpython and Silverlight

Dynamic keyword, Ironpython and Silverlight? - IronPython - Python on .NET & Mono | Google Groupes

Using an IronPython object from C#

Jorge Fioranelli: Using an IronPython object from C#

 

Calling Python from C#

Calling Python from C# « Network Programming in .NET

 

Using the Dynamic Language Runtime to Call IronPython for VS2010

Using the Dynamic Language Runtime to Call IronPython for VS2010 - Paul Kimmel's Blog

 

Using dynamic in the real world with IronPython

http://blog.filipekberg.se/2011/10/04/using-dynamic-in-the-real-world-with-ironpython/

Using MVVM to bring IronPython and WPF together

Nice sample

http://blogs.southworks.net/dschenkelman/2010/09/21/using-mvvm-to-bring-ironpython-and-wpf-together/

Tuesday, January 17, 2012

IronPyhon - SilverLight Deployment

In order to make IIS serves the application
the following MIME-TYPES must be configured

.py -> text/plain
.slvx -> octet/stream

Scripting C# Silverlight apps with IronPython

From Jimmy Schementi, excelent as usual.

http://blog.jimmy.schementi.com/2009/03/scripting-c-silverlight-apps-with.html

WPF Tutorials

Great links

http://www.wpftutorial.net/

http://www.abhisheksur.com/2010/12/wpf-tutorial.html

DLR in C# - Scripting language

Little example on how to use IronPython in C#

http://www.abhisheksur.com/2011/05/dlr-in-c-using-scripting-language.html

Patterns For Large-Scale JavaScript Application Architecture

Nice article

Patterns For Large-Scale JavaScript Application Architecture

Javascript: self invoked functions

Immediately-Invoked Function Expression (IIFE)



Ben Alman » Immediately-Invoked Function Expression (IIFE)