Code sample update in January, 2011 - Microsoft All-In-One Code Framework
The code samples in Microsoft All-In-One Code Framework are updated on 2011-1-23.
Download address: http://1code.codeplex.com/releases/view/59640#DownloadId=201866
You can download individual code samples or browse code samples grouped by technology inthe updated code sample index.
If it’s the first time that you hear about Microsoft All-In-One Code Framework, please read this Microsoft News Center article http://www.microsoft.com/presspass/features/2011/jan11/01-13codeframework.mspx, or watch the introduction video on YouTube https://www.youtube.com/watch?v=cO5Li3APU58, or read the introduction on our homepage http://1code.codeplex.com/.
New Azure Code code samples
CSAzureBingMaps and VBAzureBingMaps
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201758
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201818
The AzureBingMaps sample is an application sample demonstrating how to design and build a solution that combines multiple cloud services and client devices. It uses the following cloud services:
- Windows Azure
- SQL Azure
- Windows Azure AppFabric
- Windows Live Messenger Connect
- Bing Maps
It also contains client applications for the following devices:
- A HTML client for web browsers
- A Silverlight client for Windows PCs and Macs
- A Silverlight client for Windows Phone devices
The sample also demonstrates a lot of technologies, such as Entity Framework, WCF, jQuery, and so on.
You can find a series of blog posts describing it on http://blogs.msdn.com/b/windows-azure-support/archive/2010/08/11/bring-the-clouds-together-azure-bing-maps.aspx. A live demonstration of the HTML client can be found at http://azurebingmaps.cloudapp.net/HtmlClient.aspx. A live demonstration of the Silverlight client can be found at http://azurebingmaps.cloudapp.net/SilverlightClient.aspx. Note we don’t promise we’ll always keep the live demonstrations alive.
Here is a screenshot of the sample application:
New Windows General and IE code samples
CppRegisterHotkey, CSRegisterHotkey and VBRegisterHotkey
C++ version: http://1code.codeplex.com/releases/view/59639#DownloadId=201731
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201780
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201839
The sample demonstrates how to register and unregister a hotkey (e.g. Alt, Control + X) for the current application. When the hotkey is hit, your application will receive a special message, and you can, for example, set your application window to the front.
CSDetectWindowsSessionState and VBDetectWindowsSessionState
C# verison: http://1code.codeplex.com/releases/view/59639#DownloadId=201764
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201823
The sample demonstrates how to detect the Windows session state. We observe that many customers ask how to detect session lock and unlock events in applications. You will get the answer in this code sample. Here is a screenshot of the code sample:
CSFTPDownload and VBFTPDownload
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201772
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201831
MSDN contains some code samples about how to download one file at a time from an FTP server. However in MSDN forums, many customers ask how to download multiple files or entire directory structure (files and sub-directories etc.) from an FTP server. This code sample will answer it. The code sample demonstrates downloading one or multiple files from FTP, and listing files. It's basically a small FTP client sample application.
CSFTPUpload and VBFTPUpload
C# verison: http://1code.codeplex.com/releases/view/59639#DownloadId=201773
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201832
This code sample demos uploading files to FTP and deleting files on FTP. It is a supplement to the above CS/VBFTPDownload code sample.
CSMultiThreadedWebDownloader and VBMultiThreadedWebDownloader
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201776
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201835
The sample demonstrates how to download file using multiple threads.
1. To pause and resume a download, or download a file using multi-threads, the server must support "Accept-Ranges" header, so that we can add range to the webrequest to download a specified block of the file.
2. If you are trying to download a single file using multiple threads/ multiple HttpWebRequest’s, multiple requests (each asking for a different range) will all be pipelined over a single connection (not necessarily all). You have to take into consideration as to how many threads you are spinning, and how many max Connections you have set for the ServicePointManager. By default, ServicePointManager has a default of 2 max connections for console applications, so only 2 requests can be active at a time and will be downloading 2 parts of the large file. So yes, your approach will speed up the download, but you also need to take into account the maximum number of connections. If you increase the number of available connections,you will get a better download rate. But, do not increase it to a very large value, otherwise you will end up spiking the CPU due to the overhead of creating multiple connections simultaneously. Try to limit the max Conn number = 12 * # CPU which asp.net uses.
CSTabbedWebBrowser and VBTabbedWebBrowser
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201793
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201850
The sample demonstrates how to create a tabbed WebBrowser. This is also frequently asked in MSDN forums. Here is a screenshot of the code sample.
CSWebBrowserAutomation and VBWebBrowserAutomation
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201794
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201851
The sample demonstrates how to create a WebBrowser which supplies following features
- Manipulate the html elements and login a website automatically.
- Block specified sites.
CSCustomCodeAnalysisRule and VBCustomCodeAnalysisRule
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201763
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201822
The sample demonstrates how to create, deploy and run custom Code Analysis rules.
New Windows Forms code samples
CSRichTextBoxSyntaxHighlighting and VBRichTextBoxSyntaxHighlighting
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201781
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201840
The sample demonstrates how to format XML and highlight the elements in a RichTextBox control.
New ASP.NET code samples
CSASPNETEmailAddressValidator and VBASPNETEmailAddressValidator
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201751
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201814
When we develop a register form, we often want the user to submit their Email address, so we can send some information to them. The easiest way is to use a regular expression to validate the format of the address. For example,
We can use Regex class to validate the format of the input string. But the problem with this way is that we can’t check whether the Email address is reachable. It is possible that the user would not input his own address or someone has a typo. So the key issue here is how to check whether the Email address is available. AS far as I know, there are two ways that we can try. The first one is to analyze the Email address to get the MX records of that mail server and send some requests to that server and check the response code. It looks a good idea and the validation is fast, but in these years, Internet is full of junk mails, we call these mails as Spam. And now almost all the mail servers have been updated to support Anti-Spam. And that’s the principle of the first way just similar with the spam robot. So we have to give up this way because the request message would act as a spam message and be rejected by the mail server. Its return code would never be accurate. So the second way, as the code sample demos, is to send a confirmation mail and let the user click a special link in that mail to complete the validation. The only shortage is that we need to wait for the user to open his received mail and could not validate the address at once. Anyway, it is a safe and possible workaround.
CSASPNETSerializeJsonString and VBASPNETSerializeJsonString
C# version: http://1code.codeplex.com/releases/view/59639#DownloadId=201755
VB version: http://1code.codeplex.com/releases/view/59639#DownloadId=201816
This sample is using .NET System.Web.Script.Serialization namespace's JSON serializer component to perform .NET --- JSON data convertion. Here is running jQuery AutoComplete to perform the AJAX request. On the sample, when user enters a character like ‘m’, the AutoComplete list will display automatically. Once choosing one item in list, the related information of this item will show on the dashboard.