?

Log in

Jan. 5th, 2009


tobes31415

New Version of Media PC Software

Yesterday I finished the latest version of the Media PC Software. My roommate Alex has been bugging me about it for quite a while now, and now its done :) yay.

What does it do?
I enter a list of File shares accessible on the network
It enumerates over those shares and generates a searchable index
When I want to watch something I type in a keyword and see all the related files accessible on the LAN, click one and it starts playing without me needing to navigate to the share myself.
It also can search by when the file was created which allows for it to detect when new files are added and they show up in a special list.
And it can be run as in kiosk mode so that anyone can use the media pc as long as they know how to use a mouse and keyboard

Its very similar to the media libraries in Winamp and Windows Media Player, but the GUI is designed with TV output in mind and it has the "recent" files list which I don't think either of them have.

Why "Media PC Software"? because we have a media PC in our living room hooked up to the TV (it's inside an old nintendo box, how cool is that!) and this is the software that runs on it.

Differences between this and the last Media PC Software
-The GUI + Indexer has been split into two processes so that you can have an instant-on index thats always up to date (leave the indexer running on the computer hosting the media).
-The two processes communicate using .Net Remoting... damn am I behind the times. I chose this option over WCF as #1 it would have been massive overkill and #2 All config file examples of WCF I've seen are cluttered at best and unintelligible at worst, and I've read that its not easy to do run time configuration changes (though I haven't verified that)
-GUI portion now plays media using VLC instead of Windows Media Player (more supported media formats)
-No Database, this was not an intended change, but it does however make things incredibly fast (at the expense of memory). Since every query needs to do a full text search of text in potentially any language and there isn't much else associated with a file I don't think switching to a database will add any value. I might keep things as they are but push the Cached results into a file and have the indexer scan through the file using IEnumerable + Yield. It will slow things down a little bit but will reduce the memory requirements to pretty much nothing.

Things to do
I lost some features such as the being able to change the list of media file "extensions", right now its hard coded but thats an easy feature to add and I lost the feature for filtering the list of results. Not all media should be viewable in the livingroom. :P Another minor feature, I'll get to it later this week perhaps.

Nov. 28th, 2008

Hey There

tobes31415

C# Null Coalescing Operator: ??

I just discovered that there is a null coalescing operator in C# that can be used to supply default values when an object being referenced is null.

Here is a silly, trivial example. (I'm very busy right now I'm primarily writing this post so I don't forget about it myself)

[WebMethod]
public String FindLog(double Value, int? Base)
{
//If the user didn't specify the base we assume base 2
return Math.Log (Value, (Base ?? 2));
}

Jul. 24th, 2008


tobes31415

Debugging C# Delegate methods, how to get rid of the breakpoint at the start of delegate

I just discovered something I consider to be amazing :)

You know how when you're trying to set a breakpoint inside a delegate method and Visual Studio sets a breakpoint at the line you requested, but also puts a breakpoint at the creation of the delegate? It seems you can override that behavior by adding a second break point anywhere inside the delegate on another line, and then removing that breakpoint. It removes the dummy break point, and it also removes the breakpoint at the start of the delegate :D
Totally, Awesome. That has been annoying me for as long as I knew delegates existed :)

Jul. 10th, 2008


tobes31415

Compile Time Semantic Checking

C# is a TypeSafe language, what about SemanticSafe?

In a project I'm working on we have a lot of database records ids being passed around as integers. Today I needed to add a new record id to this list. Adding the new item to the function signature is easy. the hard part comes in making sure the right value is being assigned.
Public void MyFunction(int TableA_ID, int TableB_ID, String someOtherValue);

int A_ID = 5;
int B_ID = 4;
MyFunction(B_ID, A_ID, "Hello World");

so what happens when I compile? nothing, it works fine. yet that line where I called the function have have just corrupted the entire database because those database ID's were transposed. Which would kinda suck.

Its one thing to guarantee type safety, what what about semantic safety? An idea popped into my head to use the existing type-checking to accomplish this.
    public struct UserID
    {
        private int value;
        public static implicit operator int(UserID source)
        { return source.value; }

        public UserID(int intValue)
        {
            value = intValue;
        }
     }

    private void TryToFail(UserID test) { }    

    UserId works = new UserId(5);
    int fails = works;

    TryToFail(works) //compiles fine
    TryToFail(fails) //Doesn't compile

Even though both works and fails contain the exact same value, the function can be made to fail if the values are put in the wrong order. And I used an implicit operator so that I didn't lose the convince of having a simple integer, neato.

Obviously this technique is not something you would want to use for every possible field as there is one extra step involved in getting the value but if you only did this for the record ids I think it'd be enough gain to make it worthwhile.

I would like to think of a way to do this so that it has compile time checking, but once compiled only contains the primitive value. Any ideas?

Jul. 8th, 2008


tobes31415

Initial Research for Embedded Scripts in .Net Applications

I did a bit of looking around yesterday at my planned personal projects. One of my requirements is a scripting language so I decided to do some light reading on LUA script. LUA is the scripting language I had chosen to use because its lightweight, I know it is currently used for World of Warcraft and a whole slew of other games and applications and already has C# libraries. One annoyance I see is that the syntax is that its vaguely reminiscent of the dark ages when I developed in basic and there are some limitations compared to other languages due to it's lightweightedness.

What would be nice is to do my scripting in ECMAscript assuming it could be made fast enough. It has curly brackets that make things easy to follow even, and its been proven that it can even be used for really complex things when the need arises. Oh, and the minor little fact that JavaScript which is pretty much everywhere is ECMAscript, so the language is guaranteed to be refined over time and everyone already know how to use it.

Is ECMAscript too heavy for what I want to use it for? Well, what do I want to use it for?
* scripting game board rules
* scripting NPC behaviors
* serializing queries and running them remotely

The last one I think would be really sweet. The general idea being something like "I want to find a Car with 2 doors, comes in the color blue, age < 10, and cost is < (10 - Age) * 1000". The first three are relatively easy, but the last one would require exposing the server to your custom SQL (which is a no-no) instead you would query on the first three using a provided interface, and then filtering out the ones that don't match the last criterion after you receive the list. If instead of calling a specific query interface we send a short script that will select what it is we want then we can have a much more rich interface without needing to have a gazillion overloads exposed.

So, if I want to code in ECMAscript in .Net, what are my options?

* JScript.Net
* Rhino (currently being ported to C#)

... That is a very short list.

JScript.Net despite being JScript based is primarily a compiled language. I'm pretty sure it uses reflection and emitting code at run time to simulate "interpretting" on the fly. This would be ridiculously expensive for any kind of dynamic use... which entirely defeats the purpose of having a scripting language in the first place. (so um... wtf?)

Rhino is a bit of a mystery. It was originally developed for java and presumably works well enough, but the pages I've seen regarding the C# port are several years old. I suspect it may have been abandoned.

Create my own implementation?
javascript and C# have many similarities. It should be possible to use c# code for the logic. And I could use all the funky new .Net 3.5 syntax to make coding the things that do need to be hardcoded easy.
A major bonus if I made my own implementation is that I'd have access to the parse tree and then could serialize scripts directly to and from binary mode (wickedly fast as compared to text). I would also be able to add a few extensions to the language such as minimal support for multi threaded environments or coroutines.

This would be cool but it'd be a lot of work too. If I went with LUA, I wouldn't be able to do the remote query thing but it'd still be good for my main purposes

Jul. 6th, 2008


tobes31415

Network Layer Rewrite

I recently have taken a second look at the networking issues I'd face in my three ongoing projects. While I'd previously posted I had a working network layer I've decided I can do better, so I reviewed all the code I'd written, extracted the 'why' in what was there and now I'm starting it from scratch. As a big Woot my first sub-component, an in-memory stream for buffering between threads, I got it transferring 2Gb of data in 600 milliseconds, verses 12000 milliseconds for the Queue class which is the closest analogue I could find. I felt really good after I'd verified the numbers. And its all using managed code too :) So without a doubt there was much room for improvement, the new design is also much simpler and more elegant.

I wonder though if I might be suffering from the "Not invented here syndrome" with this network layer I'm writing. Windows XP has an installable P2P network protocol, PNRP. As well the Windows Communication Framework has P2P support too. My justification for doing this anyway is that use of the PNRP protocol requires an additional windows-only installation which would be like pulling teeth to get some people to install, exclude non-windows platforms, and since no one is using it I'm not sure of it's even reliable. The WCF features sound amazing, but the caveat is that all the uber cool .Net 3.5 WCF examples I've looked at seem to involve WAAAY to much configuration and meta data just to run. I don't want to mess around with addressing, contracts, and bindings for every small networked application I write just so I can send a few bytes of data. My network layer would use TCP P2P (Only one binding) stream based (no contract management), and available services/endpoints listed as objects at run time (no addressing required). No built in serialization or communication management either, just a byte stream between processes. less powerful than WCF, but sufficient for most of what I want to use it for.

-- UPDATE --
Actually it looks like the WCF P2P support requires you to have PNRP installed anyway... so nvm I guess. Since I don't want to use PNRP I do actually need my own P2P network component.

May. 3rd, 2008


tobes31415

C# Networking Layer Hello World Successful

Below is a section of text from Visual Studio Output window. I'm very excited about it.

ASDFGH229$ Sending identity ASDFGH229$
QWERTY19$ Received Identity ASDFGH229$
QWERTY19$ Sending identity QWERTY19$
ASDFGH229$ Received Identity QWERTY19$
ASDFGH229$ Entered main Client loop with client QWERTY19$
ASDFGH229$:0 sent a message to QWERTY19$:1 Length 11 Bytes
QWERTY19$ Entered main Client loop with client ASDFGH229$
QWERTY19$:1 Received Message from ASDFGH229$
"Hello World"

This is showing a handshaking protocol followed by sending and receiving a message. Its special though because it's hiding the low level details (like IP addresses, and the tcp connections). Once complete this will maintain a short lived p2p network for sending messages between specialized processes. Ie games :) and it supports multiple endpoint addressing, so I'll be able to completly issolate the client and server code, even on the machine acting as the server itself :D

This is the next immediete step for the media pc, a big step for Starship Catan online... I will finish it one day, and in the far futre that big game I'm going to make, they all require this project to advance. (Though the Media PC is unblocked right now with this current milestone)