public void GetXmlTest() { string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <function controlid=""unittest""> <installApp> <appxml><![CDATA[<somexml>hello,world</somexml>]]></appxml> </installApp> </function>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.IndentChars = " "; var fileName = "input"; var fileExtension = "xml"; var path = @"c:\" + fileName + "." + fileExtension; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { path, new MockFileData("<somexml>hello,world</somexml>") }, }); var applicationInstall = new ApplicationInstall(fileSystem, "unittest"); applicationInstall.XmlFilename = path; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); applicationInstall.WriteXml(ref xml); xml.Flush(); stream.Position = 0; StreamReader reader = new StreamReader(stream); Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd()) .WithDifferenceEvaluator(DifferenceEvaluators.Default) .Build(); Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString()); }
private ApplicationVersion GetPlatformVersion(ApplicationInstall app) { if (app.VersionCount == 1) { return(app.Versions[0]); } else { foreach (ApplicationVersion version in app.Versions) { if (version.Architechture == "x64" && Environment.Is64BitOperatingSystem) { return(version); } if (version.Architechture == "x86" && !Environment.Is64BitOperatingSystem) { return(version); } } } return(null); }
private void ProcessApplication(int index) { List <ApplicationInstall> apps = (List <ApplicationInstall>)dtGridApps.DataSource; BackgroundWorker bwInstallerDownloader = new BackgroundWorker(); BackgroundWorker bwInstallation = new BackgroundWorker(); bwInstallerDownloader.WorkerReportsProgress = false; bwInstallation.WorkerReportsProgress = false; bwInstallerDownloader.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args) { BackgroundWorker b = o as BackgroundWorker; ApplicationInstall app = apps[index]; string installer = null; ApplicationVersion version = null; try { version = GetPlatformVersion(apps, index); installer = DownloadInstaller(version.DownloadLink); } catch (WebException) { args.Cancel = true; return; } args.Result = installer; }); bwInstallerDownloader.RunWorkerCompleted += new RunWorkerCompletedEventHandler( delegate(object o, RunWorkerCompletedEventArgs args) { if (args.Cancelled) { lblProgress.Text = "Cannot progress. Do you have a working internet connection?"; pbProgress.Style = ProgressBarStyle.Continuous; pbProgress.Value = 0; apps[index].Status = "Error downloading installer"; dtGridApps.Refresh(); } else { lblProgress.Text = string.Format(String.Format("Running installer for {0}...", apps[index].Name)); apps[index].Status = "Installing..."; pbProgress.Style = ProgressBarStyle.Marquee; dtGridApps.Refresh(); string installer = (string)args.Result; bwInstallation.RunWorkerAsync(installer); } }); bwInstallation.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args) { BackgroundWorker b = o as BackgroundWorker; string installerPath = (string)args.Argument; ApplicationInstall app = apps[index]; ApplicationVersion version = GetPlatformVersion(apps, index); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = false; startInfo.UseShellExecute = false; startInfo.FileName = installerPath; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.Arguments = version.SilentInstallArgs; try { using (Process exeProcess = Process.Start(startInfo)) { exeProcess.WaitForExit(); File.Delete(installerPath); } } catch { // Log error. } }); bwInstallation.RunWorkerCompleted += new RunWorkerCompletedEventHandler( delegate(object o, RunWorkerCompletedEventArgs args) { lblProgress.Text = string.Format(String.Format("Installed {0}", apps[index].Name)); apps[index].Status = "Complete"; pbProgress.Style = ProgressBarStyle.Continuous; pbProgress.Value = 0; dtGridApps.Refresh(); if (++index < apps.Count) { ProcessApplication(index); } else { lblProgress.Text = string.Format(String.Format("Installation complete!")); pbProgress.Style = ProgressBarStyle.Continuous; pbProgress.Value = 0; dtGridApps.Refresh(); } }); lblProgress.Text = string.Format(String.Format("Downloading installer for {0}...", apps[index].Name)); apps[index].Status = "Downloading installer..."; pbProgress.Style = ProgressBarStyle.Marquee; dtGridApps.Refresh(); bwInstallerDownloader.RunWorkerAsync(); }
private ApplicationVersion GetPlatformVersion(List <ApplicationInstall> apps, int index) { ApplicationInstall app = apps[index]; return(GetPlatformVersion(app)); }