Вопрос как правильно объявить переменную, чтобы она была уникальной для каждого экземмпляра explorer, но общей для всех создаваемых классов rootfolder в каждом экземпляре explorer? Если такое возможно вообще. Сдается мне что нет.
З.Ы. Пробовал передавать Sock из класса в класс на всяких перекладных - не получается. Пробовал создавать массив Friend Shared Sock(), в котором индекс был бы каким-нибудь уникальным идентификатором каждого экземпляра explorer, например hwnd его окна, тоже не получается, т.к. когда explorer сам вызывает рефреш содержимого, то он нормально передает свой hwnd, а когда ты вручную вызываешь рефреш (типа root.refreshview()), то hwnd равен 0. Видимо это уже глюк EZNamespaceExtensions.NET.
- Код: Выделить всё
Imports System.IO
Imports System.Runtime.InteropServices
Imports SkySoftware.EZNamespaceExtensions
Imports SocketWrenchCtl
Imports Microsoft.VisualBasic.Strings
Imports System.Text
Namespace ONS_Ext
<Guid("93D3BFCF-2066-4573-952A-F15E10A61B06")> _
Public Class ONSRootFolder
Inherits NSEFolder
Friend Children() As NSEItem
Friend WithEvents Sock As New SocketWrenchClass
'Friend Shared SockSh() As SocketWrenchClass
Friend Root As ONSRootFolder
Friend RefreshFolder As ONSFolder
Friend TreeFI() As FI
Friend TreeDI() As DI
Friend KolFI As Long
Friend KolDI As Long
Friend posarr As Long
Friend CommandSock As String = ""
Friend StatusServer As String = ""
<ComRegisterFunction()> _
Protected Shared Sub Register(ByVal t As System.Type)
NSEFolder.RegisterExtension(GetType(ONSRootFolder))
End Sub
<ComUnregisterFunction()> _
Protected Shared Sub UnRegister(ByVal t As System.Type)
NSEFolder.UnregisterExtension(GetType(ONSRootFolder))
End Sub
Public Overrides Function GetNSETargetInfo() As NSETargetInfo
Dim tempAttrib As NSEItemAttributes
tempAttrib = NSEItemAttributes.Folder Or NSEItemAttributes.HasSubFolder Or NSEItemAttributes.Browsable Or NSEItemAttributes.FileSysAncestor Or NSEItemAttributes.FileSystem
Dim nti As NSETargetInfo = New NSETargetInfo("ONS_Ext", NSETarget.MyComputer, tempAttrib)
nti.IconFile = Path.Combine(Utils.GetWindowsDirectory(), "explorer.exe")
nti.IconIndex = 1
nti.InfoTip = "ONS Extension"
Return nti
End Function
Public Overrides Function GetColumns() As ShellColumn()
Return ONSFolder.columns
End Function
Public Overrides Function GetChildren(ByVal e As GetChildrenEventArgs) As IEnumerable
Root = Me
Dim ret As ArrayList = New ArrayList(1)
If ((e.ChildrenType And ChildrenType.Folders) <> 0) Then
If Sock.Connected = True Then
ReDim Root.Children(1)
ret.Add(New ONSFolder(Me, RootHiveType.Projects))
ret.Add(New ONSFolder(Me, RootHiveType.Contracts))
Root.Children(0) = ret.Item(0)
Root.Children(1) = ret.Item(1)
'SockArr(e.HWnd) = Sock
End If
End If
Return ret
End Function
Public Overrides Function DeserializeChild(ByVal reader As BinaryReader) As NSEItem
reader.ReadInt32()
Dim hive As RootHiveType = CType(reader.ReadInt32(), RootHiveType)
Dim name As String = reader.ReadString()
Return New ONSFolder(Me, hive)
End Function
Public Overrides Function GetDisplayNameEx(ByVal flags As DisplayNameFlags) As String
If flags = DisplayNameFlags.ForParsing Then
Return Path.GetTempPath()
End If
Return MyBase.GetDisplayNameEx(flags)
End Function
Public Overrides Sub OnViewinitialized()
If Sock.Connected = False And Sock.Interval = 0 Then
Sock.Interval = 1000
End If
End Sub
Public Overrides Sub OnViewDestroyed()
Sock.Interval = 0
Sock = Nothing
End Sub
Private Sub Sock_Timer() Handles Sock.OnTimer
If Sock.Connected = False Then
With Sock
.AutoResolve = False
.Protocol = ProtocolConstants.swProtocolTcp
.Timeout = 5000
.Blocking = False
.HostAddress = "127.0.0.1"
.RemotePort = 7117
.Connect()
End With
End If
End Sub
Private Sub Sock_Connect() Handles Sock.OnConnect
Sock.Interval = 0
Root.RefreshView()
End Sub
Private Sub Sock_DisConnect() Handles Sock.OnDisconnect
Sock.Disconnect()
Root.Children(0).Delete()
Root.Children(1).Delete()
Root.RefreshView()
Sock.Interval = 1000
End Sub
Private Sub Sock_Read() Handles Sock.OnRead
Dim rcvl As Object
Dim NewCommand As String = ""
Dim bt() As Byte
If StatusServer = "" Then 'если мы ничего не ждем от сервера
ElseIf StatusServer = "filltree" Then
Sock.Read(NewCommand)
If Left(NewCommand, 17) = "filltreebeginsend" Then
KolFI = CInt(Mid(NewCommand, InStr(1, NewCommand, "_", 1) + 1, InStr(InStr(1, NewCommand, "_", 1) + 1, NewCommand, "_", 1) - InStr(1, NewCommand, "_", 1) - 1))
KolDI = CInt(Right(NewCommand, Len(NewCommand) - InStr(InStr(1, NewCommand, "_", 1) + 1, NewCommand, "_", 1)))
If KolFI > 0 Then ReDim TreeFI(KolFI - 1)
If KolDI > 0 Then ReDim TreeDI(KolDI - 1)
StatusServer = "sendingtree"
CommandSock = "filltreebeginsend_ok"
posarr = 0
Sock.Write(CommandSock, Len(CommandSock))
End If
ElseIf StatusServer = "sendingtree" Then
ReDim bt(769)
rcvl = Sock.Read(bt)
If rcvl = 770 Then
TreeFI(posarr) = ByteToStruct(bt, 512)
TreeDI(posarr) = ByteToStruct(bt, 258)
ElseIf rcvl = 512 Then
TreeFI(posarr) = ByteToStruct(bt, 512)
ElseIf rcvl = 258 Then
TreeDI(posarr) = ByteToStruct(bt, 258)
End If
If KolFI = 0 And KolDI = 0 Then
CommandSock = "gettree_ok"
Sock.Write(CommandSock, Len(CommandSock))
StatusServer = "gettree_ok"
Else
If posarr = KolFI - 1 And posarr > KolDI - 1 Then
CommandSock = "gettree_ok"
Sock.Write(CommandSock, Len(CommandSock))
StatusServer = "gettree_ok"
ElseIf posarr = KolDI - 1 And posarr > KolFI - 1 Then
CommandSock = "gettree_ok"
Sock.Write(CommandSock, Len(CommandSock))
StatusServer = "gettree_ok"
ElseIf posarr = KolDI - 1 And posarr = KolFI - 1 Then
CommandSock = "gettree_ok"
Sock.Write(CommandSock, Len(CommandSock))
StatusServer = "gettree_ok"
Else
posarr = posarr + 1
CommandSock = Str(posarr)
Sock.Write(CommandSock, Len(CommandSock))
StatusServer = "sendingtree"
End If
End If
ElseIf StatusServer = "gettree_ok" Then
Sock.Read(NewCommand)
If NewCommand = "gettree_ok" Then
StatusServer = ""
RefreshFolder.RefreshView()
End If
End If
End Sub
Private Function ByteToStruct(ByVal buffer() As Byte, Optional ByVal numbytes As Integer = 0) As Object
Dim retFI As New ONSDeclaration.FI
Dim retDI As ONSDeclaration.DI
If UBound(buffer) = 769 Then
If numbytes = 512 Then
retFI.Folder = BitConverter.ToInt32(buffer, 0)
retFI.Name = BitConverter.ToString(buffer, 4)
retFI.ServerPath = BitConverter.ToString(buffer, 254)
retFI.Level = BitConverter.ToInt32(buffer, 504)
retFI.Parent = BitConverter.ToInt32(buffer, 508)
Return retFI
ElseIf numbytes = 258 Then
retDI.Document = BitConverter.ToInt32(buffer, 0)
retDI.Name = BitConverter.ToString(buffer, 4)
retDI.Parent = BitConverter.ToInt32(buffer, 254)
Return retDI
Else
End If
ElseIf UBound(buffer) = 511 Then
retFI.Folder = BitConverter.ToInt32(buffer, 0)
retFI.Name = BitConverter.ToString(buffer, 4)
retFI.ServerPath = BitConverter.ToString(buffer, 254)
retFI.Level = BitConverter.ToInt32(buffer, 504)
retFI.Parent = BitConverter.ToInt32(buffer, 508)
Return retFI
ElseIf UBound(buffer) = 257 Then
retDI.Document = BitConverter.ToInt32(buffer, 0)
retDI.Name = BitConverter.ToString(buffer, 4)
retDI.Parent = BitConverter.ToInt32(buffer, 254)
Return retDI
End If
Return Nothing
End Function
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
Public Class ONSFolder
Inherits NSEFolder
Friend FolderName As String
Friend RootHive As RootHiveType
Friend FolderPath As String
Friend Root As ONSRootFolder
Friend Folder As Long
Friend Shared columns As ShellColumn()
Shared Sub New()
Dim colName As ShellColumn = New ShellColumn("Name")
colName.FormatIdentifier = New Guid("b725f130-47ef-101a-a5f1-02608c9eebac")
colName.PropertyIdentifier = 10
columns = New ShellColumn() {colName}
End Sub
Friend Sub New(ByVal parent As ONSFolder, ByVal name As String)
Folder = 123
Root = parent.Root
RootHive = parent.RootHive
If (parent.FolderPath = String.Empty) Then
FolderPath = name + "\"
Else
FolderPath = parent.FolderPath + name + "\"
End If
FolderName = name
End Sub
Friend Sub New(ByVal rootfld As ONSRootFolder, ByVal hive As RootHiveType)
Folder = 0
Root = rootfld
RootHive = hive
FolderPath = DisplayNameFromRootHive(hive)
FolderName = DisplayNameFromRootHive(hive)
End Sub
Public Overrides Sub Serialize(ByVal writer As BinaryWriter)
writer.Write(CInt(ItemType.Folder))
writer.Write(CInt(RootHive))
writer.Write(FolderName)
End Sub
Public Overrides Function GetChildren(ByVal e As GetChildrenEventArgs) As IEnumerable
Dim ret As ArrayList = New ArrayList(0)
'If RootHive = RootHiveType.Projects Then
' Root.CommandSock = "filltree_" & Trim(Str(Folder))
' Root.Sock.Write(Root.CommandSock, Len(Root.CommandSock))
' Root.StatusServer = "filltree"
' Root.RefreshFolder = Me
'End If
Return ret
End Function
Public Overrides Function DeserializeChild(ByVal reader As BinaryReader) As NSEItem
Dim itype As ItemType = CType(reader.ReadInt32(), ItemType)
If itype = ItemType.Folder Then
Dim hive As RootHiveType = CType(reader.ReadInt32(), RootHiveType)
Dim name As String = reader.ReadString()
Return New ONSFolder(Me, name)
Else
Dim name As String = reader.ReadString()
Return New ONSFile(Me, name)
End If
End Function
Public Overrides Function GetAttributes(ByVal attributes As NSEItemAttributes) As NSEItemAttributes
Dim ret As NSEItemAttributes = NSEItemAttributes.Folder _
Or NSEItemAttributes.CanRename Or NSEItemAttributes.CanDelete _
Or NSEItemAttributes.CanLink Or NSEItemAttributes.CanCopy _
Or NSEItemAttributes.CanMove Or NSEItemAttributes.DropTarget _
Or NSEItemAttributes.FileSysAncestor Or NSEItemAttributes.FileSystem _
Or NSEItemAttributes.Browsable Or NSEItemAttributes.HasSubFolder
Return ret
End Function
Friend Shared Function DisplayNameFromRootHive(ByVal rh As RootHiveType) As String
Select Case rh
Case RootHiveType.Projects
Return "Проекты"
Case RootHiveType.Contracts
Return "Договора"
Case Else
Return "UNKNOWN"
End Select
End Function
Public Overrides Sub OnViewinitialized()
End Sub
Public Overrides Sub GetIconFileAndIndex(ByVal e As GetIconFileAndIndexEventArgs)
e.IconExtractMode = IconExtractMode.IconFileAndIndex
e.IconFile = Path.Combine(Environment.SystemDirectory, "Shell32.dll")
e.IconIndex = -5
End Sub
Public Overrides Function GetColumns() As ShellColumn()
Return columns
End Function
Public Overrides Function GetDisplayName() As String
Return FolderName
End Function
Public Overrides Function GetDisplayNameEx(ByVal flags As DisplayNameFlags) As String
If flags = DisplayNameFlags.ForParsing Then
Directory.CreateDirectory(Path.GetTempPath() + FolderPath + "\")
Return Path.GetTempPath() + FolderPath + "\"
End If
Return FolderName
End Function
End Class
Public Class ONSFile
Inherits NSEItem
Friend FileName As String
Friend RootHive As RootHiveType
Friend FolderPath As String
Friend Sub New(ByVal parent As ONSFolder, ByVal name As String)
RootHive = parent.RootHive
FolderPath = parent.FolderPath
Me.FileName = name
End Sub
Public Overrides Sub Serialize(ByVal writer As BinaryWriter)
writer.Write(CInt(ItemType.File))
writer.Write(FileName)
End Sub
Public Overrides Function GetAttributes(ByVal attributes As NSEItemAttributes) As NSEItemAttributes
Dim ret As NSEItemAttributes = NSEItemAttributes.CanRename Or NSEItemAttributes.CanDelete Or NSEItemAttributes.CanMove Or NSEItemAttributes.CanCopy Or NSEItemAttributes.FileSystem
Return ret
End Function
Public Overrides Function GetDisplayName() As String
Return FileName
End Function
Public Overrides Function GetDisplayNameEx(ByVal flags As DisplayNameFlags) As String
If flags = DisplayNameFlags.ForParsing Then
Directory.CreateDirectory(Path.GetTempPath() + FolderPath + "\")
Return Path.GetTempPath() + FolderPath + "\"
End If
Return FileName
End Function
End Class
Module ONSDeclaration
Friend Enum ItemType
Folder = 1
File = 2
End Enum
Friend Enum RootHiveType
Projects = 1
Contracts = 2
End Enum
Friend Structure FI
Dim Folder As Long
<VBFixedString(250)> Dim Name As String
<VBFixedString(250)> Dim ServerPath As String
Dim Level As Long
Dim Parent As Long
End Structure
Friend Structure DI
Dim Document As Long
<VBFixedString(250)> Dim Name As String
Dim Parent As Long
End Structure
End Module
End Namespace