public
Description: Dynamic languages in Silverlight
Homepage: http://sdlsdk.codeplex.com
Clone URL: git://github.com/jschementi/agdlr.git
100644 72 lines (61 sloc) 2.81 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Resources;
using System.Collections.Generic;
 
namespace Microsoft.Scripting.Silverlight {
 
public static class Extension {
 
        private static Action _downloadsCompleted;
 
        public static void FetchCompleted(List<string> assemblyNames, object sender, OpenReadCompletedEventArgs e) {
            var sri = new StreamResourceInfo(e.Result, null);
            foreach (var assembly in assemblyNames) {
                var dll = Application.GetResourceStream(sri,
                    new Uri(string.Format("{0}.dll", assembly), UriKind.Relative));
                if (dll != null) {
                    Package.LanguageAssemblies.Add(dll);
                }
            }
        }
 
        public static void FetchDLR(Action downloadsCompleted) {
            _downloadsCompleted = downloadsCompleted;
            WebClient wc = new WebClient();
            string sRequest = Package.LanguageExtensionUris[0]; // DLR
            wc.OpenReadCompleted += new OpenReadCompletedEventHandler(FetchDLRCompleted);
            wc.OpenReadAsync(new Uri(sRequest, UriKind.Absolute));
        }
 
        public static void FetchDLRCompleted(object sender, OpenReadCompletedEventArgs e) {
            FetchCompleted(Package.DLRAssemblyNames, sender, e);
            FetchRuby();
        }
 
        public static void FetchRuby() {
            WebClient wc = new WebClient();
            var index = 1; // Ruby
            var uri = Package.LanguageExtensionUris[index];
            wc.OpenReadCompleted += new OpenReadCompletedEventHandler(FetchRubyCompleted);
            wc.OpenReadAsync(new Uri(uri));
        }
 
        public static void FetchRubyCompleted(object sender, OpenReadCompletedEventArgs e) {
            FetchCompleted(Package.LanguageAssemblyNames, sender, e);
            FetchPythonExtensions();
        }
 
        public static void FetchPythonExtensions() {
            WebClient wc = new WebClient();
            var index = 2; // Python
            var uri = Package.LanguageExtensionUris[index];
            wc.OpenReadCompleted += new OpenReadCompletedEventHandler(FetchPythonExtensionsCompleted);
            wc.OpenReadAsync(new Uri(uri));
        }
 
        public static void FetchPythonExtensionsCompleted(object sender, OpenReadCompletedEventArgs e) {
            FetchCompleted(Package.LanguageAssemblyNames, sender, e);
            _downloadsCompleted.Invoke();
            _downloadsCompleted = null;
        }
}
}