This is a mirror of official site: http://jasper-net.blogspot.com/

How to use the IEnumerable/IEnumerator interfaces

| Thursday, March 29, 2012
Introduction

IEnumerable is an interface implemented by the System.Collecetion type in .NET that provides the iterator pattern. The definition according to MSDN is:

“Exposes the enumerator, which supports simple iteration over non-generic collections.”

It’s something that you can loop over. That might be a List or Array or anything else that supports a foreach loop. IEnumerator allows you to iterate over List or Array and process each element one by one.

Objective

Explore the usage of IEnumerable and IEnumerator for a user defined class.

Using the code

Let’s first show how both IEnumerable and IEnumerator work: Let’s define a List of strings and iterate each element using the iterator pattern.

// This is a collection that eventually we will use an Enumertor to loop through
// rather than a typical index number if we used a for loop.
List<string> Continents = new List<string>();

Continents.Add("Asia");
Continents.Add("Europe");
Continents.Add("Africa");
Continents.Add("North America");
Continents.Add("South America");
Continents.Add("Australia");
Continents.Add("Antartica");
Now we already knows how to iterate each element using a foreach loop:

// Here is where loop iterate over each item of collection
foreach(string continent in Continents)
{
    Console.WriteLine(continent);
}

Read more: Codeproject
QR: Inline image 1

Posted via email from Jasper-net

Why can't I delete a file immediately after terminating the process that has the file open?

|
A customer discovered a bug where terminating a process did not close the handles that the process had open, resulting in their emergency cleanup code not working:

TerminateProcess(processHandle, EXITCODE_TERMINATED);
DeleteFile(someFile);

Their workaround was to insert a call to Wait­For­Single­Object(process­Handle, 500) before deleting the file. The customer wanted to know whether they discovered a bug in Terminate­Process, and they were concerned that their workaround could add up to a half second to their cleanup code, during which the end user is sitting there waiting for everything to clean up.

As MSDN notes,

TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled.
(Emphasis mine.)

Read more: The old new thing
QR: Inline image 1

Posted via email from Jasper-net

WinRT Samples: Running Background Tasks

|
The next Win8 sample shows the general form of the background task contract for Windows 8 Metro applications.

There are two parts to implementing a background task for a Metro style application: 

Implement the IBackgroundTask interface (contract).
Register the background task with the system so that Windows starts the task at the appropriate time.
The IBackgroundTask interface has only one method: Run().  The only parameter to Run() is an IBackgroundTaskInstance.  Your background task will communicate with the Windows system through the IBackgroundTaskInstance. In this sample, the background task registers to receive the Cancelled event from the IBackgroundTaskInstance if it should stop working on the current problem. The background task also updates the IBackgroundTaskInstance.Progress property to notify the system of its progress on the current problem.

You can think of the IBackgroundTask.Run() method as similar to the Task.Run() method in today’s .NET environment: it’s the entry point for your background task.

Registering a background task in WinRT is a bit more involved. Remember that this background task is not the same as just running something asynchronously. Instead, these background tasks communicate with the OS, so that they can receive events while your application is suspended. For example, a Mail client will be awakened, check mail, then update its live tile periodically when suspended. That requires using the Windows system Background Task contract.

You register a Background Task in a few steps, using a BackgroundTaskBuilder object. There are several properties you need to set on the BackgroundTaskBuilder:

var builder = new BackgroundTaskBuilder();
builder.Name = name;
builder.TaskEntryPoint = taskEntryPoint;
builder.SetTrigger(trigger);
The name is simply a name you use to identify the task (uniquely) in your application. The TaskEntryPoint is the fully qualified class name for the type that implements IBackgroundTask.

Read more: SRT Solutions
QR: Inline image 1

Posted via email from Jasper-net

SignalR

|
Async signaling library for .NET to help build real-time, multi-user interactive web applications.

Install
Install-Package SignalR

To install SignalR, run the following command in the Package Manager Console

PM> Install-Package SignalR

Documentation
Read the docs to get started.

License
MIT

Example: DarksideCookie

Read more: SignalR
QR: Inline image 1

Posted via email from Jasper-net

Build p2p chat application with WPF and ASP.NET Web API

| Monday, March 26, 2012
Inline image 2

Recently I’ve been really enjoying myself with ASP.NET Web API. It is a tremendous beast, and with it’s self-hosting capabilities, it’s suitable as an HTTP-channeled-communication not only for ASP.NET websites, but also for any other .NET applications. In this post, I’m gonna try to show you the outcome of my weekend mash up – a peer-to-peer WPF chat application (clients connect directly to each other), fueled by ASP.NET Web API.

More after the jump.

What are we gonna do

So, as mentioned, we’ll try to build a chat application with WPF. It’s gonna be targeted for .NET 4.5 (possible to refactor it into .NET 4 easily as well), make use of of ASP.NET Web Api self-host, and allow us to communicate smoothly over the network through HTTP. Heck, we might even have to ditch Live and Skype by the end of this article.

With ASP.NET Web Api self-host, we can turn any C# product into a web server. What this means, is that each of our chat apps (or “clients”) will essentially be web servers, listening to incoming HTTP requests on a certain port. The idea is simple – if we have two chat “clients” out there in the network, and each of them is a web server with IP address and a port to which they listen – they can easily communicate between each other in a P2P way. We are going to use POST requests as a way to transport messages between the clients.

Getting started

We’ll start off with a normal WPF project, target it to .NET 4.5 and get the necessary self host packagaes from Nuget. To do that, go to Nuget and grab AspNetWebApi.SelfHost. If you do it from VS, it will automaticall get all dependencies as well. If not, you need the Core as well.

Read more: Strath Web
QR: Inline image 1

Posted via email from Jasper-net

30 Free UI Kits

|
Inline image 2 Inline image 3

The graphic interface is the first thing our users see on our websites. To have a good interface is key to guide them through the content and meet their expectations. A good UI is consistent and can make a website easier to understand and use. Also, a beautiful UI can be a critical point for users when deciding between two websites or applications.

Having a set of editable UI elements is essential for every web-designer to make fast layouts and prototypes for their projects. We have collected 30 of the best free UI kits you can find around the Internet and gathered them for you in this post. We hope you find them useful.

Read more: Awwwards
QR: Inline image 1

Posted via email from Jasper-net

Metro XAML and HTML Control Sample Packs (Two downloads, bunches of controls sampled, lots of code examples, hours of...)

|
Inline image 2

A set of Metro style app samples that demonstrate how to use controls.

Description
A set of Metro style app samples that demonstrate how to use controls.

The Windows Samples Gallery contains a variety of code samples that exercise the various new programming models, platforms, features, and components available in Windows 8 Consumer Preview and/or Windows Server 8 Beta. These downloadable samples are provided as compressed ZIP files that contain a Visual Studio solution (SLN) file for the sample, along with the source files, assets, resources, and metadata necessary to successfully compile and run the sample. For more information about the programming models, platforms, languages, and APIs demonstrated in this sample, please refer to the guidance, tutorials, and reference topics provided in the Windows 8 documentation available in the Windows Developer Center. This sample is provided as-is in order to indicate or demonstrate the functionality of the programming models and feature APIs for Windows 8 and/or Windows Server 8 Beta. Please provide feedback on this sample!

QR: Inline image 1

Posted via email from Jasper-net

MSBuild tracing using MSBUILDDEBUGCOMM

|
We know that building in parallel feature is not new in MSBuild.

Here is how it works. When we start a build using IDE/command-line options, the first instance or the parent MSBuild instance starts. The project / solution dependency graph suggests if parallel builds can be spawned or not. If yes, the parent MSbuild process spawns several new instances.

Between the child and the parent instances, there is a handshaking that needs to take place.

In case of unsuccessful handshaking, newer instances cannot be spawned and ultimately the entire build process may fail. It was felt that we should know where the failure is.

Following is the basic criteria for successful handshaking:

The location and version of “microsoft.build.dll” loaded by parent and child msbuild instances should be same.
Recently I was working on an issue where an antivirus was interrupting the build process and we were getting MSB4014 error.

MSbuild team has come up with a logging mechanism which can help us diagnose whether the handshaking between different instances of MSBuild is successful or not.

This mechanism is dependent on the environment variable MSBUILDDEBUGCOMM which enables tracing.

Here is how we can do this:

  1. Make sure no instance of MSBuild.exe are running and that any instance of MSBuild_CommsTrace_xxxx.txt files in %TEMP% are removed.
  2. Close all instances of Visual Studio if any.
  3. Set the environment variable MSBUILDDEBUGCOMM=1.
  4. Run visual studio in that environment. (We can also open up a Visual Studio Command Window from the start menu, set the environment variable, then run devenv.exe.).
  5. Build the project / solution.
  6. Click Start->Run->%TEMP%
  7. Some files will get generated to called MSBuild_CommsTrace_xxxx.txt.

QR: Inline image 1

Posted via email from Jasper-net

Windows 8: 1,000 Metro icons you already have installed

|
Inline image 2

Windows 8 metro applications have a few things in common. One of them is typography. Segoe (pronounced “se-go” not “see-go” or anything else), specifically we’re talking about the Segoe UI font (or a derivative of it), is the standard san serif font in Windows 8 metro applications – and more.

Preview Segoe UI
What does Segoe UI look like? Take a look:

“Segoe is either a registered trademark or a trademark of Microsoft Corporation in the United States and/or other countries.” In all reality, Segoe UI has become “the Microsoft font”, and it’s beautiful.

Wikipedia: [Microsoft] uses Segoe in their online and printed marketing materials, including recent logos for a number of products. Additionally, the Segoe UI family of fonts is utilized by numerous Microsoft applications, and may be installed by applications (such as Microsoft Office 2007 and Windows Live Messenger 2009) or bundled with certain operating systems (including Windows Vista and Windows 7).

Bruce: Segoe UI is an approachable, open, and friendly typeface, and as a result has better readability than Tahoma, Microsoft Sans Serif, and Arial. It is smoother and more book-like than ITC Franklin Gothic. It has the characteristics of a humanist sans serif: the varying widths of its capitals (narrow E and S, for instance, compared with Helvetica, where the widths are more alike, fairly wide); the stress and letterforms of its lowercase; and its true italic (rather than an “oblique” or slanted roman, like many industrial–looking sans serifs). The typeface is meant to give the same visual effect on screen and in print while being highly readable on its own. It was designed to be a humanist sans serif with no strong character or distracting quirkiness.

Read more: Jerry Nixon
QR: Inline image 1

Posted via email from Jasper-net

An easy way to create awesome looking Windows Phone7 icons using expression Design

|
I am always having problems when it comes to creating icons for my Wp7 apps. I am a coder and not a designer, so drawing something nice looking is really really out of my comfort zone.

Previously I spent hours trying to draw symbols myself, but I never really liked the outcome. But lately, I found a quick and effective way to create nice looking icons for my Windows Phone 7 apps. Here it goes:

The Noun project

First, I go to the nounproject website to find some nice looking symbols. This website has hundreeds of symbols and you can download them for free in vector format. The graphics comes with a Creative Commons license, so you’re free to do whatever you want with them. Sounds pretty neat, if you ask me!

Inline image 1

Once, you found the symbol you like, download and extract it. The symbol is in SVG format. I am using Expression Design for drawing my icons, but Design unfortunately does not support SVG yet. I need a tool that can convert SVG to something that I can import to Expression Design.

Inline image 2

Inkscape

With Inkscape I can do exactly this. Inkscape can import SVG and can export .PDF and .PDF can be imported to Expression Design. Inkscape is a very cool, free and open source drawing application. You can download it from here.

Read more: littlebigtomatoes
QR: Inline image 3

Posted via email from Jasper-net

How to disable Windows 8 toaster notification

|
Toaster notification is one of thousand new features that you’ll see built-in to Windows 8.

This may well be a good feature to alert the user for certain events that may be happening inside of your system, but for many users will feel that it can get in the middle of what they are doing.

So in Pureinfotech How-To you are going to learn how easy is to disable toaster notification in Windows 8 for all or just for certain applications .

Disabling toaster notification

1 Use the Inline image 1 + I to bring the Desktop menu and click Notifications.

Inline image 3

Read more: PureInfoTech
QR: Inline image 2

Posted via email from Jasper-net

SCSS — немного практики, часть I

|
Inline image 2

Статей про SASS(SCSS), Less на хабрахабре уже полно, но на мой взгляд не хватает такой, в которой было бы немного реальной практики. Я постараюсь восполнить этот пробел. Около года назад одна из SASS-статей меня «зацепила», и с тех пор я полюбил эту технологию настолько, что ручной набор обычного CSS кода представляется мне лишней тратой времени. Сия статья посвящается тем верстальщикам (или web-программистам), которые про SCSS ещё не слышали, или же ещё не пробовали в деле. Более опытным товарищам, полагаю, в ней ловить нечего.

Что такое SCSS

SCSS — «диалект» языка SASS. А что такое SASS? SASS это язык похожий на HAML (весьма лаконичный шаблонизатор), но предназначенный для упрощения создания CSS-кода. Проще говоря, SASS это такой язык, код которого специальной ruby-программой транслируется в обычный CSS код. Синтаксис этого языка очень гибок, он учитывает множество мелочей, которые так желанны в CSS. Более того, в нём есть даже логика (@if, @each), математика (можно складывать как числа, строки, так и цвета). Возможно, некоторые возможности SCSS покажутся вам избыточными, но, на мой взгляд, лишними они не будут, останутся «про запас».

Отличие SCSS от SASS заключается в том, что SCSS больше похож на обычный CSS код. Пример SASS-кода:
$blue: #3bbfce
$margin: 16px

.content-navigation
  border-color: $blue
  color: darken($blue, 9%)

.border
  padding: $margin / 2
  margin: $margin / 2
  border-color: $blue

И тоже самое на SCSS:
$blue: #3bbfce;
$margin: 16px;

.content-navigation {
  border-color: $blue;
  color: darken($blue, 9%);
}

.border {
  padding: $margin / 2;
  margin: $margin / 2;
  border-color: $blue;
}

Read more: Habrahabr.ru
QR: Inline image 1

Posted via email from Jasper-net

New Duqu Sample Found in the Wild

|
Inline image 1

We recently received a file that looked very familiar. A quick investigation showed it to be a new version of W32.Duqu. The file we received is only one component of the Duqu threat however—it is the loader file used to load the rest of the threat when the computer restarts (the rest of the threat is stored encrypted on disk). The component we received has been highlighted below (Driver file .sys) in an image taken from our Duqu whitepaper:

Read more: Symantec
QR: Inline image 2

Posted via email from Jasper-net

כיצד ניתן לבטל את ההתראה לפני מחיקת קבצים במערכת ההפעלה ?

|
בשימוש היום יומי במחשב אנו מבצעים פעולות רבות עם הקבצים השונים במערכת ההפעלה ; שולחים אותם בדואר אלקטרוני , מעתיקים , מוחקים  משנים את שמותיהם ועוד פעולות רבות ומגוונות . כל אחת מהפעולות הנ"ל מתבצעות באופן מיידי ברגע בו נתנו פקודה למערכת לבצען למעט פקודת המחיקה . פקודה זו תגרום להופעת חלון התראה לפני מחיקת הקובץ אשר בו יהיה עלינו לאשר את הפעולה על מנת לבצע את המחיקה בפועל  – אם כך כיצד ניתן לבטל את ההתראה לפני מחיקת קבצים במערכת ההפעלה ?

שלום לכולם ,

כאן רותם כהן מצוות התמיכה של Microsoft והיום נלמד כיצד לבטל את ההתראה לפני המחיקה וכיצד לאפשר למנהל המחשב או הרשת למנוע את היכולת לבטל התראה זו .

קבצים הנמחקים במערכת ההפעלה אינם נמחקים מיידית אלא מועברים אל תקיית סל המיחזור עד למחיקה סופית שלהם מתקיה זו . על אף קיומו של סל המחזור במערכת ההפעלה עדיין מופעלת במערכת הגנה נוספת בדמות התראה על המסך אותה המשתמש צריך לאשר על מנת לבצע את העברת הקובץ אל סל המחזור .

Inline image 1

משתמשים מתקדמים וודאי מכירים את האפשרות להחזיק את כפתור SHIFT במקלדת וללחוץ על כפתור DELETE על מנת למחוק את הקובץ ישירות ממערכת ההפעלה מבלי להעבירו אל סל המחזור תחילה .

מאחד , משתמשים מתקדמים ומנוסים יכולים למצוא את התראת המחיקה כגורם מעכב בשימוש במערכת אך מנגד עומדים מנהלי הרשת או מנהלי המחשב שרוצים להגן על המשתמשים ממחיקת קבצים בטעות. על מנת לשרת את שני הצדדים נלמד כיצד לבטל את הופעת ההתראה ומנגד נלמד כיצד למנוע מהמשתמשים את היכולת לבטלה .

ביטול ההתראה לפני מחיקת קבצים במערכת ההפעלה

על מנת לבטל את התראה המחיקה כל שעלינו לעשות הוא לפעול על פי השלבים הבאים :

1.לחצו מקש ימני על סל המחזור ובחרו במאפיינים

QR: Inline image 2

Posted via email from Jasper-net

Debugging C/C++ and CPython using GDB 7′s new Python extension support

|
I’ve recently been looking into ways to improve my debugging experience with mixed Python and C/C++ programs. I spend a fair amount of time working on systems built using both languages in tandem, and the tools available for debugging across the languages have historically been very limited. Often, logging and/or intimate knowledge of the Python C-API (and, in my case, boost.python) were the primary tools available.

I was naturally very excited, then, when GDB 7 introduced support for extension via Python. This seemed like an obvious step towards a “unified” debugging environment, one where I could step naturally between the languages, set breakpoints, etc. This new GDB feature doesn’t solve the problem directly, but it opens the door for more sophisticated extensions to GDB than were previously practical.

Building on this new GDB feature, recent Python source releases include GDB extensions as a build product. That is, starting at around python-3.2, when you build Python from source one of the build products is a set of GDB extensions that make it possible to do very natural debugging of Python from inside GDB. These extensions allow you, for example, to step up and down the Python call stack, display frame information (locals), and so forth. And this can be done while also navigating the base C call stack. This provides a very intuitive and productive debugging environment for anyone working across the two runtime environment.

edit: It was pointed out on reddit that gdb’s embedded Python interpreter has been around since 2009 and is thus not particularly new.

GDB 7′s Python extension system

What exactly is GDB’s new Python extension system? Broadly speaking, it’s a way to script GDB using Python rather than GDB’s own internal language. From around version 7 onward, GDB embeds a Python interpreter that you can invoke from the prompt and from scripts. For example:

(gdb) python
&>import sys

To support writing extensions, you can import the module “gdb” from this embedded interpreter. This module provides access and hooks into GDB so that you can control it via Python scripts. You can read all about this Python extension support in GDB’s documentation.

This new facility has been used to implement, for example, pretty printers for STL containers. But in this article we’re interested in improving the CPython debugging experience, so we’ll cover that in the next section.

Read more: Misspent
QR: Inline image 1

Posted via email from Jasper-net