private Downloader( int id, ResourceLocation rl, ResourceLocation[] mirrors, string localFile) { this.threads = new List<Thread>(); this.id = id; this.resourceLocation = rl; if (mirrors == null) { this.mirrors = new List<ResourceLocation>(); } else { this.mirrors = new List<ResourceLocation>(mirrors); } this.localFile = localFile; extentedProperties = new Dictionary<string, object>(); defaultDownloadProvider = rl.BindProtocolProviderInstance(this); segmentCalculator = new MinSizeSegmentCalculator(); this.MirrorSelector = new SequentialMirrorSelector(); }
private Downloader( int id, ResourceLocation rl, ResourceLocation[] mirrors, string localFile) { this.threads = new List <Thread>(); this.id = id; this.resourceLocation = rl; if (mirrors == null) { this.mirrors = new List <ResourceLocation>(); } else { this.mirrors = new List <ResourceLocation>(mirrors); } this.localFile = localFile; extentedProperties = new Dictionary <string, object>(); defaultDownloadProvider = rl.BindProtocolProviderInstance(this); segmentCalculator = new MinSizeSegmentCalculator(); this.MirrorSelector = new SequentialMirrorSelector(); }
private void ValidateProtocolProvider(IProtocolProvider provider) { if (provider == null) { throw new InvalidProtocolProviderException("External protocol provider cannot be null"); } if (string.IsNullOrWhiteSpace(provider.ProtocolIdentifier)) { throw new InvalidProtocolProviderException($"Invalid protocol provider '{provider.GetType().GetRESTableTypeName()}'. " + "ProtocolIdentifier cannot be null or whitespace"); } if (!Regex.IsMatch(provider.ProtocolIdentifier, "^[a-zA-Z]+$")) { throw new InvalidProtocolProviderException($"Invalid protocol provider '{provider.GetType().GetRESTableTypeName()}'. " + "ProtocolIdentifier can only contain letters a-z and A-Z"); } if (provider.ExternalContentTypeProviderSettings == ExternalContentTypeProviderSettings.DontAllow) { var contentProviders = provider.GetCustomContentTypeProviders()?.ToList(); if (contentProviders?.Any() != true) { throw new InvalidProtocolProviderException($"Invalid protocol provider '{provider.GetType().GetRESTableTypeName()}'. " + "The protocol provider allows no external content type providers " + "and does not provide any content type providers of its own."); } if (contentProviders.All(p => !p.CanRead) && contentProviders.All(p => !p.CanWrite)) { throw new InvalidProtocolProviderException($"Invalid protocol provider '{provider.GetType().GetRESTableTypeName()}'. " + "The protocol provider allows no external content type providers " + "and none of the provided content type providers can read or write."); } } }
public DefaultProtocolUriComponents(IProtocolProvider protocolProvider) { ProtocolIdentifier = protocolProvider.ProtocolIdentifier; ProtocolProvider = protocolProvider; Conditions = new List <IUriCondition>(); MetaConditions = new List <IUriCondition>(); }
public void BindProtocolProviderType() { provider = null; if (!String.IsNullOrEmpty(this.URL)) { protocolProviderType = ProtocolProviderFactory.GetProviderType(this.URL); } }
/// <inheritdoc /> public UriComponents(string resourceSpecifier, string viewName, IEnumerable <IUriCondition> conditions, IEnumerable <IUriCondition> metaConditions, IProtocolProvider protocolProvider, IMacro macro) { ResourceSpecifier = resourceSpecifier; ViewName = viewName; Conditions = conditions.ToList(); MetaConditions = metaConditions.ToList(); ProtocolProvider = protocolProvider; Macro = macro; }
public ZipRemoteFile(ResourceLocation url, IProtocolProvider protocolProvider) { if (protocolProvider == null) { throw new ArgumentNullException("protocolProvider"); } this.url = url; this.protocolProvider = protocolProvider; }
// Token: 0x0600015F RID: 351 RVA: 0x00007C90 File Offset: 0x00005E90 public static IProtocolProvider CreateProvider(string uri, Downloader downloader) { IProtocolProvider protocolProvider = ProtocolProviderFactory.InternalGetProvider(uri); bool flag = downloader != null; if (flag) { protocolProvider.Initialize(downloader); } return(protocolProvider); }
public static IProtocolProvider CreateProvider(string uri, Downloader downloader) { IProtocolProvider provider = InternalGetProvider(uri); if (downloader != null) { provider.Initialize(downloader); } return(provider); }
// Token: 0x06000163 RID: 355 RVA: 0x00007D70 File Offset: 0x00005F70 private static IProtocolProvider InternalGetProvider(string uri) { IProtocolProvider protocolProvider = ProtocolProviderFactory.CreateFromType(ProtocolProviderFactory.GetProviderType(uri)); bool flag = ProtocolProviderFactory.ResolvingProtocolProvider != null; if (flag) { ResolvingProtocolProviderEventArgs resolvingProtocolProviderEventArgs = new ResolvingProtocolProviderEventArgs(protocolProvider, uri); ProtocolProviderFactory.ResolvingProtocolProvider(null, resolvingProtocolProviderEventArgs); protocolProvider = resolvingProtocolProviderEventArgs.ProtocolProvider; } return(protocolProvider); }
private IProtocolProvider[] GetCarrierProtocols(string strPayloadProtocol) { if (dictPayloadLookupTree.ContainsKey(strPayloadProtocol)) { Dictionary <string, IProtocolProvider> dictCarriers = dictPayloadLookupTree[strPayloadProtocol]; IProtocolProvider[] ipCarriers = new IProtocolProvider[dictCarriers.Values.Count]; dictCarriers.Values.CopyTo(ipCarriers, 0); return(ipCarriers); } return(new IProtocolProvider[0]); }
private CachedProtocolProvider GetCachedProtocolProvider(IProtocolProvider provider) { var cProvider = new CachedProtocolProvider(provider); var contentTypeProviders = provider.GetCustomContentTypeProviders()?.ToList() ?? new List <IContentTypeProvider>(); foreach (var contentTypeProvider in contentTypeProviders.Where(p => p.MatchStrings != null)) { if (contentTypeProvider.CanRead) { foreach (var mimeType in contentTypeProvider.MatchStrings) { cProvider.InputMimeBindings[mimeType] = contentTypeProvider; } } if (contentTypeProvider.CanWrite) { foreach (var mimeType in contentTypeProvider.MatchStrings) { cProvider.OutputMimeBindings[mimeType] = contentTypeProvider; } } } switch (provider.ExternalContentTypeProviderSettings) { case ExternalContentTypeProviderSettings.AllowAll: foreach (var pair in ContentTypeProviderManager.InputContentTypeProviders.Where(p => !cProvider.InputMimeBindings.ContainsKey(p.Key))) { cProvider.InputMimeBindings.Add(pair); } foreach (var pair in ContentTypeProviderManager.OutputContentTypeProviders.Where(p => !cProvider.OutputMimeBindings.ContainsKey(p.Key))) { cProvider.OutputMimeBindings.Add(pair); } break; case ExternalContentTypeProviderSettings.AllowInput: foreach (var pair in ContentTypeProviderManager.InputContentTypeProviders.Where(p => !cProvider.InputMimeBindings.ContainsKey(p.Key))) { cProvider.InputMimeBindings.Add(pair); } break; case ExternalContentTypeProviderSettings.AllowOutput: foreach (var pair in ContentTypeProviderManager.OutputContentTypeProviders.Where(p => !cProvider.OutputMimeBindings.ContainsKey(p.Key))) { cProvider.OutputMimeBindings.Add(pair); } break; } return(cProvider); }
public IProtocolProvider BindProtocolProviderInstance(Downloader downloader) { if (protocolProviderType == null) { BindProtocolProviderType(); } if (provider == null) { provider = ProtocolProviderFactory.CreateProvider(protocolProviderType, downloader); } return(provider); }
private static IProtocolProvider InternalGetProvider(string uri) { Type type = GetProviderType(uri); IProtocolProvider provider = CreateFromType(type); if (ResolvingProtocolProvider != null) { ResolvingProtocolProviderEventArgs e = new ResolvingProtocolProviderEventArgs(provider, uri); ResolvingProtocolProvider(null, e); provider = e.ProtocolProvider; } return(provider); }
public static IProtocolProvider CreateProvider(Type providerType, Downloader downloader) { IProtocolProvider provider = CreateFromType(providerType); if (ResolvingProtocolProvider != null) { ResolvingProtocolProviderEventArgs e = new ResolvingProtocolProviderEventArgs(provider, null); ResolvingProtocolProvider(null, e); provider = e.ProtocolProvider; } if (downloader != null) { provider.Initialize(downloader); } return(provider); }
// Token: 0x06000162 RID: 354 RVA: 0x00007D18 File Offset: 0x00005F18 public static IProtocolProvider CreateProvider(Type providerType, Downloader downloader) { IProtocolProvider protocolProvider = ProtocolProviderFactory.CreateFromType(providerType); bool flag = ProtocolProviderFactory.ResolvingProtocolProvider != null; if (flag) { ResolvingProtocolProviderEventArgs resolvingProtocolProviderEventArgs = new ResolvingProtocolProviderEventArgs(protocolProvider, null); ProtocolProviderFactory.ResolvingProtocolProvider(null, resolvingProtocolProviderEventArgs); protocolProvider = resolvingProtocolProviderEventArgs.ProtocolProvider; } bool flag2 = downloader != null; if (flag2) { protocolProvider.Initialize(downloader); } return(protocolProvider); }
private static CachedProtocolProvider GetCachedProtocolProvider(IProtocolProvider provider) { var cProvider = new CachedProtocolProvider(provider); var contentTypeProviders = provider.GetContentTypeProviders()?.ToList(); contentTypeProviders?.ForEach(contentTypeProvider => { if (contentTypeProvider.CanRead) { contentTypeProvider.MatchStrings?.ForEach(mimeType => cProvider.InputMimeBindings[mimeType] = contentTypeProvider); } if (contentTypeProvider.CanWrite) { contentTypeProvider.MatchStrings?.ForEach(mimeType => cProvider.OutputMimeBindings[mimeType] = contentTypeProvider); } }); switch (provider.ExternalContentTypeProviderSettings) { case ExternalContentTypeProviderSettings.AllowAll: ContentTypeController.InputContentTypeProviders.Where(p => !cProvider.InputMimeBindings.ContainsKey(p.Key)) .ForEach(cProvider.InputMimeBindings.Add); ContentTypeController.OutputContentTypeProviders.Where(p => !cProvider.OutputMimeBindings.ContainsKey(p.Key)) .ForEach(cProvider.OutputMimeBindings.Add); break; case ExternalContentTypeProviderSettings.AllowInput: ContentTypeController.InputContentTypeProviders.Where(p => !cProvider.InputMimeBindings.ContainsKey(p.Key)) .ForEach(cProvider.InputMimeBindings.Add); break; case ExternalContentTypeProviderSettings.AllowOutput: ContentTypeController.OutputContentTypeProviders.Where(p => !cProvider.OutputMimeBindings.ContainsKey(p.Key)) .ForEach(cProvider.OutputMimeBindings.Add); break; } return(cProvider); }
public ProtocolProviderProxy(IProtocolProvider proxy, SpeedLimitExtension speedLimit) { this.proxy = proxy; this.speedLimit = speedLimit; }
public CachedProtocolProvider(IProtocolProvider protocolProvider) { ProtocolProvider = protocolProvider; InputMimeBindings = new Dictionary <string, IContentTypeProvider>(StringComparer.OrdinalIgnoreCase); OutputMimeBindings = new Dictionary <string, IContentTypeProvider>(StringComparer.OrdinalIgnoreCase); }
private void SegmentThreadProc(object objSegment) { Segment segment = (Segment)objSegment; segment.LastError = null; try { if (segment.EndPosition > 0 && segment.StartPosition >= segment.EndPosition) { segment.State = SegmentState.Finished; // raise the event OnSegmentStoped(segment); return; } int buffSize = 8192; byte[] buffer = new byte[buffSize]; segment.State = SegmentState.Connecting; // raise the event OnSegmentStarting(segment); if (segment.InputStream == null) { // get the next URL (It can the the main url or some mirror) ResourceLocation location = this.MirrorSelector.GetNextResourceLocation(); // get the protocol provider for that mirror IProtocolProvider provider = location.BindProtocolProviderInstance(this); while (location != this.ResourceLocation) { // get the remote file info on mirror RemoteFileInfo tempRemoteInfo = provider.GetFileInfo(location, out Stream tempStream); if (tempStream != null) { tempStream.Dispose(); } // check if the file on mirror is the same if (tempRemoteInfo.FileSize == remoteFileInfo.FileSize && tempRemoteInfo.AcceptRanges == remoteFileInfo.AcceptRanges) { // if yes, stop looking for the mirror break; } lock (mirrors) { // the file on the mirror is not the same, so remove from the mirror list mirrors.Remove(location); } // the file on the mirror is different // so get other mirror to use in the segment location = this.MirrorSelector.GetNextResourceLocation(); provider = location.BindProtocolProviderInstance(this); } // get the input stream from start position segment.InputStream = provider.CreateStream(location, segment.StartPosition, segment.EndPosition); // change the segment URL to the mirror URL segment.CurrentURL = location.URL; } else { // change the segment URL to the main URL segment.CurrentURL = this.resourceLocation.URL; } using (segment.InputStream) { // raise the event OnSegmentStarted(segment); // change the segment state segment.State = SegmentState.Downloading; segment.CurrentTry = 0; long readSize; do { // reads the buffer from input stream segment.InputStream.ReadTimeout = streamTimeout; readSize = segment.InputStream.Read(buffer, 0, buffSize); // check if the segment has reached the end if (segment.EndPosition > 0 && segment.StartPosition + readSize > segment.EndPosition) { // adjust the 'readSize' to write only necessary bytes readSize = (segment.EndPosition - segment.StartPosition); if (readSize <= 0) { segment.StartPosition = segment.EndPosition; break; } } // locks the stream to avoid that other threads changes // the position of stream while this thread is writing into the stream lock (segment.OutputStream) { segment.OutputStream.Position = segment.StartPosition; segment.OutputStream.Write(buffer, 0, (int)readSize); } // increse the start position of the segment and also calculates the rate segment.IncreaseStartPosition(readSize); // check if the stream has reached its end if (segment.EndPosition > 0 && segment.StartPosition >= segment.EndPosition) { segment.StartPosition = segment.EndPosition; break; } // check if the user have requested to pause the download if (state == DownloaderState.Pausing) { segment.State = SegmentState.Paused; break; } //Thread.Sleep(1500); }while (readSize > 0); if (segment.State == SegmentState.Downloading) { segment.State = SegmentState.Finished; // try to create other segment, // spliting the missing bytes from one existing segment AddNewSegmentIfNeeded(); } } // raise the event OnSegmentStoped(segment); } catch (Exception ex) { // store the error information segment.State = SegmentState.Error; segment.LastError = ex; Debug.WriteLine(ex.Message); // raise the event OnSegmentFailed(segment); } finally { // clean up the segment segment.InputStream = null; } }
public ResolvingProtocolProviderEventArgs(IProtocolProvider provider, string url) { this.url = url; this.provider = provider; }
public ProtocolHandler(int maximumFramesPerSecond, IProtocolProvider protocolProvider, IScreenProvider screenProvider) { _maximumFramesPerSecond = maximumFramesPerSecond; _protocolProvider = protocolProvider; _screenProvider = screenProvider; }
internal NotCompliantWithProtocol(IProtocolProvider provider, string message) : base(ErrorCodes.NotCompliantWithProtocol, $"The request was not compliant with the {provider.ProtocolName} protocol. {message}") { }
public IProtocolProvider BindProtocolProviderInstance(Downloader downloader) { if (protocolProviderType == null) { BindProtocolProviderType(); } if (provider == null) { provider = ProtocolProviderFactory.CreateProvider(protocolProviderType, downloader); } return provider; }
private static IProtocolProvider CreateFromType(Type type) { IProtocolProvider provider = (IProtocolProvider)Activator.CreateInstance(type); return(provider); }
public ODataUriComponents(IProtocolProvider protocolProvider) { ProtocolProvider = protocolProvider; Conditions = new List <IUriCondition>(); MetaConditions = new List <IUriCondition>(); }
internal URI() { Conditions = new List <IUriCondition>(); MetaConditions = new List <IUriCondition>(); ProtocolProvider = ProtocolController.DefaultProtocolProvider.ProtocolProvider; }
public ProtocolParser(IProtocolProvider[] arUserProviders, bool bIncludeDefaultProviders) { IProtocolProvider[] arProviders; if (bIncludeDefaultProviders) { IProtocolProvider[] arDefaultProviders = new IProtocolProvider[] { new Providers.TrafficDescriptionFrameProtocolProvider(), new Providers.EthernetProtocolProvider(), new Providers.ARPProtocolProvider(), new Providers.TCPProtocolProvider(), new Providers.UDPProtocolProvider(), new Providers.OSPFProtocolProvider(), new Providers.DHCPProtocolProvider(), new Providers.DNSProtocolProvider(), new Providers.ICMPv4ProtocolProvider(), new Providers.ICMPv6ProtocolProvider(), new Providers.IPv4ProtocolProvider(), new Providers.IPv6ProtocolProvider() }; arProviders = new IProtocolProvider[arUserProviders.Length + arDefaultProviders.Length]; arDefaultProviders.CopyTo(arProviders, 0); arUserProviders.CopyTo(arProviders, arDefaultProviders.Length); } else { arProviders = arUserProviders; } dictProtocolProviders = new Dictionary <string, IProtocolProvider>(); dictPayloadLookupTree = new Dictionary <string, Dictionary <string, IProtocolProvider> >(); foreach (IProtocolProvider ipProtocol in arProviders) { if (dictProtocolProviders.ContainsKey(ipProtocol.Protocol)) { throw new ArgumentException("The protocol " + ipProtocol.Protocol + " was already defined. Another provider for this protocol cannot be added."); } dictProtocolProviders.Add(ipProtocol.Protocol, ipProtocol); foreach (string strKnownPayload in ipProtocol.KnownPayloads) { if (!dictPayloadLookupTree.ContainsKey(strKnownPayload)) { dictPayloadLookupTree.Add(strKnownPayload, new Dictionary <string, IProtocolProvider>()); } Dictionary <string, IProtocolProvider> dictCarriers = dictPayloadLookupTree[strKnownPayload]; if (!dictCarriers.ContainsKey(ipProtocol.Protocol)) { dictCarriers.Add(ipProtocol.Protocol, ipProtocol); } } } }
// Token: 0x06000124 RID: 292 RVA: 0x000068CC File Offset: 0x00004ACC private void SegmentThreadProc(object objSegment) { Segment segment = (Segment)objSegment; segment.LastError = null; try { bool flag = segment.EndPosition > 0L && segment.StartPosition >= segment.EndPosition; if (flag) { segment.State = SegmentState.Finished; this.OnSegmentStoped(segment); } else { byte[] array = new byte[4096]; segment.State = SegmentState.Connecting; this.OnSegmentStarting(segment); bool flag2 = segment.InputStream == null; if (flag2) { ResourceLocation nextResourceLocation = this.MirrorSelector.GetNextResourceLocation(); IProtocolProvider protocolProvider = nextResourceLocation.BindProtocolProviderInstance(this); while (nextResourceLocation != this.ResourceLocation) { Stream stream; RemoteFileInfo fileInfo = protocolProvider.GetFileInfo(nextResourceLocation, out stream); bool flag3 = stream != null; if (flag3) { stream.Dispose(); } bool flag4 = fileInfo.FileSize == this.remoteFileInfo.FileSize && fileInfo.AcceptRanges == this.remoteFileInfo.AcceptRanges; if (flag4) { break; } List <ResourceLocation> list = this.mirrors; List <ResourceLocation> obj = list; lock (obj) { this.mirrors.Remove(nextResourceLocation); } nextResourceLocation = this.MirrorSelector.GetNextResourceLocation(); protocolProvider = nextResourceLocation.BindProtocolProviderInstance(this); } segment.InputStream = protocolProvider.CreateStream(nextResourceLocation, segment.StartPosition, segment.EndPosition); segment.CurrentURL = nextResourceLocation.URL; } else { segment.CurrentURL = this.resourceLocation.URL; } using (segment.InputStream) { this.OnSegmentStarted(segment); segment.State = SegmentState.Downloading; segment.CurrentTry = 0; for (;;) { long num = (long)segment.InputStream.Read(array, 0, array.Length); bool flag6 = segment.EndPosition > 0L && segment.StartPosition + num > segment.EndPosition; if (flag6) { num = segment.EndPosition - segment.StartPosition; bool flag7 = num <= 0L; if (flag7) { break; } } Stream outputStream = segment.OutputStream; Stream obj2 = outputStream; lock (obj2) { segment.OutputStream.Position = segment.StartPosition; segment.OutputStream.Write(array, 0, (int)num); } segment.IncreaseStartPosition(num); bool flag9 = segment.EndPosition > 0L && segment.StartPosition >= segment.EndPosition; if (flag9) { goto Block_21; } bool flag10 = this.state == DownloaderState.Pausing; if (flag10) { goto Block_22; } bool flag11 = num <= 0L; if (flag11) { goto Block_23; } } segment.StartPosition = segment.EndPosition; goto IL_2E4; Block_21: segment.StartPosition = segment.EndPosition; goto IL_2E4; Block_22: segment.State = SegmentState.Paused; Block_23: IL_2E4: bool flag12 = segment.State == SegmentState.Downloading; if (flag12) { segment.State = SegmentState.Finished; this.AddNewSegmentIfNeeded(); } } this.OnSegmentStoped(segment); } } catch (Exception ex) { segment.State = SegmentState.Error; segment.LastError = ex; this.OnSegmentFailed(segment); } finally { segment.InputStream = null; } }
/// <summary> /// bind protocol provider for resource /// </summary> /// <returns>IProtocolProvider object for resource</returns> public IProtocolProvider BindProtocolProviderInstance() { if (provider == null) { provider = new HttpProtocolProvider(); } return provider; }
/// <summary> /// bind proxy speed limit provider to resource provider /// </summary> /// <param name="speedLimit">speed limit for download</param> /// <returns>proxy provider</returns> public IProtocolProvider BindProtocolProviderProxy(SpeedLimitHelper speedLimit) { if (provider == null) { provider = new HttpProtocolProviderSpeedLimitProxy(provider, speedLimit); } return provider; }
public HttpProtocolProviderSpeedLimitProxy(IProtocolProvider proxy, SpeedLimitHelper speedLimit) { this.proxy = proxy; this.speedLimit = speedLimit; }