C# Script version of PyBinding for WPF - c#

I wrote a CSharpScriptBinding roughly equivalent to the PyBinding on CodePlex. It uses the C# script engine from http://www.csscript.net.
After I wrote it, I kind of decided it might not really be something good to use. Although it caches the compiled script code as an already compiled Assembly, my concern is that I will have one temporary Assembly created each time I use the binding. Will this add up to a problem in the future? If so, maybe there is a way in the C# script engine that I don't know about to optimize this further...? Any thoughts to confirm my suspicion that this was just a bad idea (but useful excersise in learning more about bindings and converters)?

Ask them if they use the DLR? Without it, I wouldn't trust it.

Related

Build script with C#

For insight into the below, read: http://martinfowler.com/articles/rake.html
I've been using Rake (with Albacore) recently, and like it alot. Mostly the strength of having the Ruby language right at hand when I need it.
I must admit I am alot more at home with C# - and that lead me to thinking if there was an equivalent to Rake in the .NET world.
What I am looking for is a way to write build scripts in C#, or maybe a DSL, having the same dependency programming model, where I can also use C#.
Maybe I'm way off base asking this question. But if it's possible to do with Ruby (and an internal DSL), then I can't right off the bat say why the same wouldn't be possible for C#. And I certainly don't understand why it hasn't already been done :-)
Anyone have some perspectives on the issue?
What we already know:
C# needs to be compiled to run, so we would need to create a seperate build-script, that is parsed, and compiled at run-time by an executable.
Thanks in advance!
Solution
Use "Cake" http://cakebuild.net/ -- with Roslyn compiler what I wanted (years ago) is now possible. Thanks Microsoft. And thanks to the people who wrote Cake.
An alternative is to use Powershell. The library is called Psake (saké)
Maybe Cake is what you're looking for: https://github.com/cake-build/cake
A lot of people do use Rake for build scripts. There are even Rake tasks just for .NET. http://albacorebuild.net/
But there is a c# based make utility I know about. http://shake.codeplex.com/ And I thought I saw one on github. But I think they require a compile and that didn't seem as cool.
I ended up on https://github.com/psake/psake mainly because I wanted to learn Powershell and everyone already had it installed.
Hmm Bounce too https://github.com/refractalize/bounce
You can script your build/deployment tasks with msbuild and then script your tasks and execute them from bat files.

Convert QT/C++ to C#

This might seem a little ridiculous, but as some of you here may already know, I'm converting an application written in C++ to C#.
I've noticed that a lot of the code uses references to objects like "QObject", "QWidget", or "QFrame."
Because of this, I'm not quite sure if I should look up the source for QT and port the basic structure of that into a bunch of C# classes which essentially mimic the same functionality, or if there's any kind of framework out there which does the same thing and can be used as a replacement for this.
Also, could someone please explain to me what a slide and a slot is, and what it is I could do to mimic this in C# as well? I'm thinking delegates, but I'm not sure...
Have a look at Qyoto it might just drop in to you code with a few modifications.
The page that Oded recommended also gave a link to qt4dotnet - have you tried this?
If you can't use one of these bindings, you will probably want to start investigating how to port all Q* references in the codebase to WinForms, WPF, or Silverlight (depending on your application needs)

PHP to ASP.Net 4.0

I am looking for a tool that can convert a PHP application into ASP.Net application either c# or VB.Net.
I tried using the 'PHP to ASP.NET Migration Assistant' from microsoft but it leaves a lot of code un coverted and doesn't even create proper codebehind files.
Any ideas or tools that you know?
It's not going to work, sorry. Not only are the languages very different (the biggest difference arguably being that one is dynamically typed and the other is statically typed), but the entire architecture of the environment is vastly different. No automated tool is going to overcome this.
Even if you can find a tool that claims to accomplish this, it's going to emit terrible .NET code. It probably won't use any of the server controls, or at least not use any of them correctly. It's going to force the .NET code to try to do things "the PHP way" and end up costing you a ton in performance and maintainability.
Basically, there's just no way, reasonable or otherwise, to do what you're trying to do. Think of it this way... Have you ever seen automated translations between vastly different spoken languages? The results are humorous to say the least, and they are not accurate representations of the target language.
You're going to need a developer (or team of developers) to do this.
I don't think you can convert automatically a full php application into dotnet, as SLaks said, these languages are very different.
I started dotnet a half year ago, after years in php, and it's really different. You cannot use common techs from php, but you can use anothers. It's a different approach with different advantages, so an automatic tool can't do this.
Maybe you can convert some general php structures with a tool, but it won't be as good as if you write it by hand. And a complete app is nearly impossible.
For example, how would you convert a native php template based view system automatically? Maybe you can achieve this (never say impossible), but you shouldn't waste your time.
You can finish it much faster by hand than searching for a probably non-existent (or not good enough) tool.
As others have stated, an automatic converter from php to c#/asp.net is going to leave a lot to be desired.
Your question got me thinking (well, googling) about php on .net. My search found this: Welcome to Phalanger 2.x.
I don't know how mature it is (though being at 2.x implies some level of maturity); but I'm thinking that with something like this you can port your code over time, while still having the app up and running and still making incremental improvements to the application.
You can now run PHP on .NET with interop using http://phalanger.codeplex.com Some genius dun it!

Is it possible to sandbox and run C++ or C# code that's entered in a textfield in a browser?

I'm diving into web development after ten years of desktop development and I'm experimenting with some testing concepts. I was wondering if it's possible to sandbox and run C++ code that's entered in a textfield in a browser? By that, I mean run the C++ or C# code on the backend webserver and return an analysis of the code. Just to be clear, I don't mean run C++ or C# code that's intended to generate any kind of markup, but simply to blackbox test the C++ or C# block of code that's entered.
How would you invoke the compiler, depending on the web server you're using?
How could you sandbox the code to prevent malicious behavior? If we're considering only one of the C variants, what about blacklisting/whitelisting specific functions and libraries to prevent malicious behavior? Or would that blacklist be too long and too limiting to allow any fair amount of code to run?
These are some fairly high-level questions that I'm asking just because I'm having a hard time finding some direction, but I'm going to continue researching them right now. Thanks so much in advance for your help!
You might find the codepad about page interesting.
# 1 is easy with C#. The Reflection capabilities of .NET allow you to compile and run code "on the fly." And here's a link to another good looking tutorial.
# 2 is a little more difficult but I suppose a basic sand boxing technique might involve executing a dynamic process under a limited, and therefore sand boxed account. Programmatically you could analyze the dynamicly built assembly's dependencies and not allow it to run if it used APIs in certain namespaces such as System.IO. This is non-trivial to say the least though.
C++ doesn't have reflection capabilities and so 3rd party libraries would be your best bet.
The Dinkumware site has something like this.
A simple Perl (or Python, ...) cgi could be used to invoke the compiler, parse it results, run the resulting executable if any and display it's results.
I would take a look at SELinux (maybe AppArmor?) for access controls. Maybe not allowing it write and read to/from the disk and limit it's running time. I don't know if the later can be done with SELinux, too.
If the server runs Linux, you may consider using chroot
We actually did just that with our product called iKnode. We are using this idea to create a Backend in the cloud.
We did this by creating a SandBox that takes an specific piece of code and executes it, captures the result and returns it to the user. This is all done in the cloud.
How would you invoke the compiler, depending on the web server you're
using?
We did this by using the CodeDom utilities from the .Net framework. And we are exploring the coming 'compiler as a service' project coming from Microsoft code-named Roslyn.
This is a good starting point on using CodeDom to programatically compile.
How could you sandbox the code to prevent malicious behavior? If we're
considering only one of the C variants, what about
blacklisting/whitelisting specific functions and libraries to prevent
malicious behavior? Or would that blacklist be too long and too
limiting to allow any fair amount of code to run?
We did this by wrapping the code execution in a separate and limited AppDomain. You can see some examples here.
Additionally, you might want to look into the MonoSandBox, which was created for Moonlight, but it is a more robust SandBox. We are experimenting with it right now, to move away from AppDomains. We believe the MonoSandBox is way better than simple AppDomains.

Is it possible to load and execute C# snippets using DLR?

The majority of material I have found regarding DLR is related to IronPython. Can you parse and execute C# using DLR? If so is there over head that would prevent you from attempting this on a web server with about 30 users?
More specifically I would like to script the configuration of my workflow objects when a user first initiates a workflow. Depending on conditions that change through out the year workflows may start at different steps, hence running configuration scripts seems like a good way to handle the variation.
It sounds like you're really talking about the C# "compiler as a service" (at the end of this video), which will hopefully be in the 5.0 timescale for .NET (although Mono has it now). For now, CSharpCodeProvider is the best we have (which works largely like "csc").
Although Marc offered an alternative for me, I read this related SO question and C# and VB are not supported as of yet.
You may find this relevant...though it doesn't run on the DLR itself.
Mono Compiler as a Service (MCS)
It has the advantage of running snippets and not loading a new assembly on every compile like CodeDom does.

Categories

Resources