/// <summary> /// Initializes a new instance of the <see cref="QBittorrentClient"/> class. /// </summary> /// <param name="uri">The qBittorrent remote server URI.</param> /// <param name="apiLevel">The qBittorrent API level.</param> /// <param name="client">Custom <see cref="HttpClient"/> instance.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="uri"/> or <paramref name="client"/> is <see langword="null"/>. /// </exception> private QBittorrentClient([NotNull] Uri uri, ApiLevel apiLevel, [NotNull] HttpClient client) { _uri = uri ?? throw new ArgumentNullException(nameof(uri)); _client = client ?? throw new ArgumentNullException(nameof(client)); _client.DefaultRequestHeaders.ExpectContinue = true; _legacyVersion = new Cached <int>(GetLegacyApiVersionPrivateAsync); _requestProvider = new Cached <IRequestProvider>(GetRequestProvider()); Func <CancellationToken, Task <IRequestProvider> > GetRequestProvider() { switch (apiLevel) { case ApiLevel.Auto: return(async token => await GetLegacyApiVersionAsync(token).ConfigureAwait(false) < NewApiLegacyVersion ? (IRequestProvider) new Api1RequestProvider(uri) : (IRequestProvider) new Api2RequestProvider(uri)); case ApiLevel.V1: return(token => Task.FromResult <IRequestProvider>(new Api1RequestProvider(uri))); case ApiLevel.V2: return(token => Task.FromResult <IRequestProvider>(new Api2RequestProvider(uri))); default: throw new ArgumentOutOfRangeException(nameof(apiLevel), apiLevel, null); } } }
public string ToVersion2String() { var fields = new [] { Action == ConstantAction.None ? "?" : Action.ToString().Substring(0, 1), ApiLevel.ToString(), JavaSignature, Value, EnumFullType, EnumMember, ToConstantFieldActionString(FieldAction), IsFlags ? "flags" : string.Empty }; return(string.Join(",", fields)); }
public override int GetHashCode() { int hash = 1; if (NickName.Length != 0) { hash ^= NickName.GetHashCode(); } if (AvatarUrl.Length != 0) { hash ^= AvatarUrl.GetHashCode(); } if (ApiLevel.Length != 0) { hash ^= ApiLevel.GetHashCode(); } if (HkQotRight != 0) { hash ^= HkQotRight.GetHashCode(); } if (UsQotRight != 0) { hash ^= UsQotRight.GetHashCode(); } if (CnQotRight != 0) { hash ^= CnQotRight.GetHashCode(); } if (IsNeedAgreeDisclaimer != false) { hash ^= IsNeedAgreeDisclaimer.GetHashCode(); } if (UserID != 0L) { hash ^= UserID.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public static Tuple <int, int, int> InheritDocs(string asmPath, string docPath, string outPath, string[] refPaths, string[] addPaths, ApiLevel trimLevel, ILogger logger) { var doc = loadDoc(docPath); var docMembers = doc.Root.Element(DocElementNames.Members); int beforeCount = docMembers.Descendants(DocElementNames.InheritDoc).Count(); int trimCount = 0; if (beforeCount == 0 && trimLevel == ApiLevel.None) { return(Tuple.Create(0, 0, 0)); } using var resolver = CecilExtensions.RefAssemblyResolver.Create(refPaths); using var asm = AssemblyDefinition.ReadAssembly(asmPath, new ReaderParameters { AssemblyResolver = resolver }); var types = asm.Modules .SelectMany(m => m.Types) .SelectManyRecursive(t => t.NestedTypes) .Where(t => !t.IsCompilerGenerated() || t.IsNamespaceDocPlaceholder()) .ToList() ; var docMap = generateDocMap(types, docMembers, trimLevel, logger); var asmTypes = types.Select(t => t.GetDocID()).ToHashSet(); var refCref = docMap.Values.SelectMany(v => v.Select(l => l.Cref)).Where(c => !asmTypes.Contains(getTypeIDFromDocID(c))).ToHashSet(); var refDocs = getRefDocs(refPaths, addPaths, refCref, logger); logger.Write(ILogger.Severity.Diag, "External ref docs found: " + refDocs.Root.Elements(DocElementNames.Member).Count().ToString()); if (trimLevel > ApiLevel.None) { beforeCount = docMembers.Descendants(DocElementNames.InheritDoc).Count(dm => !dm.Ancestors(DocElementNames.Member).Any(m => m.HasAttribute(DocAttributeNames._trimmed))); } var mem = default(XElement); while ((mem = docMembers.Elements(DocElementNames.Member).FirstOrDefault(m => isInheritDocCandidate(m))) != null) { replaceInheritDoc(docPath, mem, docMap, docMembers, refDocs, logger); } foreach (var md in docMembers.Elements(DocElementNames.Member).Where(m => m.HasAttribute(DocAttributeNames._visited))) { md.SetAttributeValue(DocAttributeNames._visited, null); } if (trimLevel > ApiLevel.None) { var totrim = docMembers.Elements(DocElementNames.Member).Where(m => m.HasAttribute(DocAttributeNames._trimmed)).ToList(); trimCount = totrim.Count(); foreach (var md in totrim) { logger.Write(ILogger.Severity.Diag, "Trimming " + (trimLevel == ApiLevel.Private ? "private" : "non-public") + " doc: " + (string)md.Attribute(DocAttributeNames.Name)); if (md.PreviousNode.IsWhiteSpace()) { md.PreviousNode.Remove(); } md.Remove(); } } int afterCount = docMembers.Descendants(DocElementNames.InheritDoc).Count(); using var writer = XmlWriter.Create(outPath, new XmlWriterSettings { Encoding = new UTF8Encoding(false), IndentChars = " " }); doc.Save(writer); return(Tuple.Create(beforeCount - afterCount, beforeCount, trimCount)); }
private static IDictionary <string, IEnumerable <DocMatch> > generateDocMap(IList <TypeDefinition> types, XElement docMembers, ApiLevel trimLevel, ILogger logger) { var docMap = new Dictionary <string, IEnumerable <DocMatch> >(); foreach (var t in types) { string typeID = t.GetDocID(); var memDocs = findDocsByID(docMembers, typeID); // Several tools include this hack to output namespace documentation // https://stackoverflow.com/questions/793210/xml-documentation-for-a-namespace if (t.IsCompilerGenerated() && t.IsNamespaceDocPlaceholder()) { foreach (var md in memDocs) { md.SetAttributeValue(DocAttributeNames.Name, "N:" + t.Namespace); } continue; } if (t.GetApiLevel() <= trimLevel) { foreach (var md in memDocs) { md.SetAttributeValue(DocAttributeNames._trimmed, true); } } if (memDocs.Descendants(DocElementNames.InheritDoc).Any()) { logger.Write(ILogger.Severity.Diag, "Processing DocID: " + typeID); var crefs = memDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(c => !string.IsNullOrWhiteSpace(c)).ToHashSet(); var dml = new List <DocMatch>(); docMap.Add(typeID, dml); foreach (var bt in t.GetBaseCandidates()) { var rbt = bt.Resolve(); string cref = rbt.GetDocID(); if (dml.Count == 0 || crefs.Contains(cref)) { dml.Add(new DocMatch(cref, t, bt)); } if (crefs.Count == 0) { break; } } foreach (var cref in crefs.Where(c => !dml.Any(dm => dm.Cref == c))) { dml.Add(new DocMatch(cref, t)); } } foreach (var m in t.Methods.Where(m => !m.IsCompilerGenerated() || m.IsEventMethod() || m.IsPropertyMethod())) { string memID = m.GetDocID(); if (docMap.ContainsKey(memID)) { continue; } var om = m.Overrides.Select(o => o.Resolve()).FirstOrDefault(o => o.DeclaringType.IsInterface); // If no docs for public explicit interface implementation, inject them // including the whitespace they would have had if they had been there. if ((om?.DeclaringType.GetApiLevel() ?? ApiLevel.None) == ApiLevel.Public && t.GetApiLevel() == ApiLevel.Public && !findDocsByID(docMembers, memID).Any()) { docMembers.Add( new XText(" "), new XElement(DocElementNames.Member, new XAttribute(DocAttributeNames.Name, memID), new XText("\n "), new XElement(DocElementNames.InheritDoc), new XText("\n ")), new XText("\n ") ); } var methDocs = findDocsByID(docMembers, memID); if ((om?.DeclaringType.GetApiLevel() ?? m.GetApiLevel()) <= trimLevel) { foreach (var md in methDocs) { md.SetAttributeValue(DocAttributeNames._trimmed, true); } } if (methDocs.Descendants(DocElementNames.InheritDoc).Any()) { logger.Write(ILogger.Severity.Diag, "Processing DocID: " + memID); var crefs = methDocs.Descendants(DocElementNames.InheritDoc).Select(i => (string)i.Attribute(DocAttributeNames.Cref)).Where(c => !string.IsNullOrWhiteSpace(c)).ToHashSet(); var dml = new List <DocMatch>(); var bases = om != null ? (new[] { om }).Concat(m.GetBaseCandidates()) : m.GetBaseCandidates(); foreach (var bm in bases) { string cref = bm.GetDocID(); if (dml.Count == 0 || crefs.Contains(cref)) { dml.Add(new DocMatch(cref, m, bm)); } if (crefs.Count == 0) { break; } } foreach (var cref in crefs.Where(c => !dml.Any(dm => dm.Cref == c))) { dml.Add(new DocMatch(cref, m)); } if (dml.Count > 0) { docMap.Add(memID, dml); } else { logger.Write(ILogger.Severity.Info, "No inherit candidate for: " + memID); } } } foreach (var fd in t.Fields.Where(f => f.GetApiLevel() <= trimLevel).SelectMany(f => findDocsByID(docMembers, f.GetDocID()))) { fd.SetAttributeValue(DocAttributeNames._trimmed, true); } } return(docMap); }
/// <summary> /// Initializes a new instance of the <see cref="QBittorrentClient"/> class. /// </summary> /// <param name="uri">qBittorrent remote server URI.</param> /// <param name="apiLevel">qBittorrent API level.</param> /// <param name="handler">Custom HTTP message handler.</param> /// <param name="disposeHandler">The value indicating whether the <paramref name="handler"/> must be disposed when disposing this object.</param> public QBittorrentClient([NotNull] Uri uri, ApiLevel apiLevel, HttpMessageHandler handler, bool disposeHandler) : this(uri, apiLevel, new HttpClient(handler, disposeHandler)) { }
/// <summary> /// Initializes a new instance of the <see cref="QBittorrentClient"/> class. /// </summary> /// <param name="uri">qBittorrent remote server URI.</param> /// <param name="apiLevel">qBittorrent API level.</param> public QBittorrentClient([NotNull] Uri uri, ApiLevel apiLevel) : this(uri, apiLevel, new HttpClient()) { }
public static Tuple <int, int, int> InheritDocs(string asmPath, string docPath, string outPath, string[] refPaths, string[] addPaths, ApiLevel trimLevel, ILogger logger) {
/// <summary> /// Initializes a new instance of <see cref="ApiNotSupportedException"/>. /// </summary> /// <param name="message">The exception message.</param> /// <param name="requiredApiLevel">The minimal required API level.</param> /// <param name="requiredApiVersion">The minimal required API version.</param> /// <param name="maxApiVersion">The maximum required API version.</param> public ApiNotSupportedException(string message, ApiLevel requiredApiLevel, Version requiredApiVersion, Version maxApiVersion) : this(message, requiredApiLevel, requiredApiVersion) { MaxApiVersion = maxApiVersion; }
/// <summary> /// Initializes a new instance of <see cref="ApiNotSupportedException"/>. /// </summary> /// <param name="message">The exception message.</param> /// <param name="requiredApiLevel">The minimal required API level.</param> public ApiNotSupportedException(string message, ApiLevel requiredApiLevel) : this(message, requiredApiLevel, null) { }
/// <summary> /// Initializes a new instance of <see cref="ApiNotSupportedException"/>. /// </summary> /// <param name="message">The exception message.</param> /// <param name="requiredApiLevel">The minimal required API level.</param> /// <param name="requiredApiVersion">The minimal required API version.</param> public ApiNotSupportedException(string message, ApiLevel requiredApiLevel, Version requiredApiVersion) : base(message) { RequiredApiLevel = requiredApiLevel; RequiredApiVersion = requiredApiVersion; }
/// <summary> /// Initializes a new instance of <see cref="ApiNotSupportedException"/>. /// </summary> /// <param name="requiredApiLevel">The minimal required API level.</param> /// <param name="requiredApiVersion">The minimal required API version.</param> /// <param name="maxApiVersion">The maximal supported API version.</param> public ApiNotSupportedException(ApiLevel requiredApiLevel, Version requiredApiVersion, Version maxApiVersion) : this(requiredApiLevel, requiredApiVersion) { MaxApiVersion = maxApiVersion; }
/// <summary> /// Initializes a new instance of <see cref="ApiNotSupportedException"/>. /// </summary> /// <param name="requiredApiLevel">The minimal required API level.</param> /// <param name="requiredApiVersion">The minimal required API version.</param> public ApiNotSupportedException(ApiLevel requiredApiLevel, Version requiredApiVersion) : this("The API version being used does not support this function.", requiredApiLevel, requiredApiVersion) { }
/// <summary> /// Initializes a new instance of <see cref="ApiNotSupportedException"/>. /// </summary> /// <param name="requiredApiLevel">The minimal required API level.</param> public ApiNotSupportedException(ApiLevel requiredApiLevel) : this(requiredApiLevel, null) { }
/// <summary> /// Initializes a new instance of the <see cref="ApiLevelAttribute"/> class. /// </summary> /// <param name="apiLevel">The minimal API Level that supports the annotated method.</param> public ApiLevelAttribute(ApiLevel apiLevel) { Level = apiLevel; }
public static (int replaced, int total, int trimmed) InheritDocs(string asmPath, string docPath, string outPath, string[] refPaths, string[] addPaths, ApiLevel trimLevel, ILogger logger) {