public async Task <string> GenerateConfigXml() { var currentDirectory = Directory.GetCurrentDirectory() + @"\Scripts"; if (!System.IO.File.Exists(currentDirectory + @"\Generate-ODTConfigurationXML.ps1")) { currentDirectory = Directory.GetCurrentDirectory() + @"\Project\Scripts"; } var xmlFilePath = Environment.ExpandEnvironmentVariables(@"%temp%\localConfig.xml"); if (System.IO.File.Exists(xmlFilePath)) { System.IO.File.Delete(xmlFilePath); } var scriptPath = currentDirectory + @"\Generate-ODTConfigurationXML.ps1"; var scriptPathTmp = currentDirectory + @"\Tmp-Generate-ODTConfigurationXML.ps1"; if (!System.IO.File.Exists(scriptPathTmp)) { System.IO.File.Copy(scriptPath, scriptPathTmp, true); } var scriptUrl = AppSettings.GenerateScriptUrl; try { await Retry.BlockAsync(5, 1, async() => { using (var webClient = new WebClient()) { await webClient.DownloadFileTaskAsync(new Uri(scriptUrl), scriptPath); } }); } catch (Exception ex) { } var n = 1; await Retry.BlockAsync(2, 1, async() => { var arguments = @"/c Powershell -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle " + @"Hidden -File .\RunGenerateXML.ps1"; if (n == 2) { System.IO.File.Copy(scriptPathTmp, scriptPath, true); } var p = new Process { StartInfo = new ProcessStartInfo() { FileName = "cmd", Arguments = arguments, CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = currentDirectory, RedirectStandardOutput = true, RedirectStandardError = true }, }; p.Start(); p.WaitForExit(); var error = await p.StandardError.ReadToEndAsync(); if (!string.IsNullOrEmpty(error)) { throw (new Exception(error)); } n++; }); await Task.Delay(100); var configXml = ""; if (System.IO.File.Exists(xmlFilePath)) { configXml = System.IO.File.ReadAllText(xmlFilePath); } try { var installOffice = new InstallOffice(); var updateUrl = installOffice.GetBaseCdnUrl(); if (!string.IsNullOrEmpty(updateUrl)) { var pd = new ProPlusDownloader(); var channelName = await pd.GetChannelNameFromUrlAsync(updateUrl, OfficeEdition.Office32Bit); if (!string.IsNullOrEmpty(configXml) && !string.IsNullOrEmpty(channelName)) { configXml = installOffice.SetUpdateChannel(configXml, channelName); } } } catch { } return(configXml); }
public async Task<string> GenerateConfigXml() { var currentDirectory = Directory.GetCurrentDirectory() + @"\Scripts"; if (!System.IO.File.Exists(currentDirectory + @"\Generate-ODTConfigurationXML.ps1")) { currentDirectory = Directory.GetCurrentDirectory() + @"\Project\Scripts"; } var xmlFilePath = Environment.ExpandEnvironmentVariables(@"%temp%\localConfig.xml"); if (System.IO.File.Exists(xmlFilePath)) { System.IO.File.Delete(xmlFilePath); } var scriptPath = currentDirectory + @"\Generate-ODTConfigurationXML.ps1"; var scriptPathTmp = currentDirectory + @"\Tmp-Generate-ODTConfigurationXML.ps1"; if (!System.IO.File.Exists(scriptPathTmp)) { System.IO.File.Copy(scriptPath, scriptPathTmp, true); } var scriptUrl = AppSettings.GenerateScriptUrl; try { await Retry.BlockAsync(5, 1, async () => { using (var webClient = new WebClient()) { await webClient.DownloadFileTaskAsync(new Uri(scriptUrl), scriptPath); } }); } catch (Exception ex) { } var n = 1; await Retry.BlockAsync(2, 1, async () => { var arguments = @"/c Powershell -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle " + @"Hidden -File .\RunGenerateXML.ps1"; if (n == 2) { System.IO.File.Copy(scriptPathTmp, scriptPath, true); } var p = new Process { StartInfo = new ProcessStartInfo() { FileName = "cmd", Arguments = arguments, CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = currentDirectory, RedirectStandardOutput = true, RedirectStandardError = true }, }; p.Start(); p.WaitForExit(); var error = await p.StandardError.ReadToEndAsync(); if (!string.IsNullOrEmpty(error)) throw (new Exception(error)); n++; }); await Task.Delay(100); var configXml = ""; if (System.IO.File.Exists(xmlFilePath)) { configXml = System.IO.File.ReadAllText(xmlFilePath); } try { var installOffice = new InstallOffice(); var updateUrl = installOffice.GetBaseCdnUrl(); if (!string.IsNullOrEmpty(updateUrl)) { var pd = new ProPlusDownloader(); var channelName = await pd.GetChannelNameFromUrlAsync(updateUrl, OfficeEdition.Office32Bit); if (!string.IsNullOrEmpty(configXml) && !string.IsNullOrEmpty(channelName)) { configXml = installOffice.SetUpdateChannel(configXml, channelName); } } } catch { } return configXml; }