示例#1
0
 /// <summary>
 /// Does sanity checking and error logging on missing data in projects
 /// </summary>
 /// <param name="project"></param>
 private void SanityCheckProject(SiteProject project, XmlNode xmlNode)
 {
     if (string.IsNullOrWhiteSpace(project.Id))
     {
         Login.Logger.Error(project.Name + " is missing a project ID. Not returned from server! xml=" + xmlNode.OuterXml);
     }
 }
示例#2
0
 /// <summary>
 /// Does sanity checking and error logging on missing data in projects
 /// </summary>
 /// <param name="project"></param>
 private void SanityCheckProject(SiteProject project, XmlNode xmlNode)
 {
     if (string.IsNullOrWhiteSpace(project.Id))
     {
         _onlineSession.StatusLog.AddError(project.Name + " is missing a project ID. Not returned from server! xml=" + xmlNode.OuterXml);
     }
 }
示例#3
0
 /// <summary>
 /// Create the request for to download Data sources from the Tableau REST API
 /// </summary>
 /// <param name="onlineUrls">Tableau Server Information</param>
 /// <param name="logInInfo">Tableau Sign In Information</param>
 /// <param name="datasource">List of Tableau Data sources to save to disk</param>
 /// <param name="localSavePath">File system location where data sources should be saved</param>
 /// <param name="project"></param>
 public DownloadDatasource(TableauServerUrls onlineUrls, TableauServerSignIn logInInfo, SiteDatasource datasource, string localSavePath, SiteProject project)
     : base(logInInfo)
 {
     _onlineUrls    = onlineUrls;
     _datasource    = datasource;
     _localSavePath = localSavePath;
     _downloadToProjectDirectory = project;
 }
        /// <summary>
        /// Fetches the assets from the data source.
        /// </summary>
        /// <param name="project">The project to fetch the data for.</param>
        /// <returns>The enumerable set of assets.</returns>
        public override IEnumerable<IAssetFile> Fetch(SiteProject project)
        {
            var skipDirectory = project.Configuration
                .Destination
                .Replace(project.Language, string.Empty);

            // Fetch and enumerate
            return Directory
                .EnumerateFiles(this.Path.FullName, "*", SearchOption.AllDirectories)
                .Select(f => new AssetInputFile(project, new FileInfo(f)))
                .Except(skipDirectory + "*")
                .ToList();
        }
        /// <summary>
        /// Fetches the assets from the data source.
        /// </summary>
        /// <param name="project">The project to fetch the data for.</param>
        /// <returns>The enumerable set of assets.</returns>
        public override IEnumerable <IAssetFile> Fetch(SiteProject project)
        {
            var skipDirectory = project.Configuration
                                .Destination
                                .Replace(project.Language, string.Empty);

            // Fetch and enumerate
            return(Directory
                   .EnumerateFiles(this.Path.FullName, "*", SearchOption.AllDirectories)
                   .Select(f => new AssetInputFile(project, new FileInfo(f)))
                   .Except(skipDirectory + "*")
                   .ToList());
        }
        /// <summary>
        /// Constructs a translation provider
        /// </summary>
        public TranslationProvider(SiteProject project)
        {
            // Set the project
            this.Project = project;

            // Make sure we have locale directory
            var localePath = Path.Combine(this.Project.Directory.FullName, "_locale");
            if (!Directory.Exists(localePath))
                Directory.CreateDirectory(localePath);
            this.LocalePath = new DirectoryInfo(localePath);

            // Load the locale files
            this.LoadOrCreate();
        }
示例#7
0
        /// <summary>
        /// Constructs a translation provider
        /// </summary>
        public TranslationProvider(SiteProject project)
        {
            // Set the project
            this.Project = project;

            // Make sure we have locale directory
            var localePath = Path.Combine(this.Project.Directory.FullName, "_locale");

            if (!Directory.Exists(localePath))
            {
                Directory.CreateDirectory(localePath);
            }
            this.LocalePath = new DirectoryInfo(localePath);

            // Load the locale files
            this.LoadOrCreate();
        }
示例#8
0
    /// <summary>
    /// Get a page's worth of Projects listing
    /// </summary>
    /// <param name="onlineProjects"></param>
    /// <param name="pageToRequest">Page # we are requesting (1 based)</param>
    /// <param name="totalNumberPages">Total # of pages of data that Server can return us</param>
    private void ExecuteRequest_ForPage(List <SiteProject> onlineProjects, int pageToRequest, out int totalNumberPages)
    {
        int pageSize = _onlineUrls.PageSize;
        //Create a web request, in including the users logged-in auth information in the request headers
        var urlQuery = _onlineUrls.Url_ProjectsList(_onlineSession, pageSize, pageToRequest);

        _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10);
        XmlDocument xmlDoc = ResourceSafe_PerformWebRequest_GetXmlDocument(urlQuery, "get projects list");
        //var webRequest = CreateLoggedInWebRequest(urlQuery);
        //webRequest.Method = "GET";
        //var response = GetWebReponseLogErrors(webRequest, "get projects list");
        //var xmlDoc = GetWebResponseAsXml(response);

        //Get all the project nodes
        var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline");
        var projects  = xmlDoc.SelectNodes("//iwsOnline:project", nsManager);

        //Get information for each of the data sources
        foreach (XmlNode itemXml in projects)
        {
            try
            {
                var proj = new SiteProject(itemXml);
                onlineProjects.Add(proj);

                SanityCheckProject(proj, itemXml);
            }
            catch
            {
                AppDiagnostics.Assert(false, "Project parse error");
                _onlineSession.StatusLog.AddError("Error parsing project: " + itemXml.OuterXml);
            }
        } //end: foreach

        //-------------------------------------------------------------------
        //Get the updated page-count
        //-------------------------------------------------------------------
        totalNumberPages = DownloadPaginationHelper.GetNumberOfPagesFromPagination(
            xmlDoc.SelectSingleNode("//iwsOnline:pagination", nsManager),
            pageSize);
    }
示例#9
0
    /// <summary>
    /// Keeps only the members of the set that have a matching project id
    /// </summary>
    /// <param name="items"></param>
    /// <param name="projectId"></param>
    /// <returns></returns>
    public static ICollection <T> KeepOnlyProjectMembers(ICollection <T> items, SiteProject project, bool nullMeansNoFilter)
    {
        //See if a blank filter implies we should return the full set
        if ((nullMeansNoFilter) && (project == null))
        {
            return(items);
        }

        var projectId = project.Id;
        var listOut   = new List <T>();

        foreach (var thisItem in items)
        {
            if (thisItem.ProjectId == projectId)
            {
                listOut.Add(thisItem);
            }
        }

        return(listOut);
    }
        /// <summary>
        /// If we have Project Mapping information, generate a project based path for the download
        /// </summary>
        /// <param name="basePath">File system location which will be the root of project paths.</param>
        /// <param name="project">Project record.</param>
        /// <param name="statusLog">Logging object.</param>
        /// <returns></returns>
        public static string EnsureProjectBasedPath(string basePath, SiteProject project, TaskStatusLogs statusLog)
        {
            //If we have no project list to do lookups in then just return the base path
            if (project == null)
            {
                return(basePath);
            }

            //Turn the project name into a directory name
            var safeDirectoryName = GenerateWindowsSafeFilename(project.Name);

            var pathWithProject = Path.Combine(basePath, safeDirectoryName);

            //If needed, create the directory
            if (!Directory.Exists(pathWithProject))
            {
                Directory.CreateDirectory(pathWithProject);
            }

            return(pathWithProject);
        }
示例#11
0
        /// <summary>
        /// Get a page's worth of Projects listing
        /// </summary>
        /// <param name="onlineProjects"></param>
        /// <param name="pageToRequest">Page # we are requesting (1 based)</param>
        /// <param name="totalNumberPages">Total # of pages of data that Server can return us</param>
        private void ExecuteRequest_ForPage(List <SiteProject> onlineProjects, int pageToRequest, out int totalNumberPages)
        {
            int pageSize = Urls.PageSize;
            //Create a web request, in including the users logged-in auth information in the request headers
            var urlQuery   = Urls.Url_ProjectsList(Login, pageSize, pageToRequest);
            var webRequest = CreateLoggedInRequest(urlQuery, HttpMethod.Get);

            Login.Logger.Information("Web request: " + urlQuery);
            var response = SendHttpRequest(webRequest);
            var xmlDoc   = GetHttpResponseAsXml(response);

            //Get all the project nodes
            var xDoc            = xmlDoc.ToXDocument();
            var projectElements = xDoc.Root.Descendants(XName.Get("project", XmlNamespace));

            //Get information for each of the data sources
            foreach (var element in projectElements)
            {
                try
                {
                    var itemXml = element.ToXmlNode();
                    var proj    = new SiteProject(itemXml);
                    onlineProjects.Add(proj);

                    SanityCheckProject(proj, itemXml);
                }
                catch
                {
                    Login.Logger.Error("Error parsing project: " + element.ToString());
                }
            } //end: foreach

            //-------------------------------------------------------------------
            //Get the updated page-count
            //-------------------------------------------------------------------

            var paginationElement = xDoc.Root.Descendants(XName.Get("pagination", XmlNamespace)).FirstOrDefault();

            totalNumberPages = GetPageCount(paginationElement, pageSize);
        }
    /// <summary>
    /// Get a page's worth of Projects listing
    /// </summary>
    /// <param name="onlineProjects"></param>
    /// <param name="pageToRequest">Page # we are requesting (1 based)</param>
    /// <param name="totalNumberPages">Total # of pages of data that Server can return us</param>
    private void ExecuteRequest_ForPage(List<SiteProject> onlineProjects, int pageToRequest, out int totalNumberPages)
    {
        int pageSize = _onlineUrls.PageSize;
        //Create a web request, in including the users logged-in auth information in the request headers
        var urlQuery = _onlineUrls.Url_ProjectsList(_onlineSession, pageSize, pageToRequest);
        var webRequest = CreateLoggedInWebRequest(urlQuery);
        webRequest.Method = "GET";

        _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10);
        var response = GetWebReponseLogErrors(webRequest, "get projects list");
        var xmlDoc = GetWebResponseAsXml(response);

        //Get all the project nodes
        var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline");
        var projects = xmlDoc.SelectNodes("//iwsOnline:project", nsManager);

        //Get information for each of the data sources
        foreach (XmlNode itemXml in projects)
        {
            try
            {
                var proj = new SiteProject(itemXml);
                onlineProjects.Add(proj);

                SanityCheckProject(proj, itemXml);
            }
            catch
            {
                AppDiagnostics.Assert(false, "Project parse error");
                _onlineSession.StatusLog.AddError("Error parsing project: " + itemXml.OuterXml);
            }
        } //end: foreach

        //-------------------------------------------------------------------
        //Get the updated page-count
        //-------------------------------------------------------------------
        totalNumberPages = DownloadPaginationHelper.GetNumberOfPagesFromPagination(
            xmlDoc.SelectSingleNode("//iwsOnline:pagination", nsManager),
            pageSize);
    }
 /// <summary>
 /// Adds a project to the list
 /// </summary>
 /// <param name="newProject"></param>
 internal void AddProject(SiteProject newProject)
 {
     _projects.Add(newProject);
 }
 /// <summary>
 /// Does sanity checking and error logging on missing data in projects
 /// </summary>
 /// <param name="project"></param>
 private void SanityCheckProject(SiteProject project, XmlNode xmlNode)
 {
     if(string.IsNullOrWhiteSpace(project.Id))
     {
         _onlineSession.StatusLog.AddError(project.Name + " is missing a project ID. Not returned from server! xml=" + xmlNode.OuterXml);
     }
 }
示例#15
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);
        }
    }
示例#16
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);
        }
    }
示例#17
0
 /// <summary>
 /// Constructs a view engine.
 /// </summary>
 /// <param name="project">The project that the view engine belongs to.</param>
 public RazorViewEngine(SiteProject project)
 {
     this.Project = project;
 }
示例#18
0
 /// <summary>
 /// Adds a project to the list
 /// </summary>
 /// <param name="newProject"></param>
 internal void AddProject(SiteProject newProject)
 {
     _projects.Add(newProject);
 }
 /// <summary>
 /// Constructs a view engine.
 /// </summary>
 /// <param name="project">The project that the view engine belongs to.</param>
 public RazorViewEngine(SiteProject project)
 {
     this.Project = project;
 }
示例#20
0
    /// <summary>
    /// Download the data sources
    /// </summary>
    /// <param name="onlineLogin"></param>
    private void Execute_DownloadDatasources(
        TableauServerSignIn onlineLogin,
        string exportToPath,
        IProjectsList projectsList,
        SiteProject singleProjectIdFilter = null,
        string exportOnlyWithThisTag      = null,
        bool deleteTagAfterExport         = false)
    {
        _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
        //-----------------------------------------------------------
        try
        {
            var datasourceDownloads = new DownloadDatasources(
                _onlineUrls,
                onlineLogin,
                filteredList,
                datasourcePath,
                projectsList);
            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);
        }
    }
示例#21
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>
    private void Execute_DownloadWorkbooks(
        TableauServerSignIn onlineLogin,
        string exportToPath,
        IProjectsList projectsList,
        SiteProject singleProjectIdFilter = null,
        string exportOnlyWithThisTag      = null,
        bool deleteTagAfterExport         = false)
    {
        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);
        try
        {
            var workbookDownloads = new DownloadWorkbooks(onlineUrls, onlineLogin, filteredList, workbookPath, projectsList);
            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);
        }
    }
示例#22
0
    /// <summary>
    /// Perform the work
    /// </summary>
    private void ExecuteTask_InternalAllTasks()
    {
        string exportToPath = _exportToLocalPath;
        var    onlineUrls   = _onlineUrls;
        var    taskOptions  = _taskOptions;

        //========================================================================================
        //Log into Tableau Online
        //========================================================================================
        var serverLogin = new TableauServerSignIn(onlineUrls, _userName, _password, _statusLog);

        try
        {
            serverLogin.ExecuteRequest();
        }
        catch (Exception exLogin)
        {
            _statusLog.AddError("Failed loging, " + exLogin.ToString());

            _isDone = true;
            return;
        }

        //========================================================================================
        //If there is a custom command we want to execute, do it
        //========================================================================================
        var customCommand1 = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ArbitraryCommand1);

        if (!string.IsNullOrWhiteSpace(customCommand1))
        {
            AttemptExecutionOfCustomHttpGet(serverLogin, customCommand1);
        }
        var customCommand2 = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ArbitraryCommand2);

        if (!string.IsNullOrWhiteSpace(customCommand2))
        {
            AttemptExecutionOfCustomHttpGet(serverLogin, customCommand2);
        }

        //========================================================================================
        //If there is a project we want to create, then do it
        //========================================================================================
        var createProjectName = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_CreateProjectWithName);

        if (!string.IsNullOrWhiteSpace(createProjectName))
        {
            Execute_CreateProjectWithName(serverLogin, createProjectName);
        }

        //========================================================================================
        //Attempt to get the list of users
        //========================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetSiteUsers))
        {
            _downloadedList_Users = Execute_DownloadSiteUsers(serverLogin);
        }

        //========================================================================================
        //Attempt to get the site information
        //========================================================================================
        SiteinfoSite site = null;

        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetSiteInfo))
        {
            site = Execute_DownloadSiteInfo(serverLogin);
        }

        //If this gets set then we will pass the information for project/name mapping to the workbook and datasource downloaders
        IProjectsList projectNameIdMapping = null;
        SiteProject   exportSingleProject  = null; //If non NULL, then look up the project

        //===================================================================================
        //Projects List
        //===================================================================================
        if ((taskOptions.IsOptionSet(TaskMasterOptions.Option_GetProjectsList)) ||
            (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadIntoProjects)) ||
            (taskOptions.IsOptionSet(TaskMasterOptions.OptionParameter_ExportSingleProject))
            )
        {
            var projectsList = Execute_DownloadProjectsList(serverLogin);

            if (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadIntoProjects))
            {
                projectNameIdMapping = projectsList;
            }

            //Determine if the there is a project filter
            exportSingleProject = helper_DetermineIfSingleProjectFilter(projectsList);
        }


        //===================================================================================
        //List of groups?
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetGroupsList))
        {
            Execute_DownloadGroupsList(serverLogin);
        }

        //===================================================================================
        //List of datasources? (does not download actual data sources, just the list)
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetDatasourcesList))
        {
            Execute_DownloadDatasourcesList(serverLogin);
        }

        //===================================================================================
        //Datasources download...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadDatasources))
        {
            Execute_DownloadDatasources(
                serverLogin
                , exportToPath
                , projectNameIdMapping
                , exportSingleProject
                , taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ExportOnlyTaggedWith)
                , taskOptions.IsOptionSet(TaskMasterOptions.OptionParameter_RemoveTagFromExportedContent)
                );
        }


        //===================================================================================
        //Workbooks download...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_DownloadWorkbooks))
        {
            Execute_DownloadWorkbooks(
                serverLogin
                , exportToPath
                , projectNameIdMapping
                , exportSingleProject
                , taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_ExportOnlyTaggedWith)
                , taskOptions.IsOptionSet(TaskMasterOptions.OptionParameter_RemoveTagFromExportedContent)
                );
        }

        //===================================================================================
        //List of workbooks? (does not download actual workbooks, just the list)
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetWorkbooksList))
        {
            Execute_DownloadWorkbooksList(serverLogin);

            //Do we want to download the connection information for each workbook?
            if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GetWorkbooksConnections))
            {
                Execute_DownloadWorkbooksConnections(
                    serverLogin
                    , this.WorkbooksList);
            }
        }

        //===================================================================================
        //Are there database credentials we need to associate with content being uploaded...
        //===================================================================================
        var pathDBCredentials = taskOptions.GetOptionValue(TaskMasterOptions.Option_DBCredentialsPath);
        CredentialManager uploadCredentialManager = null;

        if (!string.IsNullOrWhiteSpace(pathDBCredentials))
        {
            uploadCredentialManager = Execute_LoadDBCredentialsFile(pathDBCredentials);
        }

        //===================================================================================
        //Datasources upload...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_UploadDatasources))
        {
            Execute_UploadDatasources(
                serverLogin,
                taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_PathUploadFrom),
                uploadCredentialManager);
        }

        //===================================================================================
        //Workbooks upload...
        //===================================================================================
        if (taskOptions.IsOptionSet(TaskMasterOptions.Option_UploadWorkbooks))
        {
            Execute_UploadWorkbooks(
                serverLogin,
                taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_PathUploadFrom),
                taskOptions.IsOptionSet(TaskMasterOptions.Option_RemapWorkbookReferencesOnUpload),
                uploadCredentialManager);
        }

        //===================================================================================
        //Save the site inventory file
        //===================================================================================
        var inventoryFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveInventoryFile);

        if (!string.IsNullOrWhiteSpace(inventoryFile))
        {
            Execute_GenerateSiteInventoryFile(inventoryFile);

            //Do we want to generate a TWB file that uses the inventory file
            if (taskOptions.IsOptionSet(TaskMasterOptions.Option_GenerateInventoryTwb))
            {
                Execute_GenerateSiteInventoryFile_Twb(inventoryFile);
            }
        }

        //===================================================================================
        //Save the manual steps file
        //===================================================================================
        var manualStepsFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveManualSteps);

        if (!string.IsNullOrWhiteSpace(manualStepsFile))
        {
            Execute_GenerateManualStepsFile(manualStepsFile);
        }

        //===================================================================================
        //Save the logs file
        //===================================================================================
        var logFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveLogFile);

        if (!string.IsNullOrWhiteSpace(logFile))
        {
            Execute_SaveLogFile(logFile);
        }

        //===================================================================================
        //Save the errors file
        //===================================================================================
        var errorsFile = taskOptions.GetOptionValue(TaskMasterOptions.OptionParameter_SaveErrorsFile);

        if (!string.IsNullOrWhiteSpace(errorsFile))
        {
            Execute_SaveErrorsFile(errorsFile);
        }
    }