Znajdowanie zainstalowane drukarki z zadań skryptu
Dane, które jest przekształcana przez Integration Services często pakietów został wydrukowany raport jako jego ostatecznego obiekt docelowy.The System.Drawing.Printing namespace in the Microsoft .NET Framework provides classes for working with printers.
Ostrzeżenie
Aby utworzyć zadanie łatwiej można użyć ponownie w wielu pakietach, należy rozważyć przy użyciu kodu w tym przykładzie zadanie skryptu jako punktu wyjścia dla niestandardowego zadania.Aby uzyskać więcej informacji, zobacz Opracowywania niestandardowego zadania.
Opis
Poniższy przykład lokalizuje drukarek zainstalowanych na serwerze, które obsługują prawnych rozmiar papieru (tak jak w Stanach Zjednoczonych).Kod sprawdzania obsługiwanych rozmiarów papieru jest hermetyzowany w funkcja prywatnych.Aby umożliwić śledzenie postępu skrypt jako sprawdza ustawienia dla każdej drukarki, skrypt używa Log metoda podnieść komunikat informacyjny dla drukarek z prawnego rozmiar papieru i podnieść ostrzeżenie dla drukarek bez prawnych rozmiar papieru.These messages appear in the Output window of the Microsoft Visual Studio Tools for Applications (VSTA) IDE when you run the package in the designer.
Aby skonfigurować ten przykład zadania skryptu
Tworzenie zmiennej o nazwie PrinterList z typem Object.
Na skryptu strona Script Editor zadania, dodać tę zmienną ReadWriteVariables właściwość.
W projekcie skryptu Dodaj odwołanie do System.Drawing obszaru nazw.
W kodzie, użyj Imports instrukcji, aby zaimportować System.Collections i System.Drawing.Printing obszarów nazw.
Kod
Public Sub Main()
Dim printerName As String
Dim currentPrinter As New PrinterSettings
Dim size As PaperSize
Dim printerList As New ArrayList
For Each printerName In PrinterSettings.InstalledPrinters
currentPrinter.PrinterName = printerName
If PrinterHasLegalPaper(currentPrinter) Then
printerList.Add(printerName)
Dts.Events.FireInformation(0, "Example", _
"Printer " & printerName & " has legal paper.", _
String.Empty, 0, False)
Else
Dts.Events.FireWarning(0, "Example", _
"Printer " & printerName & " DOES NOT have legal paper.", _
String.Empty, 0)
End If
Next
Dts.Variables("PrinterList").Value = printerList
Dts.TaskResult = ScriptResults.Success
End Sub
Private Function PrinterHasLegalPaper( _
ByVal thisPrinter As PrinterSettings) As Boolean
Dim size As PaperSize
Dim hasLegal As Boolean = False
For Each size In thisPrinter.PaperSizes
If size.Kind = PaperKind.Legal Then
hasLegal = True
End If
Next
Return hasLegal
End Function
public void Main()
{
PrinterSettings currentPrinter = new PrinterSettings();
PaperSize size;
Boolean Flag = false;
ArrayList printerList = new ArrayList();
foreach (string printerName in PrinterSettings.InstalledPrinters)
{
currentPrinter.PrinterName = printerName;
if (PrinterHasLegalPaper(currentPrinter))
{
printerList.Add(printerName);
Dts.Events.FireInformation(0, "Example", "Printer " + printerName + " has legal paper.", String.Empty, 0, ref Flag);
}
else
{
Dts.Events.FireWarning(0, "Example", "Printer " + printerName + " DOES NOT have legal paper.", String.Empty, 0);
}
}
Dts.Variables["PrinterList"].Value = printerList;
Dts.TaskResult = (int)ScriptResults.Success;
}
private bool PrinterHasLegalPaper(PrinterSettings thisPrinter)
{
bool hasLegal = false;
foreach (PaperSize size in thisPrinter.PaperSizes)
{
if (size.Kind == PaperKind.Legal)
{
hasLegal = true;
}
}
return hasLegal;
}
|
Bieżąco z usług integracji