Tuesday, November 24, 2015

"Source control provider could not be initialized" in Dexterity

In Dexterity I open Options > Source Control > and change the Provider = Team Foundation Server 2010. I point the RootDirectory to the local folder I pulled down from TFS. Then i click Projects and get the error "Source control provider could not be initialized"

1. Windows 10
2. Visual Studio 2015
3. GP2015R2
4. Dex 14.00.84

1. Made sure security was set to Everyone on the RootDirectory
2. Turned off Firewall
3. Ran as administrator
4. Double-checked that Team Explorer 2010 was installed

After double-checking all of this stuff I still had the error. Eventually I ran Process Monitor on a computer where it was working and the new computer where it wasn't working, filtered for Process Name = Dex.exe, then got Dex to a point where I could just click on "Projects" in source control and clicked it. 

The first line in Process Monitor where it differentiates is when it tries to load this file:
C:\Users\<USER>\AppData\Local\Microsoft\Team Foundation\3.0\Cache\7553ef4f-f18b-4db8-b064-7a31ae2040f9\LocationServiceData.config

I looked on the new computer that's not working and checked folder C:\Users\<USER>\AppData\Local\Microsoft\Team Foundation\3.0\Cache\
and noticed that it was empty. 

So I tried copying the data from the working computer to the new computer. The two computers have the same folder structure, and they're using the same source control, so I figured why not? Well, IT WORKED!

Subsequent error
After copying the Cache folder from a working environment, it made Dex's source control work. However, when trying to do a lock/checkout on a file it's crashing Dex with a vague error that says
Faulting application name: Dex.exe, version:, time stamp: 0x55510397
Faulting module name: KERNELBASE.dll, version: 10.0.10240.16384, time stamp:

1. Install VS2010
2. Install VS2010 SP1
3. Cut&Paste files from C:\Users\<USER>\AppData\Local\Microsoft\Team Foundation\3.0\Cache\ into a folder, just in case
4. Open VS2010
5. Connect to TFS
6. Pull down the Dex root folder. This populates the Cache folder with valid files.
7. Open Dexterity, set the source control, do a Lock on a file to make sure it's working

Sunday, November 15, 2015

JSON web request using Python

Get the requests module
If you don't already have the requests module, follow these steps:
1. Download the requests module ZIP. Here's a direct link to the ZIP: https://github.com/kennethreitz/requests/archive/master.zip

2. Unzip

3. Copy and paste the "requests" folder to C:\<python installation folder>\Lib\
Note: I'm using python 2.6, and my installation folder is C:\Python26

Source: https://www.youtube.com/watch?v=Ng5T18HyA-Q 

The explanation of what it's doing
#I'm using the Yahoo API to request the USD:EUR exchange rate
#It's passing back json format
#so i'm using a json decoder from the requests object
#then i'm navigating the dictionary of dictionaries to get to the exchange rate
#Note: There's no error handling or anything, this is just to show a simple example of how to do a web request in python

The Code
import json import requests #Get exchange rates req = requests.get('http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDEUR")&format=json&env=store://datatables.org/alltableswithkeys') res = req.json() exchangeRate = float(res["query"]["results"]["rate"]["Rate"]) #Get euros euros = float(raw_input("How many euros?")) #Convert USD = (euros * exchangeRate) #Output print """ Exchange rate: {0} Euros: {1} USD: {2} """.format(exchangeRate, euros, USD)

Sunday, October 25, 2015

Minimizing the distance between class property declaration and initialization in auto-backed properties

In C# you can do:
public class Foo1
    public string Bar {get; set;}

The compiler automatically creates the backing field for the Bar property.
Before this auto-backing syntax sugar you would do this:

public class Foo2
private string bar = "";
public string Bar
   get {return bar;}
   set {bar = value;}

Ouch, my fingers hurt from all that extra typing.

This is some nice syntax sugar. However, there's a problem with it. When I heard about this feature and started using it, I incorrectly assumed that the backing field would be initialized to something. Nope! So Foo1 != Foo2. To make Foo1 be equivalent to Foo2 you'd have to initialize bar in the constructor.
public class Foo1Again
    public string Bar {get; set;}
    public Foo1Again()
        Bar = "";

The problem with this is you might be used to typing the backing field, and incorrectly assume that it's initialized for you. That's when Null Reference exceptions start happening. So if you decide to use auto-backed properties, you need to remember to init in the constructor. Ouch... I'd rather stick with typing out the backing field myself, so I don't randomly forget to initialize the field.

However, in C#6 they solved this, and you can now initialize the property inline with the declaration!!
See this: http://stackoverflow.com/a/169872/1538717

public class FooCharp6
    public string Foo {get;} = "";


Friday, October 23, 2015

PInvoke for finding all MSI locations of installers with a specific UpgradeCode

class Program { /* References http://www.pinvoke.net/default.aspx/msi/MsiEnumRelatedProducts.html http://stackoverflow.com/questions/3475793/how-to-find-program-location-in-registry-if-i-know-msi-guid */ static void Main(string[] args) { string upgradeCode = "{CC6ED12E-5384-4C17-A293-D6D19371A5E8}"; StringBuilder sbProductCode = new StringBuilder(39); int iIndex = 0; while (0 == MsiEnumRelatedProducts(upgradeCode, 0, iIndex++, sbProductCode)) { Int32 len = 512; StringBuilder builder = new StringBuilder(len); MsiGetProductInfo(sbProductCode.ToString(), "LocalPackage", builder, ref len); Console.WriteLine(builder.ToString()); } Console.ReadLine(); } [DllImport("msi.dll", CharSet = CharSet.Unicode)] static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len); [DllImport("msi.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern UInt32 MsiEnumRelatedProducts(string strUpgradeCode, int reserved, int iIndex, StringBuilder sbProductCode); }

Pinvoke.net references

PInvoke reference site: pinvoke.net

PInvoke Visual Studio Extension: https://visualstudiogallery.msdn.microsoft.com/9CA9D544-05D2-487B-AB49-31851483C1CC

Thursday, October 22, 2015

Paste stopped working in an RDP session

Do these steps on BOTH your computer and the computer you're RDPing to
     1. Open Task Manager
     2. Click Processes
     3. Find rdpclip.exe > right-click > End Process (this might not be running)
     4. Start > Run > rdpclip.exe


Sunday, October 4, 2015

Playing Starcraft on Windows 7

Fix the colors
1. Create a batch file
2. Put this in it
taskkill /f /IM explorer.exe


3. Execute the batch file anytime you want to play.

note: Without explorer open you can still alt-tab between programs. So i recommend opening a cmd prompt + a web browser in case you need to look something in while having Starcraft open

The latency of the game creator is too high1. Open your router configuration page.
2. Find Port Forwarding (this could be called Applications and Gaming as well) - it will depend on your router model
3. Add port range 6112-6119 TCP and UDP

Monday, September 28, 2015

TestClass could not be found -- or -- cannot find Microsoft.VisualStudio.TestTools.UnitTesting

Severity Code Description Project File Line
Error CS0246 The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?)

And other errors having to do with not being able to find things in the Microsoft.VisualStudio.TestTools.UnitTesting namespace.

This started happening to me after I upgraded from VS2013 to VS2015 Community.

To troubleshoot, I created a new unit test project to see what reference that would have. It has a reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll, which is located here:

1. Remove the current reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
2. Add reference to <driveletter>:\VisualStudioCommunity\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

Sunday, September 27, 2015

Maintaining syntax coloring when pasting code on blogger

What code looks like when it doesn't maintain syntax coloring on blogger:
    private static void removeChildrenOfEmptyParents() {
        for (String parent : reverseIndex.keySet()) {
            if (map.containsKey((parent))) {
                for (String child : reverseIndex.get(parent)) {

When it looks like with syntax coloring:
private static void removeChildrenOfEmptyParents() { for (String parent : reverseIndex.keySet()) { if (map.containsKey((parent))) { for (String child : reverseIndex.get(parent)) { map.remove(child); } } } }

1. Get Notepad++ (NPP): https://notepad-plus-plus.org/download/v6.8.3.html
2. Paste code into NPP, or open the source file
3. Set the appropriate language in the Language menu
4. Plugins > NppExport > Export to HTML
5. Open the HTML file in a browser
6. Copy and paste into blogger

Reference: http://superuser.com/a/578059 

IronPython: creating a GUI in Visual Studio

#Here's how you create a window with IronPython in Visual Studio

import sys import clr clr.AddReference("System.Drawing") clr.AddReference("System.Windows.Forms") from System.Drawing import Point from System.Windows.Forms import Application, Button, Form, Label, TextBox class MacsTest(Form): def __init__(self): self.Text = "GUI Tutorial" self.Height, self.Width = 250, 250 self.label = Label(); self.label.Text = "Hello"; self.label.Location = Point(50, 50) self.label.AutoSize = True self.textbox = TextBox() self.textbox.Width,self.textbox.Height = 100, 50; self.textbox.Location = Point(100, 50) self.textbox.KeyUp += self.handleKeyPress self.lblCharCounts = Label(); self.lblCharCounts.Text = "No chars"; self.lblCharCounts.Location = Point(50, 100) self.lblCharCounts.AutoSize = True self.Controls.Add(self.label) self.Controls.Add(self.textbox) self.Controls.Add(self.lblCharCounts) def handleKeyPress(self, sender, args): self.lblCharCounts.Text = "{0} chars".format(len(self.textbox.Text)) Application.EnableVisualStyles() Application.SetCompatibleTextRenderingDefault(False) form = MacsTest() Application.Run(form)

#Reference: http://www.voidspace.org.uk/ironpython/winforms/index.shtml

Python: string formatting

input = raw_input("What's the word? ") length = len(input); #named arguments print "{input} has {length} chars".format(input=input, length=length) #positions print "{0} has {1} chars".format(input, length) #using function pointer output = "{0} has {1} chars".format print output(input, length)