تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
طلب كتابة كلاس تحميل ملف
#1
السلام عليكم ورحمة الله

اريد حد من الاخوة الافاضل يساعدني بتصميم كلاس لتحميل ملف لاني محتاجة بس مشغول جدا في شئ اخر

الطرق
1- الغاء التحميل
2 - ايقاف مؤقت للتحميل
3 - استكمال التحميل

ويكون فيه تحميل عادي وتحميل في مسار خفي لعدم التأثير علي البرنامج

DownloadFileAsync
DownloadFile

الاحداث
اريد حدث واحد فقط يحدث وهو متعلق بانتهاء التحميل او توقفه بحيث e يحمل حالة التحميل سواء اكتمل او توقف او الغي وهكذا

وعند حدوث مشكلة اثناء التحميل لا يتم الغاء تحميل الملف بل يتم عمل ايقاف مؤقت لامكانية الاستكمال

وجزاكم الله خيرا
الرد }}}
تم الشكر بواسطة:
#2
http://www.vbforums.com/showthread.php?6...me-support
الرد }}}
تم الشكر بواسطة: ناجي إبراهيم , ربيع , Aly El-Haddad , جاسم عبد
#3
The variable 'ListViewEx' is either undeclared or was never assigned
الرد }}}
تم الشكر بواسطة:
#4
شكرا اخي سعود وبارك الله فيك
الموضوع ده انا شفته قبل كده
فيه مشكلة عند حدوث مشكلة اثناء التحميل يتم الغاء التحميل ولا يتم عمل ايقاف مؤقت
الرد }}}
تم الشكر بواسطة:
#5
فيه عدة نقاط ارجو ان اتوصل لفهمها:
. دعم استئناف التحميل كيف اعرفه.
. الاستئناف عند الحاجة كيف يكون اصلا.
المثال يبدا من جديد بعد اعادة تشغيله.
الرد }}}
تم الشكر بواسطة:
#6
يمكنك إضافة الملفات التالية الي مشروعك

1- IFileDownloader
2- FileDownloaderUtility
3- Enum FileDownloadStatus
4- FileDownloader
5- FileDownloadProgressChangedEventArgs
6- FileDownloadCompletedEventArgs
7- القورم الرئيسي للمشروع

ستجد الكود الخاص بكل ملف في مشاركة مختلفة لتسهيل الأمر عليك
الرد }}}
تم الشكر بواسطة: سعود
#7
كود :
' This interface defines the basic properties and methods of a Downloader.

Imports System.Net

Public Interface IFileDownloader

#Region " Property "

    ' Basic settings of a Downloader
    Property Url() As Uri
    Property DownloadPath() As String
    Property TotalSize() As Long
    Property Credentials() As ICredentials
    Property Proxy() As IWebProxy

    ' Support the ""Pause"", ""Resume"" and Multi-Threads feature.
    Property IsRangeSupported() As Boolean
    Property StartPoint() As Long
    Property EndPoint() As Long

    ' The downloaded data and status.
    Property DownloadedSize() As Long
    Property CachedSize() As Integer
    Property HasChecked() As Boolean
    Property Status() As FileDownloadStatus
    ReadOnly Property TotalUsedTime() As TimeSpan

    ' Advanced settings of a Downloader
    Property BufferSize() As Integer
    Property BufferCountPerNotification() As Integer
    Property MaxCacheSize() As Integer

#End Region

#Region " Methods "

    Sub CheckUrl(<System.Runtime.InteropServices.Out()> ByRef fileName As String)
    Sub BeginDownload()
    Sub Download()
    Sub Pause()
    Sub [Resume]()
    Sub BeginResume()
    Sub Cancel()

#End Region

#Region " Events "

    Event DownloadCompleted As EventHandler(Of FileDownloadCompletedEventArgs)
    Event DownloadProgressChanged As EventHandler(Of FileDownloadProgressChangedEventArgs)
    Event StatusChanged As EventHandler

#End Region

End Interface
الرد }}}
تم الشكر بواسطة: سعود , kslawy
#8
كود :
' This class helps and supplies the methods to
' 1. Initialize a HttpWebRequest object.
' 2. Check the url and initialize some properties of a downloader.
' 3. Check whether the destination file exists. If not, create a file with
'    the same size as the file to be downloaded.

Imports System.Net
Imports System.Text.RegularExpressions
Imports System.IO

Public NotInheritable Class FileDownloaderUtility

    Private Sub New()
    End Sub

    Public Shared Function InitializeHttpWebRequest(ByVal downloader As IFileDownloader) As HttpWebRequest
        Dim request = CType(WebRequest.Create(downloader.Url), HttpWebRequest)

        If downloader.Credentials IsNot Nothing Then
            request.Credentials = downloader.Credentials
        Else
            request.Credentials = CredentialCache.DefaultCredentials
        End If

        If downloader.Proxy IsNot Nothing Then
            request.Proxy = downloader.Proxy
        Else
            request.Proxy = WebRequest.DefaultWebProxy
        End If

        Return request
    End Function

    ''' <summary>
    ''' Check the URL to download, including whether it supports Range,
    ''' </summary>
    ''' <param name="downloader"></param>
    ''' <returns></returns>
    Public Shared Function CheckUrl(ByVal downloader As IFileDownloader) As String
        Dim fileName As String = String.Empty

        ' Check the file information on the remote server.
        Dim webRequest = InitializeHttpWebRequest(downloader)

        Using response = webRequest.GetResponse()
            For Each header In response.Headers.AllKeys
                If header.Equals("Accept-Ranges", StringComparison.OrdinalIgnoreCase) Then
                    downloader.IsRangeSupported = True
                End If

                If header.Equals("Content-Disposition", StringComparison.OrdinalIgnoreCase) Then
                    Dim contentDisposition As String = response.Headers(header)

                    Dim pattern As String = ".[^;]*;\s+filename=""(?<file>.*)"""
                    Dim r As New Regex(pattern)
                    Dim m As Match = r.Match(contentDisposition)
                    If m.Success Then
                        fileName = m.Groups("file").Value
                    End If
                End If
            Next header

            downloader.TotalSize = response.ContentLength

            If downloader.TotalSize <= 0 Then
                Throw New ApplicationException("The file to download does not exist!")
            End If

            If Not downloader.IsRangeSupported Then
                downloader.StartPoint = 0
                downloader.EndPoint = Integer.MaxValue
            End If
        End Using

        If downloader.IsRangeSupported AndAlso (downloader.StartPoint <> 0 _
                                                OrElse downloader.EndPoint <> Long.MaxValue) Then
            webRequest = InitializeHttpWebRequest(downloader)

            If downloader.EndPoint <> Integer.MaxValue Then
                webRequest.AddRange(downloader.StartPoint, downloader.EndPoint)
            Else
                webRequest.AddRange(downloader.StartPoint)
            End If
            Using response = webRequest.GetResponse()
                downloader.TotalSize = response.ContentLength
            End Using
        End If

        Return fileName
    End Function


    ''' <summary>
    ''' Check whether the destination file exists. If not, create a file with the same
    ''' size as the file to be downloaded.
    ''' </summary>
    Public Shared Sub CheckFileOrCreateFile(ByVal downloader As IFileDownloader, ByVal fileLocker As Object)
        ' Lock other threads or processes to prevent from creating the file.
        SyncLock fileLocker
            Dim fileToDownload As New FileInfo(downloader.DownloadPath)
            If fileToDownload.Exists Then

                ' The destination file should have the same size as the file to be downloaded.
                If fileToDownload.Length <> downloader.TotalSize Then
                    Throw New ApplicationException(
                        "The download path already has a file which does not match" _
                        & " the file to download. ")
                End If

                ' Create a file.
            Else
                If downloader.TotalSize = 0 Then
                    Throw New ApplicationException("The file to download does not exist!")
                End If

                Using fileStream As FileStream = File.Create(downloader.DownloadPath)
                    Dim createdSize As Long = 0
                    Dim buffer(4095) As Byte
                    Do While createdSize < downloader.TotalSize
                        Dim bufferSize As Integer = If((downloader.TotalSize - createdSize) < 4096, CInt(Fix(downloader.TotalSize - createdSize)), 4096)
                        fileStream.Write(buffer, 0, bufferSize)
                        createdSize += bufferSize
                    Loop
                End Using
            End If
        End SyncLock
    End Sub

End Class
الرد }}}
تم الشكر بواسطة: سعود , kslawy
#9
كود :
' The enum DownloadStatus contains all status of FileDownloader.

Public Enum FileDownloadStatus
    ''' <summary>
    ''' The DownloadClient is initialized.
    ''' </summary>
    Initialized

    ''' <summary>
    ''' The client is waiting for an idle thread / resource to start downloading.
    ''' </summary>
    Waiting

    ''' <summary>
    ''' The client is downloading data.
    ''' </summary>
    Downloading

    ''' <summary>
    ''' The client is releasing the resource, and then the downloading
    ''' will be paused.
    ''' </summary>
    Pausing

    ''' <summary>
    ''' The downloading is paused.
    ''' </summary>
    Paused

    ''' <summary>
    ''' The client is releasing the resource, and then the downloading
    ''' will be canceled.
    ''' </summary>
    Canceling

    ''' <summary>
    ''' The downloading is Canceled.
    ''' </summary>
    Canceled

    ''' <summary>
    ''' The downloading is Completed.
    ''' </summary>
    Completed
End Enum
الرد }}}
تم الشكر بواسطة: سعود , kslawy
#10
جربت و لم أجد أي مشاكل في التحميل و الإيقاف المؤقت و استكمال التحميل بالمثال الذي وضعه الأخ سعود..
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [VB.NET] تحديث بيانات فى كلاس من جدول سيكوال asdfar1977 6 184 26-02-24, 01:07 AM
آخر رد: asdfar1977
  تحميل جميع الماسحات الضوئية المتصلة بالجهاز في كومبوبوكس جيولوجي مبتدئ 2 202 22-02-24, 07:10 PM
آخر رد: جيولوجي مبتدئ
  يوجد مشكلة عند تحميل البيانات فى كمبوبوكس داخل داتا جريد new_programer 2 473 17-10-23, 06:51 PM
آخر رد: new_programer
  رجاء التعديل على الكود المرفق - كلاس لعرض كود المورد new_programer 4 357 13-10-23, 01:47 AM
آخر رد: new_programer
  [VB.NET] مساعدة فى طريقة كتابة الاستعلام ZEEN4ZEEN 4 435 11-10-23, 03:33 PM
آخر رد: ZEEN4ZEEN
  كيف يمكن تأخير الـSplash Screen حتى يتم تحميل الأدوات بالكامل؟ hazim1 0 270 28-09-23, 08:23 AM
آخر رد: hazim1
Photo [سؤال] ظور رسالة خطأ عند تحميل قاعدة بيانات تحتوي على صور أبو خالد الشكري 4 396 11-09-23, 09:51 PM
آخر رد: أبو خالد الشكري
  مساعدة كتابة التاريخ داخل داتا جريد فيو كريم عبودي 2 523 22-06-23, 12:28 AM
آخر رد: كريم عبودي
  يوجد خطاء عند تحميل الفورم - مثال شجرة الحسابات new_programer 6 755 11-06-23, 06:47 PM
آخر رد: new_programer
  كتابة النصوص حرف ، حرف ابو روضة 2 401 30-04-23, 04:51 PM
آخر رد: ابو روضة

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم