Rob Bittner's Programming blog. I'm not sure how this is going to evolve, but I'm going to make every effort to keep it rolling..
Friday, August 17, 2012
EXIF Extraction
I figured that it's bound to have come up before and lo and behold I found many a library. Most did pretty much what I wanted, but this is for a web app and every single library left a lock on the file after it was done executing. I guess I could have restarted the app pool after every page load, but that seemed a bit excessive.
I poked around MSDN and saw that it wasn't that difficult to read it by myself.
So, I wrote my own chunk of code:
b = new System.Drawing.Bitmap(fileInfo.FullName)
Dim encoding As New System.Text.ASCIIEncoding()
for each pi in b.PropertyItems
if pi.ID = 40091 then ' I only need the title
description = System.Text.Encoding.Unicode.GetString(pi.value)
exit for
end if
Next
and viola, EXIF data.
Sidebar here: I am a c# guy. I cannot stand using vb. but, DotNetNuke is written in vb so, I don't have much of a choice (I'm not rolling a new class for 15 lines of code)
But, with the EXIF data came the aforementioned file lock.
Back to MSDN to poke around at the Image Class. Skip down a bit and lookie lookie it implements IDisposible. Oh boy, is it really this easy?
yes, in fact it is.
using b = new System.Drawing.Bitmap(fileInfo.FullName)
Dim encoding As New System.Text.ASCIIEncoding()
for each pi in b.PropertyItems
if pi.ID = 40091 then
description = System.Text.Encoding.Unicode.GetString(pi.value)
exit for
end if
Next
End Using
Game, set, match.
Friday, January 27, 2012
Integrate Resharper Unit Test Runner after a successful build
I scraped together a few snippets from teh interwebs and came up with the following to be added to the VS Macros: Pop open the Macros IDE (Tools - Macros - Macros IDE) and in the Project Explorer choose the Environment Events Module. Then Add the following code:
Private SolutionBuildSuccess As Boolean
Private Sub BuildEvents_OnBuildBegin( _
ByVal Scope As vsBuildScope, _
ByVal Action As vsBuildAction _
) Handles BuildEvents.OnBuildBegin
SolutionBuildSuccess = True
End Sub
Private Sub BuildEvents_OnBuildProjConfigDone( _
ByVal Project As String, _
ByVal ProjectConfig As String, _
ByVal Platform As String, _
ByVal SolutionConfig As String, _
ByVal Success As Boolean _
) Handles BuildEvents.OnBuildProjConfigDone
If Success = False Then
SolutionBuildSuccess = False
End If
End Sub
Private Sub BuildEvents_OnBuildDone( _
ByVal Scope As EnvDTE.vsBuildScope, _
ByVal Action As EnvDTE.vsBuildAction _
) Handles BuildEvents.OnBuildDone
If SolutionBuildSuccess Then
Dim win As Window
win = DTE.ActiveWindow
DTE.ExecuteCommand("ReSharper.ReSharper_UnitTest_RunSolution")
win.Activate()
End If
End Sub
Going through each of these:
SolutionBuildSuccess: This is just a boolean that will be true if every project builds. No sense in even running tests if you can't even compile
BuildEvent_OnBuildBegin: This just resets the SolutionBuildSuccess at the begin of each build
BuildEvents_OnProjConfigDone: So, there are 2 events when a build finishes. One fires when the complete build process is done (OnBuildDone). This one, however, does not carry the result of the project build(s). So, there is OnProjConfigDone which fires for each project that builds and has the result. This will just set the SolutionBuildSuccess to false if any of the projects fail to build.
BuildEvents_OnBuildDone: This one fires when the build is all done. So, I need to check to see if all the projects built successfully. Then I save the currently active window. Finally we run the tests and make that previously saved active window active again. The reason for that is that after I'm done building and running the tests, generally I'm ready to code more. So, instead of remembering that I have to smash ctrl-tab (I think) to jump back, I took the lazy approach and put it into the step.
Now, I remember back in the old days when F6 was the command to build stuff. I'm not sure what one of my tomfooleries changed it, but it did. So, I re-assigned it back to being my keyboard shortcut for build.
Any Comments or suggestions will probably be ignored, but feel free to leave them anyway..
Thursday, September 23, 2010
Invalid URI scheme 'file://' for map control. Control must be hosted in a HTTP(s) website.
But... I'm not using file:// for my map control.
So, I'm programming with ESRI's Silverlight Map control. This started out as a test project, but it's become more of a production application. Instead of moving all my code to a new project, I'll just rename it from SilverlightApplication1 to MyProdcutionApplication.
I rename all the namespaces, remembering to rename the corresponding XAML references that don't get refactored. Then I rename the projects themselves and have to organize the folders.
So, I remove all the projects from the solution, rename the folders, and add them back in. I hit compile and woohoo, no errors. So, I go to run it and I get the following gem:
I recheck my map references and sure enough, I <am> using http://path/to/my/rest/endpoint ... so.. off to google.
After a 20 minute search trying all variations of the error, I finally stumble upon this thread in the ESRI forums. Back in 2009, Don Freeman got the same error and lo and behold, it was because the default start project was the Silverlight Application, not the Test Website.
I flipped my startup project to the test web app and poof... all is well
Thursday, November 12, 2009
Custom LINQ orderby expression
LINQ expressions are so slick that I don't know how I lived without them for so long. I had a little issue with a custom orderby, however, and found a pretty neat solution.
Here's the objects:
Festival{ String FestivalName, IEnumerable Events ...}
Event { String Type, DateTime Date ...}
A festival has many different Events: Start, Finish, Performances, etc. I want a list of festivals in order according to the start date. I was going to expose a specific property in Festival that returned the date of the Start event if it existed, but I wanted to generalize it. I knew about FirstOrDefault and came up with the following:
List Festival=
(from d in FestivalList
orderby s.Events.FirstOrDefault(q => q.Type=="Start").Date
select d)
I ended up getting a NullReferenceException because not all festivals were properly entered and some didn't have Start events. I decided that these should show up first. So I had to use a different approach with the orderby by using another inline LINQ query.
List Festival=
(from d in FestivalList
orderby
(from e in s.Events
where e.Type == "Start"
select e
).DefaultIfEmpty(new Event()).First().Date
select d)
The DefaultIfEmpty specifies how we should handle when there isn't an Event. In this case, I'm returning an empty event which will return DateTime.MinValue (This is part of the Event.Date definition). Slicker than snot.