コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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
                );
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 /// <inheritdoc />
 public abstract Task InvokeAsync(ILoadingContext <TSource> context, LoadingPipeDelegate <TSource> next, CancellationToken cancellationToken = default);
コード例 #6
0
        /// <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);
        }
コード例 #7
0
 public AttributeRule(XElement element, ILoadingContext context)
 {
     Attribute = (FileAttributes)Enum.Parse(typeof(FileAttributes), element.Value);
 }
コード例 #8
0
 /// <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);
コード例 #9
0
 public AndRule(XElement element, ILoadingContext context) : this()
 {
     Rules.AddRange(LoadRules(element, context));
 }
コード例 #10
0
 public ArchiveRule(XElement element, ILoadingContext context) : this()
 {
 }
コード例 #11
0
 protected StorageBase(XElement element, ILoadingContext context)
 {
 }
コード例 #12
0
 public DirectoryRule(XElement element, ILoadingContext context)
 {
 }
コード例 #13
0
        public SyncJob(XElement element, ILoadingContext context) : base(element, context)
        {
            Initialize();

            Pairs.AddRange(LoadPairs(element.Element("Pairs"), context));
        }
コード例 #14
0
 public DirectoryStorage(XElement element, ILoadingContext context)
 {
     Path    = element.Element("Path").Value;
     Options = new DirectoryStorageOptions(element.Element("Options"), context);
 }
コード例 #15
0
 public ReadOnlyRule(XElement element, ILoadingContext context) : this()
 {
 }
コード例 #16
0
 public static void GetReferenceIds <TId>(this ILoadingContext context)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
 public abstract T Create <T>(string name, XElement element, ILoadingContext context);
コード例 #18
0
 public abstract Task InvokeAsync(ILoadingContext <TResult> context, PipeDelegate <TResult> next, CancellationToken cancellationToken = default(CancellationToken));
コード例 #19
0
 protected SourceBase(XElement element, ILoadingContext context)
 {
 }
コード例 #20
0
 protected ContainerBase(XElement element, ILoadingContext context)
 {
 }
コード例 #21
0
 public FileRoot(XElement element, ILoadingContext context) : this(element.Value, context.ServiceContainer.Get <IFileSystem>())
 {
 }
コード例 #22
0
 public PathRule(XElement element, ILoadingContext context) : this(element.Value, context.ServiceContainer)
 {
 }
コード例 #23
0
 public Solution(XElement element, ILoadingContext context) : this()
 {
     Jobs.AddRange(LoadJobs(element.Element("Jobs"), context));
 }
コード例 #24
0
 public FixedDrivesRoot(XElement element, ILoadingContext context) : this(context.ServiceContainer.Get <IFileSystem>())
 {
 }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
 public static void AddReferences <TReference, TId>(this ILoadingContext context, IEnumerable <TReference> references, Func <TReference, TId> getReferenceId)
 {
     throw new NotImplementedException();
 }
コード例 #27
0
 public FileRule(XElement element, ILoadingContext context)
 {
 }
コード例 #28
0
 public static void AddReferences <TReference, TId>(this ILoadingContext context, IDictionary <TId, TReference> referencesById)
 {
     throw new NotImplementedException();
 }
コード例 #29
0
 public SystemRule(XElement element, ILoadingContext context) : this()
 {
 }
コード例 #30
0
 public MetadataFileStorage(XElement element, ILoadingContext context)
 {
     Path = element.Element("Path").Value;
 }