<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>2016-11 on Funky Si's Blog (Dev)</title><link>https://blog-dev.funkysi1701.com/2016/11/</link><description>Recent content in 2016-11 on Funky Si's Blog (Dev)</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><managingEditor>funkysi1701@gmail.com (Simon Foster)</managingEditor><webMaster>funkysi1701@gmail.com (Simon Foster)</webMaster><lastBuildDate>Thu, 24 Nov 2016 20:00:45 +0000</lastBuildDate><atom:link href="https://blog-dev.funkysi1701.com/2016/11/index.xml" rel="self" type="application/rss+xml"/><item><title>What should be in Source Control?</title><link>https://blog-dev.funkysi1701.com/posts/2016/what-should-be-in-source-control/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Thu, 24 Nov 2016 20:00:45 +0000</pubDate><guid>https://blog-dev.funkysi1701.com/posts/2016/what-should-be-in-source-control/</guid><category term="Git">Git</category><category term="SourceCode">SourceCode</category><category term="SourceControl">SourceControl</category><category term="C-Sharp">C-Sharp</category><description>&lt;p&gt;I am currently working on source code that is over 5Gb in size. This is mostly due to a poorly thought out folder structure, there are code files, images and Excel files all jumbled together. I think a clear distinction should be made between source code and data.&lt;/p&gt;
&lt;h2 id="source-code"&gt;Source Code&lt;a class="anchor ms-1" href="#source-code" aria-label="Permalink: Source Code"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I will define source code as anything that is written in order to compile and run the project. If it is a webpage it will be all the HTML, CSS and Javascript or any file used to produce these. I would also include any configuration files and files used to build/deploy the website or project. Anything that is compiled from your source files can safely be ignored.&lt;/p&gt;
&lt;h2 id="data"&gt;Data&lt;a class="anchor ms-1" href="#data" aria-label="Permalink: Data"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;I would define data as anything that is added to the project during its life. So if you have an upload option, anything that is uploaded I would describe as data. The site should still function without (or very little) data.&lt;/p&gt;
&lt;h2 id="images"&gt;Images&lt;a class="anchor ms-1" href="#images" aria-label="Permalink: Images"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Images can fit into both groups. Any icons or images attached to the functionality of the project I would class as source code. However anything that is uploaded should be classed as Data.&lt;/p&gt;
&lt;h2 id="databases"&gt;Databases&lt;a class="anchor ms-1" href="#databases" aria-label="Permalink: Databases"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The database should also be classed as both. The data, anything that is inside a database table should normally be classed as data. Stored Procedures, Functions and Views are all Source Code and would benefit from version control.&lt;/p&gt;
&lt;h2 id="source-control--backup"&gt;Source Control != Backup&lt;a class="anchor ms-1" href="#source-control--backup" aria-label="Permalink: Source Control != Backup"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Source control is not an excuse not to backup things. Don’t just commit files to source control so you know you can restore them if you need to. Files in general in source control are there so you can see how they changed over time as the code base changed. Files in you backup are a snapshot of what the application was at a point in time and will include ALL the data.&lt;/p&gt;
&lt;p&gt;One last point before I end. If you are hosting on a Cloud Computing platform like Azure it gives you an easy way to distinguish between Data and Code.&lt;/p&gt;
&lt;p&gt;Anything in your&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Web App = Code&lt;/li&gt;
&lt;li&gt;Blob Storage = Data&lt;/li&gt;
&lt;li&gt;SQL = Data/Code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each project is unique and there will always be exceptions to these suggestions but I think this is a good goal to have. What do you think?&lt;/p&gt;</description></item><item><title>Getting control of a codebase</title><link>https://blog-dev.funkysi1701.com/posts/2016/getting-control-of-a-codebase/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Thu, 17 Nov 2016 20:00:45 +0000</pubDate><guid>https://blog-dev.funkysi1701.com/posts/2016/getting-control-of-a-codebase/</guid><category term="JavaScript">JavaScript</category><category term="AzureDevOps">AzureDevOps</category><category term="SQL">SQL</category><category term="VisualStudio">VisualStudio</category><category term="C-Sharp">C-Sharp</category><description>&lt;p&gt;So recently I started working on a new codebase. I will be honest when I first saw it, it was a mess. Here are a few of the things I did to try and regain control.&lt;/p&gt;
&lt;p&gt;I was given access to the source code on Visual Studio Team Services. However this consisted of a single commit 3 months ago. When I looked at what was running on the production server it was clear that changes were being made live with no regard for source control.&lt;/p&gt;
&lt;p&gt;The first thing I did was commit everything that was running live into source control.&lt;/p&gt;
&lt;p&gt;Next I created a SQL Server Data Tools (SSDT) project to keep track of all the database objects. Previously there was a folder with some stored procedures in it, but these did not match with what was currently running.&lt;/p&gt;
&lt;p&gt;
&lt;img class="img-fluid" alt="SQL Server 2012 Management Studio Splash Screen" src="https://blog-dev.funkysi1701.com/images/2016/sql-server-2012-management-studio-splash-screen.png" loading="lazy"
width="529" height="360"
/&gt;
&lt;/p&gt;
&lt;p&gt;I now had in source control the current state of the website and the database, so I knew I could get things back to this state if I made some bad changes.&lt;/p&gt;
&lt;p&gt;Lets start by looking at the website code I had. There was no solution file, the only way to look at the website was to setup my local IIS to run what was in the website folder. I could then use Visual Studio to &amp;ldquo;open&amp;rdquo; my local IIS website and attach to process to debug it.&lt;/p&gt;
&lt;p&gt;Next I Looked at Default.aspx to see how the website worked. The majority of the website code was stored in the database stored procedures. After the tag there was a &amp;lt;% %&amp;gt; which contained a Response.Write(RunSP.RunStoredProcedure(Parameter1, Parameter2, &amp;hellip;) command, which executed a stored procedure and the results of the stored procedure was the html code including any javascript that the webpage needed to display. I will be honest I have never seen any code like it. My guess is that the developer was secretly a DBA and wanted to make any web page changes by just changing how the stored procedures work.&lt;/p&gt;
&lt;p&gt;This meant that the website is not going to do anything without a backup of the database running, and meant my SSDT project was going to be vital. However the database was in a bad state, it consisted of a fair few broken objects and SSDT would not build.&lt;/p&gt;
&lt;p&gt;Using find I went through each of the broken database objects to find where in the code they were being used. Luckily most were referenced in commented out code, so I just removed all the broken database objects. The database could now be built. However there was a dependency on the users table of another database. (This was the developers solution to sharing logins between websites) As I was using SSDT I added a database dependency, problem solved for now.&lt;/p&gt;
&lt;p&gt;Next I tried publishing my database. SQL CMD encountered a parsing error. The reason for this was my SPs contained javascript eg $(document), SQL CMD uses $(DatabaseName) as variables for different database so it was getting itself confused.&lt;/p&gt;
&lt;p&gt;My solution was to use Find and Replace to replace all the $ with &amp;rsquo; + CHAR(36) + '&lt;/p&gt;
&lt;p&gt;So I now have a SSDT project that builds and publishes but still no website project.&lt;/p&gt;
&lt;p&gt;To get the website running from Visual Studio I started off creating a .Net 4 website project and added Entity Framework 5 and MVC 3 via nuget. I then copied all the website code into the new project, and with a bit of work I got it to build. Most of the work was relating to namespaces and referencing the correct one and moving the EF model from AppCode to a custom named folder. A bit of trial and error later I had a version of the website that could be run from Visual Studio.&lt;/p&gt;
&lt;p&gt;I have not deployed my new version of the website as it needs further testing. No automated testing or even a smoke test checklist currently exist.&lt;/p&gt;
&lt;p&gt;
&lt;img class="img-fluid" alt="Visual Studio Team Services build pipeline for source code commits" src="https://blog-dev.funkysi1701.com/images/2016/Visual-Studio-Team-Services.png" loading="lazy"
width="960" height="434"
/&gt;
&lt;/p&gt;
&lt;p&gt;As my source code is hosted on Visual Studio Team Services (VSTS), I can get VSTS to build each commit and check I haven’t broken the build. This is not that helpful at the moment, hopefully one day I will have automated tests that can be run here as well.&lt;/p&gt;
&lt;p&gt;Wow, I feel like I have done loads with this code so far but there is loads more still to do. I need to understand more about the business processes behind the code with a hope to understand why some architectural decisions have been made. I want to refactor the code as much as is possible, I would like to remove much of the html/javascript from the stored procedures as I can’t see that there is any advantage to running a website like this. Please correct my if I am wrong.&lt;/p&gt;</description></item></channel></rss>