Advertisement
Robomatics

POV-Ray Distribute Server

Apr 21st, 2013
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 25.46 KB | None | 0 0
  1. 'fancy fancy progress bar that shows biggest contributors by color
  2.  
  3. Imports System.Net.Sockets
  4. Imports System.Security.AccessControl
  5. Imports System.Security.Principal
  6.  
  7. Public Class Form1
  8.  
  9.     Dim Jobname As String = ""
  10.     Dim Source As String = ""
  11.     Dim Frames As New List(Of String)
  12.     Dim frameworking As New List(Of Boolean)
  13.     Dim Framedone As New List(Of Boolean)
  14.     Dim Frameby As New List(Of String)
  15.     Dim framestart As New List(Of TimeSpan)
  16.     Dim frameend As New List(Of TimeSpan)
  17.     Dim frameduration As New List(Of TimeSpan)
  18.     Dim Clients As New List(Of String)
  19.     Dim ClientPubPorts As New List(Of Integer)
  20.     Dim ClientSubPorts As New List(Of Integer)
  21.     Dim ClientFrame As New List(Of Integer)
  22.     Dim Clienttotal As New List(Of Integer)
  23.     Dim clientconnected As New List(Of Boolean)
  24.     Dim clientbusy As New List(Of Boolean)
  25.     Dim clientdescription As New List(Of String)
  26.     Dim Widthz As Integer = 320
  27.     Dim Heightz As Integer = 240
  28.     Dim Started As Boolean
  29.     Dim networkshare As String = ""
  30.     Dim jobfilename As String
  31.     Dim filesearch As Boolean = False
  32.     Dim finished As Boolean = False
  33.  
  34.     Dim publishers As New List(Of UdpClient)
  35.     Dim subscribers As New List(Of UdpClient)
  36.     Dim mycomputername As String = Environment.MachineName
  37.     Dim startport As Integer = 10100
  38.     Dim mycomputerconnections() As Net.NetworkInformation.NetworkInterface
  39.  
  40.     Dim MCPub As New UdpClient()
  41.  
  42.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  43.  
  44.         mycomputerconnections = Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
  45.         TBServer.Text = mycomputername
  46.  
  47.         MCPub.JoinMulticastGroup(Net.IPAddress.Parse("239.80.8.5"), 4)
  48.         MCPub.EnableBroadcast = True
  49.         MCPub.Client.Blocking = False
  50.         MCPub.Client.ReceiveTimeout = 100
  51.         MCPub.ExclusiveAddressUse = False
  52.         MCPub.Client.MulticastLoopback = True
  53.  
  54.         For i = 0 To mycomputerconnections.Length - 1
  55.             CBConnections.Items.Add(mycomputerconnections(i).Name)
  56.         Next
  57.  
  58.         CBConnections.SelectedIndex = My.Settings.Connection
  59.  
  60.     End Sub
  61.  
  62.     'Initial Setup
  63.     Private Sub PBSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PBSource.Click
  64.         OFDSource.ShowDialog()
  65.     End Sub
  66.     Private Sub OFDSource_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFDSource.FileOk
  67.         Source = OFDSource.FileName.Substring(0, OFDSource.FileName.LastIndexOf("\"))
  68.         jobfilename = OFDSource.FileName.Substring(OFDSource.FileName.LastIndexOf("\") + 1)
  69.         TBSource.Text = Source
  70.         filesearch = False
  71.         finished = False
  72.  
  73.         If RadioButton1.Checked = True Then
  74.             If IO.Directory.Exists("C:\POVShare") = False Then
  75.                 IO.Directory.CreateDirectory("C:\POVShare")
  76.                 Dim managementClass As New ManagementClass("Win32_Share")
  77.                 Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create")
  78.                 inParams.Item("Description") = "POVShare"
  79.                 inParams.Item("Name") = "POVShare"
  80.                 inParams.Item("Path") = "C:\POVShare"
  81.                 inParams.Item("Type") = 0
  82.                 inParams.Item("Password") = Nothing
  83.                 inParams.Item("Access") = Nothing
  84.                 inParams.Item("MaximumAllowed") = Nothing
  85.                 If (DirectCast(managementClass.InvokeMethod("Create", inParams, Nothing).Properties.Item("ReturnValue").Value, UInt32) <> 0) Then
  86.                     Throw New Exception("Unable to share directory.")
  87.                 End If
  88.  
  89.                 Dim FilePath As String = "C:\POVShare"
  90.                 Dim dirinfo As New IO.DirectoryInfo(FilePath)
  91.                 Dim dirsec As DirectorySecurity = dirinfo.GetAccessControl()
  92.                 dirsec.AddAccessRule(New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow))
  93.                 dirsec.AddAccessRule(New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow))
  94.                 dirsec.AddAccessRule(New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.InheritOnly, AccessControlType.Allow))
  95.                 dirinfo.SetAccessControl(dirsec)
  96.  
  97.                 'SID
  98.                 Dim NTacc As New NTAccount("Everyone")
  99.                 Dim userSID As SecurityIdentifier = DirectCast(NTacc.Translate(GetType(SecurityIdentifier)), SecurityIdentifier)
  100.                 Dim utenteSIDArray(userSID.BinaryLength) As Byte
  101.                 'TRUSTEE
  102.                 Dim usertrustee As ManagementObject = New ManagementClass(New ManagementPath("Win32_Trustee"), Nothing)
  103.                 usertrustee.Item("Name") = "Everyone"
  104.                 usertrustee.Item("SID") = utenteSIDArray
  105.                 'ACE
  106.                 Dim userACE As ManagementObject = New ManagementClass(New ManagementPath("Win32_Ace"), Nothing)
  107.                 userACE.Item("AccessMask") = 2032127 'Full access
  108.                 userACE.Item("AceFlags") = AceFlags.ObjectInherit & AceFlags.ContainerInherit
  109.                 userACE.Item("AceType") = AceType.AccessAllowed
  110.                 userACE.Item("Trustee") = usertrustee
  111.                 Dim userSecurityDescriptor As ManagementObject = New ManagementClass(New ManagementPath("Win32_SecurityDescriptor"), Nothing)
  112.                 userSecurityDescriptor("ControlFlags") = 4
  113.                 userSecurityDescriptor("DACL") = New Object() {userACE}
  114.                 'Permission
  115.                 Dim mc As ManagementClass = New ManagementClass("Win32_Share")
  116.                 Dim share As ManagementObject = New ManagementObject(mc.Path.ToString & ".Name='" & "POVShare" & "'")
  117.                 share.InvokeMethod("SetShareInfo", New Object() {Int32.MaxValue, "POVShare", userSecurityDescriptor})
  118.  
  119.             End If
  120.  
  121.             If IO.Directory.Exists("C:\POVShare\" & Jobname) = False Then
  122.                 My.Computer.FileSystem.CopyDirectory(Source, "C:\POVShare\" & Jobname, FileIO.UIOption.AllDialogs)
  123.                 Dim FilePath As String = "C:\POVShare\" & Jobname
  124.                 Dim dirinfo As New IO.DirectoryInfo(FilePath)
  125.                 Dim dirsec As DirectorySecurity = dirinfo.GetAccessControl()
  126.                 dirsec.AddAccessRule(New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow))
  127.                 dirsec.AddAccessRule(New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow))
  128.                 dirsec.AddAccessRule(New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.InheritOnly, AccessControlType.Allow))
  129.                 dirinfo.SetAccessControl(dirsec)
  130.             End If
  131.             '
  132.             Source = "C:\POVShare\" & Jobname
  133.         Else
  134.             networkshare = FBDShare.SelectedPath
  135.             If IO.Directory.Exists(networkshare & "\" & Jobname) = False Then
  136.                 My.Computer.FileSystem.CopyDirectory(Source, networkshare & "\" & Jobname, FileIO.UIOption.AllDialogs)
  137.                 Dim filepath As String = networkshare & "\" & Jobname
  138.             End If
  139.  
  140.         End If
  141.  
  142.         Timer1.Enabled = True
  143.         FrameRead()
  144.     End Sub
  145.  
  146.     'Frame Length
  147.     Private Sub FrameRead()
  148.         Dim filelist() As String = IO.Directory.GetFiles(Source)
  149.         Dim ini As String = "naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame"
  150.         For i = 0 To filelist.Count - 1
  151.             Dim fName As String = filelist(i).Substring(Source.Length + 1)
  152.             If fName.Contains("ini") And fName.Count < ini.Count Then
  153.                 ini = fName
  154.             End If
  155.         Next
  156.  
  157.         If ini = "naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame" Then
  158.             MsgBox("Unable to find job INI")
  159.             Source = ""
  160.             Return
  161.         End If
  162.  
  163.         ini = IO.Path.Combine(Source, ini)
  164.  
  165.         Dim filelines() As String
  166.         GC.Collect()
  167.         filelines = IO.File.ReadAllLines(ini)
  168.         GC.Collect()
  169.  
  170.         Dim framecount As Integer = 0
  171.         For i = 0 To filelines.Count - 1
  172.             If filelines(i).Contains("Final_Frame") Then
  173.                 framecount = filelines(i).Substring(12)
  174.             End If
  175.         Next
  176.  
  177.         For i = 0 To framecount - 1
  178.             DGVFrames.Rows.Add()
  179.             DGVFrames.Rows(DGVFrames.Rows.Count - 1).Cells(0).Value = i + 1
  180.             Frames.Add("")
  181.             Framedone.Add(False)
  182.             frameworking.Add(False)
  183.             Frameby.Add("")
  184.             framestart.Add(New TimeSpan)
  185.             frameend.Add(New TimeSpan)
  186.             frameduration.Add(New TimeSpan)
  187.         Next
  188.  
  189.     End Sub
  190.  
  191.     'Main Loop
  192.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  193.  
  194.         'MCPub-------------------------------------------------------
  195.         Dim ep2 As Net.IPEndPoint = New Net.IPEndPoint(Net.IPAddress.Parse("239.80.8.5"), 10100)
  196.  
  197.         Try
  198.             Dim rcvbytes() As Byte = MCPub.Receive(ep2)
  199.             Dim MCSubRcv As String = System.Text.Encoding.ASCII.GetString(rcvbytes)
  200.  
  201.             If MCSubRcv.Contains("%PVD%MCP") Then
  202.                 Dim MCsubRcvLines() As String = MCSubRcv.Split("%")
  203.                 Connect(MCsubRcvLines(3), MCsubRcvLines(4))
  204.             End If
  205.         Catch ex As Exception
  206.         End Try
  207.  
  208.         Dim lastportused As Integer = startport
  209.         For i = 0 To ClientPubPorts.Count - 1
  210.             If ClientPubPorts(i) >= lastportused Then
  211.                 lastportused = ClientPubPorts(i)
  212.             End If
  213.         Next
  214.         For i = 0 To ClientSubPorts.Count - 1
  215.             If ClientSubPorts(i) >= lastportused Then
  216.                 lastportused = ClientSubPorts(i)
  217.             End If
  218.         Next
  219.  
  220.         Try
  221.             Dim stringz As String = "%PVD%MCS%" & mycomputername & "%" & lastportused + 1 & "%" & lastportused + 2
  222.             Dim sendbytes() As Byte = System.Text.Encoding.ASCII.GetBytes(stringz)
  223.             MCPub.Send(sendbytes, sendbytes.Length, ep2)
  224.         Catch ex As Exception
  225.         End Try
  226.  
  227.         'Complete?---------------------------------------------------
  228.         Dim complete As Boolean = True
  229.         Dim framesdone As Integer = 0
  230.         If Source <> "" And Frames.Count > 0 Then
  231.             For i = 0 To Framedone.Count - 1
  232.                 If Framedone(i) = False Then
  233.                     complete = False
  234.                 Else
  235.                     framesdone = framesdone + 1
  236.                 End If
  237.             Next
  238.             If complete = True Then
  239.                 Timer1.Enabled = False
  240.                 finished = True
  241.                 MsgBox("POV Ray Complete")
  242.             End If
  243.         End If
  244.  
  245.         'Draw Progress-----------------------------------------------
  246.         If Frames.Count > 0 Then
  247.             Dim ratio As Integer = (framesdone / Frames.Count) * PictureBox1.Size.Width
  248.             Dim graphpic As New Bitmap(PictureBox1.Width, PictureBox1.Height)
  249.             Dim graphgfx As Graphics = Graphics.FromImage(graphpic)
  250.             graphgfx.FillRectangle(Brushes.Black, New Rectangle(0, 0, graphpic.Width, graphpic.Height))
  251.             graphgfx.FillRectangle(Brushes.LimeGreen, New Rectangle(0, 0, ratio, graphpic.Height))
  252.             PictureBox1.Image = graphpic
  253.         End If
  254.  
  255.         '--------------------------------
  256.         For i = 0 To Clients.Count - 1
  257.  
  258.             Dim stringz As String = ""
  259.             Dim Received As String = ""
  260.  
  261.  
  262.             'Send Section----------------------------------------------
  263.             If clientconnected(i) = False Then
  264.                 stringz = "%PVD%N" & mycomputername
  265.             Else
  266.                 If ClientFrame(i) = 0 And Source <> "" And Started = True And filesearch = True And finished = False Then
  267.  
  268.                     Dim frametogive As Integer = 1
  269.                     For i2 = 0 To Frames.Count - 1
  270.                         If frameworking(i2) = False And Framedone(i2) = False Then
  271.                             frameworking(i2) = True
  272.                             ClientFrame(i) = i2 + 1
  273.                             frametogive = i2 + 1
  274.                             Exit For
  275.                         End If
  276.                     Next
  277.  
  278.                     Widthz = NumericUpDown2.Value
  279.                     Heightz = NumericUpDown3.Value
  280.  
  281.                     If RadioButton1.Checked = True Then
  282.                         networkshare = ""
  283.                     End If
  284.  
  285.                     stringz = "%PVD%J" & Jobname & "%S" & networkshare & "%W" & Widthz & "%H" & Heightz & "%F" & frametogive
  286.  
  287.                 End If
  288.             End If
  289.  
  290.             'UDPs--------------------------------------------------------
  291.             If stringz <> "" Then
  292.                 Try
  293.                     Dim sendbytes() As Byte = System.Text.Encoding.ASCII.GetBytes(stringz)
  294.                     publishers(i).Send(sendbytes, sendbytes.Length)
  295.                 Catch ex As Exception
  296.                 End Try
  297.             End If
  298.  
  299.             Try
  300.                 Dim ep As System.Net.IPEndPoint = New System.Net.IPEndPoint(System.Net.IPAddress.Any, ClientSubPorts(i))
  301.                 Dim rcvbytes() As Byte = subscribers(i).Receive(ep)
  302.                 Received = System.Text.Encoding.ASCII.GetString(rcvbytes)
  303.             Catch ex As Exception
  304.             End Try
  305.  
  306.             'Receive Section------------------------------------------------
  307.             If Received <> "" Then
  308.  
  309.                 'Connect ACK
  310.                 If Received = "%PVD%C" Then
  311.                     clientconnected(i) = True
  312.                 End If
  313.  
  314.                 'Frame Done
  315.                 If Received.Contains("%PVD%F") Then
  316.                     Dim reclines() As String = Received.Split("%")
  317.                     Dim framecomplete As Integer = reclines(2).Substring(1)
  318.                     ClientFrame(i) = 0
  319.                     Frames(framecomplete - 1) = reclines(3).Substring(1)
  320.                     Framedone(framecomplete - 1) = True
  321.                     frameend(framecomplete - 1) = My.Computer.Clock.LocalTime.TimeOfDay
  322.                     DGVFrames.Rows(framecomplete - 1).Cells(4).Value = frameend(framecomplete - 1).Hours.ToString & ":" & frameend(framecomplete - 1).Minutes.ToString & ":" & frameend(framecomplete - 1).Seconds.ToString
  323.                     frameworking(framecomplete - 1) = False
  324.                     DGVFrames.Rows(framecomplete - 1).Cells(1).Value = "Rendered"
  325.                     Frameby(framecomplete - 1) = Clients(i)
  326.                     DGVFrames.Rows(framecomplete - 1).Cells(2).Value = Clients(i)
  327.                     Clienttotal(i) = Clienttotal(i) + 1
  328.                 End If
  329.  
  330.                 'Frame Start ACK
  331.                 If Received.Contains("%PVD%J") Then
  332.                     Dim frametogive As Integer = Received.Substring(6)
  333.                     clientbusy(i) = True
  334.                     ClientFrame(i) = frametogive
  335.                     frameworking(frametogive - 1) = True
  336.                     framestart(frametogive - 1) = My.Computer.Clock.LocalTime.TimeOfDay
  337.                     DGVFrames.Rows(frametogive - 1).Cells(3).Value = framestart(frametogive - 1).Hours.ToString & ":" & framestart(frametogive - 1).Minutes.ToString & ":" & framestart(frametogive - 1).Seconds.ToString
  338.                     DGVFrames.Rows(frametogive - 1).Cells(1).Value = "Working"
  339.                 End If
  340.  
  341.             End If
  342.         Next
  343.  
  344.         'Frame Finder----------------------------------------------------
  345.         If filesearch = False Then
  346.             Dim path As String = ""
  347.             If RadioButton1.Checked = True Then
  348.                 path = "C:\POVShare\" & Jobname
  349.             Else
  350.                 path = networkshare
  351.             End If
  352.  
  353.             For i = 0 To Frames.Count - 1
  354.                 Dim maxstring As Integer = (Frames.Count).ToString.Length
  355.                 Dim filepath As String = path & "Images\" & jobfilename.Substring(0, jobfilename.Length - 4) & (i + 1).ToString().PadLeft(maxstring, "0") & ".png"
  356.                 If IO.File.Exists(filepath) Then
  357.                     Framedone(i) = True
  358.                     DGVFrames.Rows(i).Cells(1).Value = "Found"
  359.                 End If
  360.             Next
  361.             filesearch = True
  362.         End If
  363.  
  364.         'DGV Update------------------------------------------------------
  365.         Dim maxworkingframe As Integer = 0
  366.         For i = 0 To Frames.Count - 1
  367.             If frameworking(i) = True Then
  368.                 Dim tempspan As TimeSpan = My.Computer.Clock.LocalTime.TimeOfDay - framestart(i)
  369.                 DGVFrames.Rows(i).Cells(5).Value = tempspan.Minutes.ToString & ":" & tempspan.Seconds.ToString
  370.                 If i > maxworkingframe Then
  371.                     maxworkingframe = i
  372.                 End If
  373.             End If
  374.         Next
  375.  
  376.         If DGVFrames.Focused = False And maxworkingframe > 7 Then
  377.             DGVFrames.FirstDisplayedScrollingRowIndex = maxworkingframe - 7
  378.         End If
  379.  
  380.         For i = 0 To Clients.Count - 1
  381.             If ClientFrame(i) = 0 Then
  382.                 DGVClients.Rows(i).Cells(4).Value = ""
  383.             Else
  384.                 DGVClients.Rows(i).Cells(4).Value = ClientFrame(i)
  385.             End If
  386.             DGVClients.Rows(i).Cells(5).Value = Clienttotal(i)
  387.         Next
  388.  
  389.     End Sub
  390.  
  391.     'Add Client
  392.     Private Sub PBAddClient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PBAddClient.Click
  393.  
  394.         If TBClient.Text Is Nothing Or TBClient.Text = "" Then
  395.             MsgBox("No Client Specified")
  396.             Return
  397.         End If
  398.  
  399.         Connect(TBClient.Text, "")
  400.  
  401.     End Sub
  402.     Private Sub Connect(ByVal clientnamez As String, ByVal description As String)
  403.         Dim pinger As New Net.NetworkInformation.Ping 'Does it ping?
  404.         Try
  405.             Dim pingreply As Net.NetworkInformation.PingReply = pinger.Send(clientnamez, 1000)
  406.             If pingreply.Status <> Net.NetworkInformation.IPStatus.Success Then
  407.                 MsgBox("Unable to Ping, verify your IP and PLC addresses are correct", MsgBoxStyle.Exclamation)
  408.                 Return
  409.             End If
  410.         Catch ex As Exception
  411.             MsgBox("Ping Error on, verify your IP and PLC addresses are correct", MsgBoxStyle.Exclamation) 'Ping fail so hard that you gotta have further info??
  412.             Return
  413.         End Try
  414.  
  415.         Clients.Add(clientnamez)
  416.  
  417.         Dim lastportused As Integer = startport
  418.         For i = 0 To ClientPubPorts.Count - 1
  419.             If ClientPubPorts(i) >= lastportused Then
  420.                 lastportused = ClientPubPorts(i)
  421.             End If
  422.         Next
  423.         For i = 0 To ClientSubPorts.Count - 1
  424.             If ClientSubPorts(i) >= lastportused Then
  425.                 lastportused = ClientSubPorts(i)
  426.             End If
  427.         Next
  428.  
  429.         ClientPubPorts.Add(lastportused + 1)
  430.         ClientSubPorts.Add(lastportused + 2)
  431.  
  432.  
  433.         publishers.Add(New UdpClient())
  434.         publishers(publishers.Count - 1).Client.Blocking = False
  435.         publishers(publishers.Count - 1).ExclusiveAddressUse = False
  436.         publishers(publishers.Count - 1).Connect(Clients(Clients.Count - 1), ClientPubPorts(ClientPubPorts.Count - 1))
  437.  
  438.         subscribers.Add(New UdpClient())
  439.         subscribers(subscribers.Count - 1).Client.Blocking = False
  440.         subscribers(subscribers.Count - 1).Client.ReceiveTimeout = 100
  441.         subscribers(subscribers.Count - 1).ExclusiveAddressUse = False
  442.         subscribers(subscribers.Count - 1).Client.Bind(New Net.IPEndPoint(Net.IPAddress.Any, ClientSubPorts(ClientSubPorts.Count - 1)))
  443.  
  444.  
  445.  
  446.         clientconnected.Add(False)
  447.         ClientFrame.Add(0)
  448.         Clienttotal.Add(0)
  449.         clientbusy.Add(False)
  450.         clientdescription.Add(description)
  451.  
  452.         DGVClients.Rows.Add()
  453.         DGVClients.Rows(DGVClients.Rows.Count - 1).Cells(0).Value = Clients(Clients.Count - 1)
  454.         DGVClients.Rows(DGVClients.Rows.Count - 1).Cells(1).Value = clientdescription(Clients.Count - 1)
  455.         DGVClients.Rows(DGVClients.Rows.Count - 1).Cells(2).Value = ClientPubPorts(ClientPubPorts.Count - 1)
  456.         DGVClients.Rows(DGVClients.Rows.Count - 1).Cells(3).Value = ClientSubPorts(ClientSubPorts.Count - 1)
  457.  
  458.     End Sub
  459.     'Delete Client
  460.     Private Sub PBDeleteClient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PBDeleteClient.Click
  461.        
  462.         Dim selectedrow As Integer = DGVClients.SelectedCells.Item(0).RowIndex
  463.  
  464.         If Started = True Then
  465.             MsgBox("Rendering must be stopped first.")
  466.             Return
  467.         End If
  468.  
  469.         If frameworking(ClientFrame(selectedrow) - 1) = True And clientbusy(selectedrow) = True Then
  470.             frameworking(ClientFrame(selectedrow) - 1) = False
  471.             DGVFrames.Rows(ClientFrame(selectedrow) - 1).Cells(1).Value = ""
  472.             DGVFrames.Rows(ClientFrame(selectedrow) - 1).Cells(3).Value = ""
  473.             DGVFrames.Rows(ClientFrame(selectedrow) - 1).Cells(5).Value = ""
  474.         End If
  475.  
  476.         ClientPubPorts.RemoveAt(ClientPubPorts.IndexOf(DGVClients.Rows(selectedrow).Cells(2).Value))
  477.         ClientSubPorts.RemoveAt(ClientSubPorts.IndexOf(DGVClients.Rows(selectedrow).Cells(3).Value))
  478.         publishers(selectedrow).Client.Dispose()
  479.         publishers.RemoveAt(selectedrow)
  480.         subscribers(selectedrow).Client.Dispose()
  481.         subscribers.RemoveAt(selectedrow)
  482.  
  483.         Clients.RemoveAt(selectedrow)
  484.         clientconnected.RemoveAt(selectedrow)
  485.         ClientFrame.RemoveAt(selectedrow)
  486.         Clienttotal.RemoveAt(selectedrow)
  487.         clientbusy.RemoveAt(selectedrow)
  488.  
  489.         DGVClients.Rows.RemoveAt(selectedrow)
  490.  
  491.     End Sub
  492.  
  493.     'Job Name
  494.     Private Sub TBJobName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TBJobName.TextChanged
  495.         If TBJobName.Text IsNot Nothing And TBJobName.Text <> "" And (RadioButton1.Checked = True Or RadioButton2.Checked = True) Then
  496.             PBSource.Enabled = True
  497.             Jobname = TBJobName.Text
  498.         Else
  499.             PBSource.Enabled = False
  500.         End If
  501.     End Sub
  502.  
  503.     'Start / Stop
  504.     Private Sub PBStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PBStart.Click
  505.         If Started = False Then
  506.             Started = True
  507.             PBStart.Text = "Stop"
  508.         Else
  509.             Started = False
  510.             PBStart.Text = "Start"
  511.         End If
  512.     End Sub
  513.  
  514.     'Network path choose
  515.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  516.         FBDShare.ShowDialog()
  517.     End Sub
  518.     Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
  519.         If RadioButton2.Checked = True Then
  520.             FBDShare.ShowDialog()
  521.             If TBJobName.Text IsNot Nothing And TBJobName.Text <> "" And (RadioButton1.Checked = True Or RadioButton2.Checked = True) Then
  522.                 PBSource.Enabled = True
  523.                 Jobname = TBJobName.Text
  524.             End If
  525.         End If
  526.     End Sub
  527.     Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
  528.         If TBJobName.Text IsNot Nothing And TBJobName.Text <> "" And (RadioButton1.Checked = True Or RadioButton2.Checked = True) Then
  529.             PBSource.Enabled = True
  530.             Jobname = TBJobName.Text
  531.         End If
  532.  
  533.     End Sub
  534.  
  535.     'Connection Set
  536.     Private Sub CBConnections_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBConnections.SelectedIndexChanged
  537.         For i = 0 To mycomputerconnections(CBConnections.SelectedIndex).GetIPProperties.UnicastAddresses.Count - 1
  538.  
  539.             If mycomputerconnections(CBConnections.SelectedIndex).GetIPProperties.UnicastAddresses(i).Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
  540.  
  541.                 Dim bytez() As Byte = mycomputerconnections(CBConnections.SelectedIndex).GetIPProperties.UnicastAddresses(i).Address.GetAddressBytes
  542.                 Dim AddressString As String = bytez(0) & "." & bytez(1) & "." & bytez(2) & "." & bytez(3)
  543.                 Dim ipep As New Net.IPEndPoint(Net.IPAddress.Parse(AddressString), 10100)
  544.  
  545.                 Try
  546.                     MCPub.Close()
  547.                     MCPub = New Net.Sockets.UdpClient(Net.Sockets.AddressFamily.InterNetwork)
  548.                     MCPub.Client.Blocking = False
  549.                     MCPub.Client.ReceiveTimeout = 100
  550.                     MCPub.ExclusiveAddressUse = False
  551.                     MCPub.Client.MulticastLoopback = True
  552.                     MCPub.EnableBroadcast = True
  553.                     MCPub.Client.Bind(ipep)
  554.                     MCPub.JoinMulticastGroup(Net.IPAddress.Parse("239.80.8.5"), 4)
  555.                     LBConnectStatus.ForeColor = Color.LimeGreen
  556.                     LBConnectStatus.Text = "√"
  557.                     My.Settings.Connection = CBConnections.SelectedIndex
  558.                     My.Settings.Save()
  559.                 Catch ex As Exception
  560.                     LBConnectStatus.ForeColor = Color.Red
  561.                     LBConnectStatus.Text = "X"
  562.                 End Try
  563.  
  564.             End If
  565.  
  566.         Next
  567.     End Sub
  568.  
  569. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement