1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| Imports System
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Math
Imports System.Xml
Imports System.Text
Imports System.IO
Imports System.Xml.XPath
Imports System.Xml.XmlNode
Imports System.Xml.XmlAttribute
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Sub Main()
Try
GenerateEan13()
'GeneratePhoto()
Catch e As Exception
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
Sub GenerateEan13()
Try
Dim doc As New XmlDocument
Dim valeur As String
'Dim sRep As String
'Dim sFileXml As String
Dim sRep As String = Dts.Variables("H_generateArboLivre").Value.ToString
MsgBox(" destination____" & sRep)
Dim sFileXml As String = Dts.Variables("generateEan13").Value.ToString
'sRep = "C:\LMG_EDDAKRI\LMG\OUT\Livre\"
'sFileXml = "C:\LMG_EDDAKRI\LMG\OUT\Livre\ean13.xml"
Dim sRead As StreamReader = New StreamReader(sFileXml, Encoding.UTF8)
'''''''''''''''''''''''''''''''''
Dim cm As ConnectionManager = Dts.Connections.Add("FTP")
cm.Properties("ServerName").SetValue(cm, "www.portail-presse.fr")
cm.Properties("ServerUserName").SetValue(cm, "ftp-lmg")
cm.Properties("ServerPassword").SetValue(cm, "lmg#3")
cm.Properties("ServerPort").SetValue(cm, "21")
cm.Properties("Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout
cm.Properties("ChunkSize").SetValue(cm, "1000") '1000 kb
cm.Properties("Retries").SetValue(cm, "1")
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
ftp.Connect()
Dim files(0) As String
doc.Load(sRead)
sRead.Close()
Dim fs As FileStream
Dim listNodes As XmlNodeList = doc.GetElementsByTagName("ean13")
For Each nodeEan13 As XmlNode In listNodes
'Dim root As XmlNode = doc.SelectSingleNode("xml/ean13")
Dim attrib As XmlAttribute = CType(nodeEan13.Attributes.GetNamedItem("ean13"), XmlAttribute)
'récupération de la valeur de l'attribut
valeur = attrib.InnerText()
Dim sRepEan13 As String = sRep & valeur 'Path.Combine(sRep, valeur)
MsgBox(" sRepEan13________" & sRepEan13)
'If Not Directory.Exists(sRepEan13) Then
'Directory.CreateDirectory(sRepEan13)
ftp.CreateRemoteDirectory(sRepEan13)
'End If
Dim dFileName As String = valeur & ".xml"
MsgBox(" dFileName" & dFileName)
Dim sFileEan13 As String = sRepEan13 & "/" & dFileName 'Path.Combine(sRepEan13, dFileName)
MsgBox(" sFileEan13" & sFileEan13)
Dim subdoc As New XmlDocument
'Dim nouvelleNode As XmlNode = nodeEan13.CloneNode(True)
'Dim nodeDec As XmlNode = subdoc.CreateXmlDeclaration("1.0", Encoding.UTF8.ToString(), "")
Dim nodeRoot As XmlNode = subdoc.CreateElement("XML")
subdoc.AppendChild(nodeRoot)
Dim nouvelleNode As XmlNode = subdoc.ImportNode(nodeEan13, True)
Dim listNodesSupprime As XmlNodeList = nouvelleNode.SelectNodes("urlOuvrage[@url=''] | urlAuteur[@url='']")
For Each nodeSupprime As XmlNode In listNodesSupprime
nouvelleNode.RemoveChild(nodeSupprime)
Next
nodeRoot.AppendChild(nouvelleNode)
MsgBox(" ddddd")
fs = file(sFileEan13)
'Dim fs As FileStream = New FileStream(sFileEan13, FileMode.Create)
MsgBox(" fs________" & fs.ToString)
Dim w As XmlTextWriter = New XmlTextWriter(fs, Encoding.UTF8)
MsgBox(" w_________" & w.ToString)
files(0) = sFileEan13
MsgBox(" sFileEan13________" & sFileEan13)
'fs = Nothing
Try
subdoc.Save(fs)
MsgBox("ici try")
Catch ex As Exception
Throw ex
MsgBox("ex")
Finally
w.Flush()
MsgBox("ici w flush")
fs.Close()
MsgBox("ici fs close")
End Try
ftp.SendFiles(files, sRepEan13, True, False)
Next
Catch e As Exception
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
' VBScript source code
Function file(ByVal sFileEan13 As String) As FileStream
Dim fs As FileStream = New FileStream(sFileEan13, FileMode.Create)
Return fs
End Function
End Class |
Partager