Finish Table Import Script

gravatar

David

Rename, change to default schema, move, and add UsedByCycle tags for a table that has been imported.

published 04.19.14

last updated 04.19.14


Share

Tags

  • Import
  • Script
  • Table
                            


<#
/*============================================================================= 
Description:     
This Script will change a table's Schema to [default], rename the file according
to our conventions, and move it to the Tables directory of the database
it is associated with, and add the UsedByCycle tag.  

It will NOT remove the original Table in AddedBiml (the file will just be missing
and can be manually removed via 'Remove Missing Items').
    
===============================================================================
History:
20140418    david.darden    Initial Version 
=============================================================================*/
#>
 
<#
WriteLine("<!--");
var tableName = TargetNode.Name;
var sourcePath = TargetNode.BimlFile.FilePath;
var newDirectory = Path.Combine(Path.GetDirectoryName(TargetNode.Schema.Database.BimlFile.FilePath), "Tables");
var targetPath = Path.Combine(newDirectory, tableName + ".biml");
var model = ProjectManager.GetInstance().CurrentProjectViewModel;
var edw3RootDirectory = new DirectoryInfo(model.DirectoryPath).Parent.Parent.FullName; // We know it is 2 levels up based on our directory structure
string addUsedByCycleTagsPath = Path.Combine(edw3RootDirectory, "Framework", "BimlScripts", "Frame_E_Nodes_AddUsedByCycleTags.biml");

WriteLine("Working on:  {0}", sourcePath);
WriteLine("Moving to : {0}", targetPath);

if (!File.Exists(sourcePath))
{
	ValidationReporter.Report("Validation", Severity.Error, string.Format("The file {0} doesn't exist.", sourcePath)); 
}

if (File.Exists(targetPath))
{
	ValidationReporter.Report("Validation", Severity.Error, string.Format("The file {0} already exists.", targetPath)); 
}

WriteLine("Set the schema to [default]");
TargetNode.Schema = TargetNode.Schema.Database.DefaultSchema;

WriteLine("Running 'Frame_E_Nodes_AddUsedByCycleTags' to add UsedByCycleTags");
this.CallBimlScript(addUsedByCycleTagsPath);

// Saving File
WriteLine("Save the file");
TargetNode.BimlFile.Save();

WriteLine("Moving to : {0}", newDirectory);
File.Move(sourcePath, targetPath);

WriteLine("Adding to the project");
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => { ProjectManager.GetInstance().Project.AddExistingPathToModel(targetPath, Varigence.Utility.Files.ExplorerItemType.File); }));
// */
WriteLine("-->");
#>

<#@ template language="C#" hostspecific="True"#>
<#@ assembly name="C:\Program Files\Varigence\Mist\3.4\Mist.exe" #>
<#@ assembly name="C:\Program Files\Varigence\Mist\3.4\WpfControls.dll" #>
<#@ assembly name="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationFramework.dll" #>
<#@ assembly name="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xaml.dll" #>
<#@ import namespace="Varigence.Mist.Managers" #>
<#@ import namespace="Varigence.Utility.Files" #>
<#@ import namespace="System.IO" #>
<#@ target type="Table" exactmatch="True" mergemode="LocalMerge" #>
<#@ annotation annotationtype="Description" tag="Summary" text="Rename, change to default schema, move, and add UsedByCycle tags for a table that has been imported." #>
<Biml></Biml>
                        

This Script will change a table's Schema to [default], rename the file according to our conventions, and move it to the Tables directory of the database it is associated with, and add the UsedByCycle tag. It will NOT remove the original Table in AddedBiml (the file will just be missing and can be manually removed via 'Remove Missing Items').

The "FrameENodes_AddUsedByCycleTags" is custom to us and may not be useful to others; I left it in the script to demonstrate going from the location of a Project to a relative path to run a script (particularly useful when you use development branches so you don't have absolute file paths).

You are not authorized to comment. A verification email has been sent to your email address. Please verify your account.

Comments

There are no comments yet.