コード例 #1
0
        public static Uri GenerateBlobFileSasLink(this MemberInfo member, string blobName,
                                                  TimeSpan?lifespan = default(TimeSpan?))
        {
            var containerName = member.BlobContainerName();

            return(GenerateBlobFileSasLink(containerName, blobName, lifespan: lifespan));
        }
コード例 #2
0
        public object UpdateInstance(string propertyKey,
                                     JsonReader reader, object instance, ParameterInfo parameterInfo, MemberInfo memberInfo,
                                     IApplication httpApp, IHttpRequest request)
        {
            var containerName = memberInfo.BlobContainerName();
            var blobRef       = GetBlobRef();

            memberInfo.SetPropertyOrFieldValue(instance, blobRef);
            return(instance);

            IBlobRef GetBlobRef()
            {
                if (reader.TokenType == JsonToken.Bytes)
                {
                    var bytes      = reader.ReadAsBytes();
                    var blobRefRaw = new BlobRefRawData(containerName, bytes);
                    return(blobRefRaw);
                }

                if (reader.TokenType != JsonToken.String)
                {
                    throw new ArgumentException($"Cannot parse token of type {reader.TokenType} into BlobRef");
                }

                var blobRefRawStr = (string)reader.Value;

                if (Guid.TryParse(blobRefRawStr, out Guid guidValue))
                {
                    var idGuidStr = guidValue.AsBlobName();
                    return(new BlobRefStorage
                    {
                        Id = idGuidStr,
                        ContainerName = containerName,
                    });
                }

                if (Uri.TryCreate(blobRefRawStr, UriKind.Absolute, out Uri rawUri))
                {
                    return(new BlobRefUrl(rawUri));
                }

                throw new Exception($"Cannot parse {blobRefRawStr} into {nameof(IBlobRef)}.");
            }
        }
コード例 #3
0
        public TResult Bind <TResult>(IDictionary <string, EntityProperty> value,
                                      Type type, string pathStart, MemberInfo member,
                                      Func <object, TResult> onBound,
                                      Func <TResult> onFailedToBind)
        {
            var containerName = member.BlobContainerName();

            return(GetId(pathStart,
                         id =>
            {
                var blobRef = new BlobRefStorage
                {
                    Id = id,
                    ContainerName = containerName,
                };
                return onBound(blobRef);
            },
                         () =>
            {
                return onBound(default(IBlobRef));
            }));

            TResult GetId(string path,
                          Func <string, TResult> onFound,
                          Func <TResult> onNoValue)
            {
                if (!value.TryGetValue(path, out EntityProperty epValue))
                {
                    if (!member.TryGetAttributeInterface(out IMigrateBlobIdAttribute migrateBlobId))
                    {
                        return(onNoValue());
                    }

                    // terminate recursion
                    if (migrateBlobId.IdName.Equals(path, StringComparison.Ordinal))
                    {
                        return(onNoValue());
                    }

                    return(GetId(migrateBlobId.IdName,
                                 onFound, onNoValue));
                }

                if (epValue.PropertyType == EdmType.String)
                {
                    if (epValue.StringValue.HasBlackSpace())
                    {
                        return(onFound(epValue.StringValue));
                    }
                    return(onNoValue());
                }
                if (epValue.PropertyType == EdmType.Guid)
                {
                    var guidValue = epValue.GuidValue;
                    if (guidValue.HasValue)
                    {
                        return(onFound(guidValue.Value.ToString("N")));
                    }
                }
                return(onNoValue());
            }
        }