Ejemplo n.º 1
0
        public override string ToString()
        {
            var sb = StringBuilderCache.Aquire();

            sb.Append("linear-gradient(");

            if (Angle != null)
            {
                sb.Append(Angle.Value);
                sb.Append("deg");
            }
            else if (Direction != default)
            {
                sb.Append("to ");

                sb.Append(LinearGradientDirectionHelper.Canonicalize(Direction));
            }

            foreach (var stop in Stops)
            {
                sb.Append(", ");

                sb.Append(stop.Color.ToString());

                if (stop.Position is double position)
                {
                    sb.Append(' ');
                    sb.Append(position.ToString("0.##%"));
                }
            }

            sb.Append(')');

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 2
0
        public string Canonicalize()
        {
            var sb = StringBuilderCache.Aquire();

            WriteTo(sb);

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 3
0
        public override string ToString()
        {
            var sb = StringBuilderCache.Aquire();

            WriteTo(sb);

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 4
0
        public override string ToString()
        {
            var sb = StringBuilderCache.Aquire();

            using var writer = new StringWriter(sb);

            WriteTo(writer);

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 5
0
        public string ToString(IEnumerable <KeyValuePair <string, CssValue> > variables)
        {
            var sb = StringBuilderCache.Aquire();

            using var sw = new StringWriter(sb);

            WriteTo(sw, variables);

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 6
0
        public override string ToString()
        {
            var sb = StringBuilderCache.Aquire();

            foreach (var token in this)
            {
                sb.Append(token.ToString());
            }

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 7
0
        public override string ToString()
        {
            var sb = StringBuilderCache.Aquire();

            using var sw = new StringWriter(sb);

            var writer = new CssWriter(sw);

            writer.WriteStyleRule(this, 0);

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 8
0
        public CssUrlValue(byte[] data, string contentType)
        {
            // Works for resources only up to 32k in size in IE8.

            var sb = StringBuilderCache.Aquire();

            sb.Append("data:");
            sb.Append(contentType);
            sb.Append(";base64,");
            sb.Append(Convert.ToBase64String(data));

            Value = StringBuilderCache.ExtractAndRelease(sb);
        }
Ejemplo n.º 9
0
        public static string GetStringToSign(CredentialScope scope, string timestamp, string canonicalRequest)
        {
            string hashedCanonicalRequest = HexString.FromBytes(ComputeSHA256(canonicalRequest));

            var sb = StringBuilderCache.Aquire();

            sb.AppendJoin('\n', new string[] {
                algorithmName,          // Algorithm + \n
                timestamp,              // Timestamp + \n
                scope.ToString(),       // Scope     + \n
                hashedCanonicalRequest  // Hex(SHA256(CanonicalRequest))
            });

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 10
0
        public override string ToString()
        {
            if (Left == Top && Bottom == Top && Right == Top)
            {
                return(Top.ToString());
            }

            var sb = StringBuilderCache.Aquire()
                     .Append(Top?.ToString() ?? "0").Append(' ')
                     .Append(Left?.ToString() ?? "0").Append(' ')
                     .Append(Bottom?.ToString() ?? "0").Append(' ')
                     .Append(Right?.ToString() ?? "0");

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 11
0
        // Timestamp format: ISO8601 Basic format, YYYYMMDD'T'HHMMSS'Z'

        public static string GetCanonicalRequest(HttpRequestMessage request)
        {
            var sb = StringBuilderCache.Aquire();

            sb.AppendJoin('\n', new string[] {
                request.Method.ToString(),                 // HTTPRequestMethod      + \n
                request.RequestUri.AbsolutePath,           // CanonicalURI           + \n
                CanonicizeQueryString(request.RequestUri), // CanonicalQueryString   + \n
                CanonicalizeHeaders(request),              // CanonicalHeaders       + \n
                string.Empty,                              // \n
                GetSignedHeaders(request),                 // SignedHeaders          + \n
                GetPayloadHash(request)                    // HexEncode(Hash(Payload))
            });

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 12
0
        public S3Request(
            HttpMethod method,
            string host,
            string bucketName,
            string?objectName,
            string?version = null)
        {
            if (host is null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            BucketName = bucketName ?? throw new ArgumentNullException(nameof(bucketName));
            ObjectName = objectName;

            // https://{bucket}.s3.amazonaws.com/{key}

            var urlBuilder = StringBuilderCache.Aquire()
                             .Append("https://")
                             .Append(host)
                             .Append('/')
                             .Append(bucketName)
                             .Append('/');

            // s3.dualstack.{region.Name}.amazonaws.com

            if (objectName != null)
            {
                urlBuilder.Append(objectName);
            }

            if (version != null)
            {
                urlBuilder.Append("?version=");
                urlBuilder.Append(version);
            }

            RequestUri = new Uri(StringBuilderCache.ExtractAndRelease(urlBuilder));
            Method     = method;
        }
Ejemplo n.º 13
0
        public override string ToString()
        {
            // 100x100,stretch,anchor:center,background:red

            var sb = StringBuilderCache.Aquire();

            sb.Append(in width);
            sb.Append('x');
            sb.Append(in height);

            if (Flags != ResizeFlags.None)
            {
                WriteOptions(sb);
            }
            else if (Anchor != null)
            {
                sb.Append('-');
                sb.Append(Anchor.Value.ToCode());
            }

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 14
0
        public static string GetCanonicalRequest(
            HttpMethod method,
            string canonicalURI,
            string canonicalQueryString,
            string canonicalHeaders,
            string signedHeaders,
            string payloadHash)
        {
            var sb = StringBuilderCache.Aquire();

            sb.AppendJoin('\n', new string[] {
                method.ToString(),    // HTTPRequestMethod      + \n
                canonicalURI,         // CanonicalURI           + \n
                canonicalQueryString, // CanonicalQueryString   + \n
                canonicalHeaders,     // CanonicalHeaders       + \n
                string.Empty,         // \n
                signedHeaders,        // SignedHeaders          + \n
                payloadHash           // HexEncode(Hash(Payload))
            });

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 15
0
        public static string GetPresignedUrl(GetPresignedUrlRequest request, IAwsCredential credential, DateTime now)
        {
            var scope = new CredentialScope(now, request.Region, AwsService.S3);

            var urlBuilder = StringBuilderCache.Aquire()
                             .Append("https://")
                             .Append(request.Host)
                             .Append('/')
                             .Append(request.BucketName)
                             .Append('/')
                             .Append(request.Key);

            // TODO: support version querystring

            var message = new HttpRequestMessage(new HttpMethod(request.Method), StringBuilderCache.ExtractAndRelease(urlBuilder));

            SignerV4.Default.Presign(credential, scope, now, request.ExpiresIn, message, "UNSIGNED-PAYLOAD");

            string signedUrl = message.RequestUri.ToString();

            return(signedUrl);
        }
Ejemplo n.º 16
0
        private static string ToPostData(this Dictionary <string, string> nvc, string?prefix)
        {
            var sb = StringBuilderCache.Aquire();

            if (prefix != null)
            {
                sb.Append(prefix);
            }

            foreach (string key in nvc.Keys)
            {
                if (sb.Length > 0)
                {
                    sb.Append('&');
                }

                sb.Append(key);
                sb.Append('=');
                sb.Append(UrlEncoder.Default.Encode(nvc[key]));
            }

            return(StringBuilderCache.ExtractAndRelease(sb));
        }
Ejemplo n.º 17
0
        private void ImportInline(ImportRule rule)
        {
            if (resolver is null)
            {
                throw new ArgumentNullException(nameof(resolver));
            }

            // var relativePath = importRule.Url;
            var absolutePath = rule.Url.GetAbsolutePath(resolver.ScopedPath);

            // Assume to be scss if there is no extension
            if (absolutePath.IndexOf('.') == -1)
            {
                absolutePath += ".scss";
            }

            var stream = resolver.Open(absolutePath.TrimStart(Seperators.ForwardSlash));

            if (stream != null)
            {
                if (absolutePath.EndsWith(".scss"))
                {
                    AddChild(new CssComment($"imported: '{absolutePath}"));

                    try
                    {
                        foreach (var node in Parse(stream, Context).Children)
                        {
                            AddChild(node);
                        }
                    }
                    catch (SyntaxException ex)
                    {
                        AddChild(new StyleRule("body, html")
                        {
                            new CssDeclaration("background-color", "red", "important")
                        });

                        AddChild(new StyleRule("body *")
                        {
                            { "display", "none" }
                        });

                        AddChild(new CssComment($" --- Syntax error reading '{absolutePath}' : {ex.Message} --- "));

                        var sb = StringBuilderCache.Aquire();

                        if (ex.Lines != null)
                        {
                            foreach (var line in ex.Lines)
                            {
                                sb.Append(line.Number.ToString().PadLeft(5));
                                sb.Append(". ");

                                if (line.Number == ex.Location.Line)
                                {
                                    sb.Append("* ");
                                }

                                sb.AppendLine(line.Text);
                            }
                        }

                        AddChild(new CssComment(StringBuilderCache.ExtractAndRelease(sb)));

                        return;
                    }
                }
                else
                {
                    throw new Exception(".css include not supported");
                    //  writer.Write(text);
                }
            }
            else
            {
                AddChild(new CssComment($"NOT FOUND: '{absolutePath}"));
            }
        }
Ejemplo n.º 18
0
        public string ToTransformPath()
        {
            if (Encode == null)
            {
                throw new Exception("Missing Encode");
            }

            var sb = StringBuilderCache.Aquire();

            if (Expires != null)
            {
                sb.Append('/');
                sb.Append("expires(");
                sb.Append(new DateTimeOffset(Expires.Value).ToUnixTimeSeconds());
                sb.Append(')');
            }

            if (Encode.Format == FormatId.Json && Metadata != null)
            {
                sb.Append('/');
                Metadata.WriteTo(sb);
                sb.Append(".json");

                return(sb.ToString());
            }

            if (Extract is ExtractFilter extract)
            {
                sb.Append('/');

                // page | timestamp | frame | poster
                sb.Append(extract.ToString());
            }

            if (Background != null)
            {
                sb.Append('/');
                sb.Append("background(");
                sb.Append(Background);
                sb.Append(')');
            }

            if (Flip != null)
            {
                sb.Append('/');

                Flip.WriteTo(sb);
            }

            // TODO: Orient...

            if (Rotate != 0)
            {
                sb.Append('/');
                sb.Append("rotate(");
                sb.Append(Rotate);
                sb.Append("deg)");
            }

            if (Crop is Rectangle crop)
            {
                sb.Append('/');
                sb.Append($"crop({crop.X},{crop.Y},{crop.Width},{crop.Height})");
            }

            if (Scale != null)
            {
                sb.Append('/');

                sb.Append(Scale.Width);
                sb.Append('x');
                sb.Append(Scale.Height);
            }

            // pad(0,0)

            if (!Padding.Equals(Padding.Zero))
            {
                sb.Append('/');
                sb.Append("pad(");
                sb.Append(Padding.ToString());
                sb.Append(")");
            }

            foreach (var filter in Filters)
            {
                sb.Append('/');

                if (filter is ICanonicalizable canonicalizable)
                {
                    canonicalizable.WriteTo(sb);
                }
                else
                {
                    sb.Append(filter.Canonicalize());
                }
            }

            if (Encode.Flags.HasFlag(EncodeFlags.Lossless))
            {
                sb.Append('/');
                sb.Append("lossless");
            }
            else if (Encode.Quality != null)
            {
                sb.Append('/');
                sb.Append("quality(");
                sb.Append(Encode.Quality.Value);
                sb.Append(')');
            }

            sb.Append('.');
            sb.Append(Encode.Format.ToString().ToLower());

            return(StringBuilderCache.ExtractAndRelease(sb).Substring(1));
        }
Ejemplo n.º 19
0
        public string Canonicalize()
        {
            var sb = StringBuilderCache.Aquire();

            sb.Append("blob#" + Source.Key);

            if (Expires != null)
            {
                sb.Append("|>expires(");
                sb.Append(new DateTimeOffset(Expires.Value).ToUnixTimeSeconds());
                sb.Append(')');
            }

            if (Encode.Format == FormatId.Json && Metadata != null)
            {
                sb.Append("|>");
                Metadata.WriteTo(sb);
                sb.Append("|>");
                Encode.WriteTo(sb);

                return(sb.ToString());
            }

            if (Extract is ExtractFilter extract)
            {
                sb.Append("|>");

                // frame | page | timestamp
                sb.Append(extract.ToString());
            }

            if (Background != null)
            {
                sb.Append("|>background(");
                sb.Append(Background);
                sb.Append(')');
            }

            if (Flip != null)
            {
                sb.Append("|>");

                Flip.WriteTo(sb);
            }

            if (Rotate != 0)
            {
                sb.Append("|>rotate(");
                sb.Append(Rotate);
                sb.Append("deg)");
            }

            if (Crop is Rectangle crop)
            {
                sb.Append("|>");
                sb.Append($"crop({crop.X},{crop.Y},{crop.Width},{crop.Height})");
            }

            if (Scale != null)
            {
                sb.Append("|>");

                Scale.WriteTo(sb);
            }

            // pad(0,0)

            if (!Padding.Equals(Padding.Zero))
            {
                sb.Append("|>");
                sb.Append("pad(");
                sb.Append(Padding.ToString());
                sb.Append(")");
            }

            foreach (var filter in Filters)
            {
                sb.Append("|>");

                if (filter is ICanonicalizable canonicalizable)
                {
                    canonicalizable.WriteTo(sb);
                }
                else
                {
                    sb.Append(filter.Canonicalize());
                }
            }

            sb.Append("|>");

            Encode.WriteTo(sb);

            if (IsDebug)
            {
                sb.Append("|>debug");
            }

            return(StringBuilderCache.ExtractAndRelease(sb));
        }