public void TestSSASConnectionChange() { using (PBIXUtils pu = new PBIXUtils("..\\..\\Resources\\A1.pbix", "..\\..\\Resources\\A2.pbix")) { pu.ReplaceSSASConnectionString("s1", "c1", "cc1"); } }
public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { int sqlIndex = 0; if (request.DataStore.KeyExists("SqlServerIndex")) { sqlIndex = int.Parse(request.DataStore.GetValue("SqlServerIndex")); } var filename = request.DataStore.GetValue("FileName"); string connectionString = request.DataStore.GetAllValues("SqlConnectionString")[sqlIndex]; var templateFullPath = request.Info.App.AppFilePath + $"/service/PowerBI/{filename}"; var tempfileName = Path.GetRandomFileName(); var templateTempFullPath = request.Info.App.AppFilePath + $"/Temp/{tempfileName}/{filename}"; Directory.CreateDirectory(request.Info.App.AppFilePath + $"/Temp/{tempfileName}"); var creds = SqlUtility.GetSqlCredentialsFromConnectionString(connectionString); using (PBIXUtils wrangler = new PBIXUtils(templateFullPath, templateTempFullPath)) { wrangler.ReplaceKnownVariableinMashup("STSqlServer", creds.Server); wrangler.ReplaceKnownVariableinMashup("STSqlDatabase", creds.Database); } string serverPath = request.Info.ServiceRootUrl + request.Info.ServiceRelativePath + request.Info.App.AppRelativeFilePath + $"/Temp/{tempfileName}/{filename}"; return(new ActionResponse(ActionStatus.Success, JsonUtility.GetJObjectFromStringValue(serverPath))); }
public override async Task <ActionResponse> ExecuteActionAsync(ActionRequest request) { string connectionString = request.DataStore.GetValueAtIndex("SqlConnectionString", "SqlServerIndex"); string[] originalFiles = request.DataStore.GetValue("FileName").Split('|'); string[] tempFolders = new string[originalFiles.Length]; for (int i = 0; i < originalFiles.Length; i++) { string templateFullPath = request.Info.App.AppFilePath + $"/service/PowerBI/{originalFiles[i]}"; tempFolders[i] = Path.GetRandomFileName(); Directory.CreateDirectory(request.Info.App.AppFilePath + $"/Temp/{tempFolders[i]}"); SqlCredentials creds = SqlUtility.GetSqlCredentialsFromConnectionString(connectionString); using (PBIXUtils wrangler = new PBIXUtils(templateFullPath, request.Info.App.AppFilePath + $"/Temp/{tempFolders[i]}/{originalFiles[i]}")) { wrangler.ReplaceKnownVariableinMashup("STSqlServer", creds.Server); wrangler.ReplaceKnownVariableinMashup("STSqlDatabase", creds.Database); } } string serverPath = string.Empty; if (originalFiles.Length == 1) { serverPath = request.Info.ServiceRootUrl + request.Info.ServiceRelativePath + request.Info.App.AppRelativeFilePath + $"/Temp/{tempFolders[0]}/{originalFiles[0]}"; } else { string randomZipFolder = Path.GetRandomFileName(); DirectoryInfo d = Directory.CreateDirectory(Path.Combine(request.Info.App.AppFilePath, "Temp", randomZipFolder)); serverPath = Path.Combine(d.FullName, "SolutionTemplate.zip"); using (FileStream zipFile = AVAwareOpen(serverPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read)) { using (ZipArchive z = new ZipArchive(zipFile, ZipArchiveMode.Update)) { for (int i = 0; i < originalFiles.Length; i++) { ZipArchiveEntry entry = z.CreateEntry(originalFiles[i], CompressionLevel.Optimal); using (Stream w = entry.Open()) { string fileToZip = Path.Combine(request.Info.App.AppFilePath, "Temp", tempFolders[i], originalFiles[i]); using (FileStream source = AVAwareOpen(fileToZip, FileMode.Open, FileAccess.Read, FileShare.Read)) { source.CopyTo(w); w.Flush(); } } } } } // reconstruct a web server path serverPath = request.Info.ServiceRootUrl + request.Info.ServiceRelativePath + request.Info.App.AppRelativeFilePath + $"/Temp/{randomZipFolder}/SolutionTemplate.zip";; } return(new ActionResponse(ActionStatus.Success, JsonUtility.GetJObjectFromStringValue(serverPath))); }