Skip to main content

Posts

Containers and Docker

Containers and Docker Docker is an app (open source, Docker Inc is a company). Docker and Containers are not the same, Docker provides a more usable way to manage Containers, without Docker it is very difficult but it can be done. Docker is not the only Container management software but it is the most popular. Docker reads Docker files. The Docker files contain instructions on how to run Containers. An Image is the signature of the Container, the Container is the instance/running image. Containers are applications. These applications need somewhere to run, they run in an Operating System provided by the Cloud of your choice e.g. Azure or AWS. Containers can contain any applications and Containers can run other Containers. You can build up complex Containers using other Containers. Containers are lightweight and start up very fast, quicker than VMs as they do not have their own OS. DockerHub is a store where you can get other Containers. Docker Containers are St...

Linq everything you need to know

  Linq Links ·          Refactor foreach to Linq https://jasonneylon.wordpress.com/2010/02/23/refactoring-to-linq-part-1-death-to-the-foreach/ ·          Linq tutorial https://app.pluralsight.com/library/courses/linq-fundamentals/table-of-contents ·          Linq cheat sheet to print http://nickberardi.com/linq-cheat-sheet/ ·          Linq Immediate and Deferred execution (intermediate) http://www.dotnetcurry.com/linq/750/deferred-vs-immediate-query-execution-linq ·          Deep Dive (advanced) https://www.simple-talk.com/dotnet/net-framework/giving-clarity-to-linq-queries-by-extending-expressions/ ·          Linq operators https://www.tutorialspoint.com/linq/linq_query_operators.htm ·       ...

Design Patterns - Abstract Factory Pattern

What? A more special and complex version of the Factory Pattern. The additional complexity is that the not only does the client now know the actual object being created but also does not know the Factory which is creating the object i.e. the Factory now also configurable. Why? Used in Dependency Injection. The pattern does not have the actual types that it needs to create but might have some way to create them based on information passed to it like the type name. How? In .NET reflection can be used to create instances using type names as strings see Activator.CreateInstance. http://stackoverflow.com/questions/2280170/why-do-we-need-abstract-factory-design-pattern

Encryption and Decryption in .NET

You want to scramble data on the server side before it's saved and also want to retrieve it later and unscramble it. Encryption and Decryption is what you want. There are 2 types, Symmetric and Asymmetric. Symmetric uses 1 key (private) and this same key is used to encrypt and decrypt. Asymmetric uses 2 keys, 1 for encryption (public) and 1 for decryption (private) So at least a key is required in all cases. This needs to be stored somewhere. Seems that hardcoded in code or in a config file seems to be the preference. When storing the key in the web.config ensure that the section is encrypted itself so that it's not human readable  http://msdn.microsoft.com/en-us/library/zhhddkxy(v=vs.100).aspx . .NET has a bunch of classes which can be do the actual work, see the System.Security.Cryptography namespace. See the SymmetricAlgorithm and the AsymmetricAlgorithm classes. Use the (SymmetricAlgorithm)CryptoConfig.CreateFromName(provider)) and get the provider form the w...

Closures in C#

Tricky topic to understand, this  is is the simplest explanation I've found. What? A Closure is a function which can be passed around like an object but it also can maintain state in it's local variables. Why? Useful in asynchronous calls where you want something to happen when the task ends, the local variables can be used to store something that should be included in the work that needs to be done when the task completes. Particularly useful in Javascript.

Debugging Windows Exceptions with Adplus V7

A tool called Adplus can be used on Windows to get more information on unexpected exceptions, hangs and crashes. If one of these has been reported on a production machine then run Adplus in the background, monitoring that process, and check from dump files afterwards. The dump files should include information on that happened just before the exception, crash or hang. The dump files can be opened in Visual Studio or Windbg for example and ran as a debugging session. There is a new version of Adplus available, Adplus V7 , it's an exe where the old was a vbs. Adplus comes with the "Debugging Tools for Windows", google this to find the latest version. First stop http://www.codeproject.com/Articles/315536/Adplus-Handling-managed-exceptions To get a dump on an exe use the -sc switch with adplus (ensure this is the last switch on the command line) and point it to the full path of the exe. If adplus is working it will launch the exe in a separate window, if not then it...

Immutable Objects

Immutable means "can not change". When an object is referred to as Immutable it means the internals cannot be changed i.e. it's member variables. This is a design choice, where you might wish objects to be passed around as method arguments but you do not want the original object's internal values to change. Remember that in C# when you pass an object of type Reference Type into a method as an argument, you are actually passing it by reference, meaning the method can change the original objects values. To protect objects  from this make them immutable. How: Objects are made immutable by simply making their internal variable readonly.

Dependency Injection IoC

"Dependancy Injection" is a more specific name for and term used "Inversion of Control". It's all about letting client developers of your code add there own implementations. To do this your code needs to be very loosly coupled (i.e. none of the usual newing up of concrete classes, the code must be written using Interfaces for example) and configurable (e.g. the client developer drops their implementation dll into a location and adds content to a XML configuration file to tell your host app what class to load and instantiate from the dll). This is a good intro to "Dependancy Injection"  http://www.martinfowler.com/articles/injection.html These are intros to Microsofts "Dependancy Injection" framework, Unity. https://www106.livemeeting.com/cc/wwe_us/view?cn=guest&id=1032382093&pw=23D44136  with sourcecode at  http://unity.codeplex.com/wikipage?title=Webcast%20demos&referringTitle=Home http://visualstudiomagazine.com/ar...

XML file for Visual Studio HelpViewer 1.0

The following XML file is used in combination with the XSLT file posted in an earlier post. These 2 files transform into HMTL that views correctly in Visual Studio 2010 HelpViewer 1.0. <? xml   version = " 1.0 "   encoding = " iso-8859-1 " ?> <? xml-stylesheet   type="text/xsl" href="../xslt/gravity.xslt" ?> < HelpDocument >   < Meta >     < title > Add </ title >     < metaTitle > Add </ metaTitle >     < metaID > Help3-7F3D2D9D-Add </ metaID >     < metaParent > Help3-7F3D2D9D-Entity </ metaParent >          < metaKeywords >       < metaKeyword >         < keyword > Add </ keyword >       </ metaKeyword >   ...

XSL XSLT file for Visual Studio HelpViewer 1.0

This XSL/XSLT file is based on a Visual Studio Help file found in "C:\ProgramData\Microsoft\HelpLibrary\content\Microsoft\store\Development_Frameworks_21823146_VS_100_en-us_9.msha" I've stripped out the content and replaced with  < xsl:if   gt; etc. The values for this content are taken from XML files which have the corresponding XML element hierachy, e.g

XML to HTML

To convert XML to HTML you need an XSL (XSLT) file and some application to transform the XML to HTML using this XSL file. Usually this work is done by the browser, by including a link to the XSL file in the XML file, when you open the file in a browser it runs the transform on the XML using the XSL file you've pointed to. But I wanted to run this as a seperate step from a batch file so that I can create my .html files on disk but maintain their content using XML. Here's how I've done it: using   System ; using   System . Collections . Generic ; using   System . Linq ; using   System . Text ; using   System . Xml . Xsl ; using   System . IO ; namespace   Tool . XMLToHTML {      class   Program     {          ///   <summary>          ///  "Help\Help3\_HelpSource\gravity.xslt" "Help\Help3\_HelpSource"...