DX Unified Infrastructure Management

 View Only
Expand all | Collapse all

example of how to send QOS using .NET api

  • 1.  example of how to send QOS using .NET api

    Posted Mar 09, 2011 10:59 PM

    Community,

    Does anyone have an example of how to create and send QOS using .NET API? 

     

    Thanks,

    Jarrod



  • 2.  Re: example of how to send QOS using .NET api

    Posted Mar 09, 2011 11:36 PM

    I am attaching the SDK.chm file, it will have the information you are looking for.



  • 3.  Re: example of how to send QOS using .NET api

    Posted Apr 06, 2011 11:27 PM

     

    Below is the VB Code example.

    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Nimsoft.NimBUS.Messaging
    Namespace test_nimsoft_qos
     Class Program
     Shared myQos As [String] = "QOS_MY_CUSTOM_DEF"
     Shared myMax As Double = 100
     Private Shared Sub Msg(sess As NimbusSession, target As [String], value As Integer)
     Using q As New QoS(myQos)
     q.SetValue(value)
     q.Target = target
     q.MaxValue = myMax
     sess.SendMessage(q)
    End Using
    End Sub
    Private Shared Sub Main(args As String())
    ' definition, only need to send it one time
    Dim def As New QoSDefinition(myQos, "This is a description", "My group", "Percent", "%", False, _
    False, True)
    Using sess As New NimbusSession()
    sess.SendMessage(def)
    End Using
    ' send 2 qos samples every 1 second for 10 seconds
    For i As Integer = 0 To 9
    Using sess As New NimbusSession()
    Msg(sess, "Target #1", i)
    Msg(sess, "Target #2", i + 20)
    End Using
    If i < 9 Then
    System.Threading.Thread.Sleep(1000)
    End If
    Next
    End Sub
    End Class
    End Namespace


  • 4.  Re: example of how to send QOS using .NET api

    Posted Apr 13, 2011 11:23 AM

    Thanks for that example...

    but would it be possible to upload this as a Visual Studio Project ? It's very hard to read it here...

    Some comments in the code would be helpfull too...

     

    Thank you

    Marco



  • 5.  Re: example of how to send QOS using .NET api

    Posted Apr 13, 2011 12:30 PM

    I just found a good example in the Documentation. It's well hidet in my opinion :smileywink:

    Nimsoft.NimBUS.Messaging -> QoS Class -> QoS Constructor -> QoS Constructor(string, boolean)

     

     



  • 6.  Re: example of how to send QOS using .NET api

    Posted Apr 13, 2011 05:45 PM

    Attached is a Zip with the C# and VB files



  • 7.  Re: example of how to send QOS using .NET api

    Posted Nov 09, 2011 11:32 PM

    Jarrod,

     

      I'm going to go out on a limb and say that I'm doing something improperly, but when I use your sample c# code I get the following:

     

    Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
    at Nimsoft.NimBUS.Messaging.NimSSL.sslUseSSL()
    at Nimsoft.NimBUS.Messaging.NimbusSession.Close()
    at Nimsoft.NimBUS.Messaging.NimbusSession.Dispose(Boolean )
    at Nimsoft.NimBUS.Messaging.NimbusSession.Dispose()
    at test_nimsoft_qos.Program.Main(String[] args)

     

    Thoughts?  As this thread would read, I'm just trying to pass QOS back to the hub.

     

     

     



  • 8.  Re: example of how to send QOS using .NET api

    Posted Nov 10, 2011 11:59 AM

    Hi

     

    Based on the exception stacktrace,

     

    at Nimsoft.NimBUS.Messaging.NimSSL.sslUseSSL()

     

    It looks like you have a version of the Nimsoft SDK for .NET which contains buggy code. I remember I have seen this issue one time before, problem was fixed by replacing the dll with an older version (because at the time, the problem existed in the latest DLL version).

     

    It may (or may not) have been fixed in todays version. I don't work in the .net department so I don't know.

     

    Geir.



  • 9.  Re: example of how to send QOS using .NET api

    Posted Nov 10, 2011 07:09 PM

    here it is, give this one a shot. I to had same issues with newest .net dll.



  • 10.  Re: example of how to send QOS using .NET api

    Posted Jan 13, 2012 08:09 PM

    Im having an issue with sending the QOS definition message.  Using the sample from the SDK and the DLL added to this thread when I execute .SendMessage I get the following error:

     

    Faulty status in reply message; expected 0 (OK), got 11 (Command not found.).

     

     

    No matter what I try I get the same result.  Any ideas?



  • 11.  Re: example of how to send QOS using .NET api

    Posted Jan 13, 2012 10:51 PM

    Looking at the sample .NET code from the Code Wizard, it looks like the method for sending QoS should be .PostMessage rather than .SendMessage. Is it possible you are just calling the wrong method, or did you simply enter it wrong in your post here?



  • 12.  Re: example of how to send QOS using .NET api

    Posted Jan 13, 2012 11:20 PM

    You must have a newer version of the code wizard.  The wizard I have only works with COM.  I see PostMessage in the SDK I have, but the session object in the version 1.7 of the API doesn't have PostMessage, but a newer version 2.5 does.  The sample that I am looking at in the SDK looks to be using SendMessage.  Can you send me the version of the code wizard you have so I can take a look at that one?

     

    The sample I am looking at is and has SendMessage.  

     

    Imports System.Threading
    Imports Nimsoft.NimBUS
    Imports Nimsoft.NimBUS.Messaging

    Module APITest

    Sub Main()

    'Create a QoS
    Dim qos As QoS = New QoS("QOS_TEST", false)

    'Create definition
    Dim definition As QoSDefinition = New QoSDefinition(qos.Name, "My Application Response", _
    "QOS_APPLICATION", "milliseconds", "ms", qos.Async, false, true)

    'Create a session for sending data
    Dim session As NimbusSession = New NimbusSession()

    'Keep session open
    session.Connect(10)

    'Send definition
    Dim ret As PDS = session.SendMessage(definition)
    If ret.CheckKey("nimid") = PdsType.PDS_PCH Then
    Console.WriteLine("QoS definition sent, NimBUS ID = " + ret.GetString("nimid"))
    End If

    'MaxValue must be set when QoS is defined with hasMax == true
    qos.MaxValue = 100

    'Set source and target
    qos.Source = "MySource"
    qos.Target = "MyTarget"

    'Set sample time and sample rate
    qos.SampleTime = DateTime.UtcNow
    qos.SampleRate = 1

    'Set and send value
    ret = session.SendMessage(qos.SetValue(3.14))
    If ret.CheckKey("nimid") = PdsType.PDS_PCH Then
    Console.WriteLine("QoS value sent, NimBUS ID = " + ret.GetString("nimid"))
    End If

    'Wait...
    Thread.Sleep(1000)

    'Set sample time
    qos.SampleTime = DateTime.UtcNow

    'Send value again
    ret = session.SendMessage(qos)
    If ret.CheckKey("nimid") = PdsType.PDS_PCH Then
    Console.WriteLine("QoS value sent, NimBUS ID = " + ret.GetString("nimid"))
    End If

    'Wait...
    Thread.Sleep(1000)

    'Set sample time
    qos.SampleTime = DateTime.UtcNow

    'Send null value
    ret = session.SendMessage(qos.SetNull())
    If ret.CheckKey("nimid") = PdsType.PDS_PCH Then
    Console.WriteLine("Null value sent, NimBUS ID = " + ret.GetString("nimid"))
    End If

    'Close session
    session.Close()

    End Sub

    End Module



  • 13.  Re: example of how to send QOS using .NET api

    Posted Jan 14, 2012 01:10 AM

    I am using Code Wizard 1.70.0 (according to the status bar at the bottom). That looks like the version that is available on the Internet archive, so you should be able to pull it down.

     

    Here is the example .NET code it produces when the only option selected is to show how to generate QoS:

     

    /*#################################################################
    # CodeWizard:  C# .net
    # This code was generated with the Nimsoft CodeWizard version 1.70
    # Date: Friday, January 13, 2012
    */
    public class example_probe : NimbusProbe {
         private XmlDocument m_config;
    
         example_probe ():base() {
             this.RegisteredEvent += new EventHandler<EventArgs>(Initialize);
         }
    
    
        public static void Main(String[] args) {
         example_probe exampleprobe =null;
            try {
                 exampleprobe = new example_probe();
                 exampleprobe.Register();
            }catch(NimException e) {
                Console.WriteLine(e.Message);
            }
              // Run probe (might be omitted)
             exampleprobe.Run(1000);
        }
    
    
        public void Run(int sleepTime) {
             while (!Stop) {
                      Sleep(sleepTime);
             }
        }
    
    
         protected override void LoadConfig() {
             LogLevel loglevel = this.GetLogLevel();
             try {
                 FileConfig cfg = new FileConfig("example_probe.cfg");
                 m_config = cfg.GetAsXml(true);
                 try {
                      this.SetLogLevel((LogLevel)int.Parse(m_config.SelectSingleNode("configuration/setup").Attributes["loglevel"].Value));
                     } catch(Exception ) {
                     }
             } catch(Exception ex) {
             } finally {
                     this.SetLogLevel(loglevel);
             }
         }
    
         private void Initialize(object sender, EventArgs e) {
             this.RegisterCallback(this, "cmdTestConnection", "TestConnection", AccessLevel.Read, "Test Query Callback", false, "", this.GetLogLevel());
         }
    
          private void SendQoS() {
             QoSDefinition QoSDef = null;
             string name = "QOS_TEST_CONNECT";
             CIHandle handle = null;
             if (!QoSDefinitions.ContainsKey(name)){
                 QoSDef = new QoSDefinition(name, "Example probe QoS testing", "QOS_APPLICATION", "Milliseconds", "ms", false, false, false);
                 int iRet = SendQoSDefinition(QoSDef);
                 if (iRet == 0){
                        QoSDefinitions.Add(name, QoSDef);
                 }
             }
             QoS qos = new QoS(name, false);
             qos.SampleRate = 1;
             qos.Target = "TestProbe_" + name;
             qos.SampleTime = DateTime.UtcNow;
             handle = ciOpenLocalDevice("citype", "ciname");
             // for remote probe monitoring, use ciOpenRemoteDevice  method instead of ciOpenlocalDevice.
             // handle = ciOpenRemoteDevice("citype", "ciname","Hostname"); 
             ciBindQoS(handle, qos, "Metric");
             PDS ret = null;
             ret = this.PostMessage(qos.SetValue(10));
    
             handle.Dispose();
         }
    }