/// <summary>
        /// Initialize export request for report
        /// </summary>
        /// <returns>Id of Export request</returns>
        private async Task <string> InitExportRequest(string pageName, FileFormat fileFormat, string pageState = null, string username = null, string role = null)
        {
            PageBookmark pageBookmark = null;

            if (!string.IsNullOrWhiteSpace(pageState))
            {
                // To export report page with current bookmark
                pageBookmark = new PageBookmark(null, pageState);
            }

            // Get Power BI report object
            var pbiReport = pbiClient.Reports.GetReportInGroup(workspaceId, reportId);

            // Create effective identity for current user
            List <EffectiveIdentity> identities = null;

            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(role))
            {
                identities = new List <EffectiveIdentity> {
                    new EffectiveIdentity(username: username, roles: new List <string> {
                        role
                    }, datasets: new List <string> {
                        pbiReport.DatasetId
                    })
                };
            }

            var powerBIReportExportConfiguration = new PowerBIReportExportConfiguration
            {
                Settings = new ExportReportSettings
                {
                    Locale = Constant.DefaultLocale
                },

                // Initialize list of pages along with their state to be exported
                Pages = new List <ExportReportPage>()
                {
                    new ExportReportPage(pageName, pageBookmark)
                },

                Identities = identities
            };

            var exportRequest = new ExportReportRequest
            {
                Format = fileFormat,
                PowerBIReportConfiguration = powerBIReportExportConfiguration,
            };

            // Initiate export process
            var export = await pbiClient.Reports.ExportToFileInGroupAsync(workspaceId, reportId, exportRequest);

            return(export.Id);
        }
예제 #2
0
        public virtual IList <PageBookmark> GetAllPageBookmarksByBookId(string bookXmlId, long userId)
        {
            using (var session = GetSession())
            {
                PageBookmark pageBookmarkAlias = null;
                Book         bookAlias         = null;

                return(session.QueryOver(() => pageBookmarkAlias)
                       .JoinAlias(() => pageBookmarkAlias.Book, () => bookAlias)
                       .Where(() => bookAlias.Guid == bookXmlId && pageBookmarkAlias.User.Id == userId)
                       .Fetch(x => x.FavoriteLabel).Eager
                       .List <PageBookmark>());
            }
        }
예제 #3
0
        public IList <long> CreatePageBookmark(string bookXmlId, string pageXmlId, string title, IList <long> labelIds)
        {
            var now      = DateTime.UtcNow;
            var user     = TryGetUser();
            var bookPage = m_bookVersionRepository.GetPageByXmlId(bookXmlId, pageXmlId);

            if (bookPage == null)
            {
                string message = string.Format("Page not found for bookXmlId: '{0}' and page xmlId: '{1}'", bookXmlId, pageXmlId);
                if (m_log.IsErrorEnabled)
                {
                    m_log.Error(message);
                }
                throw new ArgumentException(message);
            }

            var labels           = GetFavoriteLabelsAndCheckAuthorization(labelIds, user.Id);
            var labelsDictionary = labels.ToDictionary(x => x.Id);
            var itemsToSave      = new List <PageBookmark>();

            foreach (var labelId in labelIds)
            {
                var label = labelsDictionary[labelId];
                label.LastUseTime = now;

                Book         book         = m_bookVersionRepository.Load <Book>(bookPage.BookVersion.Book.Id);
                PageBookmark favoriteItem = new PageBookmark
                {
                    PageXmlId     = pageXmlId,
                    User          = user,
                    PagePosition  = bookPage.Position,
                    Book          = book,
                    Title         = title,
                    FavoriteLabel = label,
                    CreateTime    = now,
                };

                itemsToSave.Add(favoriteItem);
            }

            var result = m_favoritesRepository.CreateAll(itemsToSave);

            return(result.Cast <long>().ToList());
        }