using System;
using
System.Collections.Generic;
using
System.Text;
using System.IO;
using
Microsoft.SqlServer.DataMining.Office.Visio.Programability;
namespace
DMDigramUsingViso
{
class Program
{
//This is the
folder where the data mining addins have been installed.
public const string
DMAddinInstallPath = @"C:\Program Files
(x86)\Microsoft SQL Server 2005 DM Add-Ins";
//This is the
name of the Visio template file for the data mining addins.
public const string
VisioTemplateName = @"Microsoft Data
Mining.vst";
//This is the
name of the target HTML file.
public const string
WebFileName = @"TargetMail.htm";
static void Main(string[]
args)
{
try
{
string
visioFile = DMAddinInstallPath + "\\"
+ VisioTemplateName;
string
webFile = System.IO.Directory.GetCurrentDirectory()
+ "\\" + WebFileName;
Console.WriteLine("DM Addin install path : {0}",
DMAddinInstallPath);
Console.WriteLine("Visio Template : {0}",
VisioTemplateName);
Console.WriteLine("Output : {0}", webFile);
//----------------------------------------------------
// Create the parameter object for the decision tree
// drawing
and populate the required parameters
//----------------------------------------------------
ParameterDecisionTree
parameter = new ParameterDecisionTree();
//Friendly
name for the connection
parameter.ConnectionName = "AdventureWorksConnection";
//Name
of the Analysis Server
parameter.DataSourceName = "localhost";
//Name
of database
parameter.CatalogName = "AdventureWorks";
//Name
of the mining model
parameter.ModelName = "Target Mail";
//Name
of the decision tree predictable
parameter.TreeName = "Bike Buyer";
//Flag
to hide the progress dialog
parameter.Silent = true;
//----------------------------------------------------
//
Optional properties for the parameter object
//----------------------------------------------------
//Shade
tree nodes using support
parameter.GradientType = GradientType.SupportGradient;
//Show
support in the nodes
parameter.ShowSupport = false;
//Fill
color for the nodes
parameter.FillColorArgb =
System.Drawing.Color.Aqua.ToArgb();
//Fill
pattern color for the nodes
parameter.PatternColorArgb =
System.Drawing.Color.Azure.ToArgb();
//----------------------------------------------------
//
Drawing helper object which performs the actual rendering
//----------------------------------------------------
DMDrawingHelper
helper = new DMDrawingHelper(visioFile,
false);
//Start
the Visio application
helper.Start();
/*
Helper object allows access
to Visio object model using the following methods:
helper.CreateNewDocument();
helper.CreateNewPage();
helper.ActiveDocument;
helper.ActivePage;
helper.Application;
*/
//Render
the decision tree on the current active page
Console.WriteLine("Rendering decision tree using the visio
engine...");
helper.DrawDecisionTree(helper.ActivePage, parameter);
//Convert
all the pages of the drawing to HTML
Console.WriteLine("Converting to HTML using the visio engine...");
helper.SaveDocumentAsWebPage(helper.ActiveDocument,
-1,
-1,
webFile,
DMDrawingHelper.ShowNavigationBar
| DMDrawingHelper.ShowPanAndZoom | DMDrawingHelper.ShowPropertiesWindow | DMDrawingHelper.ShowSearchTool);
//Close
the Visio App
helper.Close();
Console.WriteLine("HTML File is generated at : {0}",
webFile);
}
catch
(Exception ex)
{
Console.WriteLine("DMDigramUsingViso Error : {0}",
ex.Message);
}
}
}
}