Tag | Csharp Posts

In this Issue: René Schulte, Walter Ferrari, Amyo Kabir, David Anson, Jesse Liberty, Mike Taulty, Erik Mork, Jeremy Likness, and Joost van Schaik. Above the Fold: Silverlight: "Swapping two elements in a bound ObservableCollection" Joost van Schaik WP7: "Tracking Sales Statistics with the Silverlight Analytics Framework for Windows Phone" René Schulte Sharepoint: "how to build a small Silverlight 4 utility to upload files in a List or Library of Sharepoint" Walter Ferrari Shoutouts: Mike Taulty blogged ...
My coworker John Sonmez had a great blog post recently illustrating how to refactor a switch statement. In short, he outlined how to take a switch statement covering all known values of a C# Enumeration and convert it into a Dictionary “map” object allowing you to quickly determine what action to take given any valid enumeration value. I really like this approach as I think it leads to more readable code. The one thing that’s always bothered me about enumerations though is that they can change with ...
I wrote in current project typical funcion to count the number of elements in db for specific criteria using NHibernate HQL: IQuery query = Session.CreateQuery(@" select count(t.ID) from Post p join p.Tags t where t.Name=:tagName and p.Blog.Name=:blogName ") .SetParameter("tagName", tagName) .SetParameter("blogName", blogName); int result=query.UniqueResult&l... I was very surpriced to see that I stuck with System.InvalidCastException: Specified cast is not valid. Solution for this was to ...
Es el rendimiento de aplicaciones por mucho, una de las cosas que más nos preocupa durante el desarrollo de nuestras aplicaciones, y digo por mucho, porque en ocasiones es muy sencillo desarrollar una interfaz gráfica excelente pero se olvida una cosa, el costo de interacción que esto brindará al usuario. Vamos a ver una forma en la que podemos medir el rendimiento de nuestra aplicación con el fin de poder trabajar en las áreas más criticas para poder lograr un mejorarlo. 1. Para nuestro ejemplo, ...
One of the first things I build for a new feature in MVC is a controller, with actions. For the C# Tutorial at C# Station, I built a CSharpTutorial controller and began looking at what actions were necessary. Considering the tutorial is at 23 lessons and growing, it doesn’t make much sense to create that many actions; especially with the glaring redundancy. The solution in this situation is a custom route. The following route definition solves this problem by isolating a parameter, lessonNumber: ...
Many sites have a contact form, instead of posting email addresses. Admittedly, email addresses are convenient for customers because they can use a mailto link that brings up their email client and allow them to start typing, archive the communication, and manage the thread. When I first started C# Station, that’s what I did; posted my email address for everyone. Holy cow, what a mistake. I received so much spam that my inbox was unusable. Fortunately, spam is more manageable these days, but it’s ...
In this Issue: Jesse Liberty, Senthil Kumar, Jason, John Papa, Jeff Blankenburg(-2-, -3-), Jeremy Likness, Richard Waddell(-2-), Karsten Januszewski, Brad Tutterow(-2-). Above the Fold: Silverlight: "Isolating the C# Code in Silverlight Class Library Projects" Richard Waddell WP7: "31 Days of Windows Phone | Day #29: Animations" Jeff Blankenburg Training: "More training videos of Windows Phone 7 for Developers" Senthil Kumar "Windows Phone 7 How-To Index" Karsten Januszewski Shoutouts: Lots of Silverlight ...
C# Station has gone through multiple updates over the years. I started it on the 4th of July 2000, shortly after the first announcement of the C# programming language, hence the name. You can find analytical information on Alexa and the Wayback Machine shows screen shots of changes over time. Whenever you pop something on the Web without much thought, there can be true ugliness. The journey from plain text links to drop-down menus evolved from necessity because the number of pages grew from 1 to ...
Today at PDC 2010, they announced Asynchronous functions in C# and VB.NET. So what exactly does that mean? I’ll give you the definition first: Asynchronous operations are methods and other function members that may have most of their execution take place after they return. In .NET the recommended pattern for asynchronous operations is for them to return a task which represents the ongoing operation and allows waiting for its eventual outcome. You completely understand right? Me neither! I have been ...
In this Issue: Michael Crump, Derik Whittaker(-2-), James Ashley, Mike Taulty, Jeff Blankenburg, Kunal Chowdhury, Richard Waddell, and Jeremy Likness. Above the Fold: Silverlight: "Choose the way to Create a Silverlight Out-of-Browser Application" Kunal Chowdhury WP7: "Why Deactivated is not the same as Tombstoned" James Ashley Blend: "More Simple Blend Layout Techniques and Quirks" Richard Waddell Shoutouts: This is clever and I just couldn't pass up mentioning it from Dean and Ying's Blog: iPhone ...
I love Silverlight and have written / talked about it a lot. I can’t help but notice that a lot of people are new to Silverlight or may have played with it a few times. Well this post is for you. It is a list of 15 things that I’ve discovered since I started developing for Silverlight. If you are a full-time Silverlight developer than I would hope you know most of these. I promise not to scare off anyone with talks of MVVM, Prism or MEF. 1) The line highlighted below represents the MIME type and ...
In this Issue: Walter Ferrari, Wei-Meng Lee, Rob Eisenberg, Timmy Kokke, Joost van Schaik, Jesse Liberty, Jeff Blankenburg, Jeremy Likness, and Victor Gaudioso(-2-). Above the Fold: Silverlight (and Sharepoint): "Silverlight and Sharepoint 2010: Getting Started" Walter Ferrari WP7: "Windows Phone 7 – Animation and Games (Part 2)" Jesse Liberty WP7 (2): "31 Days of Windows Phone | Day #19: Push Notifications" Jeff Blankenburg Shoutouts: Tim Sneath has some (not messy) pumpkin-carving fun to share ...
There is a good deal of Ruby envy among the more outspoken .NET developers. This post is an attempt to aggregate the many blog posts from .NET developers expressing their love of ruby. Rob Conery Why I Like Ruby Why I Like Ruby, Part 2: Blocks Contrasting Ruby and C# Using My College Friends Scott Bellware Ruby For .NET Developers Justin Etheredge What is so great about Ruby? Jeremy Miller Silly thing I want from Ruby in C# David Tchepak Essence and ceremony, Ruby and C# John V. Petersen Why I Love ...
AutoMapper is very useful and flexible tool. Using it we can avoid writing stupic mapping code for each entity to it's DTO representation to send it e.g. throught web service. If entity and dto object are mapping 1:1, there what we need to do is only write two lines of code: Mapper.CreateMap<Article, ArticleDTO>(); //e.g. in Global.asax and var result=Mapper.Map<Article, ArticleDTO>(article); It's not important, if Article class have ten or tousand fields. That's all. Think how horrible ...
UPDATED: Feb 16th 2012: Workaround #1 and #2 only works when run-time checking is not enabled. Added workaround #2B which seems to work. Thanks to David S, Michael S and ZbynekZ for pointing this out, and sorry for not responding faster to this. Also added comments and overviews over what happens for different settings. There have been several reports on problems with the Static Code Analysis (SCA) not adhering to the statements of the Code Contract tools. See these links: connect, forum1, forum2. ...
Entity Framework 4 Code First CTP4 was released in July and the API for developing without any edmx continues to mature and get better. Code First allows you to define your entity framework configuration with a Fluent API similar to Fluent NHibernate. Although the API for EF Code First is very user friendly, you should still have integration tests to verify that you’ve configured your entities correctly. This post will walk through configuring EF4 Code First optimistic concurrency. Suppose I have ...
As I mentioned in my last post I talked some about how my side project, PiX Eyewear, has given me an opportunity to venture out of the predominantly server-side .NET programming that I’ve been doing at my “day job” for the past several years. In this post I’ll be digging into a simple way that I’ve been able to leverage jQuery to solve a little problem I had with my Shopify site. Before I go any further I want to call out an excellent approach for displaying “related products” on a product page that ...
Using named arguments everywhere is tedious and unnecessary, but can be applied as needed to improve the readability of your code. Here’s an example, using Directory.Delete() that helps document the meaning of a bool argument: Directory.Delete(pathToDelete, recursive: true); If Directory.Delete was your own code, you could re-write the parameter to use an Enum and get away from the bool code smell. However, Directory is a class in the .NET Framework’s System.Diagnostics namespace, which demonstrates ...
I received (by chance, mostly) a Netduino last tuesday. Netduino is an open-source hardware project based on Arduino and the .Net Micro Framework. And it’s extremely cool. I’m a C# developer and I was always interested in electronics. This is an excellent tool to start to understand that incredible world. I was about to buy an Arduino when the Netduino fell on my lap, so I was really happy about it. Netduino has various disadvantages over Arduino (for starters, it’s more expensive, not all the shields ...
Today, I added a new extensibility feature to LINQ to Twitter, called Raw Queries. The Twitter API has historically changed suddenly and without warning, leaving 3rd party libraries, such as LINQ to Twitter deficient in full support. On occasion, LINQ to Twitter encounters bugs that leave users without a means for accomplishing specific tasks. Therefore, we need work arounds to allow users to quickly adapt to changes and new features. Raw queries include two points of extensibility: the ability to ...
I am using the mouse with my left hand but I am not swapping the mouse buttons. (Old habit from the times I was using public workstations at the university. I was too lazy to play with the system setup every time, so that I just moved the mouse from the right to the left side.) I am also using multiple pointing devices with my notebook. (a gaming mouse with multiple buttons at home, a simpler one at work, and also from time to time the touchpad ). Normally I would setup the mouse button layout in ...
In this Issue: Sandrino Di Mattia, Kranthi Kiran Gullapalli(-2-), Mike Snow, David Anson, Jeremy Likness, Vikram Pendse, Paul Sheriff(-2-), Markus Egger, Johan Danforth, and Beth Massi. Above the Fold: Silverlight: "Change Templates Dynamically in Silverlight" Paul Sheriff WP7: "Silverlight On Mobile : InputScope in Windows Phone 7" Vikram Pendse MEF: "MEF in the Wild: A Retrospective " Jeremy Likness Shoutouts: Jesse Liberty posted The Great Silverlight Competency Test #6 From SilverlightCream.com: ...
In this Issue: Michael Washington, Jeff Wilcox, Erik Mork(-2-), Jesse Liberty(-2-), Morten Nielsen, Josh Smith, Mohamed Mosallem, and Jose Fajardo. Above the Fold: Silverlight: "Consuming resources from external assemblies in Silverlight 4 " Josh Smith WP7: "Using an image as a mask so that WP7 theme’s are honoured " Jose Fajardo Shoutouts: Jeremy Likness has posted his Intro to MVVM: Slides and Sample Code from his presentation at the Atlanta Silverlight Meetup group. Mark Tucker has a video up ...
I am hanging recently around a lot in the MS SQL Server Forums where I have a lot of fun. One of the interesting questions that popped up today was about how to execute several operating system commands that span multiple lines. Besides, even though the job step editor presents you with a text box, this is not the same as writing a batch file. All the editor does it sees the first command statement. What to do? Some people resorted to writing subsequent commands in the next job step, but this sounded ...
Recently I blogged about WCF REST services with no svc file and no config. In this post I also discussed the pros/cons of WCF services as compared to using MVC controller actions for web services and I made the case that, in many instances, WCF REST services is better than using the MVC infrastructure because WCF provides: a more RESTful API with less work a convenient automatic help page to assist consumers of your service automatic format selection (i.e., xml/json) depending on HTTP headers In ...
I’ve seen a lot of post describing how to customize a Silverlight Listbox during design time, but sometimes we want the user to have the ability to switch “themes” while the application is running. I originally started working on this for a project that would switch themes during different times of the day and decided to share here. Go ahead and fire up Blend 4 and select Silverlight Application + Website. Give it a name and hit OK. We are going to create sample data first. This will give us a Listbox ...
This blog post has moved:http://gruffcode.com/... ...
In this Issue: Michael Washington, Paul Patterson, Gergely Orosz, Dimitris - Ilias Gkanatsios, Kirupa Chinnathambi, SilverLaw(-2-), Sergey Barskiy, Jeremy Likness, and Sigurd Snørteland. Above the Fold: Silverlight: "CodeBox - Syntax Highlighting In Silverlight For Any Programming Language " SilverLaw WP7: "Back to Windows Phone 7 Database " Sergey Barskiy Lightswitch: "LightSwitch Student Information System (Part 2): Business Rules and Screen Permissions " Michael Washington Shoutouts: Karl Shifflett ...
When you first run Visual Studio 2010 (VS2010), it asks you to select a profile (e.g. C#, C++). This determines the Start Page displayed when VS2010 starts. Once you pick this, there appears to be no easy way to change your selection (at least none that I've found). To see which start pages are available to you, look in the following directory: 32-bit Windows: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\StartPages\en 64-bit Windows: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\StartPages\en ...
If you’ve played around with the WP7 emulator, you may have gotten into the settings screen and may have noticed that there are these things called “themes”. The emulator’s default is the “dark” background with the “blue” accent. However the phone can also have a “light” background, and supports the following accents: “magenta”, “purple”, “teal”, “lime”, “brown”, “pink”, “orange”, “blue”, “red”, “green”, and an eleventh optional color that the manufacturer of the phone can set. Most people naturally ...
I've got a solution to running and debugging unit tests for WCF hosted services that utilize the CMServiceHost. Whether your generate your serivce proxy via WSDL (Add Service Reference) or Shared Contract (ClientFactory), the solution is similar. This email will detail how to invoke a WCF Service Host for testing in both scenarios. Testing a service client generated via "Add Service Reference" I'll illustrate the solution using the following sample unit test. Let's assume you've created a service ...
In this Issue: Michael Washington(-2-), Brian Noyes, Michael Ossou, Sharker Khaleed Mahmud, Mike Taulty, Jeremy Likness, Brad Tutterow(-2-), and András Velvárt. Above the Fold: Silverlight: "Best Practices for Themes in Modular Silverlight Applications " Jeremy Likness WP7: "Being theme aware in Windows Phone 7 Silverlight apps" András Velvárt Lightswitch: "LightSwitch Student Information System" Michael Washington Shoutouts: Erik Mork & Crew have their latest podcast up: Show 106: Jetpack themes ...
I love Silverlight and have written / talked about it a lot. I can’t help but notice that a lot of people are new to Silverlight or may have played with it a few times. Well this post is for you. It is a list of 15 things that I’ve discovered since I started developing for Silverlight. If you are a full-time Silverlight developer than I would hope you know most of these. I promise not to scare off anyone with talks of MVVM, Prism or MEF. 1) The line highlighted below represents the MIME type and ...
in and between operators if (x in (1, 2, 3)) if (x in 1:5) if (x between(1,5)) · Like Python - Without having to use extension methods Data Structure Improvements · Make BCL collections to be generic: all this ControlCollection, XmlAttributeCollection, SqlErrorCollection, StringCollection becomes Collection<Control>, Collection<XmlAttribute> and Collection<SqlError> · Tuple Packing and Unpacking - Like python: public Tuple<string, int, double> ReturnMyTuple() { return "Hello ...
I created a getting started guide for the MVVM pattern back in June 2010. Since the guide came out, I had several developers ask me when I was going to publish my MVVM example that I had promised. I played around with a way to present this that did not seem like the same old MVVM blog post that everyone has already written. Most of the blog post that I ran across explaining the pattern had lots of complicated diagrams and code snippets that would leave out vital pieces of information. I decided that ...
In this Issue: Ben Wintringham, XNA Creators Club(-2-), Sony Arouje, John Papa, Mike Ormond, Microsoft(-2-), Jaana Metsamaa(-2-), Todd Knudsen, Jeremy Likness. Above the Fold: Silverlight: "Design-Time Friendly ViewModels with MEF " Jeremy Likness WP7: "XNA from Silverlight on Windows Phone 7 – Saving Pictures " Mike Ormond Training: "Create Games for Windows Phone 7 " XNA Creators Club Shoutouts: Charles Petzold will be presenting on WP7 in New York on October: Author news: Charles Petzold presenting ...
Recently we had a project where we needed to render certain questions on the screen dynamically based on answers to previous questions on previous screens. For questions that need to dynamically be visible/invisible on the same screen, this can simply be controlled with jQuery. However, in this case, based on the user’s input on previous screens we know there are certain questions that will not be applicable before the current screen even loads. In this case, we could use jQuery to set those questions ...
In this Issue: Tony Champion, Tim H, Roger Gullhaug, Jeremy Likness, Brad Tutterow, Derik Whittaker, Paul Patterson, Sam Judson, SilverLaw, Dave Edson, Silverlight Team, and Sergey Barskiy. I'm test-driving something new today... I'm listing 'my' pick(s) from the list of things I'm discussing in each of the various categories I've posted on... which will change daily. Today I'm highlighting a Silverlight post, a WP7 post, and a training one. I'm listing these as "Above the Fold" because they will ...
Technorati Tags: Linq,Enumerable.Range,Inter... Basic,VB MSDN Reference: Enumerable.Range Method I deal with a lot of RANGES at work for a multitude of reasons. When auditing data and databases, it’s often necessary to check the boundaries of values or to set them. I’ve recently become very fond of Enumerable.Range because it offers a lot of convenience when dealing with certain types of ranges and can allow a fair amount of complexity. For instance: If I need to represent ...
Problem context We use a backgroundworker to load MXD documents from several places of the system and extract meta data and thumbnails which a GUI component shows in an asynchron way. The unit tests for this logic throws an exception during the access the thumbnail: 'mapDocument.Thumbnail' threw an exception of type 'System.Runtime.InteropServ... exception = {"Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"TargetSite = {stdole.IPicture get_Thumbnail()} Solution ...
(This is a series of posts covering how to include a WinForm app inside a SharePoint 2007 application, which allows users to upload batches of files to a SharePoint document library. For further info, please see Posts One, Two, and Three. All of the code can be downloaded in Post Two.) Just a quick review of our solution, as detailed in the first three posts of this series: a Custom Action adds a menu choice to a document library’s Upload menu, which links to a Windows Form application deployed using ...
I have a listView that is populated every 1/2 sec and when I set the TopItem to an ListItem whose index > visible items, then the list jumped between the topItem and back 2 spots. To correct the problem, I set the TopIterm AFTER the call to EndUpdate as shown in this code snippet: 1: lvB.EndUpdate(); 2: lvI.EndUpdate(); 3: lvR.EndUpdate(); 4: 5: if (lstEntryInts.Items.Count > 0) lstEntryInts.TopItem = lstEntryInts.Items[iTopVisI... 6: if (lstEntryBools.Items.Count > 0) lstEntryBools.TopItem ...
I use structures to group data, such as messages or data records. I also use structures to pass groups of data between functions so that I don't have a long parameter list. Ususually, structures are used within the same class, but I use them to between classes. To allow more than one class to use the structure, I encapsulate the structure(s) within another class that is used by all the classes that use the structure. In this example, I pass a structure from a function in one class to another function ...
C# supports what I call waitForEvent threads or formally known as synchronous event threads. This is a thread that is fired whenever an event in another thread occurs. I use this type of thread to perform an action when a bit transitions from true to false, a variable transitions above/below a limit. The reason for doing this is because we do not want to interrupt the timer thread which checks these values on a 1-sec basis with the chore of building & sending messages, updating database tables, ...
Many times, especially during development, you could have certificates that are out of date, aren’t singed by any real authority (makecert, etc.), or even don’t match the host name that the request is issued against, but you want to test, etc. One example is if you want to run Fiddler to get a good over-the-wire trace of the HTTP traffic, when the endpoint is accessed over HTTPS. With Fiddler, you can capture HTTPS traffic, only thing is, it sticks it’s own certificate in the chain which doesn't ...
In the past when I needed to test what my application looked like with sample data. I’d create a class named Data.cs and write some code like the following: Data.cs public class Data { public string Name { get; set; } public int Age { get; set; } } Code Behind: List<Data> source = new List<Data>(); for (int i = 0; i < 50; i++) { source.Add(new Data() { Name= "MIKE" + i, Age = i, }); } dg.ItemsSource = source; This would provide me with some quick and dirty sample data, but it really ...
In part 1 of Crack .Net Applications I demonstrated how easy it was to reverse engineer an an unprotected .Net application. In this post my aim is to highlight a few techniques that one can employ to protect ones code from this type of hacking. So, my take on software protection is that one can never be 100% protected – given infinite time you can guarantee someone with enough intelligence will be able to bypass all security measures that you ever implement – that being said, we don’t have infinite ...
(This is a series of posts covering how to include a WinForm app inside a SharePoint 2007 application. For further info, please see Posts One, Two, and Four. All of the code can be downloaded in Post Two.) As I promised several months ago, I’ll cover the Custom Action piece of our solution. The custom action is used to allow the users to launch our Windows Forms application using Click Once deployment. Our custom action adds a new link to the Action menu of a document library’s toolbar: Adding a ...
The ObjectID is assigned to each document when the document is persisted in the MongoDb database. The ObjectID is a unique ID to distinguish between different documents. The ObjectID is kept in the field/attribute called “_id”. This attribute is very important when fetching and updating the records. When using MongoDb with C# driver I usually create a property called “_id”. This property maps directly with the _id field of the MongoDb storage system. Let’s say you do not have _id in your C# entity ...