Solved

Installer Class To Edit Config File

Posted on 2013-06-20
4
410 Views
Last Modified: 2013-06-21
Hi Experts!

Thanks for reading this.

Using setup and deployment to create an msi and based on the response from the User Interface (RadioButtons):

user interface in setup and deploymentWe'll use the button selected to determine the Region.
In the Installer class in the Commit method it will edit the config file for TimeToSleep depending on the Region selected (RadioButton):
<Security.Permissions.SecurityPermission(Security.Permissions.SecurityAction.Demand)>
Public Overrides Sub Commit(ByVal savedState As IDictionary)

    Try
        MyBase.Commit(savedState)
        If MyBase.Context.Parameters("Region").ToString() = "1" Then
            My.Settings.Item("TimeToSleep") = "1000"          
        ElseIf MyBase.Context.Parameters("Region").ToString() = "2" Then
            My.Settings.Item("TimeToSleep") = "100"        
        ElseIf MyBase.Context.Parameters("Region").ToString() = "3" Then
            My.Settings.Item("TimeToSleep") = "10"        
        End If

    Catch exc As Exception
        MsgBox("Error performing commit tasks - " & exc.ToString(), "AppName Setup")
    End Try

End Sub 'Commit

Open in new window

Can you please help convert the above to C# (tried using VB.NET -> C# converter didn't help). This is what we have so far:
public override void Commit(IDictionary savedState)
{
    base.Commit(savedState);
}

Open in new window


TIA!!
0
Comment
Question by:allanau20
  • 2
  • 2
4 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 39265066
Translated code:
        public  override void Commit(IDictionary savedState)
        {
            try
            {
                base.Commit(savedState);
                string myRegion = base.Context.Parameters["Region"].ToString();
                if (myRegion == "1")
                    Properties.Settings.Default.TimeToSleep = "1000";
                else if (myRegion == "2")
                    Properties.Settings.Default.TimeToSleep = "100";
                else if (myRegion == "3")
                    Properties.Settings.Default.TimeToSleep = "10";
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error performing commit tasks - " + exc.ToString(), "AppName Setup");
            }
        }

Open in new window

where settings  are mapped as shown here.
0
 
LVL 5

Author Comment

by:allanau20
ID: 39266923
Thanks; that's helpful mas_oz2003.

In the article it doesn't specific what to reference to use 'Properties'.
I'll try to look around ..
0
 
LVL 5

Author Comment

by:allanau20
ID: 39266996
got it; it was a namespace issue. Thanks!
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 39267483
No worries. Please accept solution to close question
Cheers,

MS
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question