[Kde-bindings] KDE/kdebindings/csharp

Arno Rehn kde at arnorehn.de
Fri Dec 5 17:35:28 UTC 2008


SVN commit 892999 by arnorehn:

* Add support for compiling sources at runtime. Supported languages for now:
  C#, Boo, Nemerle, VB.NET (this one doesn't quite work yet - the compiler seems
  to be buggy).
  The first non-blank line in the mainscript file needs to be a comment in the form
  // language:csharp references:System.Xml sources:otherfile.cs
  'meta-comments' for different languages look equivalent. By default references for
  qt-dotnet, kde-dotnet and plasma-dll are added. The default language is C#, the
  default source file is only 'main'. So if a script is written in C#, only needs
  qt, kde and plasma bindings and all the code is contained in 'main', this comment
  can be omitted.
  For each source file a md5 hash is created so it's only recompiled if the source
  was modified.

CCMAIL: kde-bindings at kde.org



 M  +0 -3      kimono/examples/kio/kio_monodoc/kio_monodoc.cs  
 M  +2 -1      plasma/CMakeLists.txt  
 M  +14 -0     plasma/ChangeLog  
 M  +30 -8     plasma/src/PlasmaScriptengineKimono_Applet.cs  
 A             plasma/src/PlasmaScriptengineKimono_Compiler.cs  
 M  +6 -0      qyoto/src/SmokeInvocation.cs  


--- trunk/KDE/kdebindings/csharp/kimono/examples/kio/kio_monodoc/kio_monodoc.cs #892998:892999
@@ -11,9 +11,6 @@
 	public MySlave(QByteArray protocol, QByteArray pool_sock, QByteArray app_sock)
 		: base(protocol, pool_sock, app_sock)
 	{
-		PropertyInfo pi = typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance);
-		AppDomainSetup setup = (AppDomainSetup) pi.GetValue(AppDomain.CurrentDomain, null);
-		setup.ConfigurationFile = Assembly.GetExecutingAssembly().Location + ".config";
 	}
 
 	public static RootTree HelpTree = RootTree.LoadTree();
--- trunk/KDE/kdebindings/csharp/plasma/CMakeLists.txt #892998:892999
@@ -19,7 +19,8 @@
 
 SET(SRC_PLASMASCRIPTENGINEKIMONO
     src/PlasmaScriptengineKimono_Applet.cs
-    src/PlasmaScriptengineKimono_DataEngine.cs)
+    src/PlasmaScriptengineKimono_DataEngine.cs
+    src/PlasmaScriptengineKimono_Compiler.cs)
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/smoke 
 	${CMAKE_CURRENT_SOURCE_DIR}/../qyoto/src ${CMAKE_CURRENT_SOURCE_DIR}/../kimono/src ${QT_INCLUDES})
--- trunk/KDE/kdebindings/csharp/plasma/ChangeLog #892998:892999
@@ -1,3 +1,17 @@
+2008-12-05  Arno Rehn  <arno at arnorehn.de>
+* Add support for compiling sources at runtime. Supported languages for now:
+  C#, Boo, Nemerle, VB.NET (this one doesn't quite work yet - the compiler seems
+  to be buggy).
+  The first non-blank line in the mainscript file needs to be a comment in the form
+  // language:csharp references:System.Xml sources:otherfile.cs
+  'meta-comments' for different languages look equivalent. By default references for
+  qt-dotnet, kde-dotnet and plasma-dll are added. The default language is C#, the
+  default source file is only 'main'. So if a script is written in C#, only needs
+  qt, kde and plasma bindings and all the code is contained in 'main', this comment
+  can be omitted.
+  For each source file a md5 hash is created so it's only recompiled if the source
+  was modified.
+
 2008-12-01  Richard Dale  <richard.j.dale at gmail.com>
 * Added UpdateAllSources() and RemoveSource() slots to the 
   PlasmScripting.DataEngine
--- trunk/KDE/kdebindings/csharp/plasma/src/PlasmaScriptengineKimono_Applet.cs #892998:892999
@@ -1,6 +1,6 @@
 /*
  *   Copyright 2008 by Richard Dale <richard.j.dale at gmail.com>
- *   Copyright 2008, Arno Rehn <arno at arnorehn.de>
+ *   Copyright 2008 by Arno Rehn <arno at arnorehn.de>
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU Library General Public License as
@@ -42,17 +42,34 @@
             QSizeF oldSize = Applet().Size;
             QFileInfo program = new QFileInfo(MainScript());
 
-            appletAssembly = Assembly.LoadFile(program.AbsoluteFilePath());
+            KMimeType mime = KMimeType.FindByFileContent(program.AbsoluteFilePath());
+            try {
+                if (mime.Name().StartsWith("text/")) {
+                    Compiler c = new Compiler(program);
+                    appletAssembly = c.GetAssembly();
+                } else {
+                    appletAssembly = Assembly.LoadFile(program.AbsoluteFilePath());
+                }
+            } catch (Exception e) {
+                Console.WriteLine(e);
+                Object[] parameters = new Object[2];
+                parameters[0] = true;
+                parameters[1] = e.ToString();
+                MethodInfo method = Applet().GetType().GetMethod("SetFailedToLaunch",
+                    BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(System.Boolean),  typeof(System.String) }, null);
+                method.Invoke(Applet(), parameters);
+                return false;
+            }
             
-            // the newly loaded assembly might contain reference other bindings that need to be initialized
+            // the newly loaded assembly might reference other bindings that need to be initialized
             foreach (AssemblyName an in appletAssembly.GetReferencedAssemblies()) {
-                // if the binding has already been initialized (e.g. in SmokeInvocation.InitRuntime()), continue.
                 Assembly a = null;
                 try {
                     a = Assembly.Load(an);
                 } catch (FileNotFoundException e) {
                     a = Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(appletAssembly.Location), an.Name + ".dll"));
                 }
+                // if the binding has already been initialized (e.g. in SmokeInvocation.InitRuntime()), continue.
                 if (SmokeInvocation.InitializedAssemblies.Contains(a)) continue;
                 AssemblySmokeInitializer attr = (AssemblySmokeInitializer) Attribute.GetCustomAttribute(a, typeof(AssemblySmokeInitializer));
                 if (attr != null) attr.CallInitSmoke();
@@ -83,21 +100,24 @@
         }
 
         public override void PaintInterface(QPainter painter, QStyleOptionGraphicsItem option, QRect contentsRect) {
-            applet.PaintInterface(painter, option, contentsRect);
+            if (applet != null) applet.PaintInterface(painter, option, contentsRect);
             return;
         }
 
         public override void ConstraintsEvent(uint constraints) {
-            applet.ConstraintsEvent(constraints);
+            if (applet != null) applet.ConstraintsEvent(constraints);
             return;
         }
 
         public override List<QAction> ContextualActions() {
-            return applet.ContextualActions();
+            if (applet != null)
+                return applet.ContextualActions();
+            else
+                return new List<QAction>();
         }
 
         public override void ShowConfigurationInterface() {
-            applet.ShowConfigurationInterface();
+            if (applet != null) applet.ShowConfigurationInterface();
         }
 
         protected new virtual bool EventFilter(QObject o, QEvent e) {
@@ -272,3 +292,5 @@
         }
     }
 }
+
+// kate: space-indent on; indent-width 4; replace-tabs on; mixed-indent off;
--- trunk/KDE/kdebindings/csharp/qyoto/src/SmokeInvocation.cs #892998:892999
@@ -426,6 +426,12 @@
 				return;
 			Qyoto.Init_qyoto();
 			SmokeMarshallers.SetUp();
+			// not set when mono is embedded
+			if (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile == null) {
+				PropertyInfo pi = typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance);
+				AppDomainSetup setup = (AppDomainSetup) pi.GetValue(AppDomain.CurrentDomain, null);
+				setup.ConfigurationFile = Assembly.GetExecutingAssembly().Location + ".config";
+			}
 			runtimeInitialized = true;
 		}
 



More information about the Kde-bindings mailing list