<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Dino's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/dinoviehland/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/dinoviehland/feed.xml</link>
    <description>.NET Stuff</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:48:54 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Announcing Python Tools for Visual Studio 1.0</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/announcing-python-tools-for-visual-studio-1-0</link>
      <pubDate>Wed, 31 Aug 2011 13:25:01 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2011/08/31/announcing-python-tools-for-visual-studio-1-0/</guid>
      <description><![CDATA[As you can see from Soma's blog on Monday we released Python Tools for Visual Studio 1.0.&nbsp; Of...]]></description>
      <content:encoded><![CDATA[<p>As you can see from <a title="Soma's Blog" href="https://blogs.msdn.com/b/somasegar/archive/2011/08/29/python-tools-for-visual-studio.aspx">Soma's blog</a> on Monday we released <a title="Python Tools for Visual Studio 1.0" href="https://pytools.codeplex.com">Python Tools for Visual Studio 1.0</a>.&nbsp; Of course I'm excited about this release as it's been the 1st stable release I've put since IronPython 2.6 (and the first blog too!).&nbsp; This release of PTVS focuses on a combination of the core IDE experience (intellisense, debugging, profiling, code navigation, etc..) as well as a set of features which target Technical / High Performance Computing.&nbsp; That includes support for MPI cluster debugging and integrated IPython support.&nbsp;</p>
<p>PTVS has been a long time in the making and it represents the fruition of a lot of effort here at Microsoft to produce a Python IDE.&nbsp; This actually goes back a long time starting it's development several years ago on the IronPython team.&nbsp; Back then we had done several small projects to figure out what we'd want to do in the Python IDE space.&nbsp; That included a couple of attempts of building a stand alone IDE using the same components Visual Studio is built upon as a few different attempts at extending Visual Studio to add Python support (some of this having seen the light of day in the form of IronPython Studio and the Python integration which ships w/ the VS SDK).&nbsp; Ultimately we were able to re-use bits and pieces from all of these attempts and release IronPython Tools for Visual Studio w/ the Alpha of IronPython 2.7.&nbsp;</p>
<p>But we needed one last push to turn PTVS into what you see today - and that final push brought support for more than just IronPython and we now have turned Visual Studio into a general purpose Python IDE.&nbsp; Whatever version of Python you'd like to use I think you'll find that PTVS provides a great experience - whether you're using traditional CPython or IronPython (which we still have special support for including WPF designer support) or another Python distribution such as the speedy PyPy.&nbsp; The only feature which doesn't currently work across Python distributions is the profiling support which for performance reasons is tied to the CPython embedding API.</p>
<p>Anyway, if you're looking for doing Python development on Windows I hope you'll give PTVS a shot and let us know what you think.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>IronPython 2.6 Released!</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/ironpython-2-6-released</link>
      <pubDate>Fri, 11 Dec 2009 15:44:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2009/12/11/ironpython-2-6-released/</guid>
      <description><![CDATA[I've very happy to announced that we've officially released IronPython 2.6!&nbsp; This is a great...]]></description>
      <content:encoded><![CDATA[<P>I've very happy to announced that we've officially released IronPython 2.6!&nbsp; This is a great release which brings us up to date with the stable CPython 2.x branch, greatly improves startup time performance, continues to improve our support for deep .NET integration, adds major new features like pdb and sys.settrace support, and as usual we've fixed a ton of bugs along the way.&nbsp; It's also identical to RC3 in every way so if you've already installed RC3 you're ready to go!&nbsp; If not you can download it now from CodePlex: <SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; COLOR: black; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><A href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=12482">https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=12482</A></SPAN></P>
<P><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; COLOR: black; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">Here's the full release notes if you'd like more details about what's changed:</SPAN></P>
<P><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; COLOR: black; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">&nbsp;</SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; COLOR: black; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><SPAN style="COLOR: black">Hello Python Community,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">We’re proud to announce the release of IronPython 2.6 final.&nbsp; This is a major release with improvements across all areas of IronPython and can be downloaded from <A href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=12482">https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=12482</A>.&nbsp; Significant changes include:<o:p></o:p></SPAN></P>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in" class=MsoListParagraph><SPAN style="FONT-FAMILY: Symbol; COLOR: black">·</SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: black">Updating the language and standard library to match CPython 2.6<o:p></o:p></SPAN></P>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in" class=MsoListParagraph><SPAN style="FONT-FAMILY: Symbol; COLOR: black">·</SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: black">Improved .NET integration<o:p></o:p></SPAN></P>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in" class=MsoListParagraph><SPAN style="FONT-FAMILY: Symbol; COLOR: black">·</SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: black">Updating to the latest version of the DLR<o:p></o:p></SPAN></P>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in" class=MsoListParagraph><SPAN style="FONT-FAMILY: Symbol; COLOR: black">·</SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: black">Adding previously missing CPython features and fixing bugs<o:p></o:p></SPAN></P>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in" class=MsoListParagraph><SPAN style="FONT-FAMILY: Symbol; COLOR: black">·</SPAN><SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: black">Performance improvements in particular startup time improvements<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">Python 2.6 support includes a large number of new features which include support for the new bytes and byte array types (<A href="https://www.python.org/dev/peps/pep-3112/" target=_blank><FONT color=#0000ff>PEP 3112</FONT></A>), decorators for classes (<A href="https://www.python.org/dev/peps/pep-3129/" target=_blank><FONT color=#0000ff>PEP 3129</FONT></A>), advanced string formatting (<A href="https://www.python.org/dev/peps/pep-3101/" target=_blank><FONT color=#0000ff>PEP 3101</FONT></A>) which will feel familiar to .NET users and integrates nicely with IFormattable, print as a function (<A href="https://www.python.org/dev/peps/pep-3105/" target=_blank><FONT color=#0000ff>PEP 3105</FONT></A>), Abstract Base Classes (<A href="https://www.python.org/dev/peps/pep-3119/" target=_blank><FONT color=#0000ff>PEP 3119</FONT></A>), support for binary literals, along with lots of other minor features and changes.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">IronPython also continues to improve .NET integration in this release.&nbsp; We’ve added the <A href="https://ironpython.net/ironpython/documentation/dotnet/dotnet.html#clrtype" target=_blank><FONT color=#0000ff>__clrtype__ method</FONT></A> to types which enables deep integration via meta-classes with the .NET type system.&nbsp; There are also a number of smaller changes such as supporting <A href="https://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=24503" target=_blank><FONT color=#0000ff>IDisposable in for loops</FONT></A> matching the behavior of other .NET languages.&nbsp; This release also includes the latest version of the DLR and fixes a number of issues related to cross-language dynamic interop.&nbsp; Not to be left out there’s improvements in Silverlight integration by supporting <A href="https://ironpython.net/browser/sl-back-to-just-text.pdf" target=_blank><FONT color=#0000ff>Python code in HTML script tags</FONT></A>.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">We’ve also continued to improve Python compatibility by adding missing features and fixing bugs.&nbsp; In this release we’ve added support for the <A href="https://docs.python.org/library/ctypes.html" target=_blank><FONT color=#0000ff>ctypes</FONT></A> module which provides interop with native code in a compatible way across Python implementations.&nbsp; We’ve also implemented sys.settrace to provide support for the <A href="https://docs.python.org/library/pdb.html" target=_blank><FONT color=#0000ff>pdb</FONT></A> module and other Python debuggers.&nbsp; This release also changes how we support sys._getframe: a fully working version is now available by a command line option;&nbsp; when not enabled sys._getframe doesn’t exist at all. This release also fixes over 400 bugs removing a large number of smaller incompatibilities.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">As always we’ve also continued to improve performance, and this release primarily focuses on improving startup time.&nbsp; The IronPython installer now pre-compiles (ngens) IronPython during installation on both 32-bit and 64-bit platforms.&nbsp; Modules are now interpreted initially and hot functions are compiled for faster import times.&nbsp; A number of other code paths that used to involve runtime code generation have been optimized to be contained within the pre-compiled IronPython binaries.&nbsp; We’ve also made a number of smaller changes which improve performance in other areas such as adding constant folding. <o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">Finally we’d like to thank everyone who reported issues and helped make this a better release:&nbsp; Anders M. Mikkelsen, Dan Eloff, Zachc, yamakox, vernondcole, VAks, tscottw, tonyandrewmeyer, tomwright, TomasMatousek, tkamiya, timers, srivatsn, sopeajw, saveenr, sanxiyn, rridge, ronniemaor, quirogaco, pythonfoo, pysunil, pm100, pl6306, paulfelix, orestis, olegt, oldman, NDHUMuscle, mycall, mmaly, mmacdonaldssfcu, maplpro, luntain, llaske, lbaker, Lawouach, laurionb, laughingboy, kurhan, kuno, kowenswp, klrohe, kevgu, jmesserly, jlunder, jdhardy, jbevain, jackeyoo, hhonisch, gz, gjones, fwereade, deadalusai, daveremy, Seo Sanghyeon, CurtHagenlocher, chaghi, cgravill, cartman, bobarnso, atifaziz, ashcor, alvanet, Helmut, fuzzyman, fabiofz, Eloff, RuiDC, Kevin Chu, Kyle Howland-Rose egonw, davec, dungen, dsblank, cjacobs, dmajnemer, leppie, Mark Rees, soulfry, tatwright, ufechner and wilberforce.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">Thank you for your continued support of IronPython.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="COLOR: black">The IronPython Team<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="mso-bidi-font-family: 'Times New Roman'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-theme-font: minor-bidi; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"><o:p>&nbsp;</o:p></SPAN></P></SPAN>]]></content:encoded>
    </item>
    <item>
      <title>World's Worst Paint Program</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/worlds-worst-paint-program</link>
      <pubDate>Tue, 17 Nov 2009 13:58:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2009/11/17/worlds-worst-paint-program/</guid>
      <description><![CDATA[I've uploaded the World's Worst Paint Program, as seen in my PDC talk,&nbsp;to IronPython's CodePlex...]]></description>
      <content:encoded><![CDATA[<P>I've uploaded the World's Worst Paint Program, as seen in my PDC talk,&nbsp;to IronPython's CodePlex site:</P>
<P>&nbsp;<A href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28125#DownloadId=93331">https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28125#DownloadId=93331</A></P>
<P>&nbsp;This is built using Visual Studio 2010 Beta 2 and the IronPython CTP for that release - so you'll need to download both of those.&nbsp; I've also included the Python and Ruby code that I used during the demonstration in a file called code.txt.&nbsp; The paint program it's self is in the final form at the end of the demo.</P>]]></content:encoded>
    </item>
    <item>
      <title>Microsoft.Dynamic - Getting Started w/ a Language</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/microsoft-dynamic-getting-started-w-a-language</link>
      <pubDate>Tue, 17 Nov 2009 13:38:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2009/11/17/microsoft-dynamic-getting-started-w-a-language/</guid>
      <description><![CDATA[Want to create a language on top of the DLR?&nbsp;&nbsp; Well the first thing you need to do is plug...]]></description>
      <content:encoded><![CDATA[<P>Want to create a language on top of the DLR?&nbsp;&nbsp; Well the first thing you need to do is plug into the language side of the hosting APIs.&nbsp; Once you've done that you'll also discover that you have a bunch of additional functionality which enables you to quickly get started with common tasks such as calling methods, getting members, etc..&nbsp; Here's just a simple code dump with some additional comments of how to get started.</P>
<P>&nbsp;First let's go ahead and create our LanguageContext:</P>
<P>public class MyContext : LanguageContext {<BR>&nbsp;&nbsp;&nbsp; public MyBinder Binder;<BR>&nbsp;&nbsp;&nbsp; public MyContext(ScriptDomainManager manager, IDictionary&lt;string, object&gt; options) : base(manager) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Binder = new MyBinder(manager);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; public override ScriptCode CompileSourceCode(Microsoft.Scripting.SourceUnit source, Microsoft.Scripting.CompilerOptions options,Microsoft.Scripting.ErrorSink errorSink) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new NotImplementedException();<BR>&nbsp;&nbsp;&nbsp; }<BR>}</P>
<P>For now you're going to have to figure out how to parse and compile code on your own.&nbsp; But the interesting point I'd like to highlight right now is the MyBinder class which is implemented&nbsp;like this:&nbsp;</P>
<P>public class MyBinder : DefaultBinder {<BR>&nbsp;&nbsp;&nbsp; public MyBinder(ScriptDomainManager manager) : base(manager) { <BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; public override bool CanConvertFrom(Type fromType, Type toType, bool toNotNullable, NarrowingLevel level) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return toType.IsAssignableFrom(fromType);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; public override Candidate PreferConvert(Type t1, Type t2) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Candidate.Ambiguous;<BR>&nbsp;&nbsp;&nbsp; }<BR>}</P>
<P>&nbsp;With this class implemented I can now start doing .NET binding when I'm trying to resolve method calls, member accesses, or other .NET APIs.&nbsp; But if I'm going to be calling methods (and you'll frequently call methods if you're resolving members - because methods are methods, properties are methods, events are implemented using methods, etc...) then you'll need something which also chooses which overload of a method to call.&nbsp; For this we have a overload resolver factory and and overload resolver.&nbsp; You need to give the binder the factory and it'll then create a resolver for a set of methods which need to be resolved:</P>
<P>internal sealed class DefaultOverloadResolverFactory : OverloadResolverFactory {<BR>&nbsp;&nbsp;&nbsp; private readonly DefaultBinder _binder;</P>
<P>&nbsp;&nbsp;&nbsp; public DefaultOverloadResolverFactory(DefaultBinder binder) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _binder = binder;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; public override DefaultOverloadResolver CreateOverloadResolver(IList&lt;DynamicMetaObject&gt; args, CallSignature signature, CallTypes callType) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new DefaultOverloadResolver(_binder, args, signature, callType);<BR>&nbsp;&nbsp;&nbsp; }<BR>}</P>
<P>Ok, now we've got a language, a binder, and an overload resolver.&nbsp; So at this point we're ready to implement a normal DLR&nbsp;binder.&nbsp; There's a bunch of base classes which can be derived from&nbsp;for&nbsp;the various protocols which are supported by the DLR.&nbsp; &nbsp;Here I'm going to implement a get member and invoke member binder to give a quick demonstration of how you interact with a DefaultBinder subclass.&nbsp; </P>
<P mce_keep="true">&nbsp;</P>
<P>public class MyGetMemberBinder : GetMemberBinder {<BR>&nbsp;&nbsp;&nbsp; private readonly MyBinder _binder;<BR>&nbsp;&nbsp;&nbsp; public MyGetMemberBinder(MyBinder binder, string name) : base(name, false) { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _binder = binder;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var resolver = new DefaultOverloadResolverFactory(_binder);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var res = _binder.GetMember(Name, target, resolver);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (res.Expression.Type.IsValueType) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res = new DynamicMetaObject(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression.Convert(res.Expression, typeof(object)),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res.Restrictions<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return res;<BR>&nbsp;&nbsp;&nbsp; }<BR>}</P>
<P>public class MyInvokeBinder : InvokeBinder {<BR>&nbsp;&nbsp;&nbsp; private readonly MyBinder _binder;<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; public MyInvokeBinder(MyBinder binder, CallInfo callInfo) : base(callInfo) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _binder = binder;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var resolver = new DefaultOverloadResolverFactory(_binder);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return _binder.Call(new CallSignature(CallInfo.ArgumentCount), resolver, target, args);<BR>&nbsp;&nbsp;&nbsp; }<BR>}</P>
<P mce_keep="true">&nbsp;</P>
<P>Finally we're ready to put it all together.&nbsp; We can create a ScriptRuntime which has our language setup, we can get our language context, and then create a few CallSites which will use our newly created binders:</P>
<P>public class Test {<BR>&nbsp;&nbsp;&nbsp; public static void Main() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScriptRuntimeSetup setup = new ScriptRuntimeSetup();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setup.LanguageSetups.Add(CreateLanguageSetup());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var sr = new ScriptRuntime(setup);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var engine = sr.GetEngine("test");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var myCtx = (MyContext)HostingHelpers.GetLanguageContext(engine);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var binder = myCtx.Binder;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CallSite&lt;Func&lt;CallSite, object, object&gt;&gt; getMemSite = CallSite&lt;Func&lt;CallSite, object, object&gt;&gt;.Create(new MyGetMemberBinder(binder, "Length"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(getMemSite.Target(getMemSite, new[] { 1, 2, 3}));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CallSite&lt;Func&lt;CallSite, object, object, object, object&gt;&gt; invokeSite = CallSite&lt;Func&lt;CallSite, object, object, object, object&gt;&gt;.Create(new MyInvokeBinder(binder, new CallInfo(2)));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(invokeSite.Target(invokeSite, new ParamsDelegate(ParamsMethod), 1, 2));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; public delegate object ParamsDelegate(params object[] args);<BR>&nbsp;&nbsp;&nbsp; public static object ParamsMethod(params object[] args) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach(object o in args) { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(o);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 42;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; public static LanguageSetup/*!*/ CreateLanguageSetup() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var setup = new LanguageSetup(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeof(MyContext).AssemblyQualifiedName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "test",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new[] { "test"},<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new[] { ".tst" } <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return setup;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>}<BR>&nbsp;</P>
<P>Viola, we've created the start of a language as far as the DLR is concerned. We don't yet support parsing and compiling code but we can interact with .NET objects.&nbsp; There's still a bunch of things we could customize on both the DefaultBinder and OverloadResolver to customize how the binding and calls occur.&nbsp; But that'll have to wait until a future blog.</P>]]></content:encoded>
    </item>
    <item>
      <title>Two IronPython releases in 1 week</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/two-ironpython-releases-in-1-week</link>
      <pubDate>Thu, 23 Jul 2009 13:04:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2009/07/23/two-ironpython-releases-in-1-week/</guid>
      <description><![CDATA[This was a good week for IronPython - we've released not one but two new versions!
The first...]]></description>
      <content:encoded><![CDATA[<P>This was a good week for IronPython - we've released not one but two new versions!</P>
<P>The first release was <A href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22981" mce_href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22981">IronPython 2.0.2</A>&nbsp;which just includes bug fixes for issues which have been particularly irritating to our users.&nbsp; This is a very minor release and doesn't include breaking changes.&nbsp; Probably the most significant fix is that we've fixed ngen on 64-bit platforms.&nbsp; Previously when you would install 2.0 and enable ngen it would only ngen the binaries for 32-bit assemblies.&nbsp; Now we'll ngen for 64-bit which should help users running on 64-bit see much faster startup times.&nbsp; I hope that this will make 2.0 much more usable until we get the really big improvements that 2.6 brings.</P>
<P>And speaking of 2.6 the other release this week was our <A href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27350" mce_href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27350">2nd and final beta</A>.&nbsp; 2.6 is shaping up to be an exciting release.&nbsp; We've significantly improved the startup time of IronPython - this has been our number one requested change.&nbsp; We've implemented more standard modules and other missing functionality to be closer to CPython.&nbsp; This includes the new ctypes module, support for sys.settrace and pdb, as well other new functionality that 2.6 has introduced such as the underlying support for the io module.&nbsp; And finally we've added a bunch of new features to improve .NET interop as well&nbsp;- we've now got support for generic method type inference and added the core support that will enable using .NET attributes and in general working better w/ .NET when static types are expected.&nbsp; I'm pretty excited about this release and can't wait to get the final version out - so please try out this beta and let us know if you run into any issues.</P>]]></content:encoded>
    </item>
    <item>
      <title>On Performance</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/on-performance</link>
      <pubDate>Fri, 22 May 2009 17:23:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2009/05/22/on-performance/</guid>
      <description><![CDATA[Ahh, performance…&nbsp; It’s so much fun!&nbsp; It’s easy to measure and as you work on it you can...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>Ahh, performance…<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It’s so much fun!<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It’s easy to measure and as you work on it you can see immediate benefits (or not!).<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>I personally enjoy getting to spend time looking at interesting performance issues and I’ll use this as a time to plug </FONT><A href="https://ironpython.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25126"><FONT size=3 face=Calibri>IronPython 2.6 Beta 1</FONT></A><FONT size=3 face=Calibri> where we’ve continued our focus in this area.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Even more fun yet is when you compare and contrast different implementations - it can be both surprising and amusing.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Recently Robert Smallshire has been doing just that: </FONT><A href="https://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/"><FONT size=3 face=Calibri>https://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-2-0-and-jython-2-5-performance-compared-to-python-2-5/</FONT></A><FONT size=3><FONT face=Calibri> Obviously Robert has found a case in IronPython where something is performing horribly.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>I’d like to take a look at what’s happening here and what we can do to improve this case.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>But before I look at what’s going on here I’d like to briefly say we love to hear feedback from users of IronPython.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>We’ve have a </FONT><A href="https://lists.ironpython.com/listinfo.cgi/users-ironpython.com"><FONT color=#0000ff size=3 face=Calibri>mailing list</FONT></A><FONT size=3 face=Calibri> you can join and give us your feedback on and </FONT><A href="https://ironpython.codeplex.com/WorkItem/List.aspx"><FONT size=3 face=Calibri>bugs</FONT></A><FONT size=3 face=Calibri> can be reported on </FONT><A href="https://ironpython.codeplex.com/WorkItem/List.aspx"><FONT size=3 face=Calibri>our website</FONT></A><FONT size=3 face=Calibri>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>We track both of these very closely and respond as quickly as we can – which is usually pretty fast.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>I just mention that because it’s easier for us to improve IronPython when people let us know about a problem vs. us having to scour the web to find issues.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Hopefully this piqued interest will have more people trying out IronPython and giving us feedback.</FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>Ok, but let’s get onto the fun technical details!<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It all comes down to one line of code “Node.counter += 1”.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>That’s a pretty innocent looking piece of code, how can it cause so many problems?<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>First you need to understand a little bit about how IronPython works.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>IronPython internally keeps versions of type objects and uses this information to generate optimal code paths for accessing those objects.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>So the next line of code in this example, “self._children = children” usually turns into something that’s like:</FONT></P><FONT face=Calibri><SPAN style="FONT-FAMILY: 'Courier New'">
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3>if (self != null &amp;&amp; self.GetType() == typeof(PyObject) &amp;&amp; self.PythonType.Version == 42) {<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>self._dict["_children"] = &lt;new value&gt;;<o:p></o:p></FONT></SPAN></P>
<P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 10pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3>}<o:p></o:p></FONT></SPAN></P></SPAN></FONT>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>What that one line of code causes then is for the version of the type to change and for this “rule” to be invalidated.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>So we’ll figure out what to do, generate a new cached rule, only to have it not work the next time around.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>The same thing applies to the calls to Node – we re-generate the “optimal” code again and again only to discover we have to throw it away.</FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3><FONT face=Calibri>So that sounds pretty bad but if you’re familiar with Python’s member access rules you’ll quickly recognize that this will be much faster than needing to do the resolution again and again.<SPAN style="mso-spacerun: yes">&nbsp; That involves looking through the class hierarchy to see if we have any data descriptors or classes defining __setattr__ and it's nice to avoid all of that work.&nbsp;&nbsp; So to get the best performance we </SPAN>require for the world to settle down and not be continuously changing.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>We’re well aware of this problem with our implementation and we have continued to focus on improving it.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>IronPython 2.0 already includes one mitigation so that we don’t need to continuously generate new code – instead we effectively patch new values into an existing piece of code.<SPAN style="mso-spacerun: yes">&nbsp; I</SPAN></FONT></FONT><FONT size=3 face=Calibri>n our IronPython 2.6 branch we’ve continued to improve performance here and significantly reduced the expense when things get mutated.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>But it turns out that there’s an easy fix for this particular problem we’ve just never thought it that important of a problem to solve.</FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>One of the amusing things about this is we’ve actually seen it before – </FONT><A href="https://www.resolversystems.com/"><FONT size=3 face=Calibri>Resolver Systems</FONT></A><FONT size=3 face=Calibri> was having some performance issues with </FONT><A href="https://www.resolversystems.com/download/"><FONT size=3 face=Calibri>Resolver One</FONT></A><FONT size=3 face=Calibri> <SPAN style="mso-spacerun: yes">&nbsp;</SPAN>which is their <SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-fareast-font-family: Calibri; mso-bidi-font-family: 'Times New Roman'; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">advanced </SPAN>spreadsheet which is written in IronPython.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>One of those issues turned to be a type which they both used frequently and mutated frequently.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This actually doesn’t seem to be a common idiom in Python code which is the reason we’ve never optimized for it before.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>In this case though it turned out that they had found an optimization that improved performance on IronPython 1.0 but was destroying perf on IronPython 2.0!<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>For Resolver fixing this was a simple change for them to no longer mutate types.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Even if you really want to use a type as a property bag you can always move that to a type which you aren’t creating instances of and executing methods on.</FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>With all that in mind let’s look at some numbers.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Here I’ve compared IronPython 2.01, IronPython 2.6 Beta 1, CPython 2.6 plus IronPython 2.6 with a fix for this issue.</FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><IMG style="WIDTH: 629px; HEIGHT: 377px" title="Perf Comparison" alt="Perf Comparison" align=middle src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/63/59/75/perf1.png" original-url="https://blogs.msdn.com/photos/dinoviehland/images/9635975/original.aspx" width=629 height=377 mce_src="https://blogs.msdn.com/photos/dinoviehland/images/9635975/original.aspx"></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal mce_keep="true">&nbsp;</P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>Like Robert’s charts I have tree size in number of nodes across the bottom and execution time in seconds across the top and the execution times are logarithmic.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>We can see the abysmal performance of 2.0.1, we can see that 2.6B1 has already made significant improvements, and with IronPython 2.6B1 plus a fix for this specific issue we actually beat CPython as the number of iterations scales up.</FONT></P><FONT size=3 face=Calibri>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal>But there’s another way we can look at this – instead of fixing IronPython let’s look what happens if we fix the benchmark to avoid this performance pitfall.<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>To do this I’ve replaced the mutation of the class with a global variable.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>When running against all of the same implementations again I get these results:</P></FONT>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><IMG style="WIDTH: 621px; HEIGHT: 449px" title="perf 2" alt="perf 2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Components.PostAttachments/00/09/63/59/79/perf2.png" original-url="https://blogs.msdn.com/photos/dinoviehland/images/9635979/original.aspx" width=621 height=449 mce_src="https://blogs.msdn.com/photos/dinoviehland/images/9635979/original.aspx"></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal mce_keep="true">&nbsp;</P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>Here you can see that all 3 versions of IronPython are performing about the same and are coming in significantly faster than CPython as the number of iterations goes up.&nbsp; These are now also matching the numbers Robert is getting when he has made the <A href="https://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-hammers-cpython-when-not-mutating-class-attributes/" mce_href="https://www.smallshire.org.uk/sufficientlysmall/2009/05/22/ironpython-hammers-cpython-when-not-mutating-class-attributes/">same change.</A></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>So you might be curious - what’s the fix?<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Well in this case we’re just mutating the type by changing a simple value stored in the type (versus say adding a property or a method to the type).<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Today we get a very slight throughput performance benefit because we can burn the value directly into the generated code instead of fetching it from the wrapper the type object keeps it in.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>With the fix we’ll burn the wrapper in and fetch the value from the wrapper each time.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Then when we go and modify the type we just modify the wrapper instead of the type and its version is unchanged!<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This fix is now checked into the IronPython source tree and you can </FONT><A href="https://ironpython.codeplex.com/SourceControl/changeset/view/51820"><FONT color=#0000ff size=3 face=Calibri>download the fixed sources</FONT></A><FONT size=3><FONT face=Calibri> right now.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></FONT></FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal><FONT size=3 face=Calibri>In conclusion I’d like to wrap up a little bit about our performance philosophy – performance is hard and deciding which numbers matter to you is important.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>We have tried to tune IronPython for apps which run for more than a fraction of a second.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>We have also tuned IronPython for code which is not constantly mutating types at runtime.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>And we’re always open to feedback when users encounter problems with IronPython and we’ll listen to what scenarios are important for them.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>But if you look at these graphs I think you can see that we’ve done a good job at making IronPython a fast implementation of Python.</FONT></P>
<P style="MARGIN: 0in 0in 10pt" class=MsoNormal mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>A Simple DLR Binder</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/a-simple-dlr-binder</link>
      <pubDate>Wed, 21 Jan 2009 22:11:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2009/01/21/a-simple-dlr-binder/</guid>
      <description><![CDATA[A lot of people find it a little confusing to write their first binder to consume dynamic objects...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>A lot of people find it a little confusing to write their first binder to consume dynamic objects running on the DLR.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It’s not actually super simple but it’s not too hard either.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>To shine some light on this I thought I’d post a very simple binder that shows how you plug in.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This example just supports adding 2 ints.&nbsp; &nbsp;If the target object is an IDynamicObject the object will get the first crack at implementing the operation.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>So for example a class written in IronPython which implements __iadd__ will call the __iadd__ method to do the addition (ok, that’ll be true once I support the current DLR way of doing operations, we’re still using an older version).<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>For objects of any other types which don’t implement IDynamicObject it will report an error indicating the types and the operation kind.&nbsp; Even if you specify a different operation kind it will still just add ints.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>There’s a few key pieces you need to understand here.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>First you’re returning an expression tree back to the DLR to tell the DLR what to do.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>The DLR will compile this expression tree and run it.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>You’re also returning a set of “restrictions”.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>These will be evaluated by the DLR to see if it can re-use the same code for other objects in the future.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>You’re unlimited in what you can do with restrictions as they can be arbitrary Expression trees.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>But here I’m simply restricting based upon the arguments .NET types which is one of the most common restrictions.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Both the expression tree and restrictions get packaged up in a DynamicMetaObject which is conveniently the same type of object you receive as your arguments.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN><o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>Finally there’s the hash identity which is how the DLR knows if it can share rules or not amongst different binders.&nbsp; The base DLR binders override GetHashCode/Equals to hash on the operation, member name, etc… depending on the binder type so I just return this here.<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3 face=Calibri>So here it is a simple binder.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>This targets the latest and greatest DLR sources which has experienced some renames and so isn’t compatible with IronPython 2.0.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>But you can always get the latest IronPython source code which this will compile against at </FONT><A href="https://www.codeplex.com/IronPython/SourceControl/ListDownloadableCommits.aspx"><FONT size=3 face=Calibri>https://www.codeplex.com/IronPython/SourceControl/ListDownloadableCommits.aspx</FONT></A><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp; class MyOperationBinder : BinaryOperationBinder {<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) {<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (target.LimitType == typeof(int) &amp;&amp; arg.LimitType == typeof(int)) {<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new DynamicMetaObject(<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression.Add(<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression.Convert(target.Expression, typeof(int)),<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression.Convert(arg.Expression, typeof(int))<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ),<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BindingRestrictions.GetTypeRestriction(target.Expression, typeof(int)).Merge(BindingRestrictions.GetTypeRestriction(arg.Expression, typeof(int)))<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new DynamicMetaObject(<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression.Throw(<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression.New(<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeof(Exception).GetConstructor(new Type[] { typeof(string) }),<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expression.Constant(<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String.Format("Can't perform operation {0} on {1} and {2}", this.Operation, target.LimitType, arg.LimitType)<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ),<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BindingRestrictions.GetTypeRestriction(target.Expression, typeof(int)).Merge(BindingRestrictions.GetTypeRestriction(arg.Expression, typeof(int)))<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override object CacheIdentity {<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return this; }<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="COLOR: #1f497d"><FONT size=3><FONT face=Calibri>&nbsp;&nbsp;&nbsp; }<o:p></o:p></FONT></FONT></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>]]></content:encoded>
    </item>
    <item>
      <title>IronPython, MS SQL, and PEP 249</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/ironpython-ms-sql-and-pep-249</link>
      <pubDate>Mon, 17 Mar 2008 13:18:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2008/03/17/ironpython-ms-sql-and-pep-249/</guid>
      <description><![CDATA[Over the past week and a half I've spent a little bit of time getting Django 0.96.1 running on...]]></description>
      <content:encoded><![CDATA[<P>Over the past week and a half I've spent a little bit of time getting Django 0.96.1 running on IronPython.&nbsp; The 1st step in doing this was getting a database provider that would run on .NET that would work with Django.&nbsp; For DB backends Django basically follows PEP 249 with a few extensions.&nbsp; Here's the basic DB provider I came up with.&nbsp; It's not quite complete but it was good enough for me to get Django's tutorial running.&nbsp; To use this you just need to copy one of the existing DB backends and replace the code in base.py with the code below.&nbsp; For the rest of the code you can pull it from ado_mssql.&nbsp; </P>
<P>&nbsp;Basically this just uses the .NET System.Data namespace to do the communication with the database server.</P>
<P>import clr<BR>clr.AddReference('System.Data')<BR>from System import Data<BR>from System.Data import SqlClient<BR>import System</P>
<P>DatabaseError = Data.DataException</P>
<P>from threading import local</P>
<P>class SqlCursor(object):<BR>&nbsp;&nbsp;&nbsp; arraysize = 1<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def __init__(self, connection):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connection = connection<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transaction = None<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.reader = None<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.record_enum = None<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def execute(self, sql, params=()):&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parameters = []<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # translate to named parameters<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if type(params) in (list, tuple):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # indexed params, replace any %s w/ @GeneratedName#<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if sql.find('%s') != -1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd = ''<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sqlSplit = sql.split('%s')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for text, value, index in zip(sqlSplit, params, range(len(params))):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd += text + <A href="mailto:'@GeneratedName'">'@GeneratedName'</A> + str(index)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parameters.Add(SqlClient.SqlParameter(<A href="mailto:'@GeneratedName'">'@GeneratedName'</A> + str(index), str(value)))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sql = cmd + sqlSplit[-1]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for name, value in params.iteritems():<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sql = sql.replace('%(' + name +')s', <A href="mailto:'@'">'@'</A> + name)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parameters.Add(SqlClient.SqlParameter(<A href="mailto:'@'">'@'</A> + name, str(value)))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; command = SqlClient.SqlCommand(sql, self.connection)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for param in parameters: command.Parameters.Add(param)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.record_enum = None<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.reader = command.ExecuteReader()<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def close(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.reader.Close()<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def executemany(self, sql, param_list):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res = []<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for s in sql:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res.append(execute(s, param_list))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return res<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def fetchall(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return [self._make_record(record) for record in self.reader]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def fetchone(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.record_enum is None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.record_enum = iter(self.reader)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.record_enum.MoveNext():<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self._make_record(self.record_enum.Current)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return None<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; def fetchmany(self, size=None):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if size is None: size = SqlCursor.arraysize<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res = []<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for i in range(size):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = self.fetchone()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if x is None: break<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; res.append(x)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return res</P>
<P>&nbsp;&nbsp;&nbsp; def _make_record(self, record):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return tuple((self._fix_one_record(record[i]) for i in xrange(record.FieldCount)))</P>
<P>&nbsp;&nbsp;&nbsp; def _fix_one_record(self, record):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if type(record) is System.DateTime:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return datetime.datetime(record)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return record<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; @property<BR>&nbsp;&nbsp;&nbsp; def rowcount(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.record is not None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.reader.RecordsAffected<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1<BR>&nbsp;&nbsp;&nbsp; <BR>class DatabaseWrapper(local):<BR>&nbsp;&nbsp;&nbsp; def __init__(self, **kwargs):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connection = None<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.queries = []<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transaction = None</P>
<P>&nbsp;&nbsp;&nbsp; def cursor(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from django.conf import settings<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.connection is None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not settings.DATABASE_HOST:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; settings.DATABASE_HOST = "(local)"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if settings.DATABASE_NAME == '' or settings.DATABASE_USER == '':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn_string = "Data Source=%s;Initial Catalog=%s;Integrated Security=SSPI;MultipleActiveResultSets=True" % (settings.DATABASE_HOST, settings.DATABASE_NAME)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn_string = "Data Source=%s;Initial Catalog=%s;User ID=%s;Password=%s;Integrated Security=SSPI;MultipleActiveResultSets=True" % (settings.DATABASE_HOST, settings.DATABASE_NAME, settings.DATABASE_USER, settings.DATABASE_PASSWORD)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connection = SqlClient.SqlConnection(conn_string)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connection.Open()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cursor = SqlCursor(self.connection)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if settings.DEBUG:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return util.CursorDebugWrapper(cursor, self)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cursor</P>
<P>&nbsp;&nbsp;&nbsp; def _commit(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.transaction is not None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.transaction.Commit()</P>
<P>&nbsp;&nbsp;&nbsp; def _rollback(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.transaction is not None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.transaction.Rollback()</P>
<P>&nbsp;&nbsp;&nbsp; def close(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.connection is not None:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connection = None<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.transaction = None<BR></P>]]></content:encoded>
    </item>
    <item>
      <title>New opportunities...</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/new-opportunities</link>
      <pubDate>Thu, 17 Nov 2005 15:24:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2005/11/17/new-opportunities/</guid>
      <description><![CDATA[After a little over 4 years it’s time for me to go and explore new opportunities…&nbsp;It's awesome...]]></description>
      <content:encoded><![CDATA[<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">After a little over 4 years it’s time for me to go and explore new opportunities…&nbsp;It's awesome to see Whidbey out there now and I'm sure the work we did to improve the reliability of the CLR and embed it in SQL Server will pay off for our customers.&nbsp; But it's time for me to go and try something new - so I'm switching from the CLR team to... join the CLR team :).</SPAN></P>
<P><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I'll be switching from my current test role over to development to work on on <A href="https://workspaces.gotdotnet.com/ironpython">IronPython</A> and improving the CLR's support for scripting languages in general.&nbsp; I started on the new team last Monday and it's already been a lot of fun.&nbsp; Today we've shipped our first release since I joined (0.9.5 - which you can <A href="https://download.microsoft.com/download/2/0/f/20f8643d-53a1-4ac0-a66f-bf890d32a21b/IronPython-0.9.5.zip">download here</A>.&nbsp; While this is the first release since I've joined the team it's the second release to which I've contributed.&nbsp; This release brings a bug fixes, support for several new built-in types and improvements when using Python objects from WPF.&nbsp; </SPAN></P>
<P><FONT face=Arial size=2>So expect to see less about reliability and hosting (when I post :) ) from me over time and more about IronPython and scripting.&nbsp; I still have some more I want to say about reliability and hosting so there should be an interesting mix going forward.</FONT></P>
<P><FONT face=Arial size=2>Anyway, I encourage everyone to check out our latest release and let us know what you think!</FONT></P>
<P>&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Fiber mode is gone...</title>
      <link>https://docs.microsoft.com/archive/blogs/dinoviehland/fiber-mode-is-gone</link>
      <pubDate>Thu, 15 Sep 2005 16:38:00 GMT</pubDate>
      <dc:creator><![CDATA[DinoV]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dinoviehland/2005/09/15/fiber-mode-is-gone/</guid>
      <description><![CDATA[Well, now that our RTM and RC-esque builds are starting to make it out into the wild it seems like a...]]></description>
      <content:encoded><![CDATA[<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">Well, now that our RTM and RC-esque builds are starting to make it out into the wild it seems like a good time to discuss a feature we had to make go away...<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></FONT></P>
<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">That feature which most readers of my blog are probably now familiar with is fiber mode.&nbsp; So why did we cut fiber mode for the released version of the product?&nbsp; And what changes will you see because of this?<o:p></o:p></SPAN></FONT></P>
<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">We had gone through great efforts to make sure that all of our core functionality worked great inside of a fiber mode host.&nbsp; Not only did the CLR team do a lot of work to make sure fiber mode was solid, but so did many other teams who picked up our toolset and verified that worked properly by running their tests inside of fiber mode.&nbsp; Not to mention the teams that typically run their tests inside of <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on"><st1:State w:st="on">Yukon</st1:State></st1:place> who also make sure their features work in fiber mode.&nbsp; We even spent extra time at the end of beta 2 to make sure we got all the last minute fiber bugs fixed from our full fiber mode test pass - but ultimately it wasn't enough.<o:p></o:p></SPAN></FONT></P>
<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">In the end we had one final exit criteria we'd have to pass in order to make sure fiber mode was solid:&nbsp; Stress.&nbsp; Between the choices of spending our time fixing the bugs that we knew ALL of our customers would hit in thread mode, or fixing the bugs that a small percentage of users would hit in fiber mode, we picked fixing&nbsp;thread mode bugs.&nbsp; In the end I think most customers will be happy as the SQL and CLR teams came together and we've spent a huge amount of time, resources and effort ensuring that SQL/CLR works great under thread mode.<o:p></o:p></SPAN></FONT></P>
<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">For those of you wanting to develop a fiber mode CLR solution I think you need to first ask yourself why you're doing this.&nbsp; If you're attempting to conserve stack space then this is not the solution you're looking for.&nbsp; If you're attempting to reduce the number of context switches experienced then you can still get much the same results using thread mode and blocking "switched out" tasks on an event that gets signaled when it's their turn to run.&nbsp; And of course there's a 3rd, although usually less desirable,&nbsp;option to redesign the way you're approaching the problem of a large number of work items.<o:p></o:p></SPAN></FONT></P>
<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">Finally what are the changes in removing fiber mode?&nbsp; Surprisingly everything will work exactly the same as it did in pre-RC and RTM builds except for one API will now return E_NOTIMPL.&nbsp; That one API is ICLRTask::SwitchOut.&nbsp; You still can do all the interesting stuff with integrating the CLR task management with your own environment, and you can still switch a logical task in on a thread that previously had another logical task running on it, but you can't switch out a logical task during the middle of its lifetime.&nbsp; <o:p></o:p></SPAN></FONT></P>
<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt">I realize removing this feature will cause some of you some pain but I hope you'll see that this was the right call for us to get a super stable Whidbey out the door in a reasonable timeframe.<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"><o:p>&nbsp;</o:p></SPAN></FONT></P>
<P><FONT face="Times New Roman" size=3><SPAN style="FONT-SIZE: 12pt"><o:p>&nbsp;</o:p></SPAN></FONT></P>]]></content:encoded>
    </item>
  </channel>
</rss>