Showing posts with label IronPython. Show all posts
Showing posts with label IronPython. Show all posts

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/

Thursday, December 22, 2011

Playing with Ironpython and Silverlight

Ironpython plays nicely with Silverlight, especially when using
Gestalt.

Here is how I manage to pass arguments to a 'click event' handler,
assuming you have a button whith an id equal to 'Button1'

<script type="text/python">
        import System
        from System import EventHandler
        class Person(object):
            def __init__(self, name):
                self.name = name
                self.greeted = False        
        def GreetHandler(p):
            def SayHello(s,e):
                if not p.greeted:
                    window.Alert("Hello " + p.name)                    
                else:                    
                    window.Alert("Happy to see you again  " + p.name)
                p.greeted = not p.greeted        
            return SayHello
        p = Person("PAUL")
        document.Button1.AttachEvent('onclick',EventHandler(GreetHandler(p)))
</script>