Dans le cadre du développement d'un module de contrôle de serveur, un outil pour avoir la liste des partitions du serveur WEB et des Occupations de celui-ci.
Dans cet objectif, j'ai utilisé la possibilité d'intégrer les Objets classiques ASP3 :
- le Server.CreateObject("Scripting.FileSystemObject")
Ainsi en reprenant et adaptant du code pour l'ASP, j'ai fait fonctionner mon outil (je l'accorde ce n'est sans doute pas le plus propre, mais au moins il fait ce que je veux :) ).
Je vous fourni donc la source de cette page, il s'agit d'un User Control avec Code Behind (xxx.ascx + xxx.ascx.vb).
Source / Exemple :
' ------ Page xxx.ASCX ------------
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="xxx.ascx.vb" Inherits="MonProjet.DisquesControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie3-2nav3-0" %>
<table class="box">
<tr class="boxheader">
<td class="boxheader">Systèmes de fichiers du Serveur</td>
</tr>
<tr class="boxbody">
<td><table width="100%" id="TableauDisque" align="center" runat="server">
<tr>
<td align="left" valign="top"><font size="-1"><b>Lettre</b></font></td>
<td align="left" valign="top"><font size="-1"><b>Chemin</b></font></td>
<td align="left" valign="top"><font size="-1"><b>Type</b></font></td>
<td align="left" valign="top"><font size="-1"><b>Utilisation</b></font></td>
<td align="right" valign="top"><font size="-1"><b>Libre</b></font></td>
<td align="right" valign="top"><font size="-1"><b>Utililisé</b></font></td>
<td align="right" valign="top"><font size="-1"><b>Taille</b></font></td>
</tr>
</table>
</td>
</tr>
</table>
' ----------------------------------------
' ------ Page xxx.ASCX.VB ------------
Imports System.Web.UI.HtmlControls
Public MustInherit Class DisquesControl
Inherits System.Web.UI.UserControl
Protected WithEvents TableauDisque As System.Web.UI.HtmlControls.HtmlTable
#Region " Code généré par le Concepteur Web Form "
'Cet appel est requis par le Concepteur Web Form.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN : cet appel de méthode est requis par le Concepteur Web Form
'Ne le modifiez pas en utilisant l'éditeur de code.
InitializeComponent()
End Sub
#End Region
' -----------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fso = Server.CreateObject("Scripting.FileSystemObject")
Dim drives = fso.Drives
Dim Drive
Dim isReady
Dim TotalDisqueLibre As Double = 0
Dim TotalDisque As Double = 0
For Each Drive In drives
Dim MaLigne As New HtmlControls.HtmlTableRow()
isReady = Drive.IsReady
If isReady Then
Dim Prop As Integer = CalculProportion(Drive.FreeSpace, Drive.TotalSize)
TotalDisque += Drive.TotalSize
TotalDisqueLibre += Drive.FreeSpace
AddCell(MaLigne, Drive.DriveLetter, "left")
AddCell(MaLigne, "[" & Drive.Path & "] (" & Drive.VolumeName & ")", "left")
AddCell(MaLigne, Drive.FileSystem, "left")
AddCell(MaLigne, RenvoiCodeImage(Prop), "left")
AddCell(MaLigne, Fonctions.AfficheTaille(Drive.FreeSpace, "o"), "right")
AddCell(MaLigne, Fonctions.AfficheTaille((Drive.TotalSize - Drive.FreeSpace), "o"), "right")
AddCell(MaLigne, Fonctions.AfficheTaille(Drive.TotalSize, "o"), "right")
Else
AddCell(MaLigne, Drive.DriveLetter, "left")
AddCell(MaLigne, "[" & Drive.Path & "]", "left")
AddCell(MaLigne, "", "left")
AddCell(MaLigne, "<i>Pas d'informations disponibles pour ce Lecteur</i>", "left", 4)
End If
TableauDisque.Rows.Add(MaLigne)
Next
Dim PropTotal As Integer = CalculProportion(TotalDisqueLibre, TotalDisque)
Dim MaLigneTotal As New HtmlControls.HtmlTableRow()
AddCell(MaLigneTotal, "<i>Totaux : </i>", "right", 3)
AddCell(MaLigneTotal, RenvoiCodeImage(PropTotal), "left")
AddCell(MaLigneTotal, Fonctions.AfficheTaille(TotalDisqueLibre, "o"), "right")
AddCell(MaLigneTotal, Fonctions.AfficheTaille((TotalDisque - TotalDisqueLibre), "o"), "right")
AddCell(MaLigneTotal, Fonctions.AfficheTaille(TotalDisque, "o"), "right")
TableauDisque.Rows.Add(MaLigneTotal)
End Sub
' -----------------------------------------------------
Private Sub AddCell(ByVal tr As HtmlTableRow, ByVal sM As String, ByVal Alignement As String, Optional ByVal ColSpan As Integer = 0)
'Ajoute une cellule dans la ligne du tableau
Dim td As New HtmlTableCell()
td.Align = Alignement
td.VAlign = "top"
If ColSpan > 0 Then
td.ColSpan = ColSpan
End If
td.InnerHtml = "<font size='-1'>" & sM & "</font>"
tr.Cells.Add(td)
End Sub
' -----------------------------------------------------
Private Function CalculProportion(ByVal TailleLibre As Double, ByVal TailleTotale As Double) As Integer
Return Int(((TailleTotale - TailleLibre) / TailleTotale) * 100)
End Function
' -----------------------------------------------------
Private Function RenvoiCodeImage(ByVal Taille As Integer) As String
Dim couleur As String = ""
Dim Retour As String = ""
If Taille > 95 Then couleur = "red"
Retour = "<img height='10' src='./images/" & couleur & "bar_left.gif'>"
Retour &= "<img src='./images/" & couleur & "bar_middle.gif' height='10' width='"
Retour &= (Taille * 2) & "'><img height='10' src='./images/" & couleur & "bar_right.gif'> " & Taille & "%"
Return Retour
End Function
' -----------------------------------------------------
End Class
' -----------------------------------------------------
Conclusion :
Ce User Control fera parti d'un projet plus conséquent en cours de développement qui sera livré bientot ici.
Bon Coding
Romelard Fabrice (Alias F___)
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.