Monorail, Mono, Content-type and the registry.....

9 views
Skip to first unread message

James Curran

unread,
Mar 17, 2010, 9:58:51 AM3/17/10
to Castle Project Development List
I've been working on implementing Portable Areas in Monorail. It's
about 95% done. One item I have left is setting the content type of a
file being read from a resource. Since I have it's extension, reading
that from the registry seem simple enough:

var contentType =
Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension).GetValue("Content
Type") as string;

But, as Monorail is expected to compile under Mono, I assume that
means the Microsoft.* namespace is off-limits. What is the portable
way of doing this?


Krzysztof Koźmic (2)

unread,
Mar 17, 2010, 10:16:22 AM3/17/10
to Castle Project Development List
how is asp.net mvc handling this? IIRC they run on Mono as well

Rafael Teixeira

unread,
Mar 17, 2010, 10:41:26 AM3/17/10
to castle-pro...@googlegroups.com
Pending further investigation on available core APIs I would suggest
that it should be abstracted into a Service (Facility?), that would
use the registry in Windows, and access the shared-mime-info database
available in Linux. I'll cross-post to Mono to get better answers on
details to that.

ASP.NET MVC may implement it's own mapping, or use some core
(System/Corlib) functionality that may already be implemented also in
Mono, investigating it is surely a good thing to do.

Just guessing but ASP.NET MVC may just skip the issue completely like
it happens with traditional ASP.NET where a developer needs to either
let IIS deal with it (by redirecting to a 'navigable' resource) or
explicitly setting a hand-computed header.

Just my guesses,

Rafael "Monoman" Teixeira
---------------------------------------
"To be creative means to be in love with life. You can be creative
only if you love life enough that you want to enhance its beauty, you
want to bring a little more music to it, a little more poetry to it, a
little more dance to it."
Osho

> --
> You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
> To post to this group, send email to castle-pro...@googlegroups.com.
> To unsubscribe from this group, send email to castle-project-d...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.
>

Mauricio Scheffer

unread,
Mar 17, 2010, 10:54:50 AM3/17/10
to Castle Project Development List
Here's something I've been using:
http://github.com/mausch/MobileRemoteBrowser/blob/master/MobileRemoteBrowser/mime-types.xml
It has mappings by extension and magic bytes. It might not be complete
but it points to other, more complete, sources.
I'm using it through this wrapper: http://www.netomatix.com/Products/DocumentManagement/MimeDetector.aspx
but it shouldn't be hard to write one if you don't want to depend on
3rd party code.

Cheers,
Mauricio

Julian Birch

unread,
Mar 17, 2010, 10:57:47 AM3/17/10
to castle-pro...@googlegroups.com
I think Rafael's right, although we're still missing one use case: Mono on Windows.  I think you're pretty much restricted to P/Invoke then.

J

Mauricio Scheffer

unread,
Mar 17, 2010, 11:02:28 AM3/17/10
to Castle Project Development List
I guess the ultimate solution would be porting the unix file command:
http://linux.die.net/man/1/file
I wonder if anyone has done this.

On Mar 17, 11:54 am, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> Here's something I've been using:http://github.com/mausch/MobileRemoteBrowser/blob/master/MobileRemote...

Rafael Teixeira

unread,
Mar 17, 2010, 11:13:41 AM3/17/10
to castle-pro...@googlegroups.com
'file' AFAIK is a shell script that searches the aforementioned
shared-mime-info database (which I think is textual and contains
extensions and magic bytes), I do think Mono already does the heavy
lifting, perhaps substituting something else in Windows, too.

Sorry can't get the time to search Mono's sources to be certain, asked
on mono-dev-list to see if someone with more familiarity with the
subject can enlighten us.

Regards,

Rafael "Monoman" Teixeira
---------------------------------------
"To be creative means to be in love with life. You can be creative
only if you love life enough that you want to enhance its beauty, you
want to bring a little more music to it, a little more poetry to it, a
little more dance to it."
Osho

Rafael Teixeira

unread,
Mar 17, 2010, 1:03:40 PM3/17/10
to castle-pro...@googlegroups.com
---------- Forwarded message ----------
From: Federico Di Gregorio <f...@initd.org>
Date: Wed, Mar 17, 2010 at 12:33 PM
Subject: Re: [Mono-dev] Fwd: Monorail, Mono, Content-type and the registry.....
To: mono-de...@lists.ximian.com


On 17/03/2010 15:48, Rafael Teixeira wrote:
> How does one determine the mime-type of a resource (normally a file)
> in a portable way?
> I know Mono on Debian does have a dependency on the shared-mime-info
> package, so it probably wraps/uses it, but is it exposed in some
> public API? Specially some API that is available in .NET?

I had the same problem and I didn't find any portable way to determine
the MIME type of a file. In the end we resolved to just hardcode the
most common file types (by extension, sigh) into our code:

https://dndg.it/cgi-bin/gitweb.cgi?p=public/wok-2.git;a=blob_plain;f=Wok.Core/Wok.Core.Utils/MimeType.cs;hb=HEAD

--
Federico Di Gregorio                                       f...@initd.org
 Questa lista non pretende di essere il riferimento torinese per il
 software libero o altre cazzate del genere.       -- Silvano, su torte


_______________________________________________
Mono-devel-list mailing list
Mono-de...@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

signature.asc

Henrik Feldt

unread,
Mar 19, 2010, 9:38:09 AM3/19/10
to castle-pro...@googlegroups.com
Machine.config contains mime-mappings.
Reply all
Reply to author
Forward
0 new messages