Recently I've been asked several questions on the TabItem tutorial I've done some time ago. Because I haven't had any sources containg the code at hand I've finally found the time to refresh my memory and cobble together a sample.
Below sample is just a proof of concept. The code shouldn't be looked at as an example of good design and was prepared only to show the validation of tab items. In a production code ViewModels wouldn't be created in the view and command would be used instead of on click event for the button. Event aggregator, message bus or some other pattern could be used for exchange of information between the view models. Please treat this code as a very rough scaffolding. The sample follows the tutorial introduced some time ago, hence no refactoring or cleaning has been done.
Previous tutorials:
TabItem Validation, Part 1
TabItem Validation, Part 2
Code:
https://github.com/simonkatanski/ValidationSample
Tuesday, 26 April 2016
Monday, 7 March 2016
Nuget cheat sheet
I use nuget from the nuget console rarely enough to always have to google for the commands I need. Hence, here's a couple of commands I use most often:
Install-Package NUnit
Uninstall-Package NUnit
Lists all package's versions available from the current source based on the filter word:
Get-Package -ListAvailable -AllVersions -filter NUnit -source https://nuget.org/api/v2/
If we want to install some specific version of a package, we can use:
Install-Package NUnit -Version 1.0.0
If we want to install specific package into specific project:
Get-Project NameOfTheProject | Install-Package NUnit
Or, if we want to install specific package for all projects:
Get-Project -All
Install-Package NUnit
Uninstall-Package NUnit
Lists all package's versions available from the current source based on the filter word:
Get-Package -ListAvailable -AllVersions -filter NUnit -source https://nuget.org/api/v2/
If we want to install some specific version of a package, we can use:
Install-Package NUnit -Version 1.0.0
If we want to install specific package into specific project:
Get-Project NameOfTheProject | Install-Package NUnit
Or, if we want to install specific package for all projects:
Get-Project -All
Sunday, 31 January 2016
ASP.NET MVC, Identity 2, Sqlite
Recently I've added users and roles with the Identity 2 support in my ASP.NET MVC project. There were several gotchas that slowed my down considerably. I'll just list them one by one:
- When googling for answers and checking stack overflow it's easy to find answers concerning either Identity 1 or Identity 2. Bear in mind it's easy to jumble them together.
- The db structure for each version is different and if we're not generating the db structure code first style, we need to know exactly what the structure is. I was using Identity 2 with sqlite. Following is the db creation script I've used on github:
https://github.com/simonkatanski/Identity2SqliteScript/blob/master/Identity2SqliteDbScript.sql - Owin comes with an IAppBuilder which is used in many examples. It uses a dependency resolver to resolve User and Role services, acts as a inversion of control container. If we are using a separate container ( and I'm using unity ) this can lead to dbcontext errors.
Following links were really helpful in getting it setup the way it should:
http://stackoverflow.com/questions/24391885/how-to-plug-my-autofac-container-into-asp-net-identity-2-1
http://tech.trailmax.info/2014/09/aspnet-identity-and-ioc-container-registration/
Tuesday, 26 January 2016
Logging of EF generated queries and errors
I've been working on a small ASP.NET MVC project lately. I've added log4net and configured some basic logging. I haven't set it up for EF. I've wanted to start off with some first entities and a sqlite db. I have been getting the missing column exception from the ef provider. There's a nifty feature in the db context which allows to log all the generated queries and more details on errors/exceptions in EF.
It's really useful when you want to add some logging quickly to see what's going on underneath.
public MyDbContext() : base(ConnectionString) { this.Database.Log = input => Debug.WriteLine(input); }
It's really useful when you want to add some logging quickly to see what's going on underneath.
Wednesday, 18 March 2015
Mocking DbContext and unit tests / integration tests
Recently I've been preparing some integration and unit tests for a repository class that was using DbContext inside. Had to mock the DbContext to return a specific list of entities for each case.
For some reason I kept on getting the following error each time I've tried to run them:
The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
It turned out that because I wasn't using Ef6 code anywhere explicitly, its use wasn't registered and the dll wasn't being loaded causing the above error. All that was required was calling something from inside of the Ef6 dll in some class.
Decided to use the static constructor of my DbContext derived class.
public class MyDbContext : DbContext { static MyDbContext() { var efUsageHack = typeof(System.Data.Entity.SqlServer.SqlProviderServices); } }
Finding out the reason and solution took a bit of searching, for example here:
http://robsneuron.blogspot.com/2013/11/entity-framework-upgrade-to-6.html
Friday, 31 October 2014
Slide animation of ajax loaded divs with jQuery
Since I'm a real newbie in terms of web development this will most probably be really helpful mostly to me sometime in the future when I've forgotten all this.
I'm building a simple single-page website which requires some sliding animation, but the divs which are getting animated are actually separate .html files loaded with ajax through jQuery. There's a lot of information on loading pages through jQuery or animating html elements. Not so much on using both at the same time. And for a beginner it posed certain problem.
First the links which trigger the animation:
Here's the html for sliding-animated divs:
Here's the CSS:
And here's the javascript:
To summarize, what I do is I juggle with 2 divs. One is being shown, the other is hidden. On click on one of the links I load the hidden div with the html from the appropriate webpages. Then I animate and slide in the div with the newly loaded html and display it while sliding out and hiding the previous one. This cycle is being done every time any link is clicked.
UPDATE:
I've noticed that the comparing with the current button wasn't working so I fixed it, also added blocking of the animation while it's running and hooked up the complete callback properly.
I'm building a simple single-page website which requires some sliding animation, but the divs which are getting animated are actually separate .html files loaded with ajax through jQuery. There's a lot of information on loading pages through jQuery or animating html elements. Not so much on using both at the same time. And for a beginner it posed certain problem.
First the links which trigger the animation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <nav id="menu"> <ul> <li> <div style="background-color: rgba(175, 120, 75, 0.5)"> <a href="#" id="mainpage">Main page</a> </div> </li> <li> <div style="background-color: rgba(120, 90, 175, 0.5)"> <a href="#" id="page2">Second page</a> </div> </li> <li> <div style="background-color: rgba(75, 175, 90, 0.5)"> <a href="#" id="page3">Third page</a> </div> </li> </ul> </nav> |
Here's the html for sliding-animated divs:
1 2 3 4 5 6 | <div id="slideWrapper"> <div id="slider1"> </div> <div id="slider2"> </div> </div> |
Here's the CSS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #slideWrapper { width: 100%; height: 300px; float: left; position: relative; } div#slideWrapper > div { margin: 0 5px 0 0; border: 1px solid black; width: 100%; height: 300px; float: left; position: absolute; overflow: hidden; } |
And here's the javascript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | var _showedSubPage = ""; $(document).ready(function () { // Configure on click events, // first argument: id of the button I'm clicking on, second: url loadPageOnClick("mainpage", "subpages/page1.html"); loadPageOnClick("page2", "subpages/page2.html"); loadPageOnClick("page3", "subpages/page3.html"); // Initial load of the page $("#slider1").load("subpages/page1.html"); $("#slider1").addClass("slidedIn"); $("#slider2").addClass("slidedOut"); _showedSubPage = "mainpage"; }); loadPageOnClick = function (sourceId, url) { jQuery(document).ready(function () { jQuery("#" + sourceId).click(function () { var divToSlideIn = $("#slideWrapper").find(".slidedOut"); var divToSlideOut = $(divToSlideIn).siblings(".slidedIn"); // don't animate if the click is on the same button if (_showedSubPage != sourceId && !$(divToSlideOut).hasClass("animating") && !$(divToSlideIn).hasClass("animating")) { _showedSubPage = sourceId; $(divToSlideOut).addClass("animating"); $(divToSlideIn).addClass("animating"); // change classes on slider divs $(divToSlideOut).removeClass("slidedIn").addClass("slidedOut"); $(divToSlideIn).removeClass("slidedOut").addClass("slidedIn"); // load webpage through ajax $(divToSlideIn).load(url); $(divToSlideOut).animate({ right: $(divToSlideOut).width() }, 600, null, function() { $(divToSlideOut).hide(); $(divToSlideOut).empty(); $(divToSlideOut).insertBefore($(divToSlideIn)); $(divToSlideOut).removeClass("animating"); }); $(divToSlideIn).show().css({ right: -($(divToSlideIn).width()) }).animate({ right: 0 }, 600, null, function() { $(divToSlideIn).removeClass("animating"); }); } }); }); }; |
To summarize, what I do is I juggle with 2 divs. One is being shown, the other is hidden. On click on one of the links I load the hidden div with the html from the appropriate webpages. Then I animate and slide in the div with the newly loaded html and display it while sliding out and hiding the previous one. This cycle is being done every time any link is clicked.
UPDATE:
I've noticed that the comparing with the current button wasn't working so I fixed it, also added blocking of the animation while it's running and hooked up the complete callback properly.
Labels:
ajax,
javascript,
jQuery,
sliding animation,
sliding divs
Tuesday, 21 October 2014
Developer Days 2014, Wrocław, Poland
I haven't been going to many IT events recently, so Developer Days in Wrocław, was a nice refreshment. I'll note down all the interesting buzzword I've heard and a small wrap-up of some of the lectures I've attended.
1. Keynote: The present and future of .NET by Tomasz Kopacz
Every lecture by Tomasz is a pleasure to listen to, and choosing him to lead with the first morning lecture was a wise thing to do. His energetic speech worked better than coffee and was full of interesting tid bits from the .NET world. He maintained this throughout all his lectures.
2. Use all of Visual Studio and be a better developer by Kate Gregory
This lecture was a bit of a let down, especially for any developer who uses resharper extensively. The target audience was around junior .NET dev level. It was nice to listen to Kate however because she's a very good lecturer and previously I really enjoyed listening to her in several .NET rocks podcasts she attended.
3. Architecting an ASP.NET MVC solution by Andrea Saltarello
Because I'm a complete newbie in terms of web development I was expecting some in-depth MVC knowledge as a requirement for this session. To my surprise the session focused on several js libraries/frameworks and SEO, which I was happy to find because of my meager knowledge on the subject.
Some keywords:
- schema ( schema.org ): by adorning html elements we're able to tell webcrawlers what type of data each element displays
- sitemaps ( sitemaps.org ): adds information about different sub pages of the website available for the webcrawlers
- google dev tools: has a free possibility of testing how "crawlable" is any given website
- bootstrap ( bootstrap.org ): allows for building a website which easily changes layout to fit available screen space
- template engine chooser on github: http://garann.github.io/template-chooser/
I'll probably add some additional pieces of information once I read up on them more
Subscribe to:
Posts (Atom)