AppMetrics.AgentService.AgentServiceClass.UpdatePlugin C# (CSharp) Method

UpdatePlugin() private method

private UpdatePlugin ( WebClient client, string pluginsUrl, string name, string newVersion ) : void
client System.Net.WebClient
pluginsUrl string
name string
newVersion string
return void
        private void UpdatePlugin(WebClient client, string pluginsUrl, string name, string newVersion)
        {
            var pluginPath = Const.WorkingAreaBinPath + @"\" + name + @"\";
            if (!Directory.Exists(pluginPath))
                Directory.CreateDirectory(pluginPath);

            // check if update is needed
            var localVersionFile = pluginPath + "version.txt";
            if (File.Exists(localVersionFile))
            {
                var localVersion = File.ReadAllText(localVersionFile).Trim();
                if (newVersion == localVersion)
                    return;
                ReportEvent(string.Format("Trying to update plugin {0} to version {1}", name, newVersion));
            }

            string zipFileName = name + ".zip";
            var zipFilePath = Const.WorkingAreaTempPath + zipFileName;
            if (File.Exists(zipFilePath))
                File.Delete(zipFilePath);

            var zipFileUrl = pluginsUrl + (name + "/" + zipFileName).Replace("//", "/");
            client.DownloadFile(zipFileUrl, zipFilePath);

            StopPlugin(name);
            FileUtil.DeleteAllFiles(pluginPath);

            using (var zipFile = new ZipFile(zipFilePath))
            {
                zipFile.TempFileFolder = Path.GetTempPath();
                zipFile.ExtractAll(pluginPath);
            }

            {
                var localVersion = File.ReadAllText(localVersionFile).Trim();
                ReportEvent(string.Format("Update of plugin {0} to version {1} is successful", name, localVersion));
            }
        }