Пример #1
0
 void IReceiveOptions.ReceiveFrom(OptionSet options)
 {
     options.AddCollector(ObjectFilter);
     options.Add("site=", "Only include objects associated with a specific site", o => Site = o);
     options.Add("base=", "Specify a base path to assume for all items", o => BasePath      = new SsrsObjectPath(o));
     options.Add("timeout=", "Number of seconds to wait for SSRS webservice responses", (int o) => ReportingServiceClientFactory.Timeout = TimeSpan.FromSeconds(o));
 }
Пример #2
0
        private SsrsDataSource ReadDataSource(XDocument xml, string itemName, SsrsObjectPath containerPath)
        {
            var connectionString = new DataSourceXmlSchema().GetConnectionString(xml);

            return(new SsrsDataSource {
                Name = itemName,
                Path = containerPath + itemName,
                ConnectionString = connectionString,
                Authentication = GetAuthenticationType()
            });

            SsrsDataSource.AuthenticationType GetAuthenticationType()
            {
                var credentials        = ConnectionStringUtils.GetNetworkCredentials(connectionString);
                var integratedSecurity = new DataSourceXmlSchema().GetIntegratedSecurity(xml);

                if (credentials != null)
                {
                    return(new SsrsDataSource.AuthenticationType.StoredCredentials {
                        UserName = credentials.UserName,
                        Domain = credentials.Domain,
                        Password = credentials.Password,
                        WindowsCredentials = integratedSecurity
                    });
                }
                if (integratedSecurity)
                {
                    return(new SsrsDataSource.AuthenticationType.WindowsIntegrated());
                }
                return(new SsrsDataSource.AuthenticationType.None());
            }
        }
Пример #3
0
        private IEnumerable <SsrsObject> MapFilesToSsrsObjects(SsrsObjectFilter filter)
        {
            var rootContainer = new DirectoryInfo(directoryPath);

            if (!rootContainer.Exists)
            {
                yield break;
            }
            var siteFilter = GetSiteFilter(filter.Site);

            foreach (var relativePath in new RelativeDirectoryExplorer().EnumerateRelativeFiles(rootContainer))
            {
                var containerPath = basePath + SsrsObjectPath.FromFileSystemPath(Path.GetDirectoryName(relativePath));
                var ssrsObject    = new SsrsObjectFileReader().Read(Path.Combine(directoryPath, relativePath), containerPath);
                if (filter.Excludes(ssrsObject))
                {
                    continue;
                }
                if (siteFilter?.Matches(ssrsObject.Path) == false)
                {
                    continue;
                }
                yield return(ssrsObject);
            }
        }
Пример #4
0
 public SsrsObject Read(Stream stream, string itemName, SsrsObjectPath containerPath)
 {
     if (!TryLoadXml(stream, out var xml))
     {
         return(null);
     }
     return(ReadXml(xml, itemName, containerPath));
 }
 private SsrsObjectPath ResolveReference(SsrsObjectPath item, string reference)
 {
     if (reference.StartsWith("/"))
     {
         return(new SsrsObjectPath(reference));
     }
     return(item.Parent + reference);
 }
        private string GetOrCreateContainer(SsrsObjectPath path)
        {
            var container     = path.Parent;
            var directoryPath = Path.Combine(basePath, container.AsRelativeFileSystemPath());

            Directory.CreateDirectory(directoryPath);
            return(directoryPath);
        }
Пример #7
0
 private SsrsReport ReadReport(XDocument xml, string itemName, SsrsObjectPath containerPath)
 {
     return(new SsrsReport {
         Name = itemName,
         Path = containerPath + itemName,
         Definition = new XmlObjectDefinition(xml)
     });
 }
Пример #8
0
 void IReceiveOptions.ReceiveFrom(OptionSet options)
 {
     options.AddCollector(ObjectFilter);
     options.Add("site=", "Only include objects associated with a specific site", o => Site = o.Unquote("'"));
     options.Add("base=", "Specify a base path to assume for all items", o => BasePath      = new SsrsObjectPath(o));
     options.Add("overwrite", "Replace existing objects", o => Overwrite          = true);
     options.Add("backup=", "Back up objects before overwriting", o => BackupPath = o);
     options.Add("rewrite=", "Modify objects prior to import", o => RewriteRules.Add(o.Unquote("'")));
     options.Add("timeout=", "Number of seconds to wait for SSRS webservice responses", (int o) => ReportingServiceClientFactory.Timeout = TimeSpan.FromSeconds(o));
 }
Пример #9
0
 public SsrsObject Read(string filePath, SsrsObjectPath containerPath)
 {
     using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         if (!TryLoadXml(fileStream, out var xml))
         {
             return(null);
         }
         return(ReadXml(xml, Path.GetFileNameWithoutExtension(filePath), containerPath));
     }
 }
        public SsrsDataSource MapToSsrsObject(string itemPath, DataSourceDefinition definition)
        {
            var path = new SsrsObjectPath(itemPath);

            return(new SsrsDataSource {
                Name = path.Name,
                Path = path,
                ConnectionString = definition.ConnectString,
                Authentication = MapToAuthenticationType(definition)
            });
        }
Пример #11
0
        private SsrsDataSet ReadDataSet(XDocument xml, string itemName, SsrsObjectPath containerPath)
        {
            var dataSourceReference = new DataSetXmlSchema().GetDataSourceReference(xml);

            return(new SsrsDataSet {
                Name = itemName,
                Path = containerPath + itemName,
                DataSourceReference = dataSourceReference.StartsWith("/") ? new SsrsObjectPath(dataSourceReference) : containerPath + dataSourceReference,
                Definition = new XmlObjectDefinition(xml)
            });
        }
Пример #12
0
        private SsrsDataSource BuildDataSource()
        {
            var path = new SsrsObjectPath(ObjectPath);

            return(new SsrsDataSource {
                Name = path.Name,
                Path = path,
                ConnectionString = ConnectionString,
                Authentication = BuildDataSourceAuthenticationType()
            });
        }
Пример #13
0
        public SingleFileObjectSource(string filePath, SsrsObjectPath basePath = null)
        {
            if (String.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }
            if (!Path.IsPathRooted(filePath))
            {
                throw new ArgumentException($"Not an absolute path: {filePath}");
            }

            this.filePath = filePath;
            this.basePath = basePath;
        }
        private IEnumerable <SsrsObject> MapEntriesToSsrsObjects(ZipArchiveEntry[] items, SsrsObjectFilter filter)
        {
            var siteFilter = GetSiteFilter(filter.Site);

            foreach (var item in items)
            {
                var containerPath = basePath + SsrsObjectPath.FromFileSystemPath(Path.GetDirectoryName(item.FullName));
                using (var stream = item.Open())
                {
                    var ssrsObject = new SsrsObjectFileReader().Read(stream, Path.GetFileNameWithoutExtension(item.Name), containerPath);
                    if (filter.Excludes(ssrsObject))
                    {
                        continue;
                    }
                    if (siteFilter?.Matches(ssrsObject.Path) == false)
                    {
                        continue;
                    }
                    yield return(ssrsObject);
                }
            }
        }
Пример #15
0
 public SsrsObject ReadXml(XDocument xml, string itemName, SsrsObjectPath containerPath)
 {
     try
     {
         if (xml.Root.Name == "RptDataSource")
         {
             return(ReadDataSource(xml, itemName, containerPath));
         }
         if (xml.Root.Name.LocalName == "Report" && ReportXmlSchema.IsReportNamespace(xml.Root.Name.Namespace, out _, out _))
         {
             return(ReadReport(xml, itemName, containerPath));
         }
         if (xml.Root.Name.LocalName == "SharedDataSet" && DataSetXmlSchema.IsDataSetNamespace(xml.Root.Name.Namespace, out _, out _))
         {
             return(ReadDataSet(xml, itemName, containerPath));
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw new SsrsObjectParseException(containerPath + itemName, ex);
     }
 }
        public static async Task <string> GetOrCreateContainer(this IReportingServiceClient service, SsrsObjectPath path, ILog log = null)
        {
            var container = path.Parent;

            if (container.IsRoot)
            {
                return(container.ToString());
            }
            if (await ItemExists(service, container))
            {
                return(container.ToString());
            }

            var parentContainer = await GetOrCreateContainer(service, container, log);

            log?.DebugFormat("Creating folder: '{0}'", container);
            var response = await service.Proxy.CreateFolderAsync(new CreateFolderRequest {
                TrustedUserHeader = new TrustedUserHeader(),
                Folder            = container.Name,
                Parent            = parentContainer
            });

            return(response.ItemInfo.Path);
        }
Пример #17
0
 public SiteManifestReader(SsrsObjectPath basePath)
 {
     this.basePath = basePath ?? throw new ArgumentNullException(nameof(basePath));
 }
 public SsrsObjectParseException(SsrsObjectPath path, Exception innerException) : base($"Failed to parse '{path}'", innerException)
 {
 }
Пример #19
0
 public void FromFileSystemPath(string path, string expectedPath)
 {
     Assert.That(SsrsObjectPath.FromFileSystemPath(path), Is.EqualTo(new SsrsObjectPath(expectedPath)));
 }
 public ZipFileObjectSource(string zipFilePath, SsrsObjectPath basePath = null)
 {
     this.zipFilePath = zipFilePath ?? throw new ArgumentNullException(nameof(zipFilePath));
     this.basePath    = basePath;
 }
Пример #21
0
 public DirectoryObjectSource(string directoryPath, SsrsObjectPath basePath = null)
 {
     this.directoryPath = directoryPath ?? throw new ArgumentNullException(nameof(directoryPath));
     this.basePath      = basePath;
 }
        public static async Task <bool> ItemExists(this IReportingServiceClient service, SsrsObjectPath path, ILog log = null)
        {
            var response = await service.Proxy.GetItemTypeAsync(new GetItemTypeRequest {
                TrustedUserHeader = new TrustedUserHeader(),
                ItemPath          = path.ToString()
            });

            if (!Enum.TryParse <CatalogItemType>(response.Type, out var type) || type == CatalogItemType.Unknown)
            {
                log?.DebugFormat("Item does not exist: '{0}', type = '{1}'", path, response.Type);
                return(false);
            }
            log?.DebugFormat("Item exists: '{0}', type = '{1}'", path, response.Type);
            return(true);
        }