Пример #1
0
        public static Func <byte[], BlobCreation> New(BlobRepositoryFactoryContext context)
        {
            return(data =>
            {
                Guid identifier = Guid.NewGuid();
                string name = identifier.ToHex();

                string hash = data.ToHash();
                string path = Path.Combine(context.Location, $"{name}-{hash}");

                if (IsValidZipContent(data))
                {
                    File.WriteAllBytes(path, data);

                    return new BlobCreation
                    {
                        Success = true,
                        GetBlob = () => BlobFactory.Create(with =>
                        {
                            with.Identifier = identifier;
                            with.Path = path;
                        })
                    };
                }

                return new BlobCreation
                {
                    Success = false
                };
            });
        }
Пример #2
0
        public static Func<byte[], BlobCreation> New(BlobRepositoryFactoryContext context)
        {
            return data =>
            {
                Guid identifier = Guid.NewGuid();
                string name = identifier.ToHex();

                string hash = data.ToHash();
                string path = Path.Combine(context.Location, $"{name}-{hash}");

                if (IsValidZipContent(data))
                {
                    File.WriteAllBytes(path, data);

                    return new BlobCreation
                    {
                        Success = true,
                        GetBlob = () => BlobFactory.Create(with =>
                        {
                            with.Identifier = identifier;
                            with.Path = path;
                        })
                    };
                }

                return new BlobCreation
                {
                    Success = false
                };
            };
        }
Пример #3
0
        private static Func<Guid, Blob> GetById(BlobRepositoryFactoryContext context)
        {
            return identifier =>
            {
                string name = identifier.ToHex();
                string[] files = Directory.GetFiles(context.Location, $"{name}-*");

                if (files.Length != 1)
                    return null;

                return BlobFactory.Create(with =>
                {
                    with.Identifier = identifier;
                    with.Path = files[0];
                });
            };
        }
Пример #4
0
        private static Func <Guid, Blob> GetById(BlobRepositoryFactoryContext context)
        {
            return(identifier =>
            {
                string name = identifier.ToHex();
                string[] files = Directory.GetFiles(context.Location, $"{name}-*");

                if (files.Length != 1)
                {
                    return null;
                }

                return BlobFactory.Create(with =>
                {
                    with.Identifier = identifier;
                    with.Path = files[0];
                });
            });
        }