Quantcast
Channel: THWACK: Message List
Viewing all articles
Browse latest Browse all 20396

Re: C# Update node fields example / toggle managed unmanaged

$
0
0

(1) create a new C# project

(2) add reference to your SW-Orion Webservices as "orion_misc.SWIS.Informa...."

(3) this is part of my code...

 

....

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

 

        var client = new orion_misc.SWIS.InformationServiceClient("BasicHttpBinding_InformationService",

                string.Format("https://{0}:17778/SolarWinds/InformationService/v3/OrionBasic", hostname));

        client.ClientCredentials.UserName.UserName = username;

        client.ClientCredentials.UserName.Password = password;

        client.Open();

 

    // create the parameter list to pass into the verb
    ProxyMarshalHelper helper = new ProxyMarshalHelper();
    helper.ArgsStart();

 

   
string netObjectID = "N:" + iNodeID.ToString();
    DateTime WindowStartDateTime = DateTime.Now;
    DateTime WindowEndDateTime = WindowStartDateTime.AddSeconds(iMins * 60);
    bool isRelative = false;

 

   
helper.ArgsAdd(typeof(string), netObjectID);
    helper.ArgsAdd(typeof(DateTime), WindowStartDateTime);
    helper.ArgsAdd(typeof(DateTime), WindowEndDateTime);
    helper.ArgsAdd(typeof(bool), isRelative);

 

   
//System.Xml.Serialization.XmlAnyElementAttribute
    var element = new orion_misc.SWIS.ArrayOfXmlElement();
    element.AddRange(helper.ArgsEnd());

 

   
// invoke the verb
    var result2 = client.Invoke("Orion.Nodes", "Unmanage", element);

 

   

client.Close();

 

 

....

 

 

 

 

internal class ProxyMarshalHelper : IDisposable

{

    private readonly MemoryStream _stream;

    private readonly XmlTextWriter _writer;

    private bool _empty;

 

    public ProxyMarshalHelper()

    {

        _stream = new MemoryStream();

        _writer = new XmlTextWriter(_stream, Encoding.UTF8);

        _empty = true;

    }

 

    public void Dispose()

    {

        _stream.Dispose();

    }

 

    public void ArgsStart()

    {

        _stream.Position = 0;

        _stream.SetLength(0);

        _empty = true;

    }

 

    public XElement[] ArgsEnd()

    {

        if (_empty)

            return new XElement[0];

 

        _writer.WriteEndElement();

        _writer.WriteEndDocument();

        _writer.Flush();

        _stream.Position = 0;

 

        XmlTextReader _reader = new XmlTextReader(_stream);

 

        return XDocument.Load(_reader).Elements().First().Elements().ToArray();

    }

 

    public void ArgsAdd(Type argType, object argValue)

    {

        if (_empty)

        {

            _empty = false;

            _writer.WriteStartDocument();

            _writer.WriteStartElement("params");

        }

 

        DataContractSerializer dcs = new DataContractSerializer(argType);

        dcs.WriteObject(_writer, argValue);

    }

 

    public object RetConvert(Type retType, XmlElement retValue)

    {

        if (retValue == null)

            return null;

 

        DataContractSerializer dcs = new DataContractSerializer(retType);

        XPathNavigator navigator = retValue.CreateNavigator();

        if (navigator == null)

            return null;

        return dcs.ReadObject(navigator.ReadSubtree(), false);

    }

}


Viewing all articles
Browse latest Browse all 20396

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>