<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RadenkoZec blog</title>
	<atom:link href="https://www.radenkozec.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.radenkozec.com/</link>
	<description>Innovator, coder, geek, speaker, blogger, founder, writer, traveler.</description>
	<lastBuildDate>Tue, 12 Feb 2019 07:32:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>
	<item>
		<title>.NET Core SignalR Automatic Reconnects</title>
		<link>https://www.radenkozec.com/net-core-signalr-automatic-reconnects/</link>
					<comments>https://www.radenkozec.com/net-core-signalr-automatic-reconnects/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Thu, 23 Aug 2018 06:42:38 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET Core]]></category>
		<category><![CDATA[SignalR]]></category>
		<guid isPermaLink="false">https://www.radenkozec.com/?p=1082</guid>

					<description><![CDATA[<p>One of the major differences between old and new .NET Core SignalR is that automatic reconnects are not supported. This means that you need explicitly open a new connection if you lost connection to the<a class="read-more" href="https://www.radenkozec.com/net-core-signalr-automatic-reconnects/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/net-core-signalr-automatic-reconnects/">.NET Core SignalR Automatic Reconnects</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>One of the major differences between old and new .NET Core SignalR is that automatic reconnects are not supported. This means that you need explicitly open a new connection if you lost connection to the server.</p>



<p>I managed to write my own implementation that do automatic reconnects on this new version of .NET Core 2 SignalR that works for me.</p>



<p>The code bellow uses <a href="https://www.nuget.org/packages/polly/" target="_blank">Polly</a> for automatic retry policy and <a href="https://www.nuget.org/packages/Serilog.AspNetCore/" target="_blank">Serilog</a> for logging.</p>



<p>Here is my implementation. Hope someone will find it useful:</p>


<pre><code class="language-csharp">
var signalRConnection = new HubConnectionBuilder()
     .WithUrl(BaseUrl + "/hubs/integrationserver", options =&gt;
     {
      options.Headers.Add("Authorization", "Basic " + Header);
     }).Build();
signalRConnection.On&lt;string, string&gt;("ReceiveMessage", (entityName, json) =&gt;<br>{</p>
       <p>});</p>
</code></pre>
<pre><code class="language-csharp">
<p>private async void OpenSignalRConnection()<br>{<br>
     var pauseBetweenFailures = TimeSpan.FromSeconds(20);</p>
     var retryPolicy = Policy
         .Handle&lt;Exception&gt;()
         .WaitAndRetryForeverAsync(i =&gt; pauseBetweenFailures
         , (exception, timeSpan) =&gt; {
             Log.Error(exception.ToString());
         });

     await retryPolicy.ExecuteAsync(async () =&gt;
     {
         Log.Information("Trying to connect to SignalR server");
         await TryOpenSignalRConnection();
     });
}
</code></pre>
<pre><code class="language-csharp">
<p>private async Task&lt;bool&gt; TryOpenSignalRConnection()<br>{</p>
<p>     Log.Information("Starting SignalR connection");</p>
<p>     await signalRConnection.StartAsync();<br>
     Log.Information("SignalR connection established");<br>
     return true;<br>
}
</p>
</code></pre>
<pre><code class="language-csharp">
<p>private async Task SignalRConnection_Closed(Exception arg)<br>{<br>
     Log.Information("SignalR connection is closed");</p>
<p>     await signalRConnection.StopAsync();</p>
<p>     signalRConnection.Closed -= SignalRConnection_Closed;<br>
     OpenSignalRConnection();
<br>}</p>
</code></pre><p>The post <a href="https://www.radenkozec.com/net-core-signalr-automatic-reconnects/">.NET Core SignalR Automatic Reconnects</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/net-core-signalr-automatic-reconnects/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Enable Unobtrusive JQuery Validation on Hidden Input Fields in ASP.NET MVC</title>
		<link>https://www.radenkozec.com/enable-unobtrusive-jquery-validation-on-hidden-input-fields-in-asp-net-mvc/</link>
					<comments>https://www.radenkozec.com/enable-unobtrusive-jquery-validation-on-hidden-input-fields-in-asp-net-mvc/#respond</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Tue, 30 Jun 2015 09:23:51 +0000</pubDate>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[JQuery]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=997</guid>

					<description><![CDATA[<p>After release of JQuery Validation Plugin 1.9 hidden elements on form are ignored by default from validation. The problem is that you sometimes need a validation on these hidden fields. However there is a nice<a class="read-more" href="https://www.radenkozec.com/enable-unobtrusive-jquery-validation-on-hidden-input-fields-in-asp-net-mvc/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/enable-unobtrusive-jquery-validation-on-hidden-input-fields-in-asp-net-mvc/">Enable Unobtrusive JQuery Validation on Hidden Input Fields in ASP.NET MVC</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After release of JQuery Validation Plugin 1.9 hidden elements on form are ignored by default from validation.</p>
<p>The problem is that you sometimes need a validation on these hidden fields.</p>
<p>However there is a nice workaround.</p>
<p>Make sure to put</p>
<pre><code class="language-csharp">$.validator.setDefaults({ ignore: '' });</code></pre>
<p>not inside</p>
<pre><code class="language-csharp">$(document).ready</code></pre>
<p>This will force client side validation to work even on hidden fields.</p>
<p>But what if you change value of hidden input from JQuery and want validation to perform after this change?</p>
<p>The code above will not help in this case.</p>
<p>I will show you a nice trick for this on example hidden input #SomeInput :</p>
<pre><code class="language-csharp"> $("#SomeInput").val("newValue").trigger("change");
 $("#SomeInput").valid();</code></pre>
<p>We must call method valid after apply change to hidden input to force validation to perform after manually changing hidden input value.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>The post <a href="https://www.radenkozec.com/enable-unobtrusive-jquery-validation-on-hidden-input-fields-in-asp-net-mvc/">Enable Unobtrusive JQuery Validation on Hidden Input Fields in ASP.NET MVC</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/enable-unobtrusive-jquery-validation-on-hidden-input-fields-in-asp-net-mvc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to enable Unobtrusive Client Validation using JQuery in ASP.NET 5</title>
		<link>https://www.radenkozec.com/how-to-enable-unobtrusive-client-validation-using-jquery-in-asp-net-mvc6/</link>
					<comments>https://www.radenkozec.com/how-to-enable-unobtrusive-client-validation-using-jquery-in-asp-net-mvc6/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Tue, 30 Jun 2015 07:04:32 +0000</pubDate>
				<category><![CDATA[ASP.NET 5]]></category>
		<category><![CDATA[ASP.NET MVC 6]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=994</guid>

					<description><![CDATA[<p>In previous versions of ASP.NET MVC we have enable unobtrusive client side validation using JQuery in simple way by adding two keys in AppSettings of your config file: &#60;configuration&#62; &#60;appSettings&#62; &#60;add key="ClientValidationEnabled" value="true" /&#62; &#60;add<a class="read-more" href="https://www.radenkozec.com/how-to-enable-unobtrusive-client-validation-using-jquery-in-asp-net-mvc6/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/how-to-enable-unobtrusive-client-validation-using-jquery-in-asp-net-mvc6/">How to enable Unobtrusive Client Validation using JQuery in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In previous versions of ASP.NET MVC we have enable unobtrusive client side validation using JQuery in simple way by adding two keys in AppSettings of your config file:</p>
<pre><code class="language-csharp">&lt;configuration&gt;
  &lt;appSettings&gt;  
    &lt;add key="ClientValidationEnabled" value="true" /&gt;
    &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
  &lt;/appSettings&gt;
&lt;/configuration&gt;</code></pre>
<p>&nbsp;</p>
<p>In ASP.NET MVC 6 process of enabling client side validation is even more simpler.</p>
<p>On views you want to enable unobtrusive client side validation just include:</p>
<pre><code class="language-aspnet">@section scripts{
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}</code></pre>
<p>&nbsp;</p>
<p>I hope this small blog post will help someone to save some time creating awesome ASP.NET MVC 6 apps.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>The post <a href="https://www.radenkozec.com/how-to-enable-unobtrusive-client-validation-using-jquery-in-asp-net-mvc6/">How to enable Unobtrusive Client Validation using JQuery in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/how-to-enable-unobtrusive-client-validation-using-jquery-in-asp-net-mvc6/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Getting user-friendly routes with Aurelia in ASP.NET 5</title>
		<link>https://www.radenkozec.com/getting-user-friendly-routes-with-aurelia-in-asp-net-5/</link>
					<comments>https://www.radenkozec.com/getting-user-friendly-routes-with-aurelia-in-asp-net-5/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Mon, 29 Jun 2015 12:49:25 +0000</pubDate>
				<category><![CDATA[ASP.NET 5]]></category>
		<category><![CDATA[AureliaJs]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=984</guid>

					<description><![CDATA[<p>If you want to use Aurelia framework inside ASP.NET 5 application you have a great tutorial from Scott Allen&#160;that will help you to jump start. When you finish configuring Aurelia app files to reside in<a class="read-more" href="https://www.radenkozec.com/getting-user-friendly-routes-with-aurelia-in-asp-net-5/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/getting-user-friendly-routes-with-aurelia-in-asp-net-5/">Getting user-friendly routes with Aurelia in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you want to use <a href="http://aurelia.io/" target="_blank">Aurelia framework</a> inside ASP.NET 5 application you have a <a href="http://odetocode.com/blogs/scott/archive/2015/02/18/using-jspm-with-visual-studio-2015-and-asp-net-5.aspx" target="_blank" rel="nofollow">great tutorial from Scott Allen</a>&nbsp;that will help you to jump start.</p>
<p>When you finish configuring Aurelia app files to reside in wwwroot folder of your ASP.NET 5 application you can run Aurelia app easily by typing for example <a href="http://localhost:5000/index.html" rel="nofollow">http://localhost:5000/index.html</a></p>
<p>The problem is if you want to mix ASP.NET MVC 6 app with Aurelia.</p>
<p>I need&nbsp;to have several&nbsp;ASP.NET MVC 6 views like Login and Registration in my Web app and after login to redirect users to Aurelia app.</p>
<p>In ASP.NET MVC 6 app I have a URL like this: <a href="http://localhost:5000/Account/Login" rel="nofollow">http://localhost:5000/Account/Login</a> and I want to my Aurelia app have a URL like this: <a href="http://localhost:5000/Aurelia" rel="nofollow">http://localhost:5000/Aurelia</a><em><strong> .</strong></em></p>
<p>If you want to use razor views there is a nice workaround&nbsp;for that in <a href="http://aurelia.io/docs.html#the-screen-activation-lifecycle" target="_blank">official Aurelia docs</a>.</p>
<p>If you want to use regular HTML files like me follow this simple tutorial.</p>
<p>Easiest way to do this is to redirect users to a controller which will return Aurelia app:</p>
<pre><code class="language-csharp">    public class AureliaController : Controller
    {
        private readonly IApplicationEnvironment _hostingEnvironment;
        public AureliaController(IApplicationEnvironment hostingEnvironment)
        {
            _hostingEnvironment = hostingEnvironment;
        }
        public IActionResult Index()
        {
            var path = _hostingEnvironment.ApplicationBasePath + "\\wwwroot\\index.html";

            if (System.IO.File.Exists(path))
            {
                return File(path, "text/html");
            }
            return HttpNotFound();
        }
    }</code></pre>
<p>You need to name the controller properly. For a route <a href="http://localhost:5000/Aurelia" rel="nofollow">http://localhost:5000/Aurelia</a> you need to name it&nbsp;&nbsp;AureliaController.</p>
<p>IApplicationEnvironment is automatically injected in the constructor by ASP.NET 5 so we can access ApplicationBasePath variable.</p>
<p>Index method will return File result&nbsp;with Aurelia root&nbsp;application file in this case index.html.</p>
<p>So my resulted route will be <a href="http://localhost:5000/Aurelia" rel="nofollow">http://localhost:5000/Aurelia</a> and when I navigate using a router to another view like <a href="http://localhost:5000/Aurelia#welcome" rel="nofollow">http://localhost:5000/Aurelia#welcome</a> my routes are persisted and not changed to <a href="http://localhost:5000/index.html" rel="nofollow">http://localhost:5000/index.html</a>.</p>
<p>I hope this tutorial will help someone to jump start with AureliaJs in Visual Studio 2015.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.radenkozec.com/getting-user-friendly-routes-with-aurelia-in-asp-net-5/">Getting user-friendly routes with Aurelia in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/getting-user-friendly-routes-with-aurelia-in-asp-net-5/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>LocalDB for Database Integration Testing in ASP.NET 5 project and XUnit.net</title>
		<link>https://www.radenkozec.com/localdb-for-database-integration-testing-in-asp-net-5-project-and-xunit-net/</link>
					<comments>https://www.radenkozec.com/localdb-for-database-integration-testing-in-asp-net-5-project-and-xunit-net/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Mon, 23 Mar 2015 10:51:08 +0000</pubDate>
				<category><![CDATA[ASP.NET 5]]></category>
		<category><![CDATA[Unit testing]]></category>
		<category><![CDATA[Integration testing]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=972</guid>

					<description><![CDATA[<p>If you need to use LocalDb for integration testing your database with EntityFramework or some other ORM this article can help. First, you will need to create .NET core class library project to hold your<a class="read-more" href="https://www.radenkozec.com/localdb-for-database-integration-testing-in-asp-net-5-project-and-xunit-net/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/localdb-for-database-integration-testing-in-asp-net-5-project-and-xunit-net/">LocalDB for Database Integration Testing in ASP.NET 5 project and XUnit.net</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you need to use LocalDb for integration testing your database with EntityFramework or some other ORM this article can help.</p>
<p>First, you will need to create .NET core class library project to hold your integration tests:</p>
<p><a href="https://www.radenkozec.com/wp-content/uploads/2015/03/ASP.NET5ClassLibrary1.png"><img fetchpriority="high" decoding="async" width="640" height="333" title="ASP.NET5ClassLibrary" style="border: 0px currentcolor; border-image: none; display: inline;" alt="ASP.NET5ClassLibrary" src="https://www.radenkozec.com/wp-content/uploads/2015/03/ASP.NET5ClassLibrary_thumb1.png" border="0"></a></p>
<p>After this you will need to set-up XUnit.net.</p>
<p>Check my previous <a href="https://www.radenkozec.com/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/" target="_blank">blog post</a> to do that.</p>
<p>After this create a folder named Data in your test project. In this folder you will need to put SQL script GenerateDb.sql (without create a database statement) which will create all objects in the database.</p>
<p>Put this LocalDb class somewhere in the project.</p>
<pre><code class="language-csharp"> public static class LocalDb
    {
        public const string DbDirectory = "Data";

        public static void CreateLocalDb(string databaseName, string scriptName, bool deleteIfExists = false)
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
           // return Path.GetDirectoryName(path);

            string outputFolder = Path.Combine(Path.GetDirectoryName(path), DbDirectory);
            string mdfFilename = databaseName + ".mdf";
            string databaseFileName = Path.Combine(outputFolder, mdfFilename);

            // Create Data Directory If It Doesn't Already Exist.
            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            if (CheckDatabaseExists(databaseName) &amp;&amp; deleteIfExists)
            {
                DropDatabaseObjects(databaseName);
            }
            else if (!CheckDatabaseExists(databaseName))
            {
                // If the database does not already exist, create it.
                CreateDatabase(databaseName, databaseFileName);
            }
            if (deleteIfExists)
            {
                ExecuteScript(databaseName, scriptName);
            }
        }

        private static void ExecuteScript(string databaseName, string scriptName)
        {
            string connectionString = string.Format(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog={0};Integrated Security=True", databaseName);

            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);

            string outputFolder = Path.Combine(Path.GetDirectoryName(path), DbDirectory);
            string scriptPath = Path.Combine(outputFolder, scriptName);

            var file = new FileInfo(scriptPath);
            string script = file.OpenText().ReadToEnd();

            string[] commands = script.Split(new[] { "GO\r\n", "GO ", "GO\t" }, StringSplitOptions.RemoveEmptyEntries);

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                foreach (string c in commands)
                {
                    var command = new SqlCommand(c, connection);
                    command.ExecuteNonQuery();
                }
            }
        }

        private static bool CheckDatabaseExists(string databaseName)
        {
            string connectionString = string.Format(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connection Timeout=300");
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand cmd = connection.CreateCommand();

                cmd.CommandText = string.Format("SELECT name FROM master.dbo.sysdatabases WHERE ('[' + name + ']' = '{0}' OR name = '{1}')", databaseName, databaseName);
                object result = cmd.ExecuteScalar();
                if (result != null)
                {
                    return true;
                }
            }

            return false;
        }

        private static void DropDatabaseObjects(string databaseName)
        {
            try
            {
                string connectionString = string.Format(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog={0};Integrated Security=True;Connection Timeout=300", databaseName);

                using (var connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    var commandSetSingle = new SqlCommand(@"declare @ord int, @cmd varchar(8000)

                    declare objs cursor for
                    select 0, 'drop trigger [' + name + '] on database' from sys.triggers
                    where parent_class = 0 and is_ms_shipped = 0
                    union
                    select 1, 'drop synonym [' + schema_name(schema_id) + '].[' + name + ']' from sys.objects o
                    where o.type = 'SN'
                    union
                    select 2, 'drop procedure [' + schema_name(schema_id) + '].[' + name + ']' from sys.objects o
                    where o.type = 'P'
                    union
                    select 3, 'drop view [' + schema_name(schema_id) + '].[' + name + ']' from sys.objects o
                    where o.type = 'V'
                    union
                    select 4, 'drop function [' + schema_name(schema_id) + '].[' + name + ']' from sys.objects o
                    where o.type IN ('FN','IF', 'TF')
                    union
                    select 5, 'alter table [' + schema_name(schema_id) + '].[' + object_name(parent_object_id) + '] drop constraint [' + name + ']'
                    from sys.objects
                    where type = 'F'
                    union
                    select 6, 'drop table [' + schema_name(schema_id) + '].[' + name + ']' from sys.objects o
                    where o.type = 'U'
                    union
                    select 7, 'drop type [' + schema_name(schema_id) + '].[' + name + ']' from sys.types
                    where is_user_defined = 1
                    union
                    select 8, 'drop default [' + schema_name(schema_id) + '].[' + name + ']' from sys.objects o
                    where o.type = 'D'
                    order by 1

                    open objs
                    fetch next from objs into @ord, @cmd

                    while @@FETCH_STATUS = 0
                    begin
                      print @cmd
                      execute (@cmd)
                      fetch next from objs into @ord, @cmd
                    end

                    close objs
                    deallocate objs",
                                    connection);
                    commandSetSingle.ExecuteNonQuery();
                }
            }
            catch
            {
            }
        }



        private static void CreateDatabase(string databaseName, string databaseFileName)
        {
            string connectionString = string.Format(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True");
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand cmd = connection.CreateCommand();

                // TryDetachDatabase(databaseName);
                cmd.CommandText = string.Format("CREATE DATABASE {0} ON (NAME = N'{0}', FILENAME = '{1}')", databaseName, databaseFileName);
                cmd.ExecuteNonQuery();
            }
        }
}</code></pre>
<p><code class="language-csharp">Please be aware that in ASP.NET 5 LocalDb connection string is changed and version numbering (v11) is removed.</code></p>
<p><code class="language-csharp">You will also need ItemDeployment to deploy script file into proper locations like in previous version of Visual Studio.</p>
<p></code></p>
<pre class="brush: c-sharp; gutter: false; toolbar: false"><code class="language-csharp"> internal static class ItemDeployment
    {
        public static void DeployItems(IEnumerable<string> items, bool retainDirectories = false)
        {
            var environmentDir = new DirectoryInfo(Directory.GetCurrentDirectory());
            var binFolderPath = GetDeploymentDirectory();

            foreach (var item in items)
            {
                if (string.IsNullOrWhiteSpace(item))
                {
                    continue;
                }

                string dirPath = retainDirectories ? Path.GetDirectoryName(item) : "";
                var filePath = item.Replace("/", @"\");
                if (environmentDir.Parent != null)
                {

                    UriBuilder uri = new UriBuilder(environmentDir.FullName);
                    string path = Uri.UnescapeDataString(uri.Path);

                    var itemPath = new Uri(Path.Combine(Path.GetDirectoryName(path), filePath)).LocalPath;
                    if (!File.Exists(itemPath))
                    {
                        throw new FileNotFoundException(string.Format("Can't find deployment source item '{0}'", itemPath));
                    }

                    if (!Directory.Exists(binFolderPath))
                    {
                        throw new DirectoryNotFoundException(
                            string.Format("Deployment target directory doesn't exist: '{0}'", binFolderPath));
                    }

                    var dirPathInBin = Path.Combine(binFolderPath, dirPath);
                    if (!Directory.Exists(dirPathInBin))
                    {
                        Directory.CreateDirectory(dirPathInBin);
                    }

                    var itemPathInBin =
                        new Uri(Path.Combine(binFolderPath, dirPath, Path.GetFileName(filePath))).LocalPath;
                    if (!File.Exists(itemPathInBin))
                    {
                        File.Copy(itemPath, itemPathInBin);
                        File.SetAttributes(itemPath, FileAttributes.Normal);

                    }
                    else
                    {
                        var hash1 = ComputeFileHash(itemPath);
                        var hash2 = ComputeFileHash(itemPathInBin);
                        string hash1String = BitConverter.ToString(hash1);
                        string hash2String = BitConverter.ToString(hash2);

                        if (!hash1String.Equals(hash2String))
                        {

                            File.Copy(itemPath, itemPathInBin ,true);
                            File.SetAttributes(itemPath, FileAttributes.Normal);
                        }
                    }
                }
            }
        }

        public static byte[] ComputeFileHash(string fileName)
        {
            using (var stream = File.OpenRead(fileName))
                return System.Security.Cryptography.MD5.Create().ComputeHash(stream);
        }

        public static string GetDeploymentDirectory()
        {
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            return Path.GetDirectoryName(path);
        }
    }
}
</string></code></pre>
<p>In constructor of your test class you just need to put Database name and script name for generating your LocalDb database.</p>
<p>We have implemented hash checking when copying files to avoid problems with multiple threads trying to copy same file.</p>
<pre><code class="language-csharp">public class TestClass
{
public TestClass()
{
     ItemDeployment.DeployItems(
               new[]
                {
                     @"ProjectName\FolderName\GenerateDb.sql"
                }, true);
     LocalDb.CreateLocalDb("Mydatabase", "GenerateDb.sql", true);
}
[Fact]
public void InsertPerson_AcceptCorrectParameters_InsertSuccess()
{
// write your database test
}

}</code></pre>
<p>You will probably need to disable running XUnit.Net tests in multiple threads to avoid dirty checks in database tests.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.radenkozec.com/localdb-for-database-integration-testing-in-asp-net-5-project-and-xunit-net/">LocalDB for Database Integration Testing in ASP.NET 5 project and XUnit.net</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/localdb-for-database-integration-testing-in-asp-net-5-project-and-xunit-net/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Unit / Integration testing in ASP.NET 5 and Visual Studio 2015 using XUnit.Net</title>
		<link>https://www.radenkozec.com/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/</link>
					<comments>https://www.radenkozec.com/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Mon, 23 Mar 2015 10:06:52 +0000</pubDate>
				<category><![CDATA[ASP.NET 5]]></category>
		<category><![CDATA[Unit testing]]></category>
		<category><![CDATA[Integration testing]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=964</guid>

					<description><![CDATA[<p>Currently in Visual Studio 2015 CTP 6 MSTests are not supported to test ASP.NET vNext projects. If you create MSTest project you are unable to add a reference to the ASP.NET vNext project. Microsoft will<a class="read-more" href="https://www.radenkozec.com/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/">Unit / Integration testing in ASP.NET 5 and Visual Studio 2015 using XUnit.Net</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Currently in Visual Studio 2015 CTP 6 MSTests are not supported to test ASP.NET vNext projects.</p>
<p>If you create MSTest project you are unable to add a reference to the ASP.NET vNext project.</p>
<p>Microsoft will enable support for MSTests for ASP.NET vNext in the next release of Visual Studio.</p>
<p>Until then you can only write unit and integration tests using XUnit.</p>
<p>First, you will need to create .NET core class library project where you will have all your tests:</p>
<p><a href="https://www.radenkozec.com/wp-content/uploads/2015/03/ASP.NET5ClassLibrary.png"><img decoding="async" style="border: 0px currentcolor; display: inline;" title="ASP.NET5ClassLibrary" src="https://www.radenkozec.com/wp-content/uploads/2015/03/ASP.NET5ClassLibrary_thumb.png" alt="ASP.NET5ClassLibrary" width="640" height="333" border="0"></a></p>
<p>Reference vNext project or any other .NET project (you can reference regular .NET projects from vNext Class Library) you want to test.</p>
<p>Create your test class and test method similar to this:</p>
<pre><code class="language-csharp">public class TestClass
{ 
 [Fact]
 public void PassingTest()
 {
     Assert.Equal(3, 2);
 }
}</code></pre>
<p>&nbsp;</p>
<p>Add reference to these 3 NuGet packages:</p>
<pre><code class="language-csharp">"xunit": "2.1.0.0-beta1-build2945",
"xunit.runner.aspnet": "2.1.0.0-beta1-build60",
"xunit.runner.visualstudio": "2.1.0.0-beta1-build1051"</code></pre>
<p>&nbsp;</p>
<p>Make sure Test Explorer is visible ( <code>Test &gt; Windows &gt; Test Explorer</code>).</p>
<p>Every time you build your project, XUnit.Net will discover unit tests in your project.</p>
<p>Now you can run or debug your unit or integration tests.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.radenkozec.com/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/">Unit / Integration testing in ASP.NET 5 and Visual Studio 2015 using XUnit.Net</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Using classic ADO.NET in ASP.NET 5</title>
		<link>https://www.radenkozec.com/using-classic-ado-net-in-asp-net-vnext/</link>
					<comments>https://www.radenkozec.com/using-classic-ado-net-in-asp-net-vnext/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Thu, 19 Mar 2015 10:17:54 +0000</pubDate>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[ASP.NET 5]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=959</guid>

					<description><![CDATA[<p>For some projects where performance makes a difference we usually use classic ADO.NET approach instead of EntityFramework or some other modern way to communicate with the database. In this post I will try to explain<a class="read-more" href="https://www.radenkozec.com/using-classic-ado-net-in-asp-net-vnext/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/using-classic-ado-net-in-asp-net-vnext/">Using classic ADO.NET in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>For some projects where performance makes a difference we usually use classic ADO.NET approach instead of EntityFramework or some other modern way to communicate with the database.</p>
<p>In this post I will try to explain how to fix some common issues with using ADO.NET in ASP.NET vNext.</p>
<p>If you have created ASP.NET 5 or ASP.NET vNext Class Library project (.NET Core Class Library project) and want to use ADO.NET you can have small issues.</p>
<p>Instead of referencing <em><strong>System.Data</strong></em> and <em><strong>System.Data.SqlClient </strong></em>you need to grab from Nuget:</p>
<p>System.Data.Common and System.Data.SqlClient.</p>
<p>Currently this creates dependency in project.json –&gt; aspnetcore50 section to these two libraries.</p>
<pre><code class="language-csharp"> "aspnetcore50": {
            "dependencies": {
                "System.Runtime": "4.0.20-beta-22523",
                "System.Data.Common": "4.0.0.0-beta-22605",
                "System.Data.SqlClient": "4.0.0.0-beta-22605"
            }
        }</code></pre>
<p>&nbsp;</p>
<p>In the current Visual Studio CTP6 after this your ADO.NET still will not compile.</p>
<p>You will need to add a reference to System.Data.Common 1.0.0-beta1 and System.Data.SqlClient into aspnet50 section of project.json like this:</p>
<pre><code class="language-csharp"> "aspnet50": {
            "dependencies": {
                "System.Data.Common": "1.0.0-beta1",
                "System.Data.SqlClient": "1.0.0-beta1"
            }
        }</code></pre>
<p>&nbsp;</p>
<p>I have also created little SqlHelper that works with ASP.NET 5 :</p>
<pre><code class="language-csharp">  public sealed class SqlHelper
    {
        //Since this class provides only static methods, make the default constructor private to prevent 
        //instances from being created with "new SqlHelper()".
        private SqlHelper()
        {

        }

        private static string connectionString;
        public static string GetConnectionString()
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                var config = new Configuration()
                      .AddJsonFile("config.json")
                      .AddEnvironmentVariables();
                connectionString = config.Get("Data:DefaultConnection:ConnectionString");
            }

            return connectionString;
        }

        public static int ExecuteNonQuery(SqlConnection conn, string cmdText, SqlParameter[] cmdParms)
        {
            SqlCommand cmd = conn.CreateCommand();
            using (conn)
            {
                PrepareCommand(cmd, conn, null, CommandType.Text, cmdText, cmdParms);
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                return val;
            }
        }

        public static int ExecuteNonQuery(SqlConnection conn, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
        {
            SqlCommand cmd = conn.CreateCommand();
            using (conn)
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                return val;
            }
        }


        public static SqlDataReader ExecuteReader(SqlConnection conn, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
        {
            SqlCommand cmd = conn.CreateCommand();
            PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
            var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            return rdr;
        }


        public static object ExecuteScalar(SqlConnection conn, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
        {
            SqlCommand cmd = conn.CreateCommand();
            PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
            object val = cmd.ExecuteScalar();
            cmd.Parameters.Clear();
            return val;
        }

        private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] commandParameters)
        {
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            cmd.Connection = conn;
            cmd.CommandText = cmdText;
            if (trans != null)
            {
                cmd.Transaction = trans;
            }
            cmd.CommandType = cmdType;
            //attach the command parameters if they are provided
            if (commandParameters != null)
            {
                AttachParameters(cmd, commandParameters);
            }
        }
        private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
        {
            foreach (SqlParameter p in commandParameters)
            {
                //check for derived output value with no value assigned
                if ((p.Direction == ParameterDirection.InputOutput) &amp;&amp; (p.Value == null))
                {
                    p.Value = DBNull.Value;
                }

                command.Parameters.Add(p);
            }
        }
    }</code></pre>
<p>&nbsp;</p>
<p>After this working with ADO.NET inside ASP.NET vNext is pretty straightforward:</p>
<pre><code class="language-csharp"> public class LogRepository
    {
        public void Add(Log log)
        {

            var parameters = new[]
                    {
                        new SqlParameter("@JobId", log.JobId),
                        new SqlParameter("@ErrorInfo", log.ErrorInfo),
                        new SqlParameter("@DateTimeProcessedUTC", log.DateTimeProcessedUTC)
                    };

            using (var conn = new SqlConnection(SqlHelper.GetConnectionString()))
            {
                     SqlHelper.ExecuteNonQuery(
                        conn,
                        CommandType.Text,
                        @" INSERT dbo.Log ([JobId],[ErrorInfo],[DateTimeProcessedUTC])
                            SELECT @JobId, @ErrorInfo, @DateTimeProcessedUTC"
                          ,
                        parameters);

            }

        }
    }
}</code></pre>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.radenkozec.com/using-classic-ado-net-in-asp-net-vnext/">Using classic ADO.NET in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/using-classic-ado-net-in-asp-net-vnext/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Read Config file in ASP.NET 5</title>
		<link>https://www.radenkozec.com/read-config-file-in-asp-net-vnext/</link>
					<comments>https://www.radenkozec.com/read-config-file-in-asp-net-vnext/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Tue, 17 Mar 2015 08:15:14 +0000</pubDate>
				<category><![CDATA[ASP.NET 5]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=952</guid>

					<description><![CDATA[<p>ASP.NET vNext has a new configuration system. With the new version of ASP.NET more than one file type is supported. Currently, there are 3 different file types that are supported: Json, Xml and Ini. For<a class="read-more" href="https://www.radenkozec.com/read-config-file-in-asp-net-vnext/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/read-config-file-in-asp-net-vnext/">Read Config file in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>ASP.NET vNext has a new configuration system.</p>
<p>With the new version of ASP.NET more than one file type is supported.</p>
<p>Currently, there are 3 different file types that are supported: Json, Xml and Ini.</p>
<p>For example, we can define connection string in <em><strong>config.json</strong></em> file:</p>
<pre><code class="language-csharp">{
    "Data": {
        "DefaultConnection": { 
            "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=DbName;Trusted_Connection=True;MultipleActiveResultSets=true"
        }
    }
}</code></pre>
<p>You can also get&nbsp; settings from Environment Variables.</p>
<p>To <em><strong>read connection string from config.json</strong></em> from any location in your app you need to add a reference to Microsoft.Framework.ConfigurationModel.Json.</p>
<p>Now simple import namespace and use code below to read connection string from config.json:</p>
<p>&nbsp;</p>
<pre><code class="language-csharp">using Microsoft.Framework.ConfigurationModel.Json;

var configuration = new Configuration()
                .AddJsonFile("config.json")
                .AddEnvironmentVariables();

var connectionString = configuration.Get("Data:DefaultConnection:ConnectionString");</code></pre>
<p>&nbsp;</p>
<p>You can also load configuration from multiple different config files:</p>
<p>&nbsp;</p>
<pre><code class="language-csharp">  var configuration = new Configuration()
                              .AddJsonFile("config.json")
                              .AddIniFile("config.ini")
                              .AddXmlFile("config.xml")
                              .AddEnvironmentVariables();</code></pre>
<p>To use xml files you need to reference Microsoft.Framework.ConfigurationModel.Xml and for Ini Microsoft.Framework.ConfigurationModel.</p>
<p>Supporting multiple config files and reading values from config files has never been easier.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.radenkozec.com/read-config-file-in-asp-net-vnext/">Read Config file in ASP.NET 5</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/read-config-file-in-asp-net-vnext/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>ASP.NET Identity 2.1 implementation for MySQL</title>
		<link>https://www.radenkozec.com/asp-net-identity-2-1-for-mysql/</link>
					<comments>https://www.radenkozec.com/asp-net-identity-2-1-for-mysql/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Fri, 23 Jan 2015 08:50:09 +0000</pubDate>
				<category><![CDATA[ASP.NET Identity]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[ASP.NET Web API]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySql ASP.NET Identity]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=934</guid>

					<description><![CDATA[<p>In this blog post I will try to cover how to use a custom ASP.NET identity provider for MySQL I have created. Default ASP.NET Identity provider uses Entity Framework and SQL Server to store information&#8217;s<a class="read-more" href="https://www.radenkozec.com/asp-net-identity-2-1-for-mysql/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/asp-net-identity-2-1-for-mysql/">ASP.NET Identity 2.1 implementation for MySQL</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this blog post I will try to cover how to use a custom ASP.NET identity provider for MySQL I have created.</p>
<p>Default ASP.NET Identity provider uses Entity Framework and SQL Server to store information&#8217;s about users.</p>
<p>If you are trying to implement ASP.NET Identity 2.1 for MySQL database, then follow this guide.</p>
<p>This implementation uses Oracle fully-managed ADO.NET driver for MySQL.</p>
<p>This means that you have a connection string in your web.config similar to this:</p>
<pre><code class="language-csharp">&lt;add name="DefaultConnection" connectionString="Server=localhost;
Database=aspnetidentity;Uid=radenko;Pwd=somepass;" providerName="MySql.Data.MySqlClient" /&gt;</code></pre>
<p>&nbsp;</p>
<p>This implementation of ASP.NET Identity 2.1 for MySQL has all the major interfaces implemented in custom UserStore class:</p>
<p><img decoding="async" style="border: 0px currentcolor; display: inline;" title="ASPIdentityUserStoreInterfaces" src="https://www.radenkozec.com/wp-content/uploads/2015/01/ASPIdentityUserStoreInterfaces.png" alt="ASPIdentityUserStoreInterfaces" width="380" height="415" border="0"></p>
<p>Source code of my implementation is available at <a href="https://github.com/radenkozec/MySqlIdentity" target="_blank" rel="nofollow">GitHub – MySqlIdentity</a></p>
<p>First, you will need to execute this <a href="https://www.radenkozec.com/wp-content/uploads/2015/01/MySqlTableSetUp.zip">a create script</a> on your MySQL database which will create the tables required for the ASP.NET Identity provider.</p>
<p><img loading="lazy" decoding="async" style="border: 0px currentcolor; display: inline;" title="MySqlAspIdentityDatabase" src="https://www.radenkozec.com/wp-content/uploads/2015/01/MySqlAspIdentityDatabase.png" alt="MySqlAspIdentityDatabase" width="222" height="240" border="0"></p>
<ul>
<li>Create a new ASP.NET MVC 5 project, choosing the Individual User Accounts authentication type.</li>
<li>Uninstall all EntityFramework NuGet packages starting with Microsoft.AspNet.Identity.EntityFramework</li>
<li>Install NuGet Package called <a href="https://www.nuget.org/packages/MySql.AspNet.Identity/" target="_blank" rel="nofollow">MySql.AspNet.Identity</a></li>
<li>In ~/Models/IdentityModels.cs:
<ul>
<li>Remove the namespaces:
<ul>
<li>Microsoft.AspNet.Identity.EntityFramework</li>
<li>System.Data.Entity</li>
</ul>
</li>
<li>Add the namespace: MySql.AspNet.Identity.<br />
Class ApplicationUser will inherit from IdentityUser class in MySql.Asp.Net.Identity namespace</li>
<li>Remove the entire ApplicationDbContext class. This class is not needed anymore.</li>
</ul>
</li>
<li>In ~/App_Start/Startup.Auth.cs
<ul>
<li>Delete this line of code</li>
</ul>
</li>
</ul>
<pre><code class="language-csharp">app.CreatePerOwinContext(ApplicationDbContext.Create);</code></pre>
<ul>
<li>In ~/App_Start/IdentityConfig.cs<br />
Remove the namespaces:</p>
<ul>
<li>Microsoft.AspNet.Identity.EntityFramework</li>
<li>System.Data.Entity</li>
</ul>
</li>
<li>In method Create inside ApplicationUserManager class replace ApplicationUserManager with another which accepts MySqlUserStore :</li>
</ul>
<pre><code class="language-csharp"> public static ApplicationUserManager Create(IdentityFactoryOptions&lt;ApplicationUserManager&gt; options, IOwinContext context) 
 {
     //var manager = new ApplicationUserManager(new UserStore&lt;ApplicationUser&gt;(context.Get&lt;ApplicationDbContext&gt;()));
        var manager = new ApplicationUserManager(new MySqlUserStore&lt;ApplicationUser&gt;());</code></pre>
<p>MySqlUserStore accepts an optional parameter in the constructor – connection string so if you are not using DefaultConnection as your connection string you can pass another connection string.</p>
<p>After this you should be able to build your ASP.NET MVC project and run it successfully using MySQL as a store for your user, roles, claims and other information&#8217;s.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.radenkozec.com/asp-net-identity-2-1-for-mysql/">ASP.NET Identity 2.1 implementation for MySQL</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/asp-net-identity-2-1-for-mysql/feed/</wfw:commentRss>
			<slash:comments>23</slash:comments>
		
		
			</item>
		<item>
		<title>Don&#8217;t read Non-Fiction, never!</title>
		<link>https://www.radenkozec.com/fiction-vs-nonfiction/</link>
					<comments>https://www.radenkozec.com/fiction-vs-nonfiction/#comments</comments>
		
		<dc:creator><![CDATA[radenko]]></dc:creator>
		<pubDate>Thu, 08 Jan 2015 13:14:35 +0000</pubDate>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Work-life balance]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[work-life balance]]></category>
		<guid isPermaLink="false">http://blog.developers.ba/?p=919</guid>

					<description><![CDATA[<p>I just read few non-fiction books. I wanted to share my experience with you. After reading few non-fiction books in short period of time I have realized that only a fraction of the information in<a class="read-more" href="https://www.radenkozec.com/fiction-vs-nonfiction/"> [Read More...]</a></p>
<p>The post <a href="https://www.radenkozec.com/fiction-vs-nonfiction/">Don&rsquo;t read Non-Fiction, never!</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I just read few non-fiction books.</p>
<p>I wanted to share my experience with you.</p>
<p>After reading few non-fiction books in short period of time I have realized that only a fraction of the information in these books is important.</p>
<p><img loading="lazy" decoding="async" width="320" height="197" title="ParetoPrinciple" style="border-width: 0px; display: inline;" alt="ParetoPrinciple" src="https://www.radenkozec.com/wp-content/uploads/2015/01/ParetoPrinciple.jpg" border="0"> </p>
<p>If we apply the Pareto principle to this: </p>
<p>20% of Non-Fiction book produce 80% value of the book. or</p>
<p><em><strong>Only 20% content inside Non-Fiction book is valuable.</strong></em></p>
<p>If that is true, why we bother reading non-fiction at all?</p>
<p>All we need to do is to get important information’s from the book.</p>
<h1>How to get only valuable information&#8217;s from non-fiction book?</h1>
<p>We live in a digital age where it’s easy to find what&#8217;s important in any popular book.</p>
<p>We can easily find lot of summaries in different forms: blog posts, videos, slideshare presentations etc.</p>
<p>Here are some great examples of that from popular books:</p>
<p><iframe loading="lazy" width="427" height="356" src="//www.slideshare.net/slideshow/embed_code/138479" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen="" style="border: 1px solid rgb(204, 204, 204); border-image: none; margin-bottom: 5px; max-width: 100%;"> </iframe></p>
<div style="margin-bottom: 5px;"><strong><a title="Rich Dad, Poor Dad B I Z" href="https://www.slideshare.net/happysammy/rich-dad-poor-dad-b-i-z" target="_blank" rel="nofollow">Rich Dad, Poor Dad B I Z</a> </strong>from <strong><a href="http://www.slideshare.net/happysammy" target="_blank" rel="nofollow">Samantha Johnson</a></strong> </div>
<p>&nbsp;</p>
<p>or </p>
<p><iframe loading="lazy" title="How to Instantly Be More Productive – The 80/20 Principle by Richard Koch" width="640" height="360" src="https://www.youtube.com/embed/V28B_xOJzK4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> </p>
<p>or</p>
<p><a title="http://charlesholmes.net/2013/05/summary-of-rich-dad-poor-dad/" href="http://charlesholmes.net/2013/05/summary-of-rich-dad-poor-dad/" rel="nofollow">http://charlesholmes.net/2013/05/summary-of-rich-dad-poor-dad/</a></p>
<p>&nbsp;</p>
<h1>What to do instead of reading non-fiction books?</h1>
<p>We actually read entire book thinking that working hard on reading will benefit us in the way we will remember more important information&#8217;s from the book.</p>
<p>If we easily get the info’s without facts to support these information’s we will not remember it as important information&#8217;s.</p>
<p><em><strong>I think that I need to focus more on practicing, teaching and writing about important information’s from non-fiction books.</strong></em></p>
<p>Just reading books, even with taking notes will not do it.</p>
<p>&nbsp;</p>
<h1>Selective ignorance of information&#8217;s</h1>
<p><img loading="lazy" decoding="async" width="640" height="389" title="selectivereading" style="border-width: 0px; display: inline;" alt="selectivereading" src="https://www.radenkozec.com/wp-content/uploads/2015/01/selectivereading.jpg" border="0"></p>
<p>&nbsp;</p>
<p>Also great example of nice visual summary of book: <a href="http://staroversky.com/blog/the-4-hour-workweek-visual-summary" target="_blank" rel="nofollow">4 hour work week visual summary</a></p>
<p>I also agree with Tim Ferris about low information diet, but only after a certain age.</p>
<p>I think we should selectively ignore information’s (this includes non-fiction books) which we don’t need today.</p>
<p>Practicing this too early in life can have negative results.</p>
<h1>Reading fiction books</h1>
<p>I am a big believer that reading fiction books, improve creativity, innovativity<strong> </strong>and intelligence.</p>
<p>Cognitive psychologist and fiction writer, Dr. Keith Oatley and other researchers have discovered that fiction activates and improves the cognitive functions that allow us to thrive socially.</p>
<p>So I’ll try to read more fiction books in the next period.</p>
<p class="promo">If you like this article don’t forget to <a href="http://eepurl.com/ZfI8v">subscribe to this blog</a> and make sure you don’t miss new upcoming blog posts.</p>
<p>&nbsp;</p>
<p>The post <a href="https://www.radenkozec.com/fiction-vs-nonfiction/">Don&rsquo;t read Non-Fiction, never!</a> appeared first on <a href="https://www.radenkozec.com">RadenkoZec blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.radenkozec.com/fiction-vs-nonfiction/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
