Follow me on Twitter RSS FEED

C# Programmatically Compiling .cs files to executables

I was thinking of making a program that generates an executable which installs an application, but how to generate the executable?

public static void Compile(String Output, String code)
{
    CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
    CompilerParameters parameters = new CompilerParameters();
    //Make sure we generate an EXE, not a DLL
    parameters.GenerateExecutable = true;
    parameters.OutputAssembly = Output;
    CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, code);
    if (results.Errors.Count > 0)
    {
        foreach (CompilerError CompErr in results.Errors)
        {
            Debug.WriteLine(
                "Line number " + CompErr.Line +
                ", Error Number: " + CompErr.ErrorNumber +
                ", '" + CompErr.ErrorText + ";" +
                Environment.NewLine + Environment.NewLine);
        }
    }
    else
    {
        Debug.WriteLine("Success!");
    }
}

In order to use this function, you must using these two classes:

using System.CodeDom.Compiler;
using System.Diagnostics;

Once you have that done, you're good to go! As a quick example, you can create a textarea named txt_code, a textbox named txt_output, and a button btn_submit. When btn_submit is clicked, then it will say:

Compile(txt_output.Text, txt_code.Text);

Which if you put a valid path in txt_output, and valid C# code in txt_code, then you will have your executable!

Original Article Here

Google Search Stories

Google came out with Google Search Stories, where you can make a video of a series [up to 7] of google searches to tell a short story. I made one to test it out:


You can make your own here:
http://www.youtube.com/searchstories

C# Remote Desktop Client

Recently, I've been trying to find a challenging C# Project to work on. I've tried stuff like a program that tells you your WPM and then submits it to the highscore table. It wasn't really very challenging, although I did learn a thing or two. But the other day, I really hit the nail on the head: A C# Remote Desktop Host/Client.

Skip this paragraph if you already know what a Remote Desktop Host/Client is
A remote desktop host/client is a program that lets one person remotely control another person's desktop. So, for example, lets say I had a friend in california, and I live in north carolina. The person in california, using this program, could control my desktop and, say, create and populate a text document. The host is the program that lets you control the desktop that the client program is running on.

So in order to pull this off, I need to have two connections: One for the server to send information to the host, and one for the client to send information to the host. I was initially going to use Sockets, but that would only work over LAN. So I created some PHP scripts to communicate with the MySQL database to do things such as post a string to the output database [the input for the other side], and check for posts to the input database [the output for the other side]. Once I got all that working, I could use WebClient.DownloadString("Script.php"); to execute the script via C#. Both Get and Post parameters work with this.

Then I set up threads on the client and the host to check for messages multiple times per second. The main problem at this point was sending an Image, 1440x900px [my screen resolution], to the database quickly. Uploading and Downloading it directly would be far to slow, so I did a google search for "C# Image Serialization". I found a really good method, using base64 encoding, and it uploads fast. So the client would take a screenshot, encode it to base64, and send it to the database via PHP. Then the server would download the encoded image as a string, decode it into an image again, and display it. All this happening multiple times per second.

So all that is the theory behind it. I still have to implement the sending and receiving, but everything else is working properly.

Death Worm: Update 1.1.2

Posted in
 I spent a lot of time on this update:

Updates:

  • Four different enemies which appear sequentially
  • Images for the enemies
  • FPS counter
  • Minor performance updates to the particle system
View version history here: http://www.theadamgaskins.com/DeathWorm/

In the next updates:
  • The white enemies will run faster if they see you [because they get scared]
  • A health system
  • Some enemies will shoot bullets, which will make you loose health
  • You can die if you run out of health
All that is a lot, so It'll probably be a update or two before I get it all finished.

Death Worm: Update 1.1.1

Posted in
Updates:

  • The screen shakes when coming out of the ground
  • NPCs/Victims added. They are just arrows for now. If you collide with them, they explode in a puff of particles.

Death Worm Homepage

Posted in
This is becoming a fun project, which I will have motivation to continue for a while yet, so I created a webpage where you can view the updates on Death Worm. I'll still update my blog, but this page has a list of all the updates, and links to them.

Death Worm Homepage

Also, I moved all the links. The links will still work, though. I'll just have the old links redirect to the new links.

Death Worm: Update 6/18/10

Posted in
  • Scrolling Added
  • Background Color Changed
  • Scenery Added [to show scrolling]


Death Worm 1.1

Older Versions:


Death Worm: Java Remake

Posted in
I haven't used Java in a while, so my skills were getting a bit rusty. I decided to pull out the WD-40, and do a game.

I saw this game on yoyogames.com. It was simple, yet extremely addicting. What I have so far is almost complete. I just need to add the NPC's [a.k.a. victims] and the game will be finished.

Small Size
Medium Size
Large Size

Java Games

Posted in
Java games are surprisingly easy to create. You just need to download the JDK from sun microsystem's website and you're all set! You don't need to download the JMF or anything for audio or images. This tutorial will really help; its how I learned:

http://www.javacooperation.gmxhome.de/TutorialStartEng.html

Good luck, and happy programming!

YouTube Embed Test

Posted in