Monday, December 19, 2011

How To: Local IIS Express using Different Host Name other that LocalHost

So, I don't like doing development on localhost. Just a pet peeve... until I found out that jquery hates it more. Trying to do ajax postbacks on a locally running service (at http://localhost:someport) failed.

In Visual Studio 2010you can set the project to use IIS Express but if you don't have "things" set right it will fail. (IIS Express doesn't, out of the box, listening to web requests for host headers other than localhost)

Create host name to point localhost to something more-fun-er by adding an alias to:

c:\windows\system32\drivers\etc\hosts

Add a line:
127.0.0.1 mylocal.dev

Then open

My Documents\IISExpress\config\applicationhost.config
Search for your Application name and change the listening settings for your app




Save the file. In Visual Studio change your project to point to the new host name:



now your app will run nicely in it's "new" home :)

Saturday, July 2, 2011

Windwos 2008 r2 Firwall Rules: Set all rule to be Domain, Private using powershell


I want to expose my server to the internet. Yes, I know, layered security, blah blah blah... (I really don't take security that flippantly but for this purpose...)

I am no Powershell Expert; not even really a user. I was searching high and low for how to use powershell to update all the default rules to be internal only (I even used Altavista; yes it is still around). The windows firewall GUI doesn't allow you to modify multiple rules at once, so I would have to sit there and go to the properties of each and update for only allowing the default rules on the two non-public profiles (Domain, Internal). YUCK! Thanks MS!

Ok, so with power shell (installed by default on windows 2008 r2) you can loop through each rule and update it.

Values to replace "#Number#" below

1 = Domain
2 = Private
3 = Domain, Private
4 = Public
5 = Domain, Public
6 = Private, Public
7 = All

Get the Nifty COM object (surprising they still make these...)
$fw = New-Object -ComObject HNetCfg.FwPolicy2

Now Loop... Powershell does allow for muliline commands so go ahead and add logic to only change the ones you want...
foreach($rule in $fw.Rules) {$rule.Profiles = #Number#}
Now this updates ALL (Disabled and Enabled) Rules in the firewall, if you are connected remotely, make sure you are connected through the appropriate interface and don't knock yourself off. (Cause that just bites)

Hope the robots find this as to help someone else... :)

Friday, December 31, 2010

Exporting Data from TopSpeed Data bases

Ugh, TopSpeed is a proprietary DB that has very limited tools that can access it. If you want to use it in an ODBC setup, you have to buy a $250 driver package! But once you do that it is still not an easy solution to get access to the data.

The easiest way I found to programatically access the data is to use MS access to pull the tps files as an external data source and then use .Net to connect to that access db. I also build a data mapper that will read the tps db, display sample data, and give you a list of "destination" fields from a text file.

I used this method to pull data from a Time Matters db and pump it into an Outlook / Exchange shared folder. The nice thing about doing it this way is I was able to map the user defined fields I wanted, and define the custom form for outlook for the client.

I can't share the tps driver, 'cause those pesky things call licenses and all, but I can definitely help someone out with pumping data if they need.

Friday, November 5, 2010

Observable Dictionary

Here is an Observable Dictionary that I threw together for a friend. It only does what we wanted it to do at that point in time, so you you need something more, add it. :)



Public Class ObservableDictionary(Of T, P)
Implements IDictionary(Of T, P)

Event ItemAdded(ByVal Key As T)
Event ItemRemoved(ByVal Key As T, ByVal value As P, ByVal Success As Boolean)
Event ItemChanged(ByVal Key As T, ByVal OldValue As P, ByVal NewValue As P)

Dim _BaseDictionary As Dictionary(Of T, P)

Sub New()
_BaseDictionary = New Dictionary(Of T, P)
End Sub

Public Sub Clear() Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of T, P)).Clear
_BaseDictionary.Clear()
End Sub

Public Function Contains(ByVal item As System.Collections.Generic.KeyValuePair(Of T, P)) As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of T, P)).Contains
Return _BaseDictionary.Contains(item)
End Function

Public Sub CopyTo(ByVal array() As System.Collections.Generic.KeyValuePair(Of T, P), ByVal arrayIndex As Integer) Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of T, P)).CopyTo
Throw New NotImplementedException
End Sub

Public ReadOnly Property Count As Integer Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of T, P)).Count
Get
Return _BaseDictionary.Count
End Get
End Property

Public ReadOnly Property IsReadOnly As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of T, P)).IsReadOnly
Get
Throw New NotImplementedException
End Get
End Property

Public Function RemovePair(ByVal item As System.Collections.Generic.KeyValuePair(Of T, P)) As Boolean Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of T, P)).Remove
Dim Value As P = _BaseDictionary(item.Key)
Dim Success = _BaseDictionary.Remove(item.Key)

RaiseEvent ItemRemoved(item.Key, Value, Success)
Return Success

End Function



Public Function ContainsKey(ByVal key As T) As Boolean Implements System.Collections.Generic.IDictionary(Of T, P).ContainsKey
Return _BaseDictionary.ContainsKey(key)
End Function

Default Public Property Item(ByVal key As T) As P Implements System.Collections.Generic.IDictionary(Of T, P).Item
Get

Return _BaseDictionary.Item(key)
End Get
Set(ByVal value As P)
Dim oldvalue As P = _BaseDictionary.Item(key)
_BaseDictionary.Item(key) = value
RaiseEvent ItemChanged(key, oldvalue, value)
End Set
End Property

Public ReadOnly Property Keys As System.Collections.Generic.ICollection(Of T) Implements System.Collections.Generic.IDictionary(Of T, P).Keys
Get
Return _BaseDictionary.Keys
End Get
End Property

Public Function Remove(ByVal key As T) As Boolean Implements System.Collections.Generic.IDictionary(Of T, P).Remove

Dim value = _BaseDictionary(key)
Dim Success = _BaseDictionary.Remove(key)
RaiseEvent ItemRemoved(key, Value, Success)

Return Success

End Function

Public Function TryGetValue(ByVal key As T, ByRef value As P) As Boolean Implements System.Collections.Generic.IDictionary(Of T, P).TryGetValue
If _BaseDictionary.ContainsKey(key) Then
value = _BaseDictionary(key)
Return True
Else
value = Nothing
Return False
End If
End Function

Public ReadOnly Property Values As System.Collections.Generic.ICollection(Of P) Implements System.Collections.Generic.IDictionary(Of T, P).Values
Get
Return _BaseDictionary.Values
End Get
End Property

Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of System.Collections.Generic.KeyValuePair(Of T, P)) Implements System.Collections.Generic.IEnumerable(Of System.Collections.Generic.KeyValuePair(Of T, P)).GetEnumerator
Return _BaseDictionary.GetEnumerator
End Function

Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Throw New NotImplementedException
End Function

Public Sub AddPair(ByVal item As System.Collections.Generic.KeyValuePair(Of T, P)) Implements System.Collections.Generic.ICollection(Of System.Collections.Generic.KeyValuePair(Of T, P)).Add

_BaseDictionary.Add(item.Key, item.Value)
RaiseEvent ItemAdded(item.Key)
End Sub

Public Sub Add(ByVal key As T, ByVal value As P) Implements System.Collections.Generic.IDictionary(Of T, P).Add
_BaseDictionary.Add(key, value)

RaiseEvent ItemAdded(key)
End Sub
End Class


Tuesday, July 27, 2010

DataForm + Combobox == Silly Bugs (combobox in dataFormToolkit:DataField)

UPDATE: So, this worked for SOME of the problems... not All.... Mosy on over to John's blog to see updates that he has for this issue. I believe he has fixed it.


Well... I haven't posted in a really long time... but this problem / workaround was worth it. My amazingly cool and awesome collegue John, had a most annoying problem. He was trying to bind a combobox to an itemsource then take the value of that itemsource and put it into a RIA Domain data source. Sounds easy right? well... not so when you're using the Silverlight 4 Toolkit DataForm / DataGrid.

Each time the form reloads (by adding, removing items from the collection) the bindings are reset, and not nicely... Long story short we found it impossible to get the combo box to work correctly using anything in XAML. For some reason "they" haven't made it easy in Silverlight.

To work around this issue the easiest thing I could come up with turns out to be pretty neat. On the Datafield that held the combo box, there is a Loaded event, so I thunk (yes, thunk; We were very frustrated...) why not just add a new combobox each time it loads so we KNOW that the bindings are correct.

Here is what we did:

Added an empty datafield to the grid in the dataform:

dataFormToolkit:DataField Grid.Row="5" Grid.Column="0" Loaded="ComboBoxField_Loaded" Label="Period Type" LabelPosition="Auto"

Note the lovely RED event handler.

in this hanlder we define the contents of this DataField:





Private Sub ComboBoxField_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)



Dim comboBoxField As DataField = sender 'Get the dataField that sent us here


Dim BindingForItems As New Binding With {.Source = ItemListDomainDataSource,
.Path = New PropertyPath("Data")}



'No need to set Source as it will pick up from the form


Dim BindingForValue As New Binding With {.Path = New PropertyPath("ItemValue"),
.Mode = BindingMode.TwoWay}



Dim combobox As ComboBox = New ComboBox 'Make a new combobox
combobox.DisplayMemberPath = "Name" 'Set Paths FIRST, yes, they have to be done first
combobox.SelectedValuePath = "PeriodType"
combobox.SetBinding(combobox.ItemsSourceProperty, BindingForItems)
combobox.SetBinding(combobox.SelectedValueProperty, BindingForValue)

'add styling wireups if not using default styling

comboBoxField.Content = combobox 'Push the new combobox back to the datafield



End Sub




So, load the data field, add the combobox, with its bindings already set. Now, for all those that are super concerned, like my friend John, about performance etc, you should go look at his blog, 'cause i am pretty sure he will take this and turn it into some shared resource.... :)




Add to Google