Skip to main content

Posts

Working with Git and Git-Flow on Windows

To install Git-Flow on Windows Download the "Binaries Zip" file (util-linux-ng-2.14.1-bin.zip) from http://gnuwin32.sourceforge.net/packages/util-linux-ng.htm Extract util-linux-ng-2.14.1-bin.zip\bin\getopt.exe to "C:\Program Files (x86)\Git\bin" Download the "Dependencies Zip" file (util-linux-ng-2.14.1-dep.zip) from http://gnuwin32.sourceforge.net/packages/util-linux-ng.htm Extract util-linux-ng-2.14.1-dep.zip\bin\libintl3.dll to "C:\Program Files (x86)\Git\bin" Run "git clone --recursive git://github.com/nvie/gitflow.git" cd into gitflow/contrib/ Run msysgit-install.cmd "C:\Program Files (x86)\Git" Run "git flow" in a cmd window to make sure it worked (adapted from http://xinyustudio.wordpress.com/2012/03/26/installing-git-flow-in-windows/ ) Git Configuration After installing Git, set up the configuration: C:\> git config --global user.name "Your Name" C:\> git config --glo...

Running PowerShell commands from Linux

There are several options for running PowerShell commands from Linux. Run the PowerShell script over a REST interface Unless you need a remote shell, the easiest option is to set up a REST interface for your PowerShell scripts. More information here . Using the winrm Ruby Gem https://github.com/WinRb/WinRM Using a WS-Management client on Linux Set up Windows for remote access: https://github.com/Openwsman/openwsman/wiki/winrm-over-openwsman-setup Install OpenWSMAN on Linux: http://openwsman.github.io/ Use Openwsman Command-Line Client: https://github.com/Openwsman/openwsman/wiki/openwsman-command-line-client OR - Use Ruby client bindings: http://users.suse.com/~kkaempf/openwsman/ Install an SSH server on Windows Install a Salt Minion on Windows Install Salt Master on Linux Install Python on Windows Install Salt Minion on Windows Open firewall on Windows for Salt access On Linux, run: # salt "winServer" cmd.run "powersh...

How to log C# exception information including all inner exceptions

/// /// Logs a type and message for and exception (and all inner exceptions) on multiple log lines. /// Lines all contain a unique ID so they can be found if other lines get between them. /// /// Method name, or whatever you want. /// Custom message for the first log line /// Exception to log public static void LogException(string tag, string message, Exception ex) { string logItemId = Guid.NewGuid().ToString("N"); Log(tag, false, logItemId + " " + message); Log(tag, false, logItemId + " Exception: " + ex.GetType().Name + ": " + ex.Message); Exception Inner = ex.InnerException; int innerNumber = 1; while( Inner != null ) { Log(tag, false, logItemId + " Inner Exception " + innerNumber + " " + Inner.GetType().Name + ": " + Inner.Message); Inner = Inner.InnerException; innerNumber++; } }

Parse and organize command line options using C#

This class will parse, organize and collect command line options. I couldn't find anything like it, so I wrote one. This works all the way down to .NET 1.1 if you are lucky enough to still be using that. Save this as ArgDictionary.cs, change the namespace as needed, and feel free to use it in your projects. using System; using System.Collections.Generic; namespace Utilities { /// /// Implements a Dictionary object for handling command line options. /// Supports options with prefixes -, --, or /. /// Supports Boolean, String, or Int32 option values. /// String options are in the following format: /// /stringOption value /// Int32 options are in the following format: /// /intOption 200 /// Boolean options are in the following format: /// /boolOption /// NOTE: if the Boolean option is present in the command line, it is true. /// /// Supports both a long and short version for each option (e.g. /a and /Account /// can be mapped to the same value). /// NOTE: When ...

How to make an HTTP request with PowerShell

If you are making an HTTP request to a RESTful web service, you can use the PowerShell  Invoke-RestMethod cmdlet. This provides a very simple HTTP REST interface, and will also format the result into a PowerShell object. If you would like to use your own functions, you can follow the instructions below. This is a helper function to format (indent) an XML response from a web service. function Format-XML { Param ([string]$xml) $out = New-Object System.IO.StringWriter $Doc=New-Object system.xml.xmlDataDocument $doc.LoadXml($xml) $writer=New-Object system.xml.xmltextwriter($out) $writer.Formatting = [System.xml.formatting]::Indented $doc.WriteContentTo($writer) $writer.Flush() $out.flush() Write-Output $out.ToString() } Here is the function to make the http call. It dumps the response data on the terminal and also returns it as a string to the caller. If there is an error it will dump the HTTP status code and comment on the terminal and return the re...

How to delete a file in C# that might be in use

int retries = 5; while (retries-- >= 0) { try { retries = -1; System.IO.File.Delete(@"C:\deleteme.txt"); } catch (System.IO.IOException ex) // "The specified file is in use." { // File is locked? Sleep and try again. System.Threading.Thread.Sleep(100); // Wait 100ms if (retries >= 0) continue; // go back to while loop throw ex; // give up } } This will also work for writing to a file, etc. This should be enclosed in a try/catch block to catch the other exceptions thrown by the System.IO.File.Delete method.