пятница, 19 марта 2010 г.

Developing Facebook applications in C# with ASP.NET


 I mentioned previously I've created my first Facebook (FB) application (which is still under development) but I've learned a lot along the way. I haven't found the Facebook documentation very useful at all and have gleened a lot through Google, the Facebook developer group and simply tinkering with things. As a result I've put together some steps I think could help save you some time if you're looking to write a Facebook application using ASP.NET and C#. Btw, you'll get no help from facebook.com regarding ASP.NET development.
One thing that took me awhile was understanding how an FB application appears on your profile page. I eventually realized that FBML can be used to push markup onto a users profile page. This block of markup can be set at the time you create a new application though the first time around, if you're like me, this may see a bit confusing keep in mind I'm new new to FB itself so a lot of this was confusing. From the FB toolkit you can also use the method setFBML to programmatically set this block of markup. Needless, to say being used to MSDN documentation FB doc leaves a lot to be desired. That said there are a few tools you can use to play with the API as well as sample your FBML markup.


Facebook start app screenshot
At any rate, here are the steps I followed to get my application working. Note, the project includes support for Microsoft AJAX so you'll want to have that installed as well although you could just tweak the .aspx and web.config files and use it without AJAX. The screenshot illustrates what you should get when your done. NOTE: In the following steps several links won't work unless you have an FB account.
UPDATE: I've created a new page on my wiki with updated steps and a VS.NET starter kit to make this much easier.


  1. Sign up for a Facebook account
  2. Add the Developer application to your account (you need an account for that link to work)
  3. Click Developer application from the left column and select click Set Up New Application
  4. Enter the Application Name and expand Optional Fields
  5. Under Optional Fields

    1. Set your callback URL http://localhost... will work just fine for development
    2. Select "Use iframe"
    3. Click Yes for "Can your application be added on FaceBook"
  6. Under Installation Options

    1. Check "Developer Mode"
    2. Under Site Nav use the same URL from Canvas Page URL (see Optional Fields)
    3. If you use my template set Edit URL to your Canvas Page URL + /settings
  7. Click Save then from the Developers Application browse to My Applications
  8. Click View About Page then click Add Application. This will allow you to easily work with your application during development.
  9. Download the Facebook Developer Toolkit from Microsoft
  10. Download my C# ASP.NET app to get you started or generate the boilerplate code for handling login (sorry I don't do VB.NET)
  11. You'll need to add a reference to the Facebook assemby to this project as I didn't want to include it as it being updated frequently right now
  12. Open Default.aspx.cs and fill in FACEBOOK_APPKEY and FACEBOOK_SECRET from your application's page on Facebook.
  13. Fire up the browser and hit your http://apps.facebook.com/ and you're off!
Please let me know what problems you have or let me know if these steps need tweaking.
Was this helpful?

воскресенье, 7 марта 2010 г.

Calling Win32 DLLs in C# with P/Invoke






Enter P/Invoke
Style
The DLL Import Attribute
Optional DllImportAttribute Properties
Data Marshaling
Marshaling Numerical and Logical Scalars
Parameters that are Pointers
Marshaling Opaque Pointers: a Special Case
Marshaling Text
Summing it Up
I have noticed a trend in my programming of late, and that trend has inspired the topic of this month's column. Recently, I have done a fair amount of Win32® Interop in my Microsoft® .NET Framework-based apps. I am not saying that my apps are full of custom interop code, but from time to time I bump into a minor, but nagging, inadequacy in the .NET Framework Class Library that can quickly be alleviated by a call into the Windows® API.
As I think about it, any feature limitation in the .NET Framework version 1.0 or 1.1 class library that is not shared by Windows doesn't come as a huge surprise. After all, 32-bit Windows, in all of its incarnations, is a mature operating system that has served a wide breadth of customers for over a decade. The .NET Framework is, in comparison, a newcomer.
As an increasing developer base moves its production applications to managed code, it seems only natural that there will be even more occasions for developers to dip down into the underlying operating system for some critical tidbit of functionality—at least for the time being.
Thankfully, the interop features of the common language run-time (CLR), called Platform Invoke (P/Invoke), are very complete. In this column I am going to focus on the practical use of P/Invoke for calling Windows API functions. P/Invoke is used as a noun when referring to the COM Interop functionality of the CLR and is used as a verb when referring to the use of this feature. I am not going to address COM Interop directly because it is paradoxically both more accessible and more complex than P/Invoke, making it less straightforward as a column topic. 


http://msdn.microsoft.com/en-us/magazine/cc164123.aspx

IOCP Thread Pooling in C# - Part II

In part 2, William will continue to explain how the create a class that will handle threads using a IOCP Thread Pool.


http://www.devarticles.com/c/a/C-Sharp/IOCP-Thread-Pooling-in-C-sharp-Part-II/

IOCP Thread Pooling in C# - Part I



This is the first part of William's two part series on thread pooling in C#. By importing a dll file for IOCP thread support.


http://www.devarticles.com/c/a/C-Sharp/IOCP-Thread-Pooling-in-C-sharp-Part-I/

PInvoke.net



Pinvoke.net is primarily a wiki, allowing developers to find, edit and add PInvoke* signatures, user-defined types, and any other information related to calling Win32 and other unmanaged APIs from managed code (written in languages such as C# or VB.NET).

Надоело писать [DllImport] руками

Здравствуйте, bezlepkin, Вы писали:

B>На мой взгляд, в библиотеке классов .NET не хватает одной очень полезной фичи.


B>В .NET FCL нет сборки, которая содержала бы DllImport-определения для функций ХОТЯ БЫ из USER32, GDI32 и KERNEL32. А лучше, также для всех DLL, входящих в Platform SDK.


B>Конечно, это не смертельно, т.к. определение можно всегда написать руками. Но необходимость делать это каждый раз для новой функции очень достаёт.


B>1) Может быть, кто-то знает где взять готовом виде?


самому писать необязательно, все уже украдено до нас

Simple Convert Byte Array to Hexadecimal String Example




You can use BitConverter.ToString Method:
byte[ ] bytes = {0,   1,   2,   4,   8,  16,  32,  64, 128, 255 }
Console.WriteLine( BitConverter.ToString( bytes ) );
Output:
00-01-02-04-08-10-20-40-80-FF


More Info: http://msdn.microsoft.com/en-us/library/3a733s97.aspx