Accueil > > > ASP.NET - AFFICHER LES DÉTAILS DE LA LISTE DES PARTITIONS DU SERVEUR WEB
ASP.NET - AFFICHER LES DÉTAILS DE LA LISTE DES PARTITIONS DU SERVEUR WEB
Information sur la source
Description
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
- ' ------ 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
-
- ' -----------------------------------------------------
-
' ------ 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___)
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
GRIDVIEW CHECKBOXGRIDVIEW CHECKBOX par invent001
Cliquez pour lire la suite par invent001 OUTIL MYSQLOUTIL MYSQL par nobla
Cliquez pour lire la suite par nobla
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|