public DirectoryStorageOptions(XElement element, ILoadingContext context) : this() { if (element == null) { return; } var directoryNameElemet = element.Element("DirectoryName"); if (directoryNameElemet != null) { DirectoryName = directoryNameElemet.Value; } var enableHardLinksElemet = element.Element("EnableHardLinks"); if (enableHardLinksElemet != null) { EnableHardLinks = bool.Parse(enableHardLinksElemet.Value); } }
private void LoadBlogPosts(ILoadingContext loadingContext) { var lookupIds = loadingContext.ReferenceIds <BlogPost, int>(); var references = lookupIds .Select(id => new BlogPost { Id = id, Author = new Author { Name = "author-name-" + id, Email = "author-email-" + id, ImageId = "id-" + (id + 500) }, MultimediaContentRef = new MultimediaContentReference { Type = id % 2 == 0 ? "image" : "media", Id = id % 2 == 0 ? "id-" + id : (object)id }, TagIds = new List <int> { 88 + id, 89 + id }, Title = "Title-" + id } ) .ToList(); loadingContext.AddResults( references, reference => reference.Id ); }
public Server(XElement element, ILoadingContext context) { Address = element.Element("Address").Value; if (element.Element("Port") != null) { Port = int.Parse(element.Element("Port").Value); } if (element.Element("Instance") != null) { Instance = element.Element("Instance").Value; } if (element.Element("Username") != null) { Username = element.Element("Username").Value; } if (element.Element("Password") != null) { Password = element.Element("Password").Value; } }
public override async Task InvokeAsync(ILoadingContext <ImageSource> context, PipeDelegate <ImageSource> next, CancellationToken cancellationToken = default(CancellationToken)) { if (context.Current is Stream stream) { var isStartWithLessThanSign = false; if (stream.CanSeek) { stream.Seek(0, SeekOrigin.Begin); isStartWithLessThanSign = stream.ReadByte() == '<'; // svg start with < stream.Seek(0, SeekOrigin.Begin); } if (isStartWithLessThanSign) { var bitmap = new SvgImageSource(); var svgImageLoadStatus = await bitmap.SetSourceAsync(stream.AsRandomAccessStream()); if (svgImageLoadStatus != SvgImageSourceLoadStatus.Success) { throw new SvgImageFailedStatusException(svgImageLoadStatus); } cancellationToken.ThrowIfCancellationRequested(); context.Current = bitmap; } else { var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(stream.AsRandomAccessStream()); cancellationToken.ThrowIfCancellationRequested(); context.Current = bitmap; } } await next(context, cancellationToken); }
/// <inheritdoc /> public abstract Task InvokeAsync(ILoadingContext <TSource> context, LoadingPipeDelegate <TSource> next, CancellationToken cancellationToken = default);
/// <inheritdoc /> public override async Task InvokeAsync(ILoadingContext <ImageExSource> context, LoadingPipeDelegate <ImageExSource> next, CancellationToken cancellationToken = default) { if (context.Current is Stream stream) { if (!stream.CanSeek) { var memoryStream = new MemoryStream(); #if NETCOREAPP3_1 await stream.CopyToAsync(memoryStream, cancellationToken); if (!ReferenceEquals(stream, context.OriginSource)) { // if the stream generated by the pipe then dispose it. await stream.DisposeAsync(); } #else await stream.CopyToAsync(memoryStream); if (!ReferenceEquals(stream, context.OriginSource)) { // if the stream generated by the pipe then dispose it. stream.Dispose(); } #endif memoryStream.Seek(0, SeekOrigin.Begin); stream = memoryStream; } var tcs = new TaskCompletionSource <ImageExSource>(); await Task.Run(() => { using var codec = SKCodec.Create(stream, out var codecResult); if (codecResult != SKCodecResult.Success) { tcs.SetException(new Exception(codecResult.ToString())); return; } var codecInfo = codec.Info; var frameCount = codec.FrameCount; if (frameCount <= 0) { var source = new ImageExSource { Frames = new ImageExFrame[1], RepetitionCount = codec.RepetitionCount, Width = codecInfo.Width, Height = codecInfo.Height }; var bitmap = new SKBitmap(codecInfo); var pointer = bitmap.GetPixels(); codec.GetPixels(bitmap.Info, pointer); source.Frames[0] = new ImageExFrame { Bitmap = bitmap }; context.InvokeOnUIThread(() => { context.AttachSource(source); }); tcs.SetResult(source); } else { var source = new ImageExSource { Frames = new ImageExFrame[frameCount], RepetitionCount = codec.RepetitionCount, Width = codecInfo.Width, Height = codecInfo.Height }; for (var frameIndex = 0; frameIndex < frameCount; frameIndex++) { var bitmap = new SKBitmap(codecInfo); var pointer = bitmap.GetPixels(); var codecOptions = new SKCodecOptions(frameIndex); codec.GetPixels(bitmap.Info, pointer, codecOptions); var frameInfo = codec.FrameInfo[frameIndex]; var duration = frameInfo.Duration; source.Frames[frameIndex] = new ImageExFrame { Bitmap = bitmap, Duration = duration }; } context.InvokeOnUIThread(() => { context.AttachSource(source); }); tcs.SetResult(source); } }, cancellationToken); context.Current = await tcs.Task; #if NETCOREAPP3_1 if (!ReferenceEquals(stream, context.OriginSource)) { // if the stream generated by the pipe then dispose it. await stream.DisposeAsync(); } #else if (!ReferenceEquals(stream, context.OriginSource)) { // if the stream generated by the pipe then dispose it. stream.Dispose(); } #endif } await next(context, cancellationToken); }
public AttributeRule(XElement element, ILoadingContext context) { Attribute = (FileAttributes)Enum.Parse(typeof(FileAttributes), element.Value); }
/// <summary> /// 执行其它 Uri 协议的加载逻辑。 /// </summary> /// <param name="context">加载上下文。</param> /// <param name="next">下一个加载管道的调用委托。</param> /// <param name="uri">Uri。</param> /// <param name="cancellationToken">要监视取消请求的标记。</param> /// <returns>表示异步加载操作的任务。</returns> protected abstract Task InvokeOtherUriSchemeAsync(ILoadingContext <TSource> context, LoadingPipeDelegate <TSource> next, Uri uri, CancellationToken cancellationToken = default);
public AndRule(XElement element, ILoadingContext context) : this() { Rules.AddRange(LoadRules(element, context)); }
public ArchiveRule(XElement element, ILoadingContext context) : this() { }
protected StorageBase(XElement element, ILoadingContext context) { }
public DirectoryRule(XElement element, ILoadingContext context) { }
public SyncJob(XElement element, ILoadingContext context) : base(element, context) { Initialize(); Pairs.AddRange(LoadPairs(element.Element("Pairs"), context)); }
public DirectoryStorage(XElement element, ILoadingContext context) { Path = element.Element("Path").Value; Options = new DirectoryStorageOptions(element.Element("Options"), context); }
public ReadOnlyRule(XElement element, ILoadingContext context) : this() { }
public static void GetReferenceIds <TId>(this ILoadingContext context) { throw new NotImplementedException(); }
public abstract T Create <T>(string name, XElement element, ILoadingContext context);
public abstract Task InvokeAsync(ILoadingContext <TResult> context, PipeDelegate <TResult> next, CancellationToken cancellationToken = default(CancellationToken));
protected SourceBase(XElement element, ILoadingContext context) { }
protected ContainerBase(XElement element, ILoadingContext context) { }
public FileRoot(XElement element, ILoadingContext context) : this(element.Value, context.ServiceContainer.Get <IFileSystem>()) { }
public PathRule(XElement element, ILoadingContext context) : this(element.Value, context.ServiceContainer) { }
public Solution(XElement element, ILoadingContext context) : this() { Jobs.AddRange(LoadJobs(element.Element("Jobs"), context)); }
public FixedDrivesRoot(XElement element, ILoadingContext context) : this(context.ServiceContainer.Get <IFileSystem>()) { }
private void LoadReference(Type referenceType, IReadOnlyList <object> referenceIds, ILoadingContext loadingContext) { if (referenceType == typeof(Media)) { LoadMedia(referenceIds, loadingContext); } if (referenceType == typeof(Tag)) { LoadTags(referenceIds, loadingContext); } if (referenceType == typeof(BlogPost)) { LoadBlogPosts(loadingContext); } if (referenceType == typeof(Image)) { LoadImages(loadingContext); } }
public static void AddReferences <TReference, TId>(this ILoadingContext context, IEnumerable <TReference> references, Func <TReference, TId> getReferenceId) { throw new NotImplementedException(); }
public FileRule(XElement element, ILoadingContext context) { }
public static void AddReferences <TReference, TId>(this ILoadingContext context, IDictionary <TId, TReference> referencesById) { throw new NotImplementedException(); }
public SystemRule(XElement element, ILoadingContext context) : this() { }
public MetadataFileStorage(XElement element, ILoadingContext context) { Path = element.Element("Path").Value; }