Options

Hotfix Application

BeliasBelias Member Posts: 2,998
edited 2011-09-07 in General Chat
Hi everyone,
during these weeks i have had to deal with some NAV R2 hotfixes, and i suddendly understood that it's very difficult to keep your version updated to the latest hotfix, because new hotfixes are released on a weekly basis (more or less).
Moreover, it's a pain to install them, because you extract the hofix from the zip file, and it contains 6 subfolders that contains the files to replace. You then have to "map" the hotfix folders with the installation folders (because they don't have the same name) and then copy the files from the hotfix to the client. (It's too odd to be true, am i missing something?)
I'd really like to semi automate this with a winform: ideally, i would like to ask the user to insert nav installation folder and the source folder of the hotfix. After that, click a button to do:
1. create a backup copy of the current files.
2. overwrite the files with the new version, automatically.

I am able to to this in nav, but it's not the correct way in my opinion. Ideally it would be (as i said) a winform, but unfortunately i don't have the knowledge to do it.
Any idea, please?
Thanks in advance
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog

Comments

  • Options
    kinekine Member Posts: 12,562
    I think it is not so hard. Creating winform app in Visual Studio is easy... just try it, you will learn new things. If you need more help, just ask me, I will try to help you.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    BeliasBelias Member Posts: 2,998
    kine wrote:
    I think it is not so hard. Creating winform app in Visual Studio is easy... just try it, you will learn new things. If you need more help, just ask me, I will try to help you.
    I just didn't want to reinvent the wheel :mrgreen: anyway, if you say so, i'll try to do it (i just have visual C# express, i hope it's enough)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    JDVyskaJDVyska Member Posts: 179
    Hey Belias,

    That sounds like a great tool. If you ever want, I can share my knowledge from my recent level of stumbling around in C# express. Kine's right, it's pretty easy to handle making an app like that.

    Shoot me a PM and we can swap contact info.
    JEREMY VYSKA
    CEO, Spare Brained Ideas, Göteborg, Sweden
    New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
  • Options
    BeliasBelias Member Posts: 2,998
    I'm working on it, but tomorrow i've got a pair of exams (DEV1&2) and i've had to spend some free time on the manuals.
    Anyway, I've made a raw project: it works, but it's reaaaaaaally ugly to see! (i'm talking about the code design, the UI is minimal)
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
    
                FolderBrowserDialog fdlg = new FolderBrowserDialog();
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    textBox1.Text = fdlg.SelectedPath;
                }
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                FolderBrowserDialog fdlg = new FolderBrowserDialog();
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    textBox2.Text = fdlg.SelectedPath;
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                FolderBrowserDialog fdlg = new FolderBrowserDialog();
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    textBox3.Text = fdlg.SelectedPath;
                }
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                DirectoryInfo di = new DirectoryInfo(textBox1.Text + "Application Server");
                FileInfo[] rgFiles = di.GetFiles();
                foreach (FileInfo fi in rgFiles)
                {
                    File.Copy(textBox1.Text + "Application Server" + "\\" + fi.Name, textBox2.Text + "TODO" + "\\" + fi.Name, true);
                }
                
                DirectoryInfo di2 = new DirectoryInfo(textBox1.Text + "Application Server");
                FileInfo[] rgFiles2 = di2.GetFiles();
                foreach (FileInfo fi in rgFiles2)
                {
                    File.Copy(textBox1.Text + "RTC" + "\\" + fi.Name, textBox2.Text + "RoleTailored Client" + "\\" + fi.Name, true);
                }
            }
        }
    }
    

    It's incomplete, as you can see...i have some problems that i don't know how to solve:
    1. if the service is up, it would be great to ask the user to shut it down, and eventually do it on his confirmation.
    2. if there are more than one service, how do i manage them (i cannot know the name of the folder of the services)?
    3. it would be great to read nav installation folder from registry entry or something
    4. it would be also great to inherit the folder where i placed the exe. In this way i can put it in the hotfix folder and automatically populate the "hotfix folder" field
    5. another great feature is to pass the paths as parameters. Something like: navhofixer /hffolder [foldername] /navfolder [foldername] /bkupfolder [foldername]
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    kinekine Member Posts: 12,562
    ad all around services, look into my NST Admin objects for NAV. I am using the .NET assemblies to get the services, check statuses, read their folders etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    BeliasBelias Member Posts: 2,998
    kine wrote:
    ad all around services, look into my NST Admin objects for NAV. I am using the .NET assemblies to get the services, check statuses, read their folders etc.
    I guessed it just after posting, i've already downloaded it, and'im going to take a look at it, thank you! :wink:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    BeliasBelias Member Posts: 2,998
    update: i'm slowly going forward with this project. i just figured out how to get dynamics nav services names (and eventually stop them)
    ServiceController[] services = ServiceController.GetServices();
    
              // try to find service name
              foreach (ServiceController myservice in services)
              {
                  string myservicestring = myservice.ServiceName.ToUpper(); 
                  if (myservicestring.IndexOf("MICROSOFTDYNAMICSNAV") != -1)
                  {
                      try
                      {
                          myservice.Stop();
                      }
                      catch { };
                  }
              }
    
    INSPIRED BY THE KINE'S NST MANAGEMENT
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    BeliasBelias Member Posts: 2,998
    question: how do I get the path of the executable of the service?
    EDIT: i found a way:
    string registryPath = @"SYSTEM\CurrentControlSet\Services\" + myservicename;
                      RegistryKey keyHKLM = Registry.LocalMachine;
    
                      RegistryKey key;
    
                      key = keyHKLM.OpenSubKey(registryPath);
    
                      textBox4.Text = key.GetValue("ImagePath").ToString();
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    BeliasBelias Member Posts: 2,998
    hi, i have some questions before going forward:

    - is there a way to distinguish between a webservice service and a nav server service? (some hardcoded character in the name, some parameter...dunno): this is needed in order to exclude the webservices services from the service list
    - in order to associate a nav server with its webservice server, i can use the exe file (because it is the same). Do you know another way to, or is this the only one? (this is not a relevant question, anyway)
    - is it possible to INSTALL the nav client in a folder that is COMPLETELY different from the one of its server? If yes, how can i get the path of the client? (for now, i get it by trimming the path of the exe server that i found in the registry key before)

    thanks in advance for your help!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.