Rectangle 27 4

I posted a question here that was brought about by the same problem: trying to both take advantage of the convenience of referring to objects by their base class, while at the same time using additional properties that their subclasses may contain.

The solution that was most useful to me was to use the visitor pattern. In your Point base class, you define an abstract method void Accept(Visitor). The Visitor class would define a method for each subclass (so you'd have to keep track of them all, any new subclass would require modifying the visitor class). For example, the visitor would look like this:

interface Visitor {

    void on1Point(1Point);

    void on2Point(2Point);

    ... etc
}

Then each BasePoint subclass would implement the accept method to delegate to the correct Visitor method. So in the 1Point class, accept would be defined as:

void accept(Visitor visitor) {
    visitor.on1Point(this);
}

Now whenever you have a BasePoint and want to do something with it depending on what extra properties it has, make a visitor, figure out what you want it to do in the case of being each possible subclass, and put the logic there. In the body of the Visitor method, the object you'll be handed will be "cast" to the correct type, so you can access any of its additional properties. It's similar to just doing a bunch of instanceof checks, but it's much cleaner, more reusable, and more elegant.

Thank you for your answer! I'd like to avoid the Visitor pattern though, because I'm still in the design phase, so I don't need to (yet) add additional functionality without compromising the OCP. In addition, I'm trying to get away from inheritance, and use composition instead here. Consequently, I think there may be a better way to model this. If there really isn't though, I may end up using the Visitor pattern. Thanks again :)

c# design object-oriented object-oriented-design inheritance
Rectangle 27 8

As you are spending some serious amount of reputation, I tryied to do my best, and spent some of my time, not only to get my hands on the bounty... but I also get something else: knowledge! =)

First of all: it is impossible to make the Setup Project point to another app.config file by using the Primary output option. So my solution is going to be a work around. I hope you find it useful in your situation.

The basic idea is:

  • Remove the forced app.config from the Setup Project;
  • Add a file pointing to the app.config, manually;
  • Use MSBuild to get into the vdproj file, and change it to match the real output of the transformed app.config.
  • The setup project only gets updated, if the project it deploys build. ahhh... not a real drawback!
  • You need MSBuild 4.0... this can also be worked around!
  • Need a custom Task, called FileUpdate... it is open source and has installer.

1) Go to your Setup Project, and select the Primary Output object, right click and go to Properties. There you will find the Exclude Filter... add a filter for *.config, so it will remove the hard-coded app.config.

2) Right click your Setup Project in the Solution Explorer -> Add -> File... select any file that ends with .config.

4) Unload your project (the csproj) and replace the code from the other question with this one:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
    <!-- Generate transformed app config in the intermediate directory -->
    <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
    <!-- Force build process to use the transformed configuration file from now on. -->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="app.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
    <PropertyGroup>
      <SetupProjectPath>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)$(TargetFileName).config</SetupProjectPath>
    </PropertyGroup>
    <!-- Change the following so that this Task can find your vdproj file -->
    <FileUpdate Files="$(MSBuildProjectDirectory)\..\Setup1\Setup1.vdproj"
                    Regex="(.SourcePath. = .8:).*\.config(.)"
                    ReplacementText="$1$(SetupProjectPath.Replace(`\`,`\\`))$2" />
    <FileUpdate Files="$(MSBuildProjectDirectory)\..\Setup1\Setup1.vdproj"
                    Regex="(.TargetName. = .8:).*\.config(.)"
                    ReplacementText="$1$(TargetFileName).config$2" />
  </Target>

5) The previous code must be changed, so that it can find your vdproj file. I have placed a comment in the code, indicating where you need to make the change.

Now, everytime you build your main project, the MSBuild will change the Setup project, so that it uses the correct app.config file. It may have drawbacks, but this solution can be polished and become better. If you need leave a comment, and I'll try to respond ASAP.

MSBuild 4.0 is needed because I need to use String's Replace function, to replace single "\" to double "\" in the path. See MSBuild Property Functions for details about using function in MSBuild.

winforms - Can I force the installer project to use the .config file f...

winforms visual-studio-2010 installer web-config-transform
Rectangle 27 8

As you are spending some serious amount of reputation, I tryied to do my best, and spent some of my time, not only to get my hands on the bounty... but I also get something else: knowledge! =)

First of all: it is impossible to make the Setup Project point to another app.config file by using the Primary output option. So my solution is going to be a work around. I hope you find it useful in your situation.

The basic idea is:

  • Remove the forced app.config from the Setup Project;
  • Add a file pointing to the app.config, manually;
  • Use MSBuild to get into the vdproj file, and change it to match the real output of the transformed app.config.
  • The setup project only gets updated, if the project it deploys build. ahhh... not a real drawback!
  • You need MSBuild 4.0... this can also be worked around!
  • Need a custom Task, called FileUpdate... it is open source and has installer.

1) Go to your Setup Project, and select the Primary Output object, right click and go to Properties. There you will find the Exclude Filter... add a filter for *.config, so it will remove the hard-coded app.config.

2) Right click your Setup Project in the Solution Explorer -> Add -> File... select any file that ends with .config.

4) Unload your project (the csproj) and replace the code from the other question with this one:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
    <!-- Generate transformed app config in the intermediate directory -->
    <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
    <!-- Force build process to use the transformed configuration file from now on. -->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="app.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
    <PropertyGroup>
      <SetupProjectPath>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)$(TargetFileName).config</SetupProjectPath>
    </PropertyGroup>
    <!-- Change the following so that this Task can find your vdproj file -->
    <FileUpdate Files="$(MSBuildProjectDirectory)\..\Setup1\Setup1.vdproj"
                    Regex="(.SourcePath. = .8:).*\.config(.)"
                    ReplacementText="$1$(SetupProjectPath.Replace(`\`,`\\`))$2" />
    <FileUpdate Files="$(MSBuildProjectDirectory)\..\Setup1\Setup1.vdproj"
                    Regex="(.TargetName. = .8:).*\.config(.)"
                    ReplacementText="$1$(TargetFileName).config$2" />
  </Target>

5) The previous code must be changed, so that it can find your vdproj file. I have placed a comment in the code, indicating where you need to make the change.

Now, everytime you build your main project, the MSBuild will change the Setup project, so that it uses the correct app.config file. It may have drawbacks, but this solution can be polished and become better. If you need leave a comment, and I'll try to respond ASAP.

MSBuild 4.0 is needed because I need to use String's Replace function, to replace single "\" to double "\" in the path. See MSBuild Property Functions for details about using function in MSBuild.

winforms - Can I force the installer project to use the .config file f...

winforms visual-studio-2010 installer web-config-transform
Rectangle 27 2

The documentation for the GMap.NET is quite lacking but if you take the time to explore the properties and methods it provides appears quite easy to use.

Here's a quick sample that should get you started:

First of all, create an empty Form in a VB.NET solution and add a reference to the three DLLs provided by the GMap.NET library.

Form1.vb
Imports GMap.NET
Imports GMap.NET.MapProviders

Public Class Form1
    Private map As GMap.NET.WindowsForms.GMapControl

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        map = New WindowsForms.GMapControl()
        Me.Controls.Add(map)

        map.Dock = DockStyle.Fill

        With map
            ' Home sweet home...
            .Position = New PointLatLng(19.442288, -70.652266)

            .MapProvider = MapProviders.GoogleMapProvider.Instance
            .MinZoom = 3
            .MaxZoom = 17
            .Zoom = 16
            .Manager.Mode = AccessMode.ServerAndCache
        End With
    End Sub
End Class

For further assistance with the control you should contact the authors directly: http://greatmaps.codeplex.com/discussions

Okay these things I got to work, but UI almost freezes for a while doing that. using background doesn't seem to be possible.

I also felt it ran quite slow. Try changing the MapProvider property to GMapProviders.OpenStreetMap and see if that speeds it up a bit.

Hey! thanks for the assistace you were giving me back. i figured it out to do it in background worker. Actually, I just got to know how to pass object to B-Worker! And, it's working all good with Bing (I just love 'em!). :)

winforms - Unable to find Google Maps solution for VB.NET - Stack Over...

vb.net winforms google-maps
Rectangle 27 2

The documentation for the GMap.NET is quite lacking but if you take the time to explore the properties and methods it provides appears quite easy to use.

Here's a quick sample that should get you started:

First of all, create an empty Form in a VB.NET solution and add a reference to the three DLLs provided by the GMap.NET library.

Form1.vb
Imports GMap.NET
Imports GMap.NET.MapProviders

Public Class Form1
    Private map As GMap.NET.WindowsForms.GMapControl

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        map = New WindowsForms.GMapControl()
        Me.Controls.Add(map)

        map.Dock = DockStyle.Fill

        With map
            ' Home sweet home...
            .Position = New PointLatLng(19.442288, -70.652266)

            .MapProvider = MapProviders.GoogleMapProvider.Instance
            .MinZoom = 3
            .MaxZoom = 17
            .Zoom = 16
            .Manager.Mode = AccessMode.ServerAndCache
        End With
    End Sub
End Class

For further assistance with the control you should contact the authors directly: http://greatmaps.codeplex.com/discussions

Okay these things I got to work, but UI almost freezes for a while doing that. using background doesn't seem to be possible.

I also felt it ran quite slow. Try changing the MapProvider property to GMapProviders.OpenStreetMap and see if that speeds it up a bit.

Hey! thanks for the assistace you were giving me back. i figured it out to do it in background worker. Actually, I just got to know how to pass object to B-Worker! And, it's working all good with Bing (I just love 'em!). :)

winforms - Unable to find Google Maps solution for VB.NET - Stack Over...

vb.net winforms google-maps
Rectangle 27 2

The documentation for the GMap.NET is quite lacking but if you take the time to explore the properties and methods it provides appears quite easy to use.

Here's a quick sample that should get you started:

First of all, create an empty Form in a VB.NET solution and add a reference to the three DLLs provided by the GMap.NET library.

Form1.vb
Imports GMap.NET
Imports GMap.NET.MapProviders

Public Class Form1
    Private map As GMap.NET.WindowsForms.GMapControl

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        map = New WindowsForms.GMapControl()
        Me.Controls.Add(map)

        map.Dock = DockStyle.Fill

        With map
            ' Home sweet home...
            .Position = New PointLatLng(19.442288, -70.652266)

            .MapProvider = MapProviders.GoogleMapProvider.Instance
            .MinZoom = 3
            .MaxZoom = 17
            .Zoom = 16
            .Manager.Mode = AccessMode.ServerAndCache
        End With
    End Sub
End Class

For further assistance with the control you should contact the authors directly: http://greatmaps.codeplex.com/discussions

Okay these things I got to work, but UI almost freezes for a while doing that. using background doesn't seem to be possible.

I also felt it ran quite slow. Try changing the MapProvider property to GMapProviders.OpenStreetMap and see if that speeds it up a bit.

Hey! thanks for the assistace you were giving me back. i figured it out to do it in background worker. Actually, I just got to know how to pass object to B-Worker! And, it's working all good with Bing (I just love 'em!). :)

winforms - Unable to find Google Maps solution for VB.NET - Stack Over...

vb.net winforms google-maps
Rectangle 27 2

The documentation for the GMap.NET is quite lacking but if you take the time to explore the properties and methods it provides appears quite easy to use.

Here's a quick sample that should get you started:

First of all, create an empty Form in a VB.NET solution and add a reference to the three DLLs provided by the GMap.NET library.

Form1.vb
Imports GMap.NET
Imports GMap.NET.MapProviders

Public Class Form1
    Private map As GMap.NET.WindowsForms.GMapControl

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        map = New WindowsForms.GMapControl()
        Me.Controls.Add(map)

        map.Dock = DockStyle.Fill

        With map
            ' Home sweet home...
            .Position = New PointLatLng(19.442288, -70.652266)

            .MapProvider = MapProviders.GoogleMapProvider.Instance
            .MinZoom = 3
            .MaxZoom = 17
            .Zoom = 16
            .Manager.Mode = AccessMode.ServerAndCache
        End With
    End Sub
End Class

For further assistance with the control you should contact the authors directly: http://greatmaps.codeplex.com/discussions

Okay these things I got to work, but UI almost freezes for a while doing that. using background doesn't seem to be possible.

I also felt it ran quite slow. Try changing the MapProvider property to GMapProviders.OpenStreetMap and see if that speeds it up a bit.

Hey! thanks for the assistace you were giving me back. i figured it out to do it in background worker. Actually, I just got to know how to pass object to B-Worker! And, it's working all good with Bing (I just love 'em!). :)

winforms - Unable to find Google Maps solution for VB.NET - Stack Over...

vb.net winforms google-maps