INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: RESOLVED: Plugin dev and SDK questions (at least one for you Gateley)  (Read 3707 times)

MrHaugen

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 3774

There are a few things I would like to implement in my plugin before releasing it.

  • John Gateley, you said you would look into the setting "Data Type" (and flags if possible) in the SDK, when making Custom Field. Have you gotten to it yet?
  • Mr ChriZ once asked for different state settings for plugins (can't find the post now). Ability to start and stop plugin, permanently on etc. Don't know exactly wich he asked for, but have there been any changes here? I need the ability to restart the plugin whenever users re enter the plugin.
  • What is the best way of checking if the SQL database is up? I found a way to ping a computer. That might work, but there would be better to telnet port 1433, so you know exactly wich service that are up or not. I do not know how to use telnet through VB.net, and I think that Vista do not come "out of the box" with telnet. So that plan might not be so good at all. Any ideas?

- Carl
Logged
- I may not always believe what I'm saying

John Gateley

  • Citizen of the Universe
  • *****
  • Posts: 4957
  • Nice haircut
Re: Plugin dev and SDK questions (at least one for you Gateley)
« Reply #1 on: April 28, 2007, 10:55:22 pm »

I haven't done CreateField with a type yet.

I don't know about the "state" settings, if you bump the posting, I'll take a look.

Can't help much with the third, the easiest is probably using SQL through whatever platform you are working on.

j

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Plugin dev and SDK questions (at least one for you Gateley)
« Reply #2 on: April 29, 2007, 06:03:21 am »

    • What is the best way of checking if the SQL database is up? I found a way to ping a computer. That might work, but there would be better to telnet port 1433, so you know exactly wich service that are up or not. I do not know how to use telnet through VB.net, and I think that Vista do not come "out of the box" with telnet. So that plan might not be so good at all. Any ideas?

    - Carl

    Do you want to check that SQL Server services are running, a SQL Server instance is running, or a database exists in an instance of SQLServer? or all 3?  :)

    In reality does it matter?  How are you intending this system to work?
    Will the users each be installing an instance of SQLExpress?
    Or are you going to be hosting a SQLServer instance for all plugin users?

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #3 on: April 29, 2007, 06:09:08 am »

    I haven't done CreateField with a type yet.
    Ok. I'll just have to be patient then. I'll just write an instruction for the plugin users in the mean time.
    Would be great if you got to it some day though. And if you do, could you possibly include the flag setting too (audio, video...)?

    Quote
    I don't know about the "state" settings, if you bump the posting, I'll take a look.
    I found it: http://yabb.jriver.com/interact/index.php?topic=36572.0
    Here they discuss the possibility of turning the plugins on and off. Would be great to have more options than starting it from the moment MC starts and when the user selects the plugin. I'm missing an option to turn off the plugin whenever the user leaves the plugin.
    Logged
    - I may not always believe what I'm saying

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #4 on: April 29, 2007, 06:17:02 am »

    Do you want to check that SQL Server services are running, a SQL Server instance is running, or a database exists in an instance of SQLServer? or all 3?  :)

    In reality does it matter?  How are you intending this system to work?
    Will the users each be installing an instance of SQLExpress?
    Or are you going to be hosting a SQLServer instance for all plugin users?

    I see I wasn't quite clear here. I'm gonna host a MS SQL database for the users of my plugin.
    If the users try to upload or download somthing from my database, and if it is not available, I want them to know.
    Don't want the plugin to gi onto a 42 second timeout untill they get a more or less cryptic message.

    I want to check the connection to my database instance, and therefore also SQL server instance and that the SQL service are running. So, yes. All 3.

    I could run a normal query to check, and set the timeout on the connection I guess. Just have not done the timeout settings before. Just a quick google search I guess, no problem. But are there other, better ways?
    Logged
    - I may not always believe what I'm saying

    Mr ChriZ

    • Citizen of the Universe
    • *****
    • Posts: 4375
    • :-D
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #5 on: April 29, 2007, 08:10:43 am »

    I think that if the client can't connect to the server,
    there's likely to always be a fair amount of delay, since
    it could just be taking along time for data to come back...
    so the most important thing is the user is aware what is happening,
    and when creating the connection the thread isn't blocking
    MC operations, and the interface is also kept looking pretty.

    You can place a try catch block around the connection opening,
    and then handle the different type of exceptions that are thrown
    for if the connection is not opened.

    I'd think that's the most obvious way of doing it.

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #6 on: April 29, 2007, 11:22:51 am »

    Alright. I tried this:
     
    Code: [Select]
    Public SQLquery As String
        Public SQLconn As New SqlConnection("Data Source=10.0.0.5;Initial Catalog=Test;User Id=moodDBUser;Password=testtest;Connect Timeout=5")

        Private Sub subGetDBInteger()
            'Create a command to execute the sql statement
            Dim command As New SqlCommand(SQLquery, SQLconn)
            Try
                'Open the connection
                SQLconn.Open()
            Catch message As Exception
                MessageBox.Show("Failed connection: /n" + message.ToString())
            End Try
            ' Execute command and put value in variable. Note, this uses the ExecuteScalar method. Only going to get single value.
            varDBqueryInt = Convert.ToInt32(command.ExecuteScalar)
            SQLconn.Close()
        End Sub

    The only thing I get is another messagebox with the error message. Don't know exectly what else I can do with this.
    The Connect Timeout does not seem to work either. The timeout is still about 40 sec.
    Any suggestions?

    EDIT: Edited the code example
    Logged
    - I may not always believe what I'm saying

    Mr ChriZ

    • Citizen of the Universe
    • *****
    • Posts: 4375
    • :-D
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #7 on: April 29, 2007, 12:50:29 pm »

    You're opening the connection twice

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #8 on: April 29, 2007, 01:08:02 pm »

    Totally right. That was not the code I was reffering to. Should be correct now.
    What can I do with it to prevent the plugin from hanging?
    Logged
    - I may not always believe what I'm saying

    Mr ChriZ

    • Citizen of the Universe
    • *****
    • Posts: 4375
    • :-D
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #9 on: April 29, 2007, 02:56:12 pm »

    You'll need to create a new thread, and open the connection
    on the new thread.  Do a google search for information
    on threading using VB.NET.  Try to avoid accessing
    information from any GUI interfaces in the new thread as this
    complexifies things significantly.

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #10 on: April 29, 2007, 04:34:41 pm »

    Threads sounds like the right thing, yes. I have tested a few ways of making threads.
    This is the most promising:

    Code: [Select]
     
      Imports System.Threading

      Private Sub Testbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Testbutton.Click
            Dim nthread As Thread
            For i As Integer = 1 To 10
                nthread = New Thread(AddressOf Me.CreateThread)
                nthread.Start()
            Next
      End Sub

      Private Sub CreateThread()
            Dim j As Integer
            For j = 1 To 5
                 i = i.ToString
                 listbox_test.Items.Add(i)
                 i += 1
                Thread.CurrentThread.Sleep(2000)
            Next
     End Sub

    If I understand correctly, this code creates 5 threads. Each one adds 10 numbers in the listbox. In this case (10 x) 10, 20 , 30, 40 and 50. If I do something while it works the numbers sometimes changes.

    When that went so well, I thought I could just replace the For loop with my own sql query and display a Messagebox with the number returned. That only resulted in a "MC have encountered an error and have to close. We are sorry...... Debug, Close."
    Can you tell me what I'm doing wrong? This is the code I tried:

    Code: [Select]
       
    Imports System.Threading

        Private Sub Testbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Testbutton.Click
            Dim nthread As Thread

            For i As Integer = 1 To 10
                nthread = New Thread(AddressOf Me.CreateThread)
                nthread.Start()
            Next
        End Sub

        Private Sub CreateThread()
            SQLquery = "SELECT COUNT(*) FROM Artist"
            subGetDBInteger()

            MessageBox.Show(varDBqueryInt)
        End Sub

    The connection are done in the sebGetDBInteger, and are working fine on it's own...
    Logged
    - I may not always believe what I'm saying

    Mr ChriZ

    • Citizen of the Universe
    • *****
    • Posts: 4375
    • :-D
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #11 on: April 29, 2007, 05:05:01 pm »

    Well for starters...  I don't think you need 10 connections
    on 10 different threads?   :)
    Just one extra should do.
    Secondly that Messagebox may cause problems being on a seperate
    thread.  I don't remember.

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #12 on: April 30, 2007, 12:55:22 pm »

    Arrrrgh! Why can't I ever get my examples right?! It should be without the FOR loop there. The real code I tried had none.

    Anyway. I tried tried what you said, and put the messagebox in the main thread. The code should be something like this:

    Code: [Select]
      ' Public SQLquery As String
      ' Public SQLconn As New SqlConnection("Data Source=10.0.0.x;Initial Catalog=Test;User Id=DBUser;Password=testtest;")
     
     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim nthread As Thread
            nthread = New Thread(AddressOf Me.CreateThread)
            nthread.Start()
            Thread.CurrentThread.Sleep(1000)
            MessageBox.Show(varDBqueryInt)
     End Sub

     Private Sub CreateThread()
            SQLquery = "SELECT COUNT(*) FROM Artist"
            Dim command As New SqlCommand(SQLquery, SQLconn)
            SQLconn.Open()
            varDBqueryInt = Convert.ToInt32(command.ExecuteScalar)
            SQLconn.Close()
      End Sub

    This resulted in almost what I was looking for. It seems that the Messagebox have to be in the main thread to appear at all.
    When the connection is up this works great. The big problem comes when the connection is down. When I put my firewall on, the result "0" pops up in the messagebox. Great! At least I thought so. I got on with my testing. Then, after 42 seconds: CRASH! Down MC goes. It obviously hates the Connection timeout produced by the new thread. I can reduce the timeout, but that will not help much.

    After this I tried to put text in a lable in the second process and it worked great! Combination with a if statement and I can make a huge "CONNECTION UP" or DOWN so the users know what to expect.

    I'll try to look up some info on the SQL timeout and crash problem on google. But if you got any suggestions, please bring them on.
    Logged
    - I may not always believe what I'm saying

    Mr ChriZ

    • Citizen of the Universe
    • *****
    • Posts: 4375
    • :-D
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #13 on: April 30, 2007, 01:08:26 pm »

    This is where it all starts getting complex,
    as you need to create Delegates/Events which will invoke
    stuff back on the main thread in order to work with
    windows forms stuff again.

    I can't really help much here at the moment you'll have to find some resources
    on the subject.

    PaulSinnema

    • Galactic Citizen
    • ****
    • Posts: 393
    • You don't know what you're missing until its gone
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #14 on: April 30, 2007, 04:19:52 pm »

    I've read bits of this thread and got a suggestion to make. Wouldn't a webservice make things a lot easier here?
    Logged

    Mr ChriZ

    • Citizen of the Universe
    • *****
    • Posts: 4375
    • :-D
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #15 on: May 01, 2007, 04:38:51 am »

    as in going three-tier?
    Client
    Server
    Database?

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #16 on: May 01, 2007, 10:33:13 am »

    I've read bits of this thread and got a suggestion to make. Wouldn't a webservice make things a lot easier here?

    A webservice that would do what exactly? I'm not sure I follow you here.
    Logged
    - I may not always believe what I'm saying

    PaulSinnema

    • Galactic Citizen
    • ****
    • Posts: 393
    • You don't know what you're missing until its gone
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #17 on: May 01, 2007, 11:25:04 am »

    MrHaugen,

    A webservice runs on the server not local. It gives you access to functions in the webservice via the Intra-, Extra- or Internet. You can implement all your code for testing if the server is up and running in this webservice running close to the Database. External programs only need to call the function on the webservice which tells it if the database is up or not. All the references to the database also run via the functions in the webservice.

    So much for the theory. I've not programmed them myself other than during a workshop about 5 years ago in JAVA. Since then this kind of functionality has also been integrated into f.i. Visual Studio and I guess it has become much easier to implement them.

    Advantage is that your clients nieed not have a direct connection to the Database, only the webservice does.

    There's a lot of info about Webservices on Wikipedia http://en.wikipedia.org/wiki/Webservice. Hope this helps you.

    Paul.
    Logged

    MrHaugen

    • Regular Member
    • Citizen of the Universe
    • *****
    • Posts: 3774
    Re: Plugin dev and SDK questions (at least one for you Gateley)
    « Reply #18 on: May 01, 2007, 01:54:14 pm »

    The idea is good, but I really don't know if I want to go there. A web service would be the correct way of doing it, but I think a noob VB programmer would get in way over his head. The security are the most beneficial effect I guess.
    I'll do without it for now. Maby I'll look at it in a few months though...

    Thanks for the suggestion.

    I finally got the SQL connection test to work! Here's the result:
       
    Code: [Select]
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim nthread As Thread
            nthread = New Thread(AddressOf Me.CreateThread)
            nthread.Start()
        End Sub

        Private Sub CreateThread()
            Try
                SQLquery = "SELECT COUNT(*) FROM Artist"
                Dim command As New SqlCommand(SQLquery, SQLconn)
                SQLconn.Open()
                varDBqueryInt = Convert.ToInt32(command.ExecuteScalar)
                SQLconn.Open()
            Catch ex As Exception
            Finally
                SQLconn.Close()
            End Try
            If varDBqueryInt = 0 Then
                lbl_test2.Text = "Warning! Database down!"
            Else
                lbl_test2.Text = "Database up and running"
            End If
      End Sub
    Logged
    - I may not always believe what I'm saying
    Pages: [1]   Go Up