Пример #1
0
        public byte[] GetXmlBytes(IDataProtection dataProtection)
        {
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Indent   = true;
            xmlWriterSettings.Encoding = Encoding.UTF8;
            MemoryStream memoryStream = new MemoryStream();
            XmlWriter    xmlWriter    = XmlWriter.Create(memoryStream, xmlWriterSettings);

            using (xmlWriter)
            {
                xmlWriter.WriteStartElement("DataSourceDefinition", "http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource");
                xmlWriter.WriteElementString("Extension", Extension);
                xmlWriter.WriteElementString("ConnectString", GetConnectionString(dataProtection));
                xmlWriter.WriteElementString("CredentialRetrieval", CredentialsRetrieval.ToString());
                if (CredentialsRetrieval == CredentialsRetrievalOption.Prompt || CredentialsRetrieval == CredentialsRetrievalOption.Store)
                {
                    xmlWriter.WriteElementString("WindowsCredentials", WindowsCredentials.ToString());
                }
                if (CredentialsRetrieval == CredentialsRetrievalOption.Prompt)
                {
                    xmlWriter.WriteElementString("Prompt", string.IsNullOrEmpty(Prompt) ? "" : Prompt);
                }
                if (CredentialsRetrieval == CredentialsRetrievalOption.Store)
                {
                    xmlWriter.WriteElementString("ImpersonateUser", ImpersonateUser.ToString());
                }
                xmlWriter.WriteElementString("Enabled", Enabled.ToString());
                xmlWriter.WriteEndElement();
                xmlWriter.Flush();
                return(memoryStream.ToArray());
            }
        }