Click here to Skip to main content
11,704,315 members (60,189 online)
Click here to Skip to main content
Add your own
alternative version

MyDownloader: A Multi-thread C# Segmented Download Manager

, 12 Feb 2008 CPOL 1.3M 86.3K 1.2K
Sample application that manages multiple segmented downloads and supports HTTP, FTP and YouTube video downloads
mydownloader_demo.zip
ffmpeg.exe
ICSharpCode.SharpZipLib.dll
MyDownloader.App.exe
MyDownloader.Core.dll
MyDownloader.Extension.dll
MyDownloader.Spider.dll
pthreadGC2.dll
TabStrip.dll
mydownloader_src.zip
TabStrip.dll
ICSharpCode.SharpZipLib.dll
Interop.SHDocVw.dll
MyDownloader.App
Controls
BlockedProgressBar.bmp
MyDownloader.App.csproj.user
Properties
Settings.settings
SingleInstancing
UI
About.rtf
MyDownloader.Core
Common
Concurrency
Extensions
Instrumentation
MyDownloader.Core.csproj.user
Properties
Settings.settings
UI
MyDownloader.Extension
AntiVirus
Settings.settings
UI
AutoDownloads
Settings.settings
UI
MyDownloader.Extension.csproj.user
Notifications
Helpers
Settings.settings
UI
PersistedList
Properties
Protocols
Settings.settings
UI
SpeedLimit
Settings.settings
UI
Video
Impl
Logos
BreakVideoDownloader.png
GoogleVideoDownloader.png
MetaCafeVideoDownloader.png
PutfileVideoDownloader.PNG
YouTubeDownloader.png
UI
WindowsIntegration
ClipboardMonitor
Settings.settings
Zip
MyDownloader.IEPlugin
BandObjectLib
MyDownloader.IEPlugin.csproj.user
MyDownloader.IEPlugin.snk
Properties
MyDownloader.Spider
Parsers
Html
Properties
UI
Web
Rules
MyDownloader.Tests
Extension
Video
MyDownloader.Tests.csproj.user
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace MyDownloader.Core
{
    [Serializable]
    public class ResourceLocation
    {
        #region Fields
        
        private string url;
        private bool authenticate;
        private string login;
        private string password;
        private Type protocolProviderType;
        private IProtocolProvider provider;

        #endregion

        #region Constructor
        public ResourceLocation()
        {
        }

        public static ResourceLocation FromURL(string url)
        {
            ResourceLocation rl = new ResourceLocation();
            rl.URL = url;
            return rl;
        }

        public static ResourceLocation[] FromURLArray(string[] urls)
        {
            List<ResourceLocation> result = new List<ResourceLocation>();

            for (int i = 0; i < urls.Length; i++)
            {
                if (IsURL(urls[i]))
                {
                    result.Add(ResourceLocation.FromURL(urls[i]));
                }
            }

            return result.ToArray();
        }

        public static ResourceLocation FromURL(
            string url,
            bool authenticate,
            string login,
            string password)
        {
            ResourceLocation rl = new ResourceLocation();
            rl.URL = url;
            rl.Authenticate = authenticate;
            rl.Login = login;
            rl.Password = password;
            return rl;
        } 
        #endregion

        #region Properties

        public string URL
        {
            get { return url; }
            set 
            { 
                url = value;
                BindProtocolProviderType();
            }
        }

        public bool Authenticate
        {
            get { return authenticate; }
            set { authenticate = value; }
        }

        public string Login
        {
            get { return login; }
            set { login = value; }
        }

        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        public string ProtocolProviderType
        {
            get
            {
                if (protocolProviderType == null)
                {
                    return null;
                }
                return protocolProviderType.AssemblyQualifiedName;
            }
            set
            {
                if (value == null)
                {
                    BindProtocolProviderType();
                }
                else
                {
                    protocolProviderType = Type.GetType(value);
                }
            }
        }

        #endregion

        #region Methods

        public IProtocolProvider GetProtocolProvider(Downloader downloader)
        {
            return BindProtocolProviderInstance(downloader);
        }

        public void BindProtocolProviderType()
        {
            provider = null;

            if (! String.IsNullOrEmpty(this.URL))
            {
                protocolProviderType = ProtocolProviderFactory.GetProviderType(this.URL);                
            }            
        }

        public IProtocolProvider BindProtocolProviderInstance(Downloader downloader)
        {
            if (protocolProviderType == null)
            {
                BindProtocolProviderType();
            }

            if (provider == null)
            {
                provider = ProtocolProviderFactory.CreateProvider(protocolProviderType, downloader);
            }

            return provider;
        }

        public ResourceLocation Clone()
        {
            return (ResourceLocation)this.MemberwiseClone();
        }

        public override string ToString()
        {
            return this.URL;
        }

        public static bool IsURL(string url)
        {
            Match m = Regex.Match(url, @"(?<Protocol>\w+):\/\/(?<Domain>[\w.]+\/?)\S*");
            if (m.ToString() != string.Empty)
            {
                return true;
            }
            return false;
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Guilherme Labigalini
Web Developer
Brazil Brazil
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 13 Feb 2008
Article Copyright 2007 by Guilherme Labigalini
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid