Wednesday, April 22, 2015

Chrome Debugger, setting breakpoints in angularjs


So, If you are like me and you live with the debugger, even in JQuery, Amglar is going to throw you for aloop... because chrome's debuggers breakpoints dont' work..

And you you get the BAtarang tool for "debugging" angular... it's aparent pretty quickly, that i'ts not debugging in a debugger, but something else entlirely...

I'ts like going back to the 1990s when Programemrs would decalre pridefuly "only bad programemrs need to use a debugger"

Fortunately there is a way to get a break point.. stepping through code is harder but if you drop the keyword 'debugger;' into you code, it will force a break point when that anglyuar function is called.

 $scope.SaveScript = function () {
        debugger;// it will break here
        if (($scope.selectedLanguage == -1) || ($scope.selectedCallscript == -1)) {
            return;
        } else {
            var ckData = CKEDITOR.instances.CkEditorId.getData();
            var dataToSend = TestService1.BuildSaveScriptCV(ckData, $scope.selectedLanguage, $scope.selectedCallscript, "test tile");
            var linkUrl = 'http://localhost/Scout3G/Maintenance/SaveScript';
            //var linkUrl = '@Url.Action("SaveScript","Maintenance")';
            TestService1.JcdcAjaxDoPostRetrieveJson1(linkUrl, $scope.DisplaySavedScript, dataToSend);
        }
    };

it's not beautiful, but at least you can tell if a function is gettign called without resoritng to cave man debugging with Alerts.

useful links in debuging angluarjs
http://24days.in/umbraco/2014/debugging-angularjs/
http://ng-inspector.org/
http://stackoverflow.com/questions/18782069/how-to-debug-angular-javascript-code
https://chrome.google.com/webstore/detail/angularjs-batarang-stable/niopocochgahfkiccpjmmpchncjoapek?hl=en-US
http://odetocode.com/blogs/scott/archive/2014/07/29/debugging-angularjs-in-the-console.aspx

Thursday, April 16, 2015

VS2013 MVC4 project as soon as you add json.net package you cant' compile

 As soon as you add the Json>net package in nut get on a new blank mvc 4 applicaiton project, you get this

Server Error in '/' Application.

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

Line 17:             AreaRegistration.RegisterAllAreas();
Line 18: 
Line 19:             WebApiConfig.Register(GlobalConfiguration.Configuration);
Line 20:             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
Line 21:             RouteConfig.RegisterRoutes(RouteTable.Routes);

Source File: c:\Users\Brown.ericw\Documents\Visual Studio 2013\Projects\AngularTest4\AngularTest4\Global.asax.cs    Line: 19 




This is the fix

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-5.0.8.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

The key is that the version on the package is 6.0.8 and you think that's what you are supposed to use , but nope, it 6.0.0.0

Friday, February 20, 2015

TFS Tricks to remember



A few things I learned about TFS painfully this week.


1. TFS in VS2013 logs to the output window, it logs important things that you'd expect it to popup in warning dialogs, so watch the window.


2. TFS will not do a get latest if the files have pending adds... It just skips them and logs it in the output window.


3. To force a get all, you have to go to the get specific version and check both the check boxes, get selected version is not available in the obvious way, you have to dig for it


Go to Source control window,
Click on rot folder (i.e. solution folder) you want to do the get from
Right click,
Choose Get Specific Version
Check both overwrite check boxes


This is the equivalent of a get with force all in StarTeam.

Wednesday, December 17, 2014

Remote Debugging....SP3G StudentPortal3G



If you are going to do remote debugging on SP3G, you have to be on the QA or Prod domain,
our security prevents... and if you are going to do that, you'd better get a clone of the QA/prod server created, and then you can just install what you need and debug directly without remoting at all


install


vs2010
vs2010 sp1
mvc 2
mvc 3
mvc 4


then just debug it.



Friday, December 12, 2014

Distance Between 2 cities, using Google Distance Matrix, in c#



public Double GetDistanceInMilesBetweenTwoCities( string city1, string city2 )
{


////Pass request to google api with origin and destination details(Map Coords)


HttpWebRequest request =

( HttpWebRequest )WebRequest.Create( "http://maps.googleapis.com/maps/api/distancematrix/json?origins="


+ city1 + "&destinations=" + city2 + "&mode=Car&language=us-en&sensor=false" );

HttpWebResponse response = ( HttpWebResponse )request.GetResponse();

using ( var streamReader = new StreamReader( response.GetResponseStream() ) )






{


var json = streamReader.ReadToEnd();

if ( !string.IsNullOrEmpty( json ) )






{


//Uses the NewtonSoft Json library that is shipped in vs 2013, the .N3.5 version to match this service. (thank you stack overflow!) - EWB


Parent parent = JsonConvert.DeserializeObject<Parent>( json );

if ( parent.rows[ 0 ].elements[ 0 ].status.ToUpper() != "OK" )






{


throw new Exception("Invalid City Name please try again");






}


Double distInKM = parent.rows[ 0 ].elements[ 0 ].distance.value;

return DistanceCoversion.ConvertMetersToMiles( distInKM );






}


}


return -1;






}





public class DistanceCoversion





{

<snip>












public static Double ConvertMetersToMiles( Double meters )






{


//


// Multiply by this constant.


//


return (meters/1000) * 0.621371192;






}


}


Friday, August 29, 2014

Adding a VSPackage to your visual Studio..





It was surprisingly hard to find this on the web, so here it is for posterity.




Once you've built your vs package, go to the bin folder


there you will see a *.visx file, double click it.


It's automatically added to VS (you need to restart VS)


To remove it click tools->Extensions and updates and look for VSPackage<yourpackagename> and uninstall it.

Wednesday, July 30, 2014

Updating package wtih nuget, installs fine, the reference is there, but when you compile, it says it's not there?



At work today, we had updated all out NuGet packages for our internal libraries.


I applied them to one of my solutions, a ton of projects...


most of them were fine... but for some of them, even though I could see the reference,
when I compiled it, it said the reference wasn't there.


Intelligence saw it, and my using statements were not RED..


WTF!


The answer of course is, assumptions...


Turns out, that the project in questions was referencing .Net4.0, and the Package referenced 4.5


there was even a yellow warning about it in my output window after the compile...
but who looks at those!(DOH)


I hope this saves someone else the pain...