2 Replies Latest reply on Jul 7, 2013 9:59 PM by dariop

    C# Update node fields example / toggle managed unmanaged

    gregj

      Hi,

      I am looking for an example of how to put a node in unmanaged mode using the API. I am developing in C#, but will settle for any example out there.

      Anything that will get me in the right direction will be helpful

       

      Thanks in advance!

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

          The SDK documentation includes an example of how to do this in PowerShell.

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

            (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);

                }

            }