Megjegyzés
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhat bejelentkezni vagy módosítani a címtárat.
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhatja módosítani a címtárat.
Az alkalmazáskezelési üzembehelyezési technológiai tartalomimportőr meghatározásához használja a osztály egy példányát Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter
. Az új osztálypéldány határozza meg a telepítő által használt tartalomimportálót.
A ContentImporter osztály felületszintű kialakítást biztosít, ahol az egyéni technológiák példányosíthatják és feltölthetik a DeploymentType objektumokat egy adott technológia számára. Ennek az osztálynak az a fogalma, hogy az adott technológiai importőr képes beolvasni egy adott tartalomfájlt, és létrehozza a megfelelő DeploymentType objektumot (telepítővel) a tartalomból beszerzett információk felhasználásával. A Windows Installer technológiája például *.msi fájlokat olvas be, és feltölti a DeploymentType objektum Cím, Leírás tulajdonságait, és létrehozza a telepítő észlelési, telepítési és eltávolítási műveleteit.
A Remote Desktop Protocol (RDP) mintaprojektben új tartalomimportőrre van szükség a Remote Desktop Protocol- (RDP-) fájlokhoz. Az RDP-fájlok tartalomimportálási támogatása nem beépített a Configuration Manager, ezért egyéni tartalomimportálóra van szükség.
Az egyéni importáló definiálásának alapszintű áttekintése
Hozza létre a ContentImporter osztály egyéni példányát.
Bírálja felül a FileTypes tulajdonságot, és adja vissza a technológiához tartozó fájltípusokat/kiterjesztéseket.
Felülbírálja a CreateDeploymentType metódust egy egyéni központi telepítési típus létrehozásához a szükséges tulajdonságok tartalomfájlból történő importálásával.
Bírálja felül az UpdateDeploymentType metódust, hogy egy egyéni telepítőtípust frissítsen egy tartalomfájl beállításaival.
Segédfüggvények: A teljesség és a kód olvashatósága két segédfüggvény. A ProcessFileLine egy UpdateDeploymentType metódusból meghívott segédfüggvény, amellyel feldolgozhatja a tartalomfájl egyes sorait, és betöltheti az értékeket az egyéni telepítőtípusba. A ParseType a ProcessFileLine segédfüggvényből származó segédfüggvény. A ParseType segédfüggvény egy .rdp fájltípus-megjelölést elemez, és .NET-típussá alakítja.
Egyéni tartalomimportőr definiálása
Hozza létre a osztály egy példányát
Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter
aMicrosoft.ConfigurationManagement.ApplicationManagement.ContentImporter
konstruktor használatával.Az RDP-mintaprojekt alábbi példája bemutatja, hogyan definiálhat tartalomimportőrt.
// Content importer for .rdp files used by the RDP installer. public class RdpContentImporter : ContentImporter
Bírálja felül a
Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter.FileTypes
tulajdonságot, és határozza meg a tartalomimportáló által támogatott fájltípusokat.Az RDP-mintaprojekt alábbi példája bemutatja, hogyan bírálhatja felül a FileTypes tulajdonságot.
// File types supported by the content importer. public override IList<FileType> FileTypes { get { return Common.RdpFileTypes; } }
Az RDP-mintaprojektben a FileTypes érték a projekt Common osztályában van definiálva.
// This defines the file extensions supported by this content importer. internal static readonly FileType[] RdpFileTypes = new[] { new FileType { Name = "RDP", Description = "Remote Desktop Configuration profile", Extensions = new[] { "rdp" } } };
Az egyéni központi telepítési típus létrehozásának kezeléséhez írja felül a
Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter.CreateDeploymentType
metódust úgy, hogy importálja a szükséges tulajdonságokat egy tartalomfájlból.Az RDP-mintaprojekt alábbi példája bemutatja, hogyan bírálhatja felül a CreateDeploymentType metódust.
// Creates a new deployment type from a content file. public override DeploymentType CreateDeploymentType(string contentFile, object context) { Validator.CheckForNull(contentFile, "contentFile"); DeploymentType deploymentType = new DeploymentType(Common.TechnologyId) { Title = Path.GetFileNameWithoutExtension(contentFile) }; UpdateDeploymentType(deploymentType, contentFile); return deploymentType; }
Az RDP-mintaprojektben a DeploymentType sztringparamétere a helyi projekt Common osztályában van definiálva.
// Internal ID of the technology. public const string TechnologyId = "Rdp";
Microsoft.ConfigurationManagement.ApplicationManagement.ContentImporter.UpdateDeploymentType
A telepítési típus tartalomfájlból származó beállításokkal való frissítéséhez írja felül a metódust.Az RDP-mintaprojekt alábbi példája bemutatja, hogyan bírálhatja felül az UpdateDeploymentType metódust.
// Updates an existing deployment type installer with settings from content file. public override void UpdateDeploymentType(DeploymentType dt, string contentFile, object context) { Validator.CheckForNull(dt, "dt"); Validator.CheckForNull(contentFile, "contentFile"); RdpInstaller installer = dt.Installer as RdpInstaller; if (null == installer) { throw new ArgumentOutOfRangeException("dt", dt.Installer, @"Installer type is not supported by this content importer."); } if (false == File.Exists(contentFile)) { throw new FileNotFoundException("Content file was not found: " + contentFile, contentFile); } string[] fileText = File.ReadAllLines(contentFile); fileText.ForEach(l => ProcessFileLine(l, installer)); installer.Filename = Path.GetFileName(contentFile); installer.Contents.Clear(); installer.Contents.Add(new Content()); installer.Contents[0].Files.Add(new ContentFile()); installer.Contents[0].Location = Path.GetDirectoryName(contentFile); installer.Contents[0].Files[0].Name = Path.GetFileName(contentFile); return; }
A ProcessFileLine egy UpdateDeploymentType metódusból meghívott segédfüggvény, amellyel feldolgozhatja a tartalomfájl egyes sorait, és betöltheti az értékeket az egyéni telepítőtípusba.
// Processes a line in an .rdp file to set corresponding RdpInstaller properties. private static void ProcessFileLine(string line, RdpInstaller installer) { if (string.IsNullOrEmpty(line)) { Trace.TraceInformation("Skipping line, it is empty."); return; } string[] elements = line.Split(':'); if (elements.Length < 2) { Trace.TraceError("Unexpected elements length: {0}. Skipping.", elements.Length); return; } string elementName = elements[0]; Type elementType = ParseType(elements[1]); string elementValueAsString = (elements.Length == 3) ? elements[2] : string.Empty; object elementValue = (false == string.IsNullOrEmpty(elementValueAsString)) ? Convert.ChangeType(elementValueAsString, elementType) : null; Trace.TraceInformation("Name: {0} Type: {1} Value: {2} ({3})", elementName, elementType, elementValue, elementValueAsString); if (string.IsNullOrEmpty(elementValueAsString) || null == elementValue) { Trace.TraceWarning("Could not parse element value. Skipping."); return; } switch (elementName.ToLowerInvariant()) { case "username": installer.Username = elementValueAsString; break; case "redirectprinters": installer.RedirectPrinters = (1 == (int)elementValue); break; case "redirectsmartcards": installer.RedirectSmartCards = (1 == (int)elementValue); break; case "alternate shell": installer.RemoteApplication = elementValueAsString; break; case "keyboardhook": installer.KeyboardMode = (RdpKeyboardMode)(int)elementValue; break; case "audiomode": installer.AudioMode = (RdpAudioMode)(int)elementValue; break; case "desktopheight": installer.DesktopHeight = (int)elementValue; break; case "desktopwidth": installer.DesktopWidth = (int)elementValue; break; case "full address": installer.FullAddress = elementValueAsString; string[] tokens = elementValueAsString.Split(':'); ushort port = 0; if (tokens.Length > 1) { bool canParse = ushort.TryParse(tokens[1], out port); if (false == canParse) { Trace.TraceError("Improperly formatted port. Skipping."); } installer.RemoteServerPort = port; } installer.RemoteServerName = tokens[0]; break; case "screen mode id": int screenMode = (int)elementValue; if (screenMode == 1 || screenMode == 2) { installer.FullScreen = (1 == screenMode) ? false : true; } else { Trace.TraceError("Invalid screen mode: {0}. Skipping.", screenMode); } break; default: Trace.TraceWarning("Unrecognized property: {0}. Skipping", elementName); break; } }
A ParseType a ProcessFileLine segédfüggvényből származó segédfüggvény. A ParseType segédfüggvény egy .rdp fájltípus-megjelölést elemez, és .NET-típussá alakítja.
// Helper Function: Parses a .rdp file type designation and converts into a .NET Type. private static Type ParseType(string type) { switch (type.ToLowerInvariant()) { case "s": return typeof(string); case "i": return typeof(int); case "b": return typeof(string); default: Trace.TraceInformation("Unrecognized type: {0}.", type); return typeof(string); } }
Névterek
Microsoft. ConfigurationManagement.ApplicationManagement
Microsoft. ConfigurationManagement.ApplicationManagement.Serialization
Szerelvények
Microsoft.ConfigurationManagement.ApplicationManagement.dll