public void ToReportingService_IntegratedSecurity()
        {
            var filename = FileOnDisk.CreatePhysicalFile("AdventureWorks_Integrated.rds", "RsPackage.Testing.Resources.AdventureWorks.rds");

            var visualStudioDoc = new XmlDocument();

            visualStudioDoc.Load(filename);

            var transformer         = new DataSourceTransformer();
            var reportingServiceDoc = transformer.ToReportingService(visualStudioDoc);

            Assert.That(reportingServiceDoc.FirstChild.NodeType, Is.EqualTo(XmlNodeType.XmlDeclaration));
            Assert.That(reportingServiceDoc.ChildNodes.Count, Is.EqualTo(2));
            Assert.That(reportingServiceDoc.LastChild.NodeType, Is.EqualTo(XmlNodeType.Element));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes.Count, Is.EqualTo(4));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes[0].Name, Is.EqualTo("Extension"));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes[0].InnerText, Is.EqualTo("SQL"));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes[1].Name, Is.EqualTo("ConnectString"));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes[2].Name, Is.EqualTo("CredentialRetrieval"));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes[2].InnerText, Is.EqualTo("Integrated"));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes[3].Name, Is.EqualTo("Enabled"));
            Assert.That(reportingServiceDoc.LastChild.ChildNodes[3].InnerText, Is.EqualTo("True"));
        }
        public virtual void Create(string name, string parent, string path, bool overwrite)
        {
            //If file extension is not specied we need to check the existence of both
            if (Path.GetExtension(path) != ".rsds" && Path.GetExtension(path) != ".rds")
            {
                if (File.Exists($"{path}.rsds"))
                {
                    path = $"{path}.rsds";
                }
                else
                {
                    path = $"{path}.rds";
                }
            }

            //If file is not found then we must throw an error
            if (!File.Exists(path))
            {
                OnError($"File '{path}' doesn't exist!");
                return;
            }

            // If file is a Visual Studio connection-string then we need to transform it
            if (Path.GetExtension(path) == ".rds")
            {
                var document = new XmlDocument();
                document.Load(path);

                var transformer = new DataSourceTransformer();
                if (transformer.IsVisualStudio(document))
                {
                    var newDocument = transformer.ToReportingService(document);
                    path = Path.ChangeExtension(path, ".rsds");
                    newDocument.Save(path);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            //If it's a rsds file we need to ensure it's a valid Reporting Server connection string
            if (Path.GetExtension(path) == ".rsds")
            {
                var document = new XmlDocument();
                document.Load(path);

                var transformer = new DataSourceTransformer();
                if (!transformer.IsReportingService(document))
                {
                    throw new InvalidOperationException();
                }
            }

            Byte[] definition = null;
            try
            {
                using (FileStream stream = File.OpenRead(path))
                {
                    definition = new Byte[stream.Length];
                    stream.Read(definition, 0, (int)stream.Length);
                }
            }
            catch (IOException e)
            {
                OnInformation(e.Message);
            }

            Warning[] warnings = null;
            OnInformation($"Creating DataSource '{name}' in '{parent}'");
            reportingService.CreateCatalogItem("DataSource", name, parent, overwrite, definition, null, out warnings);

            if (warnings != null)
            {
                foreach (var warning in warnings)
                {
                    OnWarning(warning.Message);
                }
            }
        }