2010-02-19 17 views
3

Je cherche un wrapper .NET pour créer et supprimer par programmation des points de publication Windows Media Services via WMI.Création/suppression par programme du point de publication Windows Media Services

Je ne peux pas être le seul à vouloir faire cela par le biais de .NET, alors avant de réinventer la roue, quelqu'un at-il vu des exemples de code là-bas pour le faire?

+0

routeNpingme - Avez-vous obtenu n'importe où avec ceci? –

+0

@PaulRowland - non, n'a pas :( – Brandon

Répondre

0

Dans le Windows SDK 7.1, il y a le fichier suivant, pourrait être un point de départ.

Windows \ v7.1 \ Samples \ multimedia \ windowsmediaservices9 \ addPub.js JScript \

/*--------------------------------------------------------------------- 
Copyright (C) Microsoft Corporation. All rights reserved. 
Script name : Add Publishing Point (addpub) 
Script version : 1.0 
Description : This script adds a publishing point to the target 
        server. 
Command line parameters : 
      [-s <Server1>] -n <pub1> -t <od|bc> -p <path> 
-s represents target server, -n represents publishing point name, 
-p represents path, -t represent type of publishing point. 
There are 4 Publishing point types. 
od = On-demand, bc = broadcast 
Example : addpub -s server1 -n odpub1 -t od -p c:/wsh1 
Returns : 
1. Usage: addpub [-s <Server1>] -n <pub1> -t <od|bc> -p <path> 
2. Server %server% is not a valid WMS Server 
3. %type% is not a valid publishing point type 
OS Requirements  : Windows Server 2003 (all versions) 
Software requirements : WMS Server 
Scripting Engine  : Jscript 
---------------------------------------------------------------------*/ 
WMS_PUBLISHING_POINT_TYPE_ON_DEMAND = 1; 
WMS_PUBLISHING_POINT_TYPE_BROADCAST = 2; 

var objServer = null; 
var dwWhichArg = 0; 
var szEachArg = ""; 
var szTemp = ""; 
var szArgServer = ""; 
var szArgPubPoint = ""; 
var szArgPubPointType = ""; 
var szArgPubPointPath = ""; 
var bCheckName = false; 
var bCheckPath = false; 
var bCheckType = false; 

var objArgs = WScript.Arguments; 

if(0 == WScript.Arguments.length) 
{ 
    DisplayUsage(); 
} 

// Parse the command to seperate out the server name and publishing points. 

while(dwWhichArg < WScript.Arguments.length) 
{ 
    szEachArg = objArgs(dwWhichArg); 
    if("-s" == szEachArg.toLowerCase()) 
    { 
     dwWhichArg = dwWhichArg + 1; 
     if(dwWhichArg >= WScript.Arguments.length) //ex: addpub ... -n p1 -s 
     { 
      DisplayUsage(); 
     } 
     szEachArg = objArgs(dwWhichArg); 
     if((szEachArg.toLowerCase()== "-n") || (szEachArg.toLowerCase()== "-p") || (szEachArg.toLowerCase()== "-t")) //if next szEachArg is -p,-t,-n display usage : since syntax is wrong 
     { 
      DisplayUsage(); 
     } 
     else 
     { 
      //accept only one server name 
      if(szEachArg.lastIndexOf(",")== -1) 
      { 
       szArgServer = szEachArg; 
      } 
      else 
      { 
       DisplayUsage(); 
      } 
     } 
    } 
    else if(szEachArg.toLowerCase()== "-n") 
    { 
     bCheckName = true; 
     dwWhichArg = dwWhichArg + 1; 

     if(dwWhichArg >=WScript.Arguments.length) //ex: addpub ... -s s1 -p 
     { 
      DisplayUsage(); 
     } 
     szEachArg = objArgs(dwWhichArg); 
     if((szEachArg.toLowerCase()== "-p") || (szEachArg.toLowerCase()== "-t") || (szEachArg.toLowerCase()== "-s")) //if next szEachArg is -s,-t,-p display usage : since syntax is wrong 
     { 
       DisplayUsage(); 
     } 
     else 
     { 
      //accept only one publishing point name 
      if(szEachArg.lastIndexOf(",")== -1) 
      { 
       szArgPubPoint=szEachArg; 
      } 
      else 
      { 
       DisplayUsage(); 
      } 
     } 
    } 
    else if(szEachArg.toLowerCase()== "-p") 
    { 
     bCheckPath = true; 
     dwWhichArg = dwWhichArg + 1; 

     if(dwWhichArg >=WScript.Arguments.length) //ex: addpub ... -s s1 -p 
     { 
      DisplayUsage(); 
     } 
     szEachArg = objArgs(dwWhichArg); 
     if((szEachArg.toLowerCase()== "-t") || (szEachArg.toLowerCase()== "-s") || (szEachArg.toLowerCase()== "-n")) //display usage : since syntax is wrong 
     { 
      DisplayUsage(); 
     } 
     else 
     { 
      //accept only one path 
      if(szEachArg.lastIndexOf(",")== -1) 
      { 
       szArgPubPointPath=szEachArg; 
      } 
      else 
      { 
       DisplayUsage(); 
      } 
     } 
    } 
    else if(szEachArg.toLowerCase()== "-t") 
    { 
     bCheckType = true; 
     dwWhichArg = dwWhichArg + 1; 

     if(dwWhichArg >=WScript.Arguments.length) 
     { 
      DisplayUsage(); 
     } 
     szEachArg = objArgs(dwWhichArg); 
     if((szEachArg.toLowerCase()== "-p") || (szEachArg.toLowerCase()== "-n") || (szEachArg.toLowerCase()== "-s")) //display usage, since syntax is wrong 
     { 
      DisplayUsage(); 
     } 
     else 
     { 
      //accept only one type 
      if(szEachArg.lastIndexOf(",")== -1) 
      { 
       szArgPubPointType=szEachArg; 
      } 
      else 
      { 
       DisplayUsage(); 
      } 
     } 
    } 
    else // if argument is not -p,-n,-t,-s i.e. if it is an invalid argument 
    { 
     DisplayUsage(); 
    } 

    dwWhichArg = dwWhichArg + 1; 
} 

if((!bCheckName) || (!bCheckPath) || (!bCheckType))  //Ex: compulsory part -p,-t or -n is missing. 
{ 
    DisplayUsage(); 
} 

// Connect to Server 
//if server name is not mentioned, then start Publishing points on localhost 
if("" == szArgServer) 
{ 
    szArgServer = "LocalHost"; 
} 

var bFailed; 
bFailed = false; 

try 
{ 
    objServer = new ActiveXObject("WMSServer.server", szArgServer); 
} 
catch(e) 
{ 
    bFailed = true; 
    szTemp = "Server '" + szArgServer + "' is not a valid WMS Server \n"; 
    Trace(szTemp); 
} 

if(!bFailed) 
{ 
    Trace("\nAdding Publishing Points at "+ szArgServer); 

    //Add Publishing Point 
    AddPublishingPoint(); 
} 


// This function checks if the publishing point name and type are valid, and then 
// adds it to server. 
function AddPublishingPoint() 
{ 
    var bFailed, nType; 
    bFailed = false; 

    //check if the type is a valid type 
    switch(szArgPubPointType) 
    { 
     case 'od' : 
      nType = WMS_PUBLISHING_POINT_TYPE_ON_DEMAND; 
      break; 
     case 'bc' : 
      nType = WMS_PUBLISHING_POINT_TYPE_BROADCAST; 
      break; 
     default : 
     { 
      bFailed = true; 
      szTemp = "Adding Publishing Point '" + szArgPubPoint + "' failed: Unknown type\n"; 
      break; 
     } 
    } 

    if(!bFailed) 
    { 
     try 
     { 
      var objPubPoint = objServer.PublishingPoints.Add(szArgPubPoint, nType, szArgPubPointPath); 
      szTemp = "Added " + szArgPubPoint; 
     } 
     catch(e) 
     { 
      var errorcode = e.number >>> 0; 
      szTemp = "Error Code 0x" + errorcode.toString(16) + ": " + e.description; 
     } 
    } 

    Trace(szTemp); 
} 

function DisplayUsage() 
{ 
    Trace("Usage: addpub [-s <Server1>] -n <pub1> -t <od|bc> -p <path>"); 
    WScript.Quit(1); 
} 

function Trace(Msg) 
{ 
    WScript.Echo(Msg); 
} 
0

J'utilise le Media Services 9 SDK qui est documenté here. Le SDK est livré avec les composants d'exécution. Vous devez donc copier les fichiers Microsoft.WindowsMediaServices.Interop.dll et WMSServerTypeLib.dll de votre machine Windows Server avec l'environnement d'exécution installé. Je les ai trouvés au C:\Windows\System32\windows media\server. Ensuite, enregistrez la bibliothèque de types et ajoutez une référence à l'assembly Interop.

Ensuite, pour utiliser le SDK:

using System.Runtime.InteropServices; 
using Microsoft.WindowsMediaServices.Interop; 

// instantiating the server for a remote host 
Type serverType = Type.GetTypeFromProgID("WMSServer.Server", "MediaServer"); 

// may need to wrap this in an impersonation context depending the server's ACL 
WMSServer server = (WMSServer)Activator.CreateInstance(serverType); 

// removing all of the publish points 
for(int i = server.PublishingPoints.Count - 1; i >= 0; i--) 
{ 
    server.PublishingPoints.Remove(i); 
} 

// adding a push broadcast point 
IWMSBroadcastPublishingPoint newPoint = 
      (IWMSBroadcastPublishingPoint) server.PublishingPoints.Add(
      "NewPoint", WMS_PUBLISHING_POINT_CATEGORY.WMS_PUBLISHING_POINT_BROADCAST, 
       "Push:*"); 

// cloning 
IWMSPublishingPoint cloned = server.PublishingPoints.Clone("Cloned", newPoint); 

I inclus clonage parce que je rencontrais une erreur (The stub received bad data) lorsque vous essayez d'ajouter un nouveau point de publication sur une machine distante. J'ai vu un autre thread où quelqu'un avait le même problème, donc je me suis dit qu'au lieu de le combattre, je créerais simplement un point de publication de modèles et créerais tous les nouveaux points en tant que clones.