Posts Tagged C# Assembly

Discogs.com API Assembly for .NET Applications v1.0 Build 2871

Greetings Everyone!

I’ve been working on the Discogs.com API Assembly for .NET Applications now for a couple days and have been able to make some progress. It’s now a bit more stable as well a a tiny bit easier to use.

I took some time and added a DEBUG class. This class allows you to find out what’s happening within the Discogs.com Assembly if you start to have issues! :) This new class has two properties:

  • Verbose (bool) – If set to TRUE, Verbose logging will be enabled allowing you to get more precise detail on what is going on within the Assembly. Otherwise, only exceptions will be logged.
  • Log (string) – This is a string containing the current debug log.

Also, it has one Method:

  • LogEvent (string sEvent) – Logs the value passed in to the debug log. This way you can use the same debug log from your own applications :) Should help make things a little easier.

New in this version as well is better error handling in the event of 404′s or an Artist/Release isn’t found. Before if you requested something that didn’t exist, the Assembly kinda crapped out while trying to deserialize the (non-existent) XML :) This has all been fixed.

I’m also including a small example program (with source code) on how to use the Discogs.com API Assembly. I’ve coded the example in C#, so sorry to all those VB.NET developers out there! :) If one of you guys would like to translate it to VB.NET, I’d be more than happy to post it here as well.

If you do not already have Microsoft Visual Studio installed, no worries! Microsoft provides a free version for C# development called Visual C# Express and you can get it here over at Microsoft.com. :)

You will need to update the Reference to the Discogs.com API Assembly. It currently points to where I had it setup on my local machine. :)
Any and all feedback is appreciated!

Cheers!

Discogs.com API Assembly for .NET Applications v1.0 Build 2871Download (9k)

Discogs.com API Assembly Example Application (with Source)Download (10k)

, , , , , ,

3 Comments

Embedded Resources in C#

So last night I was trying to think of the best way to compile images into the WWWinamp EXE.

One way I had considered was converting the images into a byte[] and then just putting this into the source code. The images I was working with were only about 200 bytes long, so this could be do-able.

Upon further investigation I came across this tutorial over at DevHood.com. It seemed a better idea to just roll with Embedded Resources in the EXE, since it would give me a few more options in the long run.

Below is the code I used to retrieve an embedded resource. You pass in the file name of the resource you want, and it’ll return a byte[] with the content:

[csharp]

public byte[] Server_ReadEmbeddedResource(string sFileName)
{
Assembly asResources = Assembly.GetExecutingAssembly(); //Referrence to the current assembly
string[] sResNames = asResources.GetManifestResourceNames(); //Store list of resources for the current assembly in an array

foreach (string sResourceName in sResNames)
{
if(sResourceName.EndsWith(sFileName))
{
BinaryReader oBR = new BinaryReader(asResources.GetManifestResourceStream(sResourceName));
return oBR.ReadBytes((int)asResources.GetManifestResourceStream(sResourceName).Length);
}
}
return new byte[] { 0 };
}

[/csharp]

, , ,

No Comments