public void ReplaceSSASConnectionString(string server, string catalog, string cube)
        {
            if (_connections == null)
            {
                return;                       // Nothing to do
            }
            string connectionJson = null;

            using (MemoryStream m = new MemoryStream())
            {
                _connections.GetStream().CopyTo(m);  // Do not cache GetStream() result
                connectionJson = m.ToArray().GetStringFromUTF8();
            }

            PbixConnection liveConnection = JsonConvert.DeserializeObject <PbixConnection>(connectionJson);

            if (liveConnection.Version != 1)
            {
                throw new Exception("SSAS connection element has an unexpected version");
            }

            if (liveConnection.Connections.Length != 1)
            {
                throw new Exception("Ambiguous connection element change request");
            }

            if (liveConnection.Connections[0] == null)
            {
                throw new Exception("Unexpected null value for connection element");
            }

            liveConnection.Connections[0].InitializeConnectionElement(server, catalog, cube);
            connectionJson = JsonConvert.SerializeObject(liveConnection);

            byte[] encodedJsonBytes = connectionJson.GetUTF8Bytes();
            _connections.GetStream().Write(encodedJsonBytes, 0, encodedJsonBytes.Length);
            _connections.GetStream().SetLength(encodedJsonBytes.Length);
            _connections.GetStream().Flush();
            _pbixPackage.Flush();
        }
        public void ReplaceKnownVariableinMashup(string variable, string newValue)
        {
            byte[] mashupBytes;
            using (var memoryStream = new MemoryStream())
            {
                _mashup.GetStream().CopyTo(memoryStream);
                mashupBytes = memoryStream.ToArray();
            }

            QDEFF qdeff = new QDEFF(mashupBytes);

            qdeff.ReplaceKnownVariable(variable, newValue);

            byte[] newContent = qdeff.RecreateContent();

            _mashup.GetStream().Write(newContent, 0, newContent.Length);
            _mashup.GetStream().SetLength(newContent.Length);
            _mashup.GetStream().Flush();
            _pbixPackage.Flush();
        }
Beispiel #3
0
            public static void WriteZip(string packagePath, string[] filePathes, string[] contentTypes, HttpResponse response, string fileName)
            {
                if (filePathes.Length != contentTypes.Length)
                {
                    throw new ArgumentException("The lengths of the number of files and the content types should be equal");
                }

                response.Clear();
                response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".zip");
                response.ContentType = "application/zip";

                using (ZipPackage package = (ZipPackage)Package.Open(packagePath, FileMode.Create))
                {
                    for (int i = 0; i < filePathes.Length; i++)
                    {
                        string destFilename = ".\\" + Path.GetFileName(filePathes[i]);
                        Uri    uri          = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.RelativeOrAbsolute));
                        if (package.PartExists(uri))
                        {
                            package.DeletePart(uri);
                        }
                        PackagePart part = package.CreatePart(uri, "", CompressionOption.Normal);
                        using (FileStream fileStream = new FileStream(filePathes[i], FileMode.Open, FileAccess.Read))
                        {
                            using (Stream dest = part.GetStream())
                            {
                                CopyStream(fileStream, dest);
                            }
                        }
                    }

                    package.Flush();
                }

                response.Write(packagePath);

                response.Flush();
                response.Close();
            }