/// <summary>
    /// Constructor.  Builds the data for the CSV file
    /// </summary>
    /// <param name="projects"></param>
    /// <param name="dataSources"></param>
    /// <param name="workbooks"></param>
    /// <param name="users"></param>
    /// <param name="groups"></param>
    public CustomerSiteInventory(
      IEnumerable<SiteProject> projects, 
      IEnumerable<SiteDatasource> dataSources,
      IEnumerable<SiteWorkbook> workbooks,
      IEnumerable<SiteUser> users,
      IEnumerable<SiteGroup> groups,
      TaskStatusLogs statusLogger)
  {
        //Somewhere to store status logs
        if (statusLogger == null)
        {
            statusLogger = new TaskStatusLogs();
        }
        this.StatusLog = statusLogger;

        //If we have a user-set, put it into a lookup class so we can quickly look up user names when we write out other data
        //that has user ids
        if(users != null)
        {
            _siteUserMapping = new KeyedLookup<SiteUser>(users);
        }

      AddProjectsData(projects);
      AddDatasourcesData(dataSources);
      AddWorkbooksData(workbooks);
      AddUsersData(users);
      AddGroupsData(groups);
  }
    /// <summary>
    /// Constructor.  Builds the data for the CSV file
    /// </summary>
    /// <param name="projects"></param>
    /// <param name="dataSources"></param>
    /// <param name="workbooks"></param>
    /// <param name="users"></param>
    /// <param name="groups"></param>
    public CustomerSiteInventory(
        IEnumerable <SiteProject> projects,
        IEnumerable <SiteDatasource> dataSources,
        IEnumerable <SiteWorkbook> workbooks,
        IEnumerable <SiteUser> users,
        IEnumerable <SiteGroup> groups,
        TaskStatusLogs statusLogger)
    {
        //Somewhere to store status logs
        if (statusLogger == null)
        {
            statusLogger = new TaskStatusLogs();
        }
        this.StatusLog = statusLogger;

        //If we have a user-set, put it into a lookup class so we can quickly look up user names when we write out other data
        //that has user ids
        if (users != null)
        {
            _siteUserMapping = new KeyedLookup <SiteUser>(users);
        }

        AddProjectsData(projects);
        AddDatasourcesData(dataSources);
        AddWorkbooksData(workbooks);
        AddUsersData(users);
        AddGroupsData(groups);
    }
Ejemplo n.º 3
0
        public static IKeyedLookup <TKey, TItem> Create <TKey, TItem>(
            this IKeyedLookup <TKey, TItem>?template,
            Messenger messenger,
            Action <Configurator <ILookupMutator <TKey, TItem> > > config
            ) where TKey : notnull
        {
            var collection   = new KeyedLookup <TKey, TItem>();
            var configurator = new Configurator <ILookupMutator <TKey, TItem> >(
                messenger,
                new KeyedLookupMutator <TKey, TItem>(collection));

            config(configurator);
            return(collection);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Looks
    /// </summary>
    /// <param name="ownerId">GUID of content owner</param>
    /// <param name="userLookups">set we are looking the owner up in</param>
    /// <returns></returns>
    internal static string helper_LookUpOwnerId(string ownerId, KeyedLookup <SiteUser> userLookups)
    {
        //Sanity test
        AppDiagnostics.Assert(!string.IsNullOrWhiteSpace(ownerId), "blank owner id to look up?");

        string contentOwnerName;
        var    contentOwner = userLookups.FindItem(ownerId);

        //This should only ever happen if there is a race condition between getting the list of users, and downloading the content, where a user did not exist when we asked for the list of users
        //Should be very rare
        if (contentOwner == null)
        {
            return(UnknownOwnerName);
        }
        return(contentOwnerName = contentOwner.Name);
    }
Ejemplo n.º 5
0
 public DownloadDatasources(
     TableauServerUrls onlineUrls,
     TableauServerSignIn login,
     IEnumerable <SiteDatasource> datasources,
     string localSavePath,
     IProjectsList projectsList,
     bool generateInfoFile,
     KeyedLookup <SiteUser> siteUserLookup,
     IHttpClientFactory httpClientFactory)
     : base(onlineUrls, login, httpClientFactory)
 {
     Datasources   = datasources;
     LocalSavePath = localSavePath;
     DownloadToProjectDirectories = projectsList;
     GenerateInfoFile             = generateInfoFile;
     SiteUserLookup = siteUserLookup;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onlineUrls"></param>
 /// <param name="login"></param>
 /// <param name="workbooks"></param>
 /// <param name="localSavePath"></param>
 /// <param name="projectsList"></param>
 /// <param name="generateInfoFile">TRUE = Generate companion file for each download that contains metadata (e.g. whether "show tabs" is selected, the owner, etc)</param>
 /// <param name="siteUsersLookup">If not NULL, use to look up the owners name, so we can write it into the InfoFile for the downloaded content</param>
 public DownloadWorkbooks(
     TableauServerUrls onlineUrls, 
     TableauServerSignIn login, 
     IEnumerable<SiteWorkbook> workbooks,
     string localSavePath,
     IProjectsList projectsList,
     bool generateInfoFile,
     KeyedLookup<SiteUser> siteUserLookup)
     : base(login)
 {
     _onlineUrls = onlineUrls;
     _workbooks = workbooks;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
     _generateInfoFile = generateInfoFile;
     _siteUserLookup = siteUserLookup;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="onlineUrls"></param>
 /// <param name="login"></param>
 /// <param name="Datasources"></param>
 /// <param name="localSavePath"></param>
 /// <param name="projectsList"></param>
 /// <param name="generateInfoFile">TRUE = Generate companion file for each download that contains metadata (e.g. whether "show tabs" is selected, the owner, etc)</param>
 /// <param name="siteUsersLookup">If not NULL, use to look up the owners name, so we can write it into the InfoFile for the downloaded content</param>
 public DownloadDatasources(
     TableauServerUrls onlineUrls,
     TableauServerSignIn login,
     IEnumerable <SiteDatasource> Datasources,
     string localSavePath,
     IProjectsList projectsList,
     bool generateInfoFile,
     KeyedLookup <SiteUser> siteUserLookup)
     : base(login)
 {
     _onlineUrls    = onlineUrls;
     _datasources   = Datasources;
     _localSavePath = localSavePath;
     _downloadToProjectDirectories = projectsList;
     _generateInfoFile             = generateInfoFile;
     _siteUserLookup = siteUserLookup;
 }
    /// <summary>
    /// Save Datasource metadata in a XML file along-side the workbook file
    /// </summary>
    /// <param name="wb">Information about the workbook we have downloaded</param>
    /// <param name="localDatasourcePath">Local path to the twb/twbx of the workbook</param>
    /// <param name="userLookups">If non-NULL contains the mapping of users/ids so we can look up the owner</param>
    internal static void CreateSettingsFile(SiteDatasource ds, string localDatasourcePath, KeyedLookup<SiteUser> userLookups)
    {
        string contentOwnerName = null; //Start off assuming we have no content owner information
        if (userLookups != null)
        {
            contentOwnerName = WorkbookPublishSettings.helper_LookUpOwnerId(ds.OwnerId, userLookups);
        }

        var xml = System.Xml.XmlWriter.Create(PathForSettingsFile(localDatasourcePath));
        xml.WriteStartDocument();
            xml.WriteStartElement(XmlElement_DatasourceInfo);

                //If we have an owner name, write it out
                if (!string.IsNullOrWhiteSpace(contentOwnerName))
                {
                  XmlHelper.WriteValueElement(xml,  WorkbookPublishSettings.XmlElement_ContentOwner, contentOwnerName);
                }
            xml.WriteEndElement(); //end: WorkbookInfo
        xml.WriteEndDocument();
        xml.Close();
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Download the workbooks
    /// </summary>
    /// <param name="onlineLogin">logged in session</param>
    /// <param name="exportToPath">local path to export to</param>
    /// <param name="projectsList">project id/name mapping</param>
    /// <param name="singleProjectIdFilter">if specified, export only from a single project</param>
    /// <param name="exportOnlyWithThisTag">if specified, export only content with this tag</param>
    /// <param name="deleteTagAfterExport">TRUE: Remove the server-side tag from exported content (only valid if we have an export tag)</param>
    /// <param name="generateInfoFile">TRUE: Each downloaded workbook will get an information file generated that has additional metadata about it</param>
    /// <param name="siteUsers"> If not NULL, then this will get used to look the user name for each downloaded workbook, and safe it into the info file</param>
    private void Execute_DownloadWorkbooks(
        TableauServerSignIn onlineLogin, 
        string exportToPath, 
        IProjectsList projectsList,
        SiteProject singleProjectIdFilter = null,
        string exportOnlyWithThisTag      = null,
        bool deleteTagAfterExport         = false,
        bool generateInfoFile             = false,
        IEnumerable<SiteUser> siteUsers   = null
        )
    {
        var onlineUrls = _onlineUrls;
        _statusLog.AddStatusHeader("Download workbooks");

        //Get the UserID we need to use for the workbooks query.
        var explicitUserId = onlineLogin.UserId; //See if we have a default user id

        //===================================================================================
        //Workbooks...
        //===================================================================================
        ICollection<SiteWorkbook> workbooksList = null;
        try
        {
            var workbooks = new DownloadWorkbooksList(onlineUrls, onlineLogin, explicitUserId);
            //Query for the list of workbook
            workbooks.ExecuteRequest();
            workbooksList = workbooks.Workbooks;

        }
        catch (Exception exWorkbooksList)
        {
            _statusLog.AddError("Error querying for list of workbooks, " + exWorkbooksList.Message.ToString());
            return;
        }

        //No list of workbooks?  Exit.
        if(workbooksList == null)
        {
            _statusLog.AddStatus("Aborting workbooks download");
            return;
        }

        //====================================================================================================
        //Apply filters to the list of content to see if we need to reduce the set of content to be downloaded
        //====================================================================================================
        var filteredList = workbooksList;
        _statusLog.AddStatus("Download workbooks count before filters: " + filteredList.Count.ToString());

        //See if we have a PROJECTS filter to apply to the set of content to be downloaded
        filteredList = FilterProjectMembership<SiteWorkbook>.KeepOnlyProjectMembers(
                            filteredList,
                            singleProjectIdFilter,
                            true);
        _statusLog.AddStatus("Download workbooks count after projects filter: " + filteredList.Count.ToString());

        //See if we have a TAGS filter to apply to the set of content to be downloaded
        filteredList = FilterTagSet<SiteWorkbook>.KeepOnlyTagged(
            filteredList,
            exportOnlyWithThisTag,
            true);
        _statusLog.AddStatus("Download workbooks count after tags filter: " + filteredList.Count.ToString());

        //-----------------------------------------------------------
        //Download the workbooks
        //-----------------------------------------------------------
        var workbookPath = Path.Combine(exportToPath, "workbooks");
        ICollection<SiteWorkbook> successfullExportSet = null;
        FileIOHelper.CreatePathIfNeeded(workbookPath);

        //If we are going to write out metadata for each download, then create the object that lets us look up the owner of each workbook
        KeyedLookup<SiteUser> workbookOwnerLookup = null;
        if ((generateInfoFile) && (siteUsers != null))
        {
            workbookOwnerLookup = new KeyedLookup<SiteUser>(siteUsers);
        }
        //Do the downloads......
        try
        {
            //Create the workbooks downloader
            var workbookDownloads = new DownloadWorkbooks(
                onlineUrls,
                onlineLogin,
                filteredList,
                workbookPath,
                projectsList,
                generateInfoFile,
                workbookOwnerLookup);
            successfullExportSet = workbookDownloads.ExecuteRequest();
        }
        catch (Exception exWorkbooksDownload)
        {
            _statusLog.AddError("Error during workbooks download, " + exWorkbooksDownload.ToString());
        }

        //--------------------------------------------------------------------------------
        //Do we want to remove tags from successfully downloaded content?
        //--------------------------------------------------------------------------------
        if ((successfullExportSet != null) && (deleteTagAfterExport) && (!string.IsNullOrWhiteSpace(exportOnlyWithThisTag)))
        {
            Execute_DeleteTagFromWorkbooks(onlineLogin, successfullExportSet, exportOnlyWithThisTag);
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="onlineLogin"></param>
    /// <param name="exportToPath"></param>
    /// <param name="projectsList"></param>
    /// <param name="singleProjectIdFilter"></param>
    /// <param name="exportOnlyWithThisTag"></param>
    /// <param name="deleteTagAfterExport"></param>
    /// <param name="generateInfoFile">TRUE: Each downloaded workbook will get an information file generated that has additional metadata about it</param>
    /// <param name="siteUsers"> If not NULL, then this will get used to look the user name for each downloaded workbook, and safe it into the info file</param>
    private void Execute_DownloadDatasources(
        TableauServerSignIn onlineLogin, 
        string exportToPath, 
        IProjectsList projectsList,
        SiteProject singleProjectIdFilter = null,
        string exportOnlyWithThisTag      = null,
        bool deleteTagAfterExport         = false,
        bool generateInfoFile             = false,
        IEnumerable<SiteUser>   siteUsers = null
        )
    {
        _statusLog.AddStatusHeader("Download datasources");
        ICollection<SiteDatasource> datasourcesList = null;
        try
        {
            //Get the list of datasources
            var datasourcesManager = new DownloadDatasourcesList(_onlineUrls, onlineLogin);
            datasourcesManager.ExecuteRequest();
            datasourcesList = datasourcesManager.Datasources;
        }
        catch(Exception exGetContentList)
        {
            _statusLog.AddError("Error querying for list of datasources, " + exGetContentList.Message.ToString());
        }

        if(datasourcesList == null)
        {
            _statusLog.AddError("Aborting datasources download");
            return;
        }

        //====================================================================================================
        //Apply filters to the list of content to see if we need to reduce the set of content to be downloaded
        //====================================================================================================
        var filteredList = datasourcesList;
        _statusLog.AddStatus("Download datasources count before filters: " + filteredList.Count.ToString());

        //See if we have a PROJECTS filter to apply to the set of content to download
        filteredList = FilterProjectMembership<SiteDatasource>.KeepOnlyProjectMembers(
            filteredList,
            singleProjectIdFilter,
            true);
        _statusLog.AddStatus("Download datasources count after projects filter: " + filteredList.Count.ToString());

        //See if we have a TAGS filter to apply to the set of content to be downloaded
        filteredList = FilterTagSet<SiteDatasource>.KeepOnlyTagged(
            filteredList,
            exportOnlyWithThisTag,
            true);
        _statusLog.AddStatus("Download datasources count after tags filter: " + filteredList.Count.ToString());

        ICollection<SiteDatasource> successfullExportSet = null;
        var datasourcePath = Path.Combine(exportToPath, "datasources");
        FileIOHelper.CreatePathIfNeeded(datasourcePath);

        //-----------------------------------------------------------
        //Download the data sources
        //-----------------------------------------------------------
        //If we are going to write out metadata for each download, then create the object that lets us look up the owner of each workbook
        KeyedLookup<SiteUser> contentOwnerLookup = null;
        if ((generateInfoFile) && (siteUsers != null))
        {
            contentOwnerLookup = new KeyedLookup<SiteUser>(siteUsers);
        }
        try
        {
            var datasourceDownloads = new DownloadDatasources(
                _onlineUrls,
                onlineLogin,
                filteredList,
                datasourcePath,
                projectsList,
                generateInfoFile,
                contentOwnerLookup);
            successfullExportSet = datasourceDownloads.ExecuteRequest();
        }
        catch (Exception exDatasourceDownload)
        {
            _statusLog.AddError("Error during datasource download, " + exDatasourceDownload.ToString());
        }

        //--------------------------------------------------------------------------------
        //Do we want to remove tags from successfully downloaded content?
        //--------------------------------------------------------------------------------
        if ((successfullExportSet != null) && (deleteTagAfterExport) && (!string.IsNullOrWhiteSpace(exportOnlyWithThisTag)))
        {
            Execute_DeleteTagFromDatasources(onlineLogin, successfullExportSet, exportOnlyWithThisTag);
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Save Workbook metadata in a XML file along-side the workbook file
    /// </summary>
    /// <param name="wb">Information about the workbook we have downloaded</param>
    /// <param name="localWorkbookPath">Local path to the twb/twbx of the workbook</param>
    /// <param name="userLookups">If non-NULL contains the mapping of users/ids so we can look up the owner</param>
    internal static void CreateSettingsFile(SiteWorkbook wb, string localWorkbookPath, KeyedLookup <SiteUser> userLookups)
    {
        string contentOwnerName = null; //Start off assuming we have no content owner information

        if (userLookups != null)
        {
            contentOwnerName = helper_LookUpOwnerId(wb.OwnerId, userLookups);
        }

        var xml = System.Xml.XmlWriter.Create(PathForSettingsFile(localWorkbookPath));

        xml.WriteStartDocument();
        xml.WriteStartElement(XmlElement_WorkbookInfo);
        XmlHelper.WriteValueElement(xml, XmlElement_ShowTabsInWorkbook, wb.ShowTabs);

        //If we have an owner name, write it out
        if (!string.IsNullOrWhiteSpace(contentOwnerName))
        {
            XmlHelper.WriteValueElement(xml, XmlElement_ContentOwner, contentOwnerName);
        }
        xml.WriteEndElement();     //end: WorkbookInfo
        xml.WriteEndDocument();
        xml.Close();
    }
Ejemplo n.º 12
0
 public KeyedLookupMutator(KeyedLookup <TKey, TItem> collection) : base(collection)
     => _collection = collection;
    /// <summary>
    /// Constructor.  Builds the data for the CSV file
    /// </summary>
    /// <param name="projects"></param>
    /// <param name="dataSources"></param>
    /// <param name="workbooks"></param>
    /// <param name="users"></param>
    /// <param name="groups"></param>
    public CustomerSiteInventory(
        IEnumerable <SiteProject> projects,
        IEnumerable <SiteDatasource> dataSources,
        IEnumerable <SiteWorkbook> workbooks,
        IEnumerable <SiteView> views,
        IEnumerable <SiteUser> users,
        IEnumerable <SiteGroup> groups,
        IEnumerable <SiteSubscription> subscriptions,
        IEnumerable <SiteSchedule> schedules,
        IEnumerable <SiteTaskExtractRefresh> extractRefreshTasks,
        TaskStatusLogs statusLogger)
    {
        //Somewhere to store status logs
        if (statusLogger == null)
        {
            statusLogger = new TaskStatusLogs();
        }
        this.StatusLog = statusLogger;

        //If we have a user-set, put it into a lookup class so we can quickly look up user names when we write out other data
        //that has user ids
        if (users != null)
        {
            _siteUserMapping = new KeyedLookup <SiteUser>(users, statusLogger);
        }

        //Want to be able to map views to workbooks (e.g. in subscriptions)
        if (views != null)
        {
            _siteViewMapping = new KeyedLookup <SiteView>(views, statusLogger);
        }

        //Want to be able to map workbooks to workbook names (e.g. in subscriptions)
        if (workbooks != null)
        {
            _siteWorkbookMapping = new KeyedLookup <SiteWorkbook>(workbooks, statusLogger);
        }

        if (dataSources != null)
        {
            _siteDatasourceMapping = new KeyedLookup <SiteDatasource>(dataSources, statusLogger);
        }

        if (projects != null)
        {
            _siteProjectMapping = new KeyedLookup <SiteProject>(projects, statusLogger);
        }

        //Want to be able to map
        if (schedules != null)
        {
            _siteScheduleMapping = new KeyedLookup <SiteSchedule>(schedules, statusLogger);
        }


        AddProjectsData(projects);
        AddDatasourcesData(dataSources);
        AddWorkbooksData(workbooks);
        AddUsersData(users);
        AddGroupsData(groups);
        AddViewsData(views);
        AddSubscriptionsData(subscriptions);
        AddSchedulesData(schedules);
        AddExtractRefreshTasksData(extractRefreshTasks);
    }
        /// <summary>
        /// Save Datasource metadata in a XML file along-side the workbook file
        /// </summary>
        internal static void CreateSettingsFile(SiteDatasource ds, string localDatasourcePath, KeyedLookup <SiteUser> userLookups)
        {
            string contentOwnerName = null; //Start off assuming we have no content owner information

            if (userLookups != null)
            {
                contentOwnerName = WorkbookPublishSettings.helper_LookUpOwnerId(ds.OwnerId, userLookups);
            }

            var xml = System.Xml.XmlWriter.Create(new FileStream(PathForSettingsFile(localDatasourcePath), FileMode.Open));

            xml.WriteStartDocument();
            xml.WriteStartElement(XmlElement_DatasourceInfo);

            //If we have an owner name, write it out
            if (!string.IsNullOrWhiteSpace(contentOwnerName))
            {
                XmlHelper.WriteValueElement(xml, WorkbookPublishSettings.XmlElement_ContentOwner, contentOwnerName);
            }
            xml.WriteEndElement(); //end: WorkbookInfo
            xml.WriteEndDocument();
            xml.Dispose();
        }
    /// <summary>
    /// Looks 
    /// </summary>
    /// <param name="ownerId">GUID of content owner</param>
    /// <param name="userLookups">set we are looking the owner up in</param>
    /// <returns></returns>
    internal static string helper_LookUpOwnerId(string ownerId, KeyedLookup<SiteUser> userLookups)
    {
        //Sanity test
        AppDiagnostics.Assert(!string.IsNullOrWhiteSpace(ownerId), "blank owner id to look up?");

        string contentOwnerName;
        var contentOwner = userLookups.FindItem(ownerId);
        //This should only ever happen if there is a race condition between getting the list of users, and downloading the content, where a user did not exist when we asked for the list of users
        //Should be very rare
        if (contentOwner == null)
        {
            return UnknownOwnerName;
        }
        return contentOwnerName = contentOwner.Name;
    }