Ejemplo n.º 1
1
        public static void Write(this BsonDocument document, string field, BsonValue value)
        {

            if (value == null) return;

            if (field.StartsWith("_")) field = "PREFIX" + field;
            // todo: make sure the search query builder also picks up this name change.

            bool forcearray = (value.BsonType == BsonType.Document);
            // anders kan er op zo'n document geen $elemMatch gedaan worden.

            BsonElement element;

            if (document.TryGetElement(field, out element))
            {
                if (element.Value.BsonType == BsonType.Array)
                {
                    element.Value.AsBsonArray.Add(value);
                }
                else
                {
                    document.Remove(field);
                    document.Append(field, new BsonArray() { element.Value, value ?? BsonNull.Value });
                }
            }
            else
            {
                if (forcearray)
                    document.Append(field, new BsonArray() { value ?? BsonNull.Value });
                else
                    document.Append(field, value);
            }
        }
Ejemplo n.º 2
0
        private static StringBuilder AppendPrettyArguments(this StringBuilder name, Type type, PrettyNameContext context)
        {
            // No args remain (ex: non-generic nested in generic)
            var count = context.GetGenericArgumentCount(type);
            if (count == 0)
                return name;

            // Completely open type
            if (context.IsGenericTypeDefinition)
                return name
                    .Append('<')
                    .Append(',', count - 1)
                    .Append('>');

            // Partially or fully closed types
            name.Append('<');

            for (var i = 0; i < count; i++)
            {
                var arg = context.GetNextGenericArgument();
                if (arg.IsGenericParameter)
                {
                    if (i != 0) name.Append(',');
                }
                else
                {
                    if (i != 0) name.Append(',').Append(' ');
                    name.AppendPrettyName(arg, context);
                }
            }

            return name.Append('>');
        }
Ejemplo n.º 3
0
        private static void WriteRows(this StringBuilder sb, IReadOnlyList<HelpRow> rows, int maxWidth)
        {
            const int indent = 4;
            var maxColumnWidth = rows.Select(r => r.Header.Length).Max();
            var helpStartColumn = maxColumnWidth + 2 * indent;

            var maxHelpWidth = maxWidth - helpStartColumn;
            if (maxHelpWidth < 0)
                maxHelpWidth = maxWidth;

            foreach (var row in rows)
            {
                var headerStart = sb.Length;

                sb.Append(' ', indent);
                sb.Append(row.Header);

                var headerLength = sb.Length - headerStart;
                var requiredSpaces = helpStartColumn - headerLength;

                sb.Append(' ', requiredSpaces);

                var words = SplitWords(row.Text);
                sb.WriteWordWrapped(words, helpStartColumn, maxHelpWidth);
            }
        }
Ejemplo n.º 4
0
        public static StringBuilder AppendRequest(this StringBuilder stringBuilder, XpoImageUrlRequest request)
        {
            var americanCulture = new CultureInfo("en-US");

            stringBuilder
                .Append(EntityName, HttpUtility.UrlEncode(request.PrimaryKey))
                .Append(Width, request.Width)
                .Append(BackgroundColor, request.BackgroundColor)
                .Append(Caching, request.Caching)
                .Append(Debug, request.Debug)
                .Append(Height, request.Height)
                .Append(DesignCaching, request.DesignCaching)
                .Append(ResizeMethod, request.ResizeMethod)
                .Append(OutputQuality, ConvertNumberToCultureNumber(request.OutputQuality, americanCulture))
                .Append(ImageType, request.ImageType)
                .Append(IsEntity, request.IsEntity)
                .Append(TransparencyColor, request.TransparencyColor)
                .Append(SceneThumbnailObjectNumber, request.SceneThumbnailObjectNumber)
                .Append(HighlightObject, request.HighlightObject)
                .Append(AllColor, request.AllColor)
                .Append(PrefillCaching, request.PrefillCaching)
                .Append(SessionId, request.SessionId)
                .Append(Overlays, request.Overlays.OrderBy(x => x.Index).Select(x => x.OverlayName).ToArray().Join(","))
                .Append(TemplateName, request.TemplateName)
                .AppendDictionary(request.CustomParameters);

            foreach (var templateParameter in request.TemplateParameters)
            {
                stringBuilder.Append(templateParameter.Index, TemeplateParameter, templateParameter.Value);
            }

            return stringBuilder;
        }
Ejemplo n.º 5
0
 public static void AppendDouble(this StringBuilder sb, double? value, int noPlaces)
 {
     if (value != null)
         sb.Append(Math.Round((double)value, noPlaces));
     else
         sb.Append(0);
 }
        public static void AppendNumber(this StringBuilder sb, int number)
        {
            // Save the current length as starting index
            int startIndex = sb.Length;

            // Handle negative
            bool isNegative;
            uint unumber;
            if (number < 0)
            {
                unumber = (uint) ((number == int.MinValue) ? number : -number);
                isNegative = true;
            }
            else
            {
                unumber = (uint) number;
                isNegative = false;
            }

            // Convert 
            do
            {
                sb.Append(charToInt[unumber % 10]);
                unumber /= 10;
            } while (unumber != 0);

            if (isNegative)
                sb.Append('-');

            sb.Swap(startIndex, sb.Length - 1);
        }
Ejemplo n.º 7
0
 public static void AppendWidthCommaBefore(this StringBuilder sb, int? value)
 {
     if (sb.Length > 0)
         sb.Append(", ");
     if (value != null)
         sb.Append(value.Value.ToString(CultureInfo.InvariantCulture));
 }
 public static StringBuilder AppendQuotedString(this StringBuilder builder, string value)
 {
     builder.Append('"');
     builder.Append(value);
     builder.Append('"');
     return builder;
 }
 public static StringBuilder AppendQuoted(this StringBuilder builder, string value)
 {
     var needEncoding = value.IndexOfAny(new[] { '=', '"', ';' }) != -1;
     return needEncoding
                ? builder.Append("\"").Append(value.Replace("\\", "\\\\").Replace("\"", "\\\"")).Append("\"")
                : builder.Append(value);
 }
Ejemplo n.º 10
0
        public static StringBuilder AppendArray(this StringBuilder @this, Type elementType, Array array)
        {
            if (elementType == typeof(byte))
            {
                @this.Append('0').Append('x');

                foreach (byte item in array)
                {
                    @this.Append(item.ToString("x2"));
                }

                return @this;
            }

            @this.Append('(');

            for (int i = 0; i < array.Length; i++)
            {
                if (i > 0)
                {
                    @this.Append(',');
                }

                @this.AppendConstant(elementType, array.GetValue(i));
            }

            return @this.Append(')');
        }
Ejemplo n.º 11
0
        public static StringBuilder AppendRequest(this StringBuilder stringBuilder, XpoUrlRequest request)
        {
            stringBuilder
                .Append("?1=1")
                .Append(Width, (request.Width == 0) ? -1 : request.Width) // Safety (0 is the default value)
                .Append(BackgroundColor, request.BackgroundColor)
                .Append(Caching, GetCachingMethod(request))
                .Append(Height, request.Height)
                .Append(DesignCaching, request.DesignCaching)
                .Append(ResizeMethod, GetResizeMethod(request))
                .Append(TextureRepeat, GetRepeatMethod(request))
                .Append(OutputQuality, request.OutputQuality)
                .Append(ImageType, GetFormat(request.ImageType))
                .Append(SceneThumbnailObjectNumber, request.SceneThumbnailObjectNumber)
                .Append(HighlightObject, request.HighlightObject)
                .Append(Watermark, request.WatermarkImage)
                .Append(Frame, request.Frame)
                .AppendDictionary(request.CustomParameters);

            if (request is XpoCoordinatesUrlRequest)
            {
                stringBuilder.Append(Coords, true);
            }

            return stringBuilder;
        }
 public static void AppendTab(this System.Text.StringBuilder s, string Message)
 {
     if (s == null)
         throw new ArgumentNullException("s");
     s.Append(Message);
     s.Append("\t");
 }
 public static void AppendTag(this StringBuilder stringBuilder, string tagName, string content, object attributes)
 {
     stringBuilder.Append("<" + tagName);
     attributes.EachProperty(property => stringBuilder.Append(" " + property.Name.ToLower() + "=\"" + attributes.GetPropertyValue(property.Name) + "\""));
     stringBuilder.Append(">" + content);
     stringBuilder.AppendClosingTag(tagName);
 }
Ejemplo n.º 14
0
        public static void AppendSql(this StringBuilder builder, string sql) {
            builder.Append(sql);
            if (builder[builder.Length - 1] != ';') {
                builder.Append(";");
            }

            builder.AppendLine();
        }
Ejemplo n.º 15
0
		public static void AppendAttribute(this System.Text.StringBuilder sb, string name, string value)
		{
			sb.Append(" ");
			sb.Append(name);
			sb.Append("=\"");
			sb.Append(value.Replace("\"", "&#34;"));
			sb.Append("\"");
		}
Ejemplo n.º 16
0
 private static void AppendWithTabs(this StringBuilder sb, string value, int tabs = 0)
 {
     for (int i = 0; i < tabs; i++) {
         sb.Append("    ");
     }
     sb.Append(value);
     sb.Append(Environment.NewLine);
 }
Ejemplo n.º 17
0
 //--- Extension Methods ---
 public static StringBuilder AppendLiteral(this StringBuilder builder, DekiScriptLiteral literal) {
     if(literal is DekiScriptString) {
         builder.Append(((DekiScriptString)literal).Value);
     } else {
         builder.Append(literal.ToString());
     }
     return builder;
 }
Ejemplo n.º 18
0
 public static void AppendFormData(this StringBuilder stringBuilder, string name, string value) {
     if (stringBuilder.Length != 0) {
         stringBuilder.Append("&");
     }
     stringBuilder.Append(name);
     stringBuilder.Append("=");
     stringBuilder.Append(value.UrlEncode());
 }
Ejemplo n.º 19
0
        public static StringBuilder AppendIndent(this StringBuilder sb, string str)
        {
            if (sb == null)
                return null;

            sb.Append (Utils.IndentString);
            sb.Append (str);
            return sb;
        }
Ejemplo n.º 20
0
 internal static StringBuilder AppendParam(this StringBuilder builder, string key, string value)
 {
     if (builder.Length > 0)
         builder.Append('&');
     builder.Append(key);
     builder.Append('=');
     builder.Append(value);
     return builder;
 }
Ejemplo n.º 21
0
 internal static void AppendWithCondition(this System.Text.StringBuilder sb, bool condition, string text, string prefixIfExistingContent = null)
 {
     if (condition)
     {
         if (sb.Length > 0 && prefixIfExistingContent != null)
             sb.Append(prefixIfExistingContent);
         sb.Append(text);
     }
 }
Ejemplo n.º 22
0
        public static StringBuilder AppendNumber(this StringBuilder builder, float number, int decimalCount, AppendNumberOptions options)
        {
            if (float.IsNaN(number)) return builder.Append("NaN");
            if (float.IsNegativeInfinity(number)) return builder.Append("-Infinity");
            if (float.IsPositiveInfinity(number)) return builder.Append("+Infinity");

            int intNumber = (int) (number * (float) Math.Pow(10, decimalCount) + 0.5f);
            return AppendNumberInternal(builder, intNumber, decimalCount, options);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Will append key/value querystring param to a specified url
 /// </summary>
 /// <param name="url"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void AppendQueryStringParam(this StringBuilder url, string key, string value)
 {
     if (url.Length > 0 && !String.IsNullOrEmpty(key) && !String.IsNullOrEmpty(value))
     {
         url.Append(!url.ToString().Contains("?") ? "?" : "&");
         url.Append(key);
         url.Append("=");
         url.Append(value);
     }
 }
Ejemplo n.º 24
0
 public static void EscapeString(this StringBuilder sb, string text, bool withQuotes = true, bool withEndingNewLine = false, string NewLineReplacment = null)
 {
     if (withQuotes) sb.Append('"');
     for (int i = 0; i < text.Length; i++)
     {
         char c = text[i];
         char p = text.CharAtOrDefault(i + 1);
         switch (c)
         {
             case '\\':
                 if (p != '\\') goto default;
                 sb.Append("\\\\");
                 break;
             case '\n':
             case '\r':
                 if (p != c && (p == '\n' || p == '\r')) i++;
                 // new line detected
                 if (NewLineReplacment != null) sb.Append(NewLineReplacment);
                 else sb.Append(EscapedNewLine);
                 break;
             case '"':
                 sb.Append("\\\"");
                 break;
             default:
                 sb.Append(c);
                 break;
         }
     }
     if (withEndingNewLine)
     {
         if (NewLineReplacment != null) sb.Append(NewLineReplacment);
         else sb.Append(EscapedNewLine);
     }
     if (withQuotes) sb.Append('"');
 }
        public static void AppendInNewLine(this System.Text.StringBuilder s, string Message)
        {
            if (s == null)
                throw new ArgumentNullException("s");

            if (!s.IsEmpty())
            {
                s.Append(Environment.NewLine);
            }
            s.Append(Message);
        }
		public static void AppendAsHexCharsUpperCase(this StringBuilder builder, byte[] array)
		{
			if (array == null) return;

			for (int i = 0; i < array.Length; i++)
			{
				byte bytic = array[i];
				builder.Append(CommonData.DigitsUpperCase[(bytic >> 4) & 0xF]);
				builder.Append(CommonData.DigitsUpperCase[bytic & 0xF]);
			}
		}
Ejemplo n.º 27
0
        /// <summary>
        /// 追加字符串,用分隔符分隔
        /// </summary>
        /// <param name="sb">StringBulider对象</param>
        /// <param name="append">要追加的字符串</param>
        /// <param name="split">分隔符</param>
        public static void AppendString(this StringBuilder sb, string append, string split)
        {
            if (sb.Length == 0)
            {
                sb.Append(append);
                return;
            }

            sb.Append(split);
            sb.Append(append);
        }
        internal static StringBuilder SafeSqlAppend(this StringBuilder stringBuilder, string stringToAppend)
        {
            if (stringBuilder.Length > 0)
            {
                stringBuilder.Append(" ");
            }

            stringBuilder.Append(stringToAppend);

            return stringBuilder;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Appends the hexadecimal string representation of a specified
        /// <see cref="Int16"/> value to this instance.
        /// </summary>
        /// <param name="source">The source <see cref="StringBuilder"/> instance.</param>
        /// <param name="value">The <see cref="Int16"/> value to append.</param>
        /// <returns>A reference to this instance after the append operation has, optionally, completed.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// Enlarging the value of this instance would exceed <see cref="p:StringBuilder.MaxCapacity"/>.
        /// </exception>
        public static StringBuilder AppendAsHexadecimal(this StringBuilder source, short value)
        {
            Contracts.Requires.NotNull(source, "source");

            source.Append(ToHex((value >> 12) & 0xf));
            source.Append(ToHex((value >> 8) & 0xf));
            source.Append(ToHex((value >> 4) & 0xf));
            source.Append(ToHex(value & 0xf));

            return source;
        }
Ejemplo n.º 30
0
        internal static StringBuilder FormatItem(this StringBuilder sb, string item)
        {
            // TODO: Chars that need escaping using a backslash:
            // { ' ', '\t', '\n', '\v', '"' }
            // Check whether this is needed.

            if (item.Contains(" "))
                sb.Append('"').Append(item).Append('"');
            else
                sb.Append(item);
            return sb;
        }