/*
Microsoft SQL Server
Integration Services Script Task
Write scripts using
Microsoft Visual C# 2008.
The ScriptMain is the entry
point class of the script.
*/
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
namespace ST_5dc7efcc7bc2413ebd429a77fa9f1964.csproj
{
[System.AddIn.AddIn("ScriptMain",
Version = "1.0", Publisher = "", Description = "")]
public
partial class ScriptMain :
Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA
generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
/*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables,
events,
and logging features are available as members of the Dts property as shown in
the following examples.
To reference a variable, call
Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test",
"hit the help message", "", 0, true);
To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial
Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto
Translate=False;";
Before returning from this method, set the value of Dts.TaskResult to indicate
success or failure.
To open Help, press F1.
*/
public void Main()
{
String path = Dts.Variables["source_file_unc"].Value.ToString();
FileInfo fi = new
FileInfo(path);
String file_name = "";
String result = "success";
String archive_folder_path = Dts.Variables["archive_folder_path"].Value.ToString();
String dups_folder_path =
Dts.Variables["dups_folder_path"].Value.ToString();
String error_folder_path = Dts.Variables["error_folder_path"].Value.ToString();
String target_folder_path = Dts.Variables["target_folder_path"].Value.ToString();
try
{
/* verify the existence of the source file*/
if (!fi.Exists) {
//MsgBox(path, MsgBoxStyle.Critical, "Invalid
source_file_unc")
throw new FileNotFoundException("The
source_file_unc (" + path + ")
does not exist!");
}
//folder/path verification archive_folder_path
if (!System.IO.Directory.Exists(archive_folder_path)){
//'MsgBox(archive_folder_path, MsgBoxStyle.Critical,
"Invalid archive_folder_path")
throw new FileNotFoundException("The
archive_folder_path (" + archive_folder_path + ") does not exist!");
}
if (!System.IO.Directory.Exists(dups_folder_path)){
//'MsgBox(dups_folder_path, MsgBoxStyle.Critical,
"Invalid dups_folder_path")
throw new FileNotFoundException("The
dups_folder_path (" + dups_folder_path + ")
does not exist!");
}
if (!System.IO.Directory.Exists(error_folder_path)){
//'MsgBox(error_folder_path, MsgBoxStyle.Critical,
"Invalid error_folder_path")
throw new FileNotFoundException("The
error_folder_path (" + error_folder_path + ")
does not exist!");
}
if (!System.IO.Directory.Exists(target_folder_path)){
//'MsgBox(target_folder_path, MsgBoxStyle.Critical,
"Invalid target_folder_path")
throw new FileNotFoundException("The
target_folder_path (" + target_folder_path + ") does not exist!");
}
//' extract file information to create the working
directory (package variable: target_file_path)
file_name = fi.Name;
String []file_Name_Parts =
file_name.Split('.');
int upper = file_Name_Parts.GetUpperBound(0);
int lower = file_Name_Parts.GetLowerBound(0);
Dts.Variables["extract_date"].Value
= fi.CreationTime.ToString();
Dts.Variables["file_extension"].Value
= file_Name_Parts [upper];
Dts.Variables["file_name"].Value =
file_name;
Dts.Variables["target_file_path"].Value
= System.IO.Path.Combine(target_folder_path,
file_name);
}
catch
{
}
finally
{
}
// TODO: Add your code here
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
No comments:
Post a Comment