tag:blogger.com,1999:blog-15212063726272298502024-03-19T04:34:50.683-07:00my cup of <T>Posts, rants and any random thoughts about software development and technology in general.Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-1521206372627229850.post-73375833716484606412014-05-28T14:28:00.002-07:002014-05-28T15:31:43.360-07:00What Xamarin 3 means to the future of Mobile Development<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBP-E7p2GvgDSOFIHDEW3bn0xd8MAz60xMfAlfNNfxIk8oHVCxdjNQnrDi7JMGKf7yKLjF0LiAWxIe34zU5wbpJX11apXMibcnWkb0EwzW33Ikh-CvHK7-L3ZPdFXCbwWhylH9VvqNXa4/s1600/crm-app.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBP-E7p2GvgDSOFIHDEW3bn0xd8MAz60xMfAlfNNfxIk8oHVCxdjNQnrDi7JMGKf7yKLjF0LiAWxIe34zU5wbpJX11apXMibcnWkb0EwzW33Ikh-CvHK7-L3ZPdFXCbwWhylH9VvqNXa4/s1600/crm-app.png" height="265" width="400" /></a></div>
<br />
It was just a few hours ago that <a href="http://xamarin.com/">Xamarin</a> release <a href="http://blog.xamarin.com/announcing-xamarin-3/">Xamarin 3. </a> With this announcement they have yet again revolutionized the way we write cross-platform mobile applications.<br />
<br />
The announcement first highlights the Designer for iOS, which is awesome, but I want to take a step forward, and instead talk about what I think Xamarin.Forms will do for your future mobile development efforts.<br />
<br />
<b>Some background: </b>For the last few months <a href="http://megsoftconsulting.com/">my company </a>worked and developed an internal MVVM framework that provides services such as Navigation, Bindings, Loosely-coupled messaging, mobile optimized Dependency Injection, List Controls for effortless displaying data, etc. to be used in our projects because we believe these are things that real apps need, and what was available at the time did not fit our style of MVVM development, so we rolled our own. Were were in the process of rolling out support for Windows Phone and were very excited to what we would be able to accomplish with this newly created framework when creating apps for all 3 platforms. <br />
<br />
While you might think that today's announcement would be annoying, or bittersweet to us, it is quite the contrary. We no longer have to maintain and evolve our framework, and instead we can focus on applying all we learned while creating this -yet to be named- framework, and instead extend (if needed) what Xamarin has just rolled out.<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7NNNeklY8WDmZ9TuWNuzR7r3inNTAYCvxqwSNn_dg-Bb9C8j1o7NmMsjmBVxSrLhzJ3qOY94kUGtT22QOKXSDeRlOlO9G1PAeIF5YYosaIHTofROiCqmJGJ50d5rX2FZ8kjgx8kYapvM/s1600/example-app.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7NNNeklY8WDmZ9TuWNuzR7r3inNTAYCvxqwSNn_dg-Bb9C8j1o7NmMsjmBVxSrLhzJ3qOY94kUGtT22QOKXSDeRlOlO9G1PAeIF5YYosaIHTofROiCqmJGJ50d5rX2FZ8kjgx8kYapvM/s1600/example-app.png" height="131" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Sample UI on all 3 Platforms.</td></tr>
</tbody></table>
One of the immediate advantages of Xamarin.Forms over other frameworks (including our own) is that these services work on not only on the two (iOS and Android) but 3 mobile platforms (Windows Phone), and it promises the ability to achieve the quintessential 100% Code sharing.<br />
<br />
"That's not something new" - You might say; and I would have to agree with you. <a href="https://github.com/MvvmCross/MvvmCross">MVVMCross </a>(the most well known mvvm framework in the Xamarin ecosystem) does that. But where Xamarin.Forms has no comparison is, in that it attempts (and in my mind succeeds) to bring XAML one step closer to being in all the mobile platforms (<a href="http://channel9.msdn.com/Events/Build/2014/3-591">Something Microsoft just recently started doing</a>).<br />
<br />
XAML in itself is might not sound like a big win for seasoned iOS and Android developers, but think for a moment in the millions of developers who are already familiar with Microsoft technologies and UI creating in WPF, Silverlight and WP8. These guys already are already familiar with constructs such as Page Based UIs, Navigation Services, Two-way Bindings, Data Templates, etc.<br />
<br />
I invite you not just to believe me, and go try it yourself. The framework is already available <a href="http://xamarin.com/download">today</a> and let me know how awesome it it!!<br />
<br />
<br />Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com4tag:blogger.com,1999:blog-1521206372627229850.post-25787504891449328352014-05-27T15:30:00.000-07:002015-05-27T09:35:08.379-07:00Lo que Xamarin 3 significa para el futuro de desarrollo móvil<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBP-E7p2GvgDSOFIHDEW3bn0xd8MAz60xMfAlfNNfxIk8oHVCxdjNQnrDi7JMGKf7yKLjF0LiAWxIe34zU5wbpJX11apXMibcnWkb0EwzW33Ikh-CvHK7-L3ZPdFXCbwWhylH9VvqNXa4/s1600/crm-app.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="265" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBP-E7p2GvgDSOFIHDEW3bn0xd8MAz60xMfAlfNNfxIk8oHVCxdjNQnrDi7JMGKf7yKLjF0LiAWxIe34zU5wbpJX11apXMibcnWkb0EwzW33Ikh-CvHK7-L3ZPdFXCbwWhylH9VvqNXa4/s1600/crm-app.png" width="400" /></a></div>
<br />
Hace pocas horas que <a href="http://xamarin.com/">Xamarin</a> lanzó oficialmente <a href="http://blog.xamarin.com/announcing-xamarin-3/">Xamarin 3</a>. Con este anuncio acaban de una vez más revolucionar la forma en que escribimos aplicaciones móviles multi-plataforma.<br />
<br />
El lanzamiento primero subraya el nuevo diseñador de pantallas para iOS en Visual Studio, el cual es sorprendente, pero por ahora vamos a avanzar un paso hacia adelante para hablar de Xamarin.Forms y lo que yo pienso logrará para tus futuros proyectos de desarrollo móvil.<br />
<br />
<b>Información de contexto:</b>Por gran parte del ultimo año <a href="http://megsoftconsulting.com/">mi compañía </a> desarrolló un framework interno basado en el patrón MVVM (Model, View, ViewModel) que provee servicios como Navegación, Bindings, Loosely-coupled messaging, mobile optimized Dependency Injection, List Controls para desplegar datos facilmente, etc. Este framework fue utilizado en varios de nuestros proyectos para clientes ya que cuando se crean apps de verdad, estos servicios son necesarios, y en aquel momento lo que estaba disponible no encajaba en nuestro estilo de desarrollo MVVM, así que creamos nuestro propio framework. Recientemente estabamos en el proceso de implementar la funcionalidad para Windows Phone y estábamos super contentos con el potencial que tendría dicho framework para crear aplicaciones para las tres plataformas (iOS, Android y Windows Phone).<br />
<br />
Mientras que podrías pensar que el anuncio del día de hoy es fastidioso para nosotros, tengo para contarte que es todo lo contrario. Ya no tendremos que mantener y evolucionar nuestro framework, y en su lugar nos podemos enfocar en aplicar todo lo que aprendimos al crear esta todavía-no-nobrada librería (y extender la de Xamarin, en caso de necesitarse).<br />
<br />
<div style="text-align: right;">
</div>
Una de las ventajas imediatas de Xamarin.Forms sobre todas las demás librerías (incluyendo la nuestra) es la de incluye todos estos servicios para no solo las dos plataformas para los que ellos tiene productos (iOS y Android) pero también para Windows Phone, y promete la habilidad de alcanzar 100% de re-utilización de código.<br />
<br />
"Esto no es nada nuevo" - Diría un lector incrédulo - Melvyn Perez- Y tendría que darte la razón. Ya existen librerías que logran traer estos servicios al eco sistema de Xamarin; <a href="https://github.com/MvvmCross/MvvmCross">MVVMCross</a> siendo la más conocida. Pero donde Xamarin.Forms se "come los bizcochitos" (modismo Dominicano que significa ser superior) es en el hecho de que logra traer a XAML un paso más cerca de estar presente en todas las plataformas móviles. Algo que Microsoft ha estado empujando desde hace tiempo y recientemente ha logrado en la plataforma Microsoft con Universal Apps. <br />
<br />
XAML per se no suena como un gran logro si eres un developer de iOS y/o Android, pero toma un momento y piensa sobre los millones de desarrollador@s que ya están familiarizados con tecnologías Microsoft para crear Interfaces de Usuario (UI por sus siglas en Inglés) en WPF, Silverlight y Windows Phone. Est@s developers ya tienen mucha experiencia con conceptos como Pages, Navegación, Bindings, Data Templates y otros.<br />
<br />
Yo los invito a que no me crean y los traten por ustedes mismos. El framework ya está disponible <a href="http://xamarin.com/download">hoy</a>. ¡¡Me dejan saber lo formidable que es!!!<br />
<div>
<br /></div>
Versión traducida del articulo original en<a href="http://claudioasanchez.blogspot.com/2014/05/what-xamarin-3-means-to-future-of.html"> inglés.</a>Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com1tag:blogger.com,1999:blog-1521206372627229850.post-27116924365955649402013-10-27T11:08:00.000-07:002015-05-27T09:40:10.978-07:00Creating Netflix-like UI for iOS with Xamarin.iOS and NucliosA Xamarin.iOS version of the XCode-based sample <span style="background-color: white;"><b><i><a href="https://github.com/claudiosanchez/Nuclios.Netflix">Creating a Netflix style iOS Grid with C#, Xamarin.iOS and NucliOS</a></i></b></span> by <a href="http://www.infragistics.com/community/blogs/stevez/archive/2012/11/13/creating-a-netflix-style-ios-grid.aspx">Stephen Zaharuk</a>.<br />
<br /><br />
While checking out my usual late afternoon reading stream (using Flipboard), I found this great article on how to put together a very sexy UI utilizing <a href="http://www.infragistics.com/products/ios/">Infragistics's iOS Controls</a>; it instantly occurred to me that this would be a great idea for an article. It was almost muscle memory, because I found my hands spinning a browser window open to my favorite Search engine -<a href="http://bing.com/" title="Shameless plug"> Bing.com </a>- and typing the keywords "Nuclios Monotouch Bindings". To my surprise the product already ships with Xamarin.iOS bindings out of the box.<br />
<blockquote>
Innovative Functionality Meets iOS Familiarity<br />
Take advantage of a powerful API that is familiar to all iOS developers. You can use NucliOS controls in native iOS projects built with Objective C and Xcode. You can even build in C#; with Xamarin.ioS support, NucliOS includes final MonoTouch bindings for all of our iOS controls. </blockquote>
And so the journey begins. Steve has done a great job of explaining in detail the implementation, so I won't bore you with the details. Instead I will highlight what things to keep in mind when "translating" code developed with XCode and Obj-C to the stuff dreams are made of (C# and Xamarin.iOS). <br />
<pre><code>// Obj-C Implementation of the model
@interface NetflixData : NSObject
@property (nonatomic, retain)NSString* category;
@property (nonatomic, retain)NSMutableArray* media;
@property (nonatomic, assign)CGFloat scrollPosition;
@end
</code></pre>
1-Remember to add the <code>[Export()]</code> Attribute to your properties in your <code>NSObject</code> derived classes. This will allow the under-laying native implementation to use the properties of your Data Model.<br />
<pre><code>public class NetflixMedia: NSObject
{
[Export("ImageUrl")]
public string ImageUrl {
get;
set;
}
[Export("Title")]
public string Title {
get;
set;
}
[Export("Genre")]
public string Genre {
get;
set;
}
}
</code></pre>
2 - Use the WeakDelagate property WeakDataSource<br />
<pre><code> //NucliosViewController.cs - Obj-C
_gridView.WeakDataSource = _ds;
...
</code></pre>
Instead of..<br />
<pre><code>//NucliosViewController.m - Obj-C
_gridView.dataSource = _ds;
...
</code></pre>
3- When creating creating overloaded constructors, remember to extract any initialization code to a separate method, so you can call it (and don't try to code on an empty stomach). <br />
<pre><code>public class MediaCell:IGGridViewCell
{
public MediaCell (string identifier): base(identifier)
{
Init ();
}
</code></pre>
4- This is not a required thing, but If you find something that just doesn't make sense to "translate" and you can make it better, then do it. That's the case of the code used to consume iTunes Web services. I wasn't going to simply translate line by line. <br />
//Obj-C +(NSMutableArray*)generateData { NSMutableDictionary* mediaLookup = [[NSMutableDictionary alloc]init]; NSMutableArray* netFlixData = [[NSMutableArray alloc]init];<br />
<pre><code>NSString* rootUrl = @"https://itunes.apple.com/search?term=%@&media=movie&entity=movie&limit=600&attribute=releaseYearTerm";
NSArray* keys = @[@"2012", @"2013"];
for(NSString* key in keys)
{
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:rootUrl, key]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSArray* results = [json valueForKey:@"results"];
if(results != nil)
{
for(NSDictionary* mediaInfo in results)
{
NSString* genre = [NSString stringWithFormat:@"%@", [mediaInfo valueForKey:@"primaryGenreName"]];
NSString* url = [mediaInfo valueForKey:@"artworkUrl100"];
MediaItem* media = [[MediaItem alloc]init];
media.title = [mediaInfo valueForKey:@"trackName"];
media.imgUrl = [NSURL URLWithString:url];
MediaData* nfd = [mediaLookup valueForKey:genre];
if(nfd == nil)
{
nfd = [[MediaData alloc]init];
nfd.genre = genre;
nfd.media = [[NSMutableArray alloc]init];
[mediaLookup setValue:nfd forKey:genre];
[netFlixData addObject:nfd];
}
[nfd.media addObject:media];
}
}
}
return netFlixData;
</code></pre>
//C#<br />
async Task> GetData () { var movies = new List (); var url = "<a href="https://itunes.apple.com/search?term=%7B0%7D&media=movie&entity=movie&limit=600&attribute=releaseYearTerm">https://itunes.apple.com/search?term={0}&media=movie&entity=movie&limit=600&attribute=releaseYearTerm</a>";<br />
<pre><code> var client = new HttpClient ();
var response = await client.GetAsync (string.Format (url, "2013"));
var stringData = await response.Content.ReadAsStringAsync ();
var json = JsonObject.Parse (stringData);
var results = json["results"];
foreach(JsonValue movie in results)
{
movies.Add (new NetflixMedia(){
Title = movie["trackName"],
ImageUrl = movie["artworkUrl100"],
Genre = movie["primaryGenreName"],
});
}
return movies;
}
</code></pre>
<code></code><br />
<h3>
Our UI</h3>
<code><a href="https://github.com/claudiosanchez/Nuclios.Netflix/blob/master/Screenshots/6332.IMG_0250.PNG" target="_blank"></a><div class="separator" style="clear: both; text-align: center;">
<a href="https://github.com/claudiosanchez/Nuclios.Netflix/blob/master/Screenshots/6332.IMG_0250.PNG" target="_blank"></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuIsG2SxGCI2404R4cUAdCoZniNjOxcOXc-SZn_SwKv1t_N50_1tGb7nkWELDVSAQG08BxoKj-QvF9ValopRgeN-wk6pvW2hIKog4RixMb0suYVUmPA-7he1V_of9MFECL4m6KxyvgLL0/s1600/6332.IMG_0250.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuIsG2SxGCI2404R4cUAdCoZniNjOxcOXc-SZn_SwKv1t_N50_1tGb7nkWELDVSAQG08BxoKj-QvF9ValopRgeN-wk6pvW2hIKog4RixMb0suYVUmPA-7he1V_of9MFECL4m6KxyvgLL0/s400/6332.IMG_0250.PNG" width="300" /></a><a href="https://github.com/claudiosanchez/Nuclios.Netflix/blob/master/Screenshots/6332.IMG_0250.PNG" target="_blank"></a></div>
<a href="https://github.com/claudiosanchez/Nuclios.Netflix/blob/master/Screenshots/6332.IMG_0250.PNG" target="_blank"></a></code><h3>
Netflix UI</h3>
<code></code><br />
<code><a href="https://github.com/claudiosanchez/Nuclios.Netflix/blob/master/Screenshots/2350.netflixSS.PNG" target="_blank"><img alt="Netflix " src="https://github.com/claudiosanchez/Nuclios.Netflix/raw/master/Screenshots/2350.netflixSS.PNG" style="max-width: 100%;" /></a></code>Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-25069512550269198532013-05-15T18:00:00.003-07:002013-05-15T18:05:40.519-07:00Creando un UI como la de Netflix para iOS con C#, Xamarin iOS y NucliOS<br />
<div style="border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
<i>Este articulo es una adaptación del articulo en inglés <b>"</b></i><span style="background-color: white;"><b><i><a href="https://github.com/claudiosanchez/Nuclios.Netflix">Creating a Netflix style iOS Grid with C#, Xamarin.iOS and NucliOS</a>".</i></b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuIsG2SxGCI2404R4cUAdCoZniNjOxcOXc-SZn_SwKv1t_N50_1tGb7nkWELDVSAQG08BxoKj-QvF9ValopRgeN-wk6pvW2hIKog4RixMb0suYVUmPA-7he1V_of9MFECL4m6KxyvgLL0/s1600/6332.IMG_0250.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuIsG2SxGCI2404R4cUAdCoZniNjOxcOXc-SZn_SwKv1t_N50_1tGb7nkWELDVSAQG08BxoKj-QvF9ValopRgeN-wk6pvW2hIKog4RixMb0suYVUmPA-7he1V_of9MFECL4m6KxyvgLL0/s200/6332.IMG_0250.PNG" width="150" /></a></div>
<span style="background-color: white;"><b><i><a href="https://github.com/claudiosanchez/Nuclios.Netflix">Repositorio</a> en Github.</i></b></span></div>
<div style="border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
<span style="font-size: 15px;">Mientras me relajaba un poco, leyendo un poco de mi lista de lectura (via Flipboard), encontré este interesante </span><span style="font-size: 15px;">articulo de como crear una </span><i style="font-size: 15px;">Interfaz de Usuario </i><span style="font-size: 15px;">utilizando la libreria </span><a href="http://www.infragistics.com/products/ios/" style="border: 0px; color: #4183c4; font-size: 15px; margin: 0px; padding: 0px; text-decoration: none;">INucliOS de Infragistics</a><span style="font-size: 15px;">. Casi instantaneamente se me ocurrió que sería una buena idea para un articulo a mi </span><a href="http://claudioasanchez.blogspot.com/" style="font-size: 15px;">blog</a><span style="font-size: 15px;">. De pronto, casi como segunda naturaleza ya mis manos se desplazaban hacia el teclado, abrieron una ventana de IE 10 y buscaron -vía Bing - por los terminos de busqueda </span><b style="font-size: 15px; font-style: italic;">"NucliOS MonoTouch Bindings"</b><span style="font-size: 15px;">. Para mi sorpresa, el producto ya viene con los </span><i style="font-size: 15px;">"bindings" </i><span style="font-size: 15px;">para Xamarin.iOS en la descarga oficial. </span></div>
<div style="border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
Es aquí cuando <i>comienza la travesía.</i> Como p<span style="font-size: 15px;">arte del trabajo de este articulo está basado en un articulo publicado por<i> </i></span><a href="http://www.infragistics.com/community/blogs/stevez/archive/2012/11/13/creating-a-netflix-style-ios-grid.aspx" style="border: 0px; color: #4183c4; font-size: 15px; margin: 0px; padding: 0px; text-decoration: none;">Stephen Zaharuk</a><span style="font-size: 15px;">, bajo el titulo </span><span style="font-size: 15px;">"<a href="http://www.infragistics.com/community/blogs/stevez/archive/2012/11/13/creating-a-netflix-style-ios-grid.aspx">Creating a Netflix style iOS Grid</a>", no les aburriré con los detalles; en vez, les monstraté como tomar el original y crear un UI similar en Xamarin.iOS sin mucho esfuerzo. </span></div>
<div style="border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
</div>
<div>
Aquí están las cosas que deben de tener en cuenta cuando <i>"traducen"</i> código en Obj-C y XCode al glorioso C# y Xamarin.iOS. </div>
<div>
<br /></div>
<div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;">// Obj-C Implementation of the model
@interface NetflixData : NSObject
@property (nonatomic, retain)NSString* category;
@property (nonatomic, retain)NSMutableArray* media;
@property (nonatomic, assign)CGFloat scrollPosition;
@end </code></pre>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;">
</code></pre>
</div>
<span style="background-color: white; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px;">1- Recuerda decorar con el atributo</span><code style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px 2px; padding: 0px 5px; white-space: nowrap;">[Export()]</code><span style="background-color: white; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px;"> a las propiedades de tus objectos que derivande </span><code style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px 2px; padding: 0px 5px; white-space: nowrap;">NSObject</code><span style="background-color: white; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px;">. Esto le permitirá a la implementación nativa usar las propiedades de tu modelo de datos.</span><br />
<br />
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;">public class NetflixMedia: NSObject
{
[Export("ImageUrl")]
public string ImageUrl {
get;
set;
}
[Export("Title")]
public string Title {
get;
set;
}
[Export("Genre")]
public string Genre {
get;
set;
}
}</code></pre>
<br />
<br />
<div style="border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
2 - Usa la propiedad WeakDelagate que se llama WeakDataSource</div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;"> //NucliosViewController.cs - Obj-C
_gridView.WeakDataSource = _ds;
...
</code></pre>
<div style="border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
Instead of..</div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;">//NucliosViewController.m - Obj-C
_gridView.dataSource = _ds;
...
</code></pre>
<div style="border: 0px; color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px; padding: 0px;">
3- Cuando crees "constructores sobrecargados", recuerda extraer el código de inicialización a un metodo aparte (eso es puro sentido común), y por último no trates de escribir código con el estomago vacío, que el "Malcomío no piensa".</div>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;">public class MediaCell:IGGridViewCell
{
public MediaCell (string identifier): base(identifier)
{
Init ();
}
</code></pre>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><span style="background-color: transparent; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px;">4- Y por último, si encuentras algo escrito de forma que no hace sentido reproducirlo tal cual, luce lo que sabes y re-escribelo, y utiliza lo que está de punta (Async) y echa vainas a tus colegas.</span></pre>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;">//Obj-C
+(NSMutableArray*)generateData
{
NSMutableDictionary* mediaLookup = [[NSMutableDictionary alloc]init];
NSMutableArray* netFlixData = [[NSMutableArray alloc]init];
NSString* rootUrl = @"https://itunes.apple.com/search?term=%@&media=movie&entity=movie&limit=600&attribute=releaseYearTerm";
NSArray* keys = @[@"2012", @"2013"];
for(NSString* key in keys)
{
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:rootUrl, key]];
NSData* data = [NSData dataWithContentsOfURL:url];
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSArray* results = [json valueForKey:@"results"];
if(results != nil)
{
for(NSDictionary* mediaInfo in results)
{
NSString* genre = [NSString stringWithFormat:@"%@", [mediaInfo valueForKey:@"primaryGenreName"]];
NSString* url = [mediaInfo valueForKey:@"artworkUrl100"];
MediaItem* media = [[MediaItem alloc]init];
media.title = [mediaInfo valueForKey:@"trackName"];
media.imgUrl = [NSURL URLWithString:url];
MediaData* nfd = [mediaLookup valueForKey:genre];
if(nfd == nil)
{
nfd = [[MediaData alloc]init];
nfd.genre = genre;
nfd.media = [[NSMutableArray alloc]init];
[mediaLookup setValue:nfd forKey:genre];
[netFlixData addObject:nfd];
}
[nfd.media addObject:media];
}
}
}
return netFlixData;
</code></pre>
<hr style="background-image: url(https://a248.e.akamai.net/assets.github.com/assets/primer/markdown/dirty-shade-bf4c1cf99dc867d1eb443f22a2647396e09b418e.png); background-position: 0px 0px; background-repeat: repeat no-repeat; border: 0px none; clear: both; color: #cccccc; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; height: 4px; line-height: 25px; margin: 15px 0px; overflow: hidden; padding: 0px;" />
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;">//C#
async Task<IList<NetflixMedia>> GetData ()
{
var movies = new List<NetflixMedia> ();
var url = "https://itunes.apple.com/search?term={0}&media=movie&entity=movie&limit=600&attribute=releaseYearTerm";
var client = new HttpClient ();
var response = await client.GetAsync (string.Format (url, "2013"));
var stringData = await response.Content.ReadAsStringAsync ();
var json = JsonObject.Parse (stringData);
var results = json["results"];
foreach(JsonValue movie in results)
{
movies.Add (new NetflixMedia(){
Title = movie["trackName"],
ImageUrl = movie["artworkUrl100"],
Genre = movie["primaryGenreName"],
});
}
return movies;
}
</code></pre>
<h2 style="-webkit-font-smoothing: antialiased; border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-width: 0px 0px 1px; color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 2em; margin: 1em 0px 15px; padding: 0px; position: relative;">
<a class="anchor" href="https://github.com/claudiosanchez/Nuclios.Netflix#the-end-result" name="the-end-result" style="border: 0px; bottom: 0px; color: #4183c4; cursor: pointer; display: block; left: 0px; line-height: 1; margin: 0px 0px 0px -22px; padding: 0px; position: absolute; text-decoration: none; top: 15%;"><span class="mini-icon mini-icon-link" style="-webkit-font-smoothing: antialiased; border: 0px; color: black; display: inline-block; font-family: 'Octicons Regular'; font-size: 16px; font-weight: normal; height: 16px; line-height: 1; margin: 0px; padding: 0px; width: 16px;"></span></a>El resultado final</h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuIsG2SxGCI2404R4cUAdCoZniNjOxcOXc-SZn_SwKv1t_N50_1tGb7nkWELDVSAQG08BxoKj-QvF9ValopRgeN-wk6pvW2hIKog4RixMb0suYVUmPA-7he1V_of9MFECL4m6KxyvgLL0/s1600/6332.IMG_0250.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuIsG2SxGCI2404R4cUAdCoZniNjOxcOXc-SZn_SwKv1t_N50_1tGb7nkWELDVSAQG08BxoKj-QvF9ValopRgeN-wk6pvW2hIKog4RixMb0suYVUmPA-7he1V_of9MFECL4m6KxyvgLL0/s1600/6332.IMG_0250.PNG" /></a></div>
<div>
<br /></div>
Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-29193267673860196192012-08-15T07:51:00.000-07:002012-08-22T07:25:44.330-07:00Código, Presentaciones y Fotos de CodeCampSDQ 2012Me complace reportar que el evento <a href="http://codecampsdq.com/">CodeCampSDQ</a> fué un éxito. <br />
Gracias a todos los que contribuyeron con su granito de arena para que este evento fuese exitoso.<br />
<br />
El evento comenzó a las 9:30 AM, y acabó a las 4:00 PM. A este acudieron 30 profesionales del desarrollo, entre ellos varios ex-alumnos del <a href="http://itesa.edu.do/">Instituto Técnico Salesiano</a> y el <a href="http://itla.edu.do/">Instituto Tecnológico de Las Américas</a>. <br />
<br />
Los temas a tratar en este primer CodeCamp fueron:<br />
<br />
<ul>
<li>Desarollo de aplicaciones Web con ASP.NET MVC 4, por Alexander Matos</li>
<li>Desarrollo de aplicaciones para iOS con C# y .NET usando MonoTouch, por Claudio Sanchez</li>
</ul>
<br />
<br />
<iframe frameborder="0" height="128" scrolling="no" src="https://skydrive.live.com/embed?cid=AE9CB076B52A5011&resid=AE9CB076B52A5011%21122&authkey=AMZ_uTwr4XmxR-w" width="165"></iframe><br />
Si el widget de SkyDrive no te funciona; para ver el código, presentaciones y fotos, eche un vistazo <a href="https://skydrive.live.com/embed?cid=AE9CB076B52A5011&amp;resid=AE9CB076B52A5011%21122&amp;authkey=AMZ_uTwr4XmxR-w">aquí</a>Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-80673625716869815222012-02-08T15:41:00.001-08:002012-02-13T07:59:51.357-08:00How to get a job with Microsoft, Apple or GoogleI recently read a very interesting article about how to get yourself noticed in the “Major Leagues” . The <a href="http://www.businessinsider.com/9-reasons-your-current-resume-will-never-get-you-a-job-at-apple-or-google-2012-2?op=1" target="_blank">article</a> is by Gayle Laakmann McDowell, who herself has worked at four of today’s big tech companies the likes of Apple, Google and Microsoft.<br />
Here is a <strong>short version</strong> of the 9 Reasons.<br />
<ul>
<li>Go to an elite school (or associate with one). </li>
<li>Intern early, and relevant to your career (knowing how to flip burgers doesn’t make you a better coder). </li>
<li>Major in something relevant. </li>
<li>Community service means: do Tech work for free, not in a soup kitchen. </li>
<li>Learn how to write (oops, that is why I could never land one of those <img alt="Winking smile" class="wlEmoticon wlEmoticon-winkingsmile" src="http://lh5.ggpht.com/-AL8s095i7os/TzMIGmADbaI/AAAAAAAAD74/UUB4feewmAg/wlEmoticon-winkingsmile%25255B2%25255D.png?imgmax=800" style="border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none;" />). </li>
<li>Be a teacher’s pet. They write good recommendation letters. </li>
<li>Be a generalist. </li>
<li>Be an entrepreneur, innovate or deliver results. </li>
<li>no one cares if you have a 4.0 GPA.</li>
</ul>
At the end of the day, make sure that whatever you do is transferable to the next step/job in your career.Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-92198563948673858002011-12-30T09:37:00.001-08:002011-12-30T09:37:12.791-08:00MSDN Training Courses<p>Microsoft’s DPE Team has put together some great training courses available for download. It is always good to “sharpen the tools”, and this would be a great starting point for learning a new skill or sharpen the already developed one.</p> <p>Some of the ones that caught my eye are: </p> <ul> <li><strong><a href="http://msdn.microsoft.com/en-us/WP7MangoTrainingCourse">Windows Phone codenamed "Mango" Training Course</a></strong></li> <li><strong><a href="http://msdn.microsoft.com/en-us/WAZPlatformTrainingCourse">Windows Azure Training Course</a></strong></li></ul> <p> Link to Training Courses: <a title="http://msdn.microsoft.com/en-us/gg299335" href="http://msdn.microsoft.com/en-us/gg299335">http://msdn.microsoft.com/en-us/gg299335</a></p> Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-75079348177332258282011-12-21T09:29:00.001-08:002011-12-21T09:29:18.175-08:00Windows Identity Foundation Training available<p>[Federated] Security is no easy thing, let’s just state that out of the gate. That is why our Federated Security guru <a href="http://www.leastprivilege.com/" target="_blank">Dominick Baier</a> has put together a two-day course. You can get some more details over <a href="http://www.leastprivilege.com/NeedWIFTraining.aspx" target="_blank">here</a>. </p> Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-92183449568390160572011-12-19T08:12:00.001-08:002012-05-11T09:14:47.920-07:00Walk-through of provisioning Identity Server v1.0<style type="text/css">
.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br />
</style>
<br />
<h2>
Introduction</h2>
If you have the need to use your own Identity Provider, and want to go with something light (<em>i.e.: not ADFS</em>), Thinktecture’s Identity Server is your product. I have been using it for the last couple of months and I love it!! I actually added a service layer over it to enable my RP to provision users in the Identity Server (yes, I know that this is contrary to the general concept of outsourcing Identity Management, but in my scenario, trust me, it makes sense). <br />
From the <a href="http://identityserver.codeplex.com/" target="_blank">CodePlex</a> site:<br />
<blockquote>
Thinktecture IdentityServer is an open source security token service based on Microsoft .NET, ASP.NET MVC, WCF and WIF.<br />
<b>High level features</b><br />
<ul>
<li>Multiple protocols support (WS-Trust, WS-Federation, OAuth2, WRAP, JSNotify, HTTP GET) </li>
<li>Multiple token support (SAML 1.1/2.0, SWT) </li>
<li>Out of the box integration with ASP.NET membership, roles and profile </li>
<li>Support for username/password and client certificates authentication </li>
<li>Support for WS-Federation metadata </li>
<li>Support for WS-Trust identity delegation </li>
<li>Extensibility points to customize configuration and user management handling</li>
</ul>
</blockquote>
<h2>
Setup</h2>
<div>
<span style="color: red; font-weight: bold;">UPDATE: </span>This walk-through assumes you are setting up Identity Server in a production/QA environment, and not as a single machine/developer setup. Hence why we are setting up by using SQL Server instead of mounting the Compact database included in the App_Data directory, as well as installing the ASP.NET Membership provider DB on the DB Server.</div>
<div>
</div>
Download <strong>source</strong> from <a href="http://identityserver.codeplex.com/releases/view/78191#DownloadId=310266" target="_blank">here</a><br />
Unzip the file and open the solution. <br />
Because Identity Server (IdSvr) needs an ASP.NET membership database, we are going to set one up (if it doesn’t exist). There are some great tutorials on the web on how to do this (if you don’t already know), <a href="http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx" target="_blank">here</a> is one of them.<br />
After having installed the <strong>ASP.NET Membership database</strong>, we are going to update the connection string in IdSvr to point to said database.<br />
The connection string file is located at \Configuration\connectionstring.config (Below is an example)<br />
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span><span class="kwrd"><</span><span class="html">connectionStrings</span><span class="kwrd">></span></pre>
<pre><span class="lnum"> 2: </span> <span style="background-color: yellow;"><span class="kwrd"><</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">="ProviderDB"</span></span></pre>
<pre class="alt"><span style="background-color: yellow;"><span class="lnum"> 3: </span> <span class="attr">connectionString</span></span><span class="kwrd"><span style="background-color: yellow;">="Persist Security Info=False;</span></span></pre>
<pre><span style="background-color: yellow;"><span class="lnum"> 4: </span> User ID=sa; </span></pre>
<pre class="alt"><span style="background-color: yellow;"><span class="lnum"> 5: </span> password=****;</span></pre>
<pre><span style="background-color: yellow;"><span class="lnum"> 6: </span> Initial Catalog=aspnetdb;</span></pre>
<pre class="alt"><span style="background-color: yellow;"><span class="lnum"> 7: </span> Data Source=mydbserver;"</span></pre>
<pre><span style="background-color: yellow;"><span class="lnum"> 8: </span> <span class="attr">providerName</span><span class="kwrd">="System.Data.SqlClient"</span> <span class="kwrd">/></span></span></pre>
<pre class="alt"><span class="lnum"> 9: </span> </pre>
<pre><span class="lnum"> </span></pre>
</div>
<br />
><br />
<br />
To test that the connection string works, in <strong>Solution Explorer</strong>, you should select the <strong>Website</strong> project, then from Visual Studio’s menu, select Project –> ASP.NET Configuration. This will launch the ASP.NET Web Site Administration Tool. <br />
<br />
<a href="http://lh3.ggpht.com/-QA1OFz5lvF4/Tu9iWBunpeI/AAAAAAAAD5A/rJKQWxtAoCE/s1600-h/Screen-Shot-2011-12-09-at-12.17.59-P.png"><img alt="Screen Shot 2011-12-09 at 12.17.59 PM" border="0" height="528" src="http://lh6.ggpht.com/-4rVNj8f4s1Q/Tu9iWcthQVI/AAAAAAAAD5I/CKDTua9wCDs/Screen-Shot-2011-12-09-at-12.17.59-P%25255B1%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="Screen Shot 2011-12-09 at 12.17.59 PM" width="353" /></a><br />
<br />
<a href="http://lh3.ggpht.com/-17URAE7JEIs/Tu9iWuztfFI/AAAAAAAAD5Q/LNbIct2bh0I/s1600-h/Screen-Shot-2011-12-09-at-12.18.14-P%25255B2%25255D.png"><img alt="Screen Shot 2011-12-09 at 12.18.14 PM" border="0" height="412" src="http://lh3.ggpht.com/-8xS8Sk5UFvo/Tu9iW4I0qCI/AAAAAAAAD5Y/7gzFGuiN5R4/Screen-Shot-2011-12-09-at-12.18.14-P%25255B1%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="Screen Shot 2011-12-09 at 12.18.14 PM" width="542" /></a><br />
<br />
<br />
<br />
Using the ASP.NET Web Site Administration Tool, proceed to create a user (i.e.: <em><strong>Administrator</strong></em>) and a roles called <strong>IdentityServerAdministrators and IdentityServerUsers. </strong>These roles are important because they allow the user created to logon to IdSvr’s administration screen, and in the case of <strong>IdentityServerUsers</strong>, to be forwarded to the RPs upon successful login. These roles are specified in the <em><strong>Constants.cs</strong></em> file inside of the<strong> Thinktecture.IdentityServer.Core</strong> project. <br />
<br />
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Constants</pre>
<pre><span class="lnum"> 2: </span> {</pre>
<pre class="alt"><span class="lnum"> 3: </span> <span class="rem">// ....</span></pre>
<pre><span class="lnum"> 4: </span> <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Roles</pre>
<pre class="alt"><span class="lnum"> 5: </span> {</pre>
<pre><span class="lnum"> 6: </span> <span class="kwrd">public</span> <span class="kwrd">const</span> <span class="kwrd">string</span> InternalRolesPrefix = <span class="str">"IdentityServer"</span>;</pre>
<pre class="alt"><span class="lnum"> 7: </span> <span class="kwrd">public</span> <span class="kwrd">const</span> <span class="kwrd">string</span> Users = <span class="str">"Users"</span>;</pre>
<pre><span class="lnum"> 8: </span> <span class="kwrd">public</span> <span class="kwrd">const</span> <span class="kwrd">string</span> Administrators = <span class="str">"Administrators"</span>;</pre>
<pre class="alt"><span class="lnum"> 9: </span> </pre>
<pre><span class="lnum"> 10: </span> <span class="kwrd">public</span> <span class="kwrd">const</span> <span class="kwrd">string</span> IdentityServerUsers = <span style="background-color: yellow;">InternalRolesPrefix + Users;</span></pre>
<pre class="alt"><span class="lnum"> 11: </span> <span class="kwrd">public</span> <span class="kwrd">const</span> <span class="kwrd">string</span> IdentityServerAdministrators = <span style="background-color: yellow;">InternalRolesPrefix + Administrators</span>;</pre>
<pre><span class="lnum"> 12: </span> }</pre>
</div>
<br />
<a href="http://lh6.ggpht.com/-wKzFGlPYogE/Tu9iXPImmAI/AAAAAAAAD5g/OzgsopSYPPA/s1600-h/image%25255B8%25255D.png"><img alt="image" border="0" height="408" src="http://lh6.ggpht.com/-cdClUSBJL9w/Tu9iXQCl4rI/AAAAAAAAD5o/WJRLjujVqkg/image_thumb%25255B4%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="558" /></a><a href="http://lh4.ggpht.com/-o-31Fpr04EY/Tu9iXuF-j1I/AAAAAAAAD5w/ADOFjTTcdr0/s1600-h/image%25255B9%25255D.png"><img alt="image" border="0" height="405" src="http://lh4.ggpht.com/-NSs0jHkWEFo/Tu9iX8vxKJI/AAAAAAAAD54/ZJCJUDMz4fE/image_thumb%25255B5%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="554" /></a><br />
<br />
<a href="http://lh5.ggpht.com/-R4DRMJy8bQk/Tu9iYOPtjHI/AAAAAAAAD6A/JFvcD4lY_ow/s1600-h/Screen-Shot-2011-12-09-at-12.18.21-P%25255B2%25255D.png"><img alt="Screen Shot 2011-12-09 at 12.18.21 PM" border="0" height="467" src="http://lh5.ggpht.com/-jrgeEl4V8Jk/Tu9iYTSIftI/AAAAAAAAD6I/vZ4i0eaXF9w/Screen-Shot-2011-12-09-at-12.18.21-P%25255B1%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="Screen Shot 2011-12-09 at 12.18.21 PM" width="613" /></a><a href="http://lh4.ggpht.com/-pkTOxLB45H0/Tu9iYsOyvfI/AAAAAAAAD6Q/C3FL0LUFFGk/s1600-h/Screen-Shot-2011-12-09-at-12.18.40-P.png"><img alt="Screen Shot 2011-12-09 at 12.18.40 PM" border="0" height="219" src="http://lh3.ggpht.com/-h7rIExuRPK4/Tu9iY7DcV_I/AAAAAAAAD6Y/e95T0Mb3ZvU/Screen-Shot-2011-12-09-at-12.18.40-P%25255B2%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="Screen Shot 2011-12-09 at 12.18.40 PM" width="632" /></a><br />
<br />
<br />
<br />
<h2>
Configuring IIS 7</h2>
<br />
Let’s proceed to configure IIS 7 to host the Identity Server website. We will need to:<br />
<br />
<ul><br />
<li>Request a Certificate for SSL (self-signed, Domain cert or commercial). Read this <a href="http://www.digicert.com/csr-creation-microsoft-iis-7.htm">tutorial</a> </li>
<li>Setup https bindings. Go to this <a href="http://learn.iis.net/page.aspx/144/how-to-set-up-ssl-on-iis/#SSL">link</a>, and scroll down to <strong>Create an SSL Binding.</strong></li>
</ul>
<br />
<h2>
Creating a certificate for Token Signing</h2>
<br />
The process of creating this certificate is the same as requesting a certificate for SSL. Why not just the SSL Certificate then? – May you ask?–, and the answer is:<br />
<br />
<blockquote>
<br />
“Using the SSL certificate for the token signing certificate will work – but this should not be the configuration you use in production. This is considered bad key hygiene.”<br />
<br />
Source:<a href="http://blogs.technet.com/b/adfs/archive/2007/07/23/adfs-certificates-ssl-token-signing-and-client-authentication-certs.aspx">Technet</a></blockquote>
<br />
In my case, I have requested two certificates to the Domain Certificate Authority. <br />
<br />
<span style="color: red;"><strong>***UPDATE: Make sure the certificate Distinguished Name of each certificate is different (i.e.: Don’t request two certificates with the same attributes). I ran into an issue where IdentityServer’s x509Certificate Helper could not find the right certificate because there were two certificates, and it didn’t like that. </strong></span><br />
<br />
<style type="text/css">
.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br />
</style><br />
<br />
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="background-color: #f4f4f4; color: black; direction: ltr; font-family: "Courier New", courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; text-align: left; width: 100%;">var certs = store.Certificates.Find(findType, <span style="color: blue;">value</span>, <span style="color: blue;">false</span>);
<span style="color: blue;">if</span> (certs.Count != 1)
{
<span style="color: blue;">throw</span> <span style="color: blue;">new</span> InvalidOperationException(String.Format(<span style="color: #006080;">"Certificate not found: {0}"</span>, <span style="color: blue;">value</span>));
}</pre>
<br /></div>
<br />
<h2>
<a href="http://lh3.ggpht.com/-SSkxrjIL4rU/Tu9iZNF7YNI/AAAAAAAAD6g/Gx4VTdergD4/s1600-h/IISCerts4.png"><img alt="IISCerts" border="0" height="431" src="http://lh5.ggpht.com/-0SFCadc7Ue4/Tu9iZV94O-I/AAAAAAAAD6o/EQkb-A4MAqI/IISCerts_thumb2.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="IISCerts" width="917" /></a></h2>
<br />
We are almost there.<br />
<br />
<h2>
Configuring Identity Server</h2>
<br />
You should be able to navigate to Identity Server’s URL. If the certificates you created are not trusted by your computer, you see this screen. This occurs if you are using a certificate issued by a CA your computer does not trust. <a href="http://msmvps.com/blogs/cgross/archive/2006/10/23/Vista-RC2_2C00_-IE7-and-SBS-Self_2D00_Signed-Certs.aspx" target="_blank">Here</a> is a link on how to trust the certificate.<br />
<br />
<a href="http://lh4.ggpht.com/-Hn4tEAEGlqo/Tu9iZgmaPLI/AAAAAAAAD6w/V9zQ87wDBUI/s1600-h/image%25255B19%25255D.png"><img alt="image" border="0" height="510" src="http://lh6.ggpht.com/-LY6Pq9fhReU/Tu9iZwnP7rI/AAAAAAAAD64/TssuuyCSxis/image_thumb%25255B13%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="553" /></a><br />
<br />
You should be seeing Identity Server’s initial configuration screen. Go ahead and customize the first two fields to match your environment, and select the certificate that will be used for token signing.<br />
<br />
<span style="color: blue;"><b>UPDATE:</b> Make sure that the IIS Worker Process Identity has access to the Private Key of your certificates. Use the Certificate MMC for this.</span><br />
<br />
<a href="http://lh3.ggpht.com/-TwnVeZnbqOY/Tu9iaMu3cYI/AAAAAAAAD7A/m4W7QuWt-1k/s1600-h/image%25255B26%25255D.png"><img alt="image" border="0" height="560" src="http://lh6.ggpht.com/-ncJCqrg9aBQ/Tu9iafGBWNI/AAAAAAAAD7I/Tjo_DbMq5tw/image_thumb%25255B18%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="572" /></a><br />
<br />
Tada!! You have successfully configured Identity Server and should be ready to add your application as a Relaying Party (RP). You can find a tutorial on how to do that over <a href="http://msdn.microsoft.com/en-us/library/ee517285.aspx" target="_blank">here</a> (scroll down to 2.Register an existing production STS).<br />
<br />
<a href="http://lh6.ggpht.com/--EBMNJQ7GjM/Tu9ia3DLXVI/AAAAAAAAD7U/LQN4BbjtCEI/s1600-h/image%25255B32%25255D.png"><img alt="image" border="0" height="441" src="http://lh3.ggpht.com/-xMVyt96vt0Q/Tu9ich3JGtI/AAAAAAAAD7c/TIJeanbZ6wM/image_thumb%25255B22%25255D.png?imgmax=800" style="background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="584" /></a>Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com12tag:blogger.com,1999:blog-1521206372627229850.post-10772757656682516572011-11-13T17:41:00.001-08:002011-11-16T16:22:12.405-08:00CMAP CodeCamp Slide DeckWow!! What an awesome experience to have participated in CMAP's CodeCamp. <br />
I have started the process of going from having a wealth of opinion and a lack of experience, to a more balanced mix. I have made a mental note of a myriad of things that need to be improved, and will continue to improve the talk and gain more experience every time I do it. <br />
Thanks to the audience for being so patient with me and not have walked out on me. The slides are <a href="http://www.megsoftconsulting.com/presentations/WIF/Intro%20to%20Windows%20Identity%20Foundation.pptx">here</a>.<br />
<br />
<iframe src="http://app.sliderocket.com:80/app/fullplayer.aspx?id=4faa3ff9-05e8-4c7f-a80f-9d5a4cfe794e" width="500" height="401" scrolling=no frameBorder="0"></iframe>Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-32498659688700179662011-11-04T06:45:00.001-07:002011-11-04T06:49:28.216-07:00Speaking at CMAP's Fall Code Camp<div class="separator" style="clear: both; text-align: left;">
It is official. I will be speaking at a local CodeCamp about Windows Identity Foundation. There are many interesting talks and the best part is that is all free. Check it out and do not miss it. </div>
<div class="separator" style="clear: both; text-align: left;">
<span class="Apple-style-span" style="color: #666666; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; font-size: 12px; line-height: 20px;"></span></div>
<blockquote class="tr_bq">
The Central Maryland Association of .NET Professionals (CMAP) is holding its Fall 2011 Code Camp on <strong style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Saturday, November 12th, 2011</strong> at the Loyola University Maryland Graduate Center in Columbia, MD.<br />The Code Camp will run from 8:30am - 5:30pm with 20-25 awesome sessions covering a wide range of database, software and portal development topics. It's totally free. No gimmicks. No sales pitches. Enjoy breakfast and lunch at no charge while you mingle with your peers.</blockquote>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
For more details click <a href="http://www.cmap-online.org/CodeCamp/Default.aspx">here</a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1pJ8QwVF4C2l3yUm2OV2M8wbMuvpFgDech3uCvSXdWn5JUOKA_WU4Cv5R3Z5kkZgg3qQVabDhCudOPysrlAIRdzjSj_2a60BQnGrOUW_XXPw1b-SDIyjxvdXyFXa7tbY4e-VYIVCXzWI/s1600/Screen+Shot+2011-11-04+at+9.44.50+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="197" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1pJ8QwVF4C2l3yUm2OV2M8wbMuvpFgDech3uCvSXdWn5JUOKA_WU4Cv5R3Z5kkZgg3qQVabDhCudOPysrlAIRdzjSj_2a60BQnGrOUW_XXPw1b-SDIyjxvdXyFXa7tbY4e-VYIVCXzWI/s400/Screen+Shot+2011-11-04+at+9.44.50+AM.png" width="400" /></a></div>
<br />Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com2tag:blogger.com,1999:blog-1521206372627229850.post-14538726522022984002011-10-05T17:57:00.000-07:002011-11-04T06:44:39.259-07:00We will remember you Steve<div class="separator" style="clear: both; text-align: left;">
Steve Jobs will always be in my mind. He was indeed an influential person in my life, an inspiration and a role model. He was living proof that you can create your own destiny, without worriying too much about the path society expects you to follow to be defined as successful.</div>
<blockquote>
<span class="Apple-style-span" style="font-family: 'lucida grande', tahoma, verdana, arial, sans-serif; font-size: 11px; line-height: 14px;">"Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma - which is living with the results of other people's thinking. Don't let the noise of other's opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary." - Steve Jobs</span></blockquote>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3hZXovrzNwq5IGXEegJWs1IWxiwPWiTrsVeCPE0vfSHLMiQ9G6GIx0wFSLZYbghwyjtk5RP1vj9A3TnY9jLnCFJrnewrljuhb9v8p5nL8_uqsymGH7LYpvJIeM7XZy9KydiCzuDjG6jw/s1600/Screen+Shot+2011-10-05+at+8.06.27+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="307" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3hZXovrzNwq5IGXEegJWs1IWxiwPWiTrsVeCPE0vfSHLMiQ9G6GIx0wFSLZYbghwyjtk5RP1vj9A3TnY9jLnCFJrnewrljuhb9v8p5nL8_uqsymGH7LYpvJIeM7XZy9KydiCzuDjG6jw/s400/Screen+Shot+2011-10-05+at+8.06.27+PM.png" width="400" /></a></div>
<br />Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-25961342242701091422011-09-28T19:07:00.000-07:002011-10-03T07:48:08.182-07:00Setting up Thinktecture’s Identity Server<p>The following tutorial assumes the reader is familiar with the following technologies/concepts:</p><ul><li>Single Sign-on (SSO) </li>
<li>Windows Identity Foundation (WIF) </li>
<li><a href="http://en.wikipedia.org/wiki/Active_Directory_Federation_Services" target="_blank">Active Directory Federation Services</a> </li>
<li><a href="http://en.wikipedia.org/wiki/Claims_Based_Identity" target="_blank">Claims-based identity</a> </li>
</ul><p>This post is a  how to setup Thinktecture’s <strike>StarterSTS</strike> <a href="http://identityserver.codeplex.com/" target="_blank">Identity Server</a> [B1]. </p><p>1. Download the Source Code from the Codeplex site [at the time of this writing, the current version is B1 Refresh] and unzip it on your local drive.</p><p><a href="http://lh3.ggpht.com/-9kbCwc7EJbk/ToR4n_h3oyI/AAAAAAAAD2g/umvOsk1JpIk/s1600-h/image3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-nxlLrzvUSPw/ToR4oNlVnGI/AAAAAAAAD2k/8sIvZvffPXQ/image_thumb1.png?imgmax=800" width="502" height="309" /></a></p><p>2) Once the Solution is opened in Visual Studio, inside of the Tools solution folder you will find a Setup project. Run the project by right clicking on it, Selecting Debug –> Start new instance.</p><p><a href="http://lh4.ggpht.com/-0vUg_drAnUM/ToR4orLRtBI/AAAAAAAAD2o/E-iLz9TuwVQ/s1600-h/image7.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-FktLkITcDcs/ToR4o6dlrLI/AAAAAAAAD2s/x1DGuow6w-A/image_thumb3.png?imgmax=800" width="502" height="454" /></a></p><p>3) Set the Location of the Configuration Database as shown below. </p><p><a href="http://lh3.ggpht.com/-QgM7k95wBi0/ToR4pUCBexI/AAAAAAAAD2w/Xe5R98cAKhw/s1600-h/image11.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-Sp9VnHZJBQY/ToR4pkwLfeI/AAAAAAAAD20/KB26aBxcrSg/image_thumb5.png?imgmax=800" width="413" height="224" /></a></p><p>You can find the file called <em><strong>IdentityServerConfiguration.sdf</strong></em> inside of the <strong>App_Data</strong> folder of the <strong>Website</strong> Project. </p><p><a href="http://lh5.ggpht.com/-pvCEgJh-Yq4/ToR4qNsYR8I/AAAAAAAAD24/SHmMimXVvQA/s1600-h/image15.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-dnpKZynOXik/ToR4qQbPUqI/AAAAAAAAD28/INVtByYBAdk/image_thumb7.png?imgmax=800" width="475" height="265" /></a></p><p> </p><p>4) Select the certificate that will be used for SSL Encryption. **Note: If you already have IIS setup with SSL, you most definitely want to use the same certificate. I suspect you will, because if you are installing this Identity Server you must be very familiar with the Windows Identity Foundation configuration dance. </p><p><a href="http://lh3.ggpht.com/-DKDWbA5z23Y/ToR4qzwTu5I/AAAAAAAAD3A/GVhDHNTzcZ8/s1600-h/image21.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-j3u9Vu76Abo/ToR4rOPhnyI/AAAAAAAAD3E/YVfn7XM8t6k/image_thumb9.png?imgmax=800" width="235" height="244" /></a></p><p>5) Select the certificate that will be used for Signing (You can use the same certificate)</p><p><a href="http://lh5.ggpht.com/-56TpPpv70ag/ToR4rVq_B_I/AAAAAAAAD3I/2M6t3vSZZPg/s1600-h/image25.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-OU0KFW4HvhU/ToR4r3OyzdI/AAAAAAAAD3M/QBMLvHKryb4/image_thumb10.png?imgmax=800" width="235" height="244" /></a></p><p><a href="http://lh6.ggpht.com/-ir6zAXka7Ak/ToR4sKPN0FI/AAAAAAAAD3Q/QkTiWFVqz2U/s1600-h/image28.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-MgClmQF80n4/ToR4srskYxI/AAAAAAAAD3U/chLJVkw7Q64/image_thumb11.png?imgmax=800" width="244" height="133" /></a></p><p>After this is done, you might be thinking that you can run the [website] project now and it should just work, right? Thought WRONG! There is no free meal in this world. Our friend Dominick [Baier] has had this running on his machine for a while, so perhaps forgot about setting up IIS, the ASP.NET provider Database and all that business. </p><p><a href="http://lh6.ggpht.com/-H10FSg_FEQs/ToR4s4zOv2I/AAAAAAAAD3Y/9FZvMNL27i0/s1600-h/image32.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-BTe2f9awzm4/ToR4tOxcwxI/AAAAAAAAD3c/QBsGwtpwJuE/image_thumb13.png?imgmax=800" width="473" height="223" /></a></p><h2>SEtting up ThE WEBSITE PROJECT TO USE IIS</h2><p>So, right after you download the source code, the Web Project Properties looks like so:</p><p><a href="http://lh6.ggpht.com/-hyM7sz_aKBc/ToR4tpmb7_I/AAAAAAAAD3g/4mXZTZtfGMI/s1600-h/image43.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-yMc_DaBvNxQ/ToR4t-CcTwI/AAAAAAAAD3k/VJ0nFzeQcTI/image_thumb18.png?imgmax=800" width="495" height="362" /></a></p><p>Notice the “[X] Use Custom Web Server” option is selected, and points to <a href="https://roadie/idsrv/">https://roadie/idsrv/</a>. You want to change these setting as follows:</p><p>Switch the setting to Use Local IIS Web Server and enter a more appropriate URL (<em>i.e.:</em><a title="http://csanchezpc/IdentityServer/idsrv" href="http://[your machine’s fully qualified name]/idsrv"><em>http://[your machine’s fully qualified name]/idsrv</em></a>), or if you are one cool cat, you may choose Use IIS Express (but then, you are on your own). </p><p>We are almost there, do not despair. </p><h2>CONFIGURING THE ASP.NET MEMBERSHIP DB. </h2><p>If you were to try to run the Website, you should get this “Yellow page of death”. And that is due to the fact (if you are one of those who do no read error pages) that the 1) you have not installed the standard ASP.NET Membership schema, and 2) the Identity under which IIS is running does not have access to said database (provided it existed). Follow <a href="http://weblogs.asp.net/sukumarraju/archive/2009/10/02/installing-asp-net-membership-services-database-in-sql-server-expreess.aspx" target="_blank">these</a> instructions to setup the ASP.NET application services schema.</p><p><a href="http://lh3.ggpht.com/-T6G9d_No5vY/ToR4uR7tJ6I/AAAAAAAAD3o/8fVmj52sun8/s1600-h/image53.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-KDJyNtshf-0/ToR4uoc3rvI/AAAAAAAAD3s/qY-PO-nW_CM/image_thumb22.png?imgmax=800" width="456" height="373" /></a></p><p>After having installed the ASP.NET Schema on your SQL Server instance, go to SQL Server Management Studio, and under Security –> Logins, and make sure that the Identity under which your IIS Application Pool is running has a valid login in SQL Server and has the right access to the ASP.NET database. In my case, the App pool Identity is <em>'IIS APPPOOL\DefaultAppPool'</em> and the database named "aspnetdb".<a href="http://lh3.ggpht.com/-dTxr2mpT4V8/ToR4vKMeNLI/AAAAAAAAD3w/HY0HsumklA8/s1600-h/image65.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-DpFULgqlRrQ/ToR4vpR4guI/AAAAAAAAD30/hcUESBmlN-Q/image_thumb28.png?imgmax=800" width="409" height="505" /></a></p><p><a href="http://lh5.ggpht.com/-nInxLMAF1yA/ToR4v1050nI/AAAAAAAAD34/2J9r2x7BRr8/s1600-h/image73.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-0WzsOnfn_7A/ToR4wKpxuSI/AAAAAAAAD38/eWxyFdkGqqY/image_thumb32.png?imgmax=800" width="481" height="411" /></a></p><p>Lastly, change the Website\Configuration\connectionStrings.config file to point to your ASP.NET application services database. </p><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 503px; padding-right: 5px; height: 187px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #0000ff"><</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">></span>
</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #0000ff"><</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"ProviderDB"</span>
</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #ff0000">connectionString</span>=<span style="color: #0000ff">"data source=.\sqlexpress;Integrated Security=SSPI;Initial Catalog=aspnetdb"</span>
</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #ff0000">providerName</span>=<span style="color: #0000ff">"System.Data.SqlClient"</span> <span style="color: #0000ff">/></span>
</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #0000ff"><</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"IdentityServerConfigurationEntities"</span>
</pre><pre style="background-color: #ffffff; margin: 0em; width: 96.19%; font-family: consolas,'Courier New',courier,monospace; height: 82px; font-size: 10px"><span style="color: #ff0000">connectionString</span>=<span style="color: #0000ff">"metadata=res://Thinktecture.IdentityServer.Core/Repositories.SqlCompact.IdentityServerConfiguration.csdl|res://Thinktecture.IdentityServer.Core/Repositories.SqlCompact.IdentityServerConfiguration.ssdl|res://Thinktecture.IdentityServer.Core/Repositories.SqlCompact.IdentityServerConfiguration.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;Data Source=|DataDirectory|\IdentityServerConfiguration.sdf&quot;"</span>
</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #ff0000">providerName</span>=<span style="color: #0000ff">"System.Data.EntityClient"</span> <span style="color: #0000ff">/></span>
</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #0000ff"></</span><span style="color: #800000">connectionStrings</span><span style="color: #0000ff">></span></pre><p> </p></pre><br />
<br />
<p>If you did everything right, you should now be able to run the application and get this page. </p><br />
<br />
<p><a href="http://lh6.ggpht.com/-dqDNx8josbI/ToR4wbwc7VI/AAAAAAAAD4A/XWAgQ51W9zU/s1600-h/image77.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-w06xJiA5mVg/ToR4ww_8pZI/AAAAAAAAD4E/atq5Y4JtScY/image_thumb34.png?imgmax=800" width="415" height="394" /></a></p><br />
<br />
<h2>Accessing the Administration Mode of Identity Server</h2><br />
<br />
<p>Out of the box, IdentityServer is configured to use the <font face="Courier New"><a href="http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.aspx" target="_blank">SqlMembershipProvider</a> </font><font face="Arial">membership provider implementation. Therefore to login you have to:</font></p><br />
<br />
<ol><li><font face="Arial">create a user (<em>i.e.: Administrator</em>)</font> </li>
<li><font face="Arial">create a role called <strong>IdentityServerAdministrators.</strong></font> </li>
</ol><br />
<br />
<p><font face="Arial">Both of these can be accomplished by using the built-in Web Site Administration Tool (in Visual Studio, go to Project –>  ASP.NET Configuration). </font></p><br />
<br />
<p><font face="Arial"><strong>[FYI] C</strong>ontrary to what  Dominik Baier’s introductory <a href="http://identity.thinktecture.com/download/identityserver/identityserverctp1.wmv" target="_blank">video</a> says [9:02] </font>, the role the code is expecting is not “TokenServiceAdministrators”, but instead, <strong>IdentityServerAdministrators</strong>).</p><br />
<br />
<p><strong>[Change for Improvement] </strong>This can be improved in the future by modifying the provided implementation of  <a href="http://msdn.microsoft.com/en-us/library/microsoft.identitymodel.claims.claimsauthorizationmanager.aspx" target="_blank">ClaimsAuthorizationManager</a>, and changing the AuthorizeAdministration Method (inside of Thinktecture.IdentityServer.Web.Security.AuthorizationManager) </p><br />
<br />
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 459px; padding-right: 5px; height: 121px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">bool</span> AuthorizeAdministration(Collection<Claim> resource, IClaimsIdentity id)
</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px">{
</pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #0000ff">return</span> (id.ClaimExists(ClaimTypes.Role, Constants.Roles.IdentityServerAdministrators));
</pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px">}</pre></pre><br />
<br />
<p>The next article will describe how to create a configure your application (Relaying Party) to trust Identity Server as an Secure Token Service (STS). </p>Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com7tag:blogger.com,1999:blog-1521206372627229850.post-37371924496621396812011-09-01T08:24:00.001-07:002011-09-01T08:34:23.030-07:00Where my data files at!?<p><strong>A bit of context:</strong> As part of my team’s development workflow, we create/modify our <a href="http://en.wikipedia.org/wiki/Domain_model" target="_blank">Domain Model</a> in code (entities such as Customer, Product, Order, etc.) and then generate the <a href="http://en.wikipedia.org/wiki/Database_model" target="_blank">Database Model</a> via a homegrown console app.  This allows us to  [efficiently]  code our Domain Model without having to worry about applying these changes to the lower layers of the system all the way to the database schema. </p> <p>The [Schema Export] console app I mentioned automatically generates a fresh database by exploring our Domain Model – <a href="http://elliottjorgensen.com/nhibernate-api-ref/NHibernate.Tool.hbm2ddl/SchemaExport.html" target="_blank">NHibernate</a> makes this very easy - for the purpose of <a href="http://msdn.microsoft.com/en-us/library/dd193250.aspx" target="_blank">comparing and synchronizing</a> with the <a href="http://msdn.microsoft.com/en-us/library/ff678491.aspx" target="_blank">Database Project</a> , thus bringing our Persistence store up-to-date with our Domain Model. </p> <p><strong>The Problem: </strong>I had a need to find out the physical path was the instance of SQL Server installed on the server [<em>c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\</em>] and thus were the data files for the database are placed [$SqlInstallPath\MSSQL\Data\].</p> <p><strong>The Solution:</strong></p> <p>The following T-SQL returned the path where the master database is located:</p> <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 491px; padding-right: 5px; height: 81px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=select&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">select</a> physical_name <a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=from&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">from</a> master.sys.databases dbs <a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=inner&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">inner</a> <a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=join&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">join</a> master.sys.master_files files <a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=on&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">on</a> dbs.database_id = files.database_id<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=where&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">where</a> dbs.name = '<span style="color: #8b0000">master</span>' <a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=and&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">and</a> type_desc = '<span style="color: #8b0000">ROWS</span>'<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"></pre></pre><br /><br /><strong>Results:</strong><br /><br /><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 456px; padding-right: 5px; height: 95px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px">physical_name<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"><span style="color: #008000">-------------------------------------------------------------------------------</span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px">c:\Program Files\Microsoft <a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=SQL&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99">SQL</a> Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\master.mdf<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px">(1 row(s) affected)<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"></pre></pre><br /><style type="text/css"><br /><br /><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>And the following function takes care of removing the filename and fiving you the path:</p><br /><br /><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 475px; padding-right: 5px; height: 328px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetDbFilePath ( SqlConnection sqlConnection, <span style="color: #0000ff">string</span> databaseName )<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">string</span> path = <span style="color: #0000ff">string</span>.Empty;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">try</span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> {<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">string</span> datafilepathQuery =<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">string</span>.Format (<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> @"<span style="color: #8b0000">select physical_name from <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> master.sys.databases dbs inner join master.sys.master_files files <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> on dbs.database_id = files.database_id<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> where dbs.name = '{0}' and type_desc = 'ROWS'</span>", databaseName );<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">using</span> ( var sqlCmd = <span style="color: #0000ff">new</span> SqlCommand ( datafilepathQuery, sqlConnection ) )<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">object</span> datafilepath = sqlCmd.ExecuteScalar ();<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> path = datafilepath.ToString ();<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> path = path.Substring(0, path.LastIndexOf('\\'));<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> }<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> }<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">catch</span> ( Exception )<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> {<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> }<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> <span style="color: #0000ff">return</span> path;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> }</pre></pre><br /><br /><p>This allowed me to subsequently run another command to create the database schema at the right location. That is all for today folks!</p><br /><br /><p><strong>FYI:</strong> I will be writing a post – or series of posts – on how to improve your development workflow and thus adhering to my favorite tenet of the <a href="http://agilemanifesto.org/principles.html" target="_blank">Agile Manifesto</a> : “maximizing the amount of work not done”.</p> Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0tag:blogger.com,1999:blog-1521206372627229850.post-89505959987657299672011-06-22T06:36:00.000-07:002011-06-22T06:52:39.972-07:00Getting rid of Literal strings - part 1<p>In my travels around MVVM Land (specially as seen on MSFT tutorials around the net), it is commonplace to find string literals being used when implementing the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx" rel="tag" target="_blank">INotifyPropertyChanged</a>, to specify the property name (as shown in the code below). </p> <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 484px; padding-right: 5px; height: 353px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 1: <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Customer : INotifyPropertyChanged<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 2: {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 3: <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> _firstName;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 4: <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 5: <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FirstName<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 6: {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 7: <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _firstName; }<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 8: <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 9: <span style="color: #0000ff">set</span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 10: {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 11: _firstName = <span style="color: #0000ff">value</span>;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 12: PropertyChanged(<span style="color: #0000ff">this</span>, <span style="color: #0000ff">new</span> PropertyChangedEventArgs("<span style="color: #8b0000">FirstName</span>"));<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 13: }<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 14: }<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 15: <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 16: #region INotifyPropertyChanged Members<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 17: <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 18: <span style="color: #0000ff">public</span> <span style="color: #0000ff">event</span> PropertyChangedEventHandler PropertyChanged;<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 19: <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 20: #endregion<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 21: }</pre></pre><br /><style type="text/css"><br /><br /><br /><br /><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><br /><br /><p>But excessive use of the <strong>Copy + Paste “design pattern”</strong>, can be error prone – often times when Copying + Pasting, I forget to change the string to the new property name, and/or misspell the intended name - causing your ViewModels not to work correctly. </p><br /><br /><p><strong>Solution: </strong>The guys at Microsoft Patterns & Practices  have included some nice "lifestyle enhancing” features in <a href="http://compositewpf.codeplex.com/" target="_blank">Prism</a> that make your everyday coding much enjoyable. One of those features is the <a href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(MICROSOFT.PRACTICES.PRISM.VIEWMODEL.NOTIFICATIONOBJECT);k(VS.OBJECTBROWSER);k(SOLUTIONITEMSPROJECT);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22)&rd=true" target="_blank">NotificationObject</a>, an abstract class that implements the INotifyPropertyChanged (INPC) interface, and allows you to write code such as this: </p><br /><br /><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 470px; padding-right: 5px; height: 253px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 1: <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Customer : NotificationObject<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 2: {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 3: <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> _firstName;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 4: <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 5: <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FirstName<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 6: {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 7: <span style="color: #0000ff">get</span> { <span style="color: #0000ff">return</span> _firstName; }<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 8: <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 9: <span style="color: #0000ff">set</span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 10: {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 11: _firstName = <span style="color: #0000ff">value</span>;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 12: RaisePropertyChanged(() => FirstName);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 13: }<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 14: }<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px"> 15: }</pre></pre><br /><br /><p>Notice that Line 12 does not use a “Magic String”, but rather a lambda expression that points to the property. This gives you compile-time checking as well as refactoring with ease. some improvements could be  made (i.e.: Only raising the Property Changed event when the value changes), but I will leave that up to you. </p><br /><br /><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:93804077-0800-4349-9e13-6c24e63ea247" class="wlWriterEditableSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/DataBinding" rel="tag">DataBinding</a>,<a href="http://del.icio.us/popular/Prism4" rel="tag">Prism4</a>,<a href="http://del.icio.us/popular/MVVM" rel="tag">MVVM</a>,<a href="http://del.icio.us/popular/WPF" rel="tag">WPF</a>,<a href="http://del.icio.us/popular/Silverlight" rel="tag">Silverlight</a></div> Claudio Sanchezhttp://www.blogger.com/profile/04611561704063156872noreply@blogger.com0