public void FindByGuidKey()
        {
            var key     = Guid.NewGuid();
            var command = _client
                          .For <TypeWithGuidKey>()
                          .Key(key);
            var commandText = command.GetCommandTextAsync().Result;

            Assert.Equal($"TypeWithGuidKey({Uri.EscapeDataString(FormatSettings.GetGuidFormat(key.ToString()))})", commandText);
        }
Exemplo n.º 2
0
        public void FindByGuidKey()
        {
            var key     = new Guid("BEC6C966-8016-46D0-A3D1-99D69DF69D74");
            var command = _client
                          .For <TypeWithGuidKey>()
                          .Key(key);
            var commandText = command.GetCommandTextAsync().Result;

            Assert.Equal($"TypeWithGuidKey({Uri.EscapeDataString(FormatSettings.GetGuidFormat(key.ToString()))})", commandText);
        }
Exemplo n.º 3
0
        public void FindByGuidFilterEqual()
        {
            var key     = new Guid("D8F3F70F-C185-49AB-9A92-0C86C344AB1B");
            var command = _client
                          .For <TypeWithGuidKey>()
                          .Filter(x => x.Key == key);
            var commandText = command.GetCommandTextAsync().Result;

            Assert.Equal(string.Format("TypeWithGuidKey({0})", Uri.EscapeDataString(FormatSettings.GetGuidFormat(key.ToString()))), commandText);
        }
Exemplo n.º 4
0
        public async Task FindAllByFilterWithDateTimeOffsetCastFromDateTimeOffset()
        {
            var created = new DateTimeOffset(2010, 12, 1, 12, 11, 10, TimeSpan.FromHours(0));
            var command = _client
                          .For <Order>()
                          .Filter(x => x.ShippedDateTimeOffset > (DateTimeOffset)created);
            var commandText = await command.GetCommandTextAsync();

            Assert.Equal($"Orders?$filter=ShippedDateTimeOffset%20gt%20{FormatSettings.GetDateTimeOffsetFormat("2010-12-01T12:11:10Z", true)}", commandText);
        }
Exemplo n.º 5
0
        private bool _penalizedAsJustified;                                     // flag indicating whether the paragraph should be penalized as fully-justified one


        /// <summary>
        /// Construct a paragraph cache to be used during optimal paragraph formatting
        /// </summary>
        internal TextParagraphCache(
            FormatSettings settings,
            int firstCharIndex,
            int paragraphWidth
            )
        {
            Invariant.Assert(settings != null);

            // create full text
            _finiteFormatWidth = settings.GetFiniteFormatWidth(paragraphWidth);
            _fullText          = FullTextState.Create(settings, firstCharIndex, _finiteFormatWidth);

            // acquiring LS context
            TextFormatterContext context = settings.Formatter.AcquireContext(_fullText, IntPtr.Zero);

            _fullText.SetTabs(context);

            IntPtr ploparabreakValue = IntPtr.Zero;

            LsErr lserr = context.CreateParaBreakingSession(
                firstCharIndex,
                _finiteFormatWidth,
                // breakrec is not needed before the first cp of para cache
                // since we handle Bidi break ourselves.
                IntPtr.Zero,
                ref ploparabreakValue,
                ref _penalizedAsJustified
                );

            // get the exception in context before it is released
            Exception callbackException = context.CallbackException;

            // release the context
            context.Release();

            if (lserr != LsErr.None)
            {
                GC.SuppressFinalize(this);
                if (callbackException != null)
                {
                    // rethrow exception thrown in callbacks
                    throw new InvalidOperationException(SR.Get(SRID.CreateParaBreakingSessionFailure, lserr), callbackException);
                }
                else
                {
                    // throw with LS error codes
                    TextFormatterContext.ThrowExceptionFromLsError(SR.Get(SRID.CreateParaBreakingSessionFailure, lserr), lserr);
                }
            }

            _ploparabreak.Value = ploparabreakValue;

            // keep context alive till here
            GC.KeepAlive(context);
        }
        public void FindAllByFilterWithDateTimeOffsetCastFromDateTime()
        {
            var created = new DateTime(2010, 12, 1, 12, 11, 10, DateTimeKind.Utc);
            var command = _client
                          .For <Order>()
                          .Filter(x => x.ShippedDateTimeOffset > (DateTimeOffset)created);
            string commandText = command.GetCommandTextAsync().Result;

            Assert.Equal(string.Format("Orders?$filter=ShippedDateTimeOffset%20gt%20{0}",
                                       FormatSettings.GetDateTimeOffsetFormat("2010-12-01T12:11:10Z", true)), commandText);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="baseFontSize">Base font size (11pt, 12pt, ...)</param>
        /// <param name="isTitle">Flag if shape is title shape (uses different default font) - optional, default: false</param>
        public TextFormat(float baseFontSize, bool isTitle = false)
        {
            _baseFontSize = baseFontSize * 2.0f;

            _settingsStack = new Stack<FormatSettings>();

            _currentSettings = new FormatSettings(_baseFontSize, isTitle);

            _changed = true;

            _firstRun = true;
        }
    public void FilterWithEnum_PrefixFree()
    {
        var enumPrefixFree = _session.Settings.EnumPrefixFree;

        _session.Settings.EnumPrefixFree = true;
        try
        {
            Expression <Func <TestEntity, bool> > filter = x => x.Address.Type == AddressType.Corporate;
            Assert.Equal($"Address/Type eq {FormatSettings.GetEnumFormat(AddressType.Corporate, typeof(AddressType), "NorthwindModel", true)}",
                         ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
        finally
        {
            _session.Settings.EnumPrefixFree = enumPrefixFree;
        }
    }
        private void DoFormatCode()
        {
            // we already pulled the first %
            if (_index == _str.Length)
            {
                throw PythonOps.ValueError("incomplete format, expected format character at index {0}", _index);
            }

            // Index is placed right after the %.
            Debug.Assert(_str[_index - 1] == '%');

            _curCh = _str[_index++];

            if (_curCh == '%')
            {
                // Escaped '%' character using "%%". Just print it and we are done
                _buf.Append('%');
                return;
            }

            string key = ReadMappingKey();

            _opts = new FormatSettings();

            ReadConversionFlags();

            ReadMinimumFieldWidth();

            ReadPrecision();

            ReadLengthModifier();

            // use the key (or lack thereof) to get the value
            object value;

            if (key == null)
            {
                value = GetData(_dataIndex++);
            }
            else
            {
                value = GetKey(key);
            }
            _opts.Value = value;

            WriteConversion();
        }
        public void FilterWithEnum_PrefixFree()
        {
            var enumPrefixFree = Session.EnumPrefixFree;

            Session = new Session(true);
            try
            {
                Expression <Func <TestEntity, bool> > filter = x => x.Address.Type == AddressType.Corporate;
                var actual     = ODataExpression.FromLinqExpression(filter).AsString(Session);
                var enumFormat = FormatSettings.GetEnumFormat(AddressType.Corporate, typeof(AddressType), typeof(AddressType).Namespace, true);
                var expected   = $"Address/Type eq {enumFormat}";
                Assert.Equal(expected, actual);
            }
            finally
            {
                Session = new Session(enumPrefixFree);
            }
        }
Exemplo n.º 11
0
        private void DoFormatCode()
        {
            // we already pulled the first %
            curCh = str[index++];

            if (curCh == '%')
            {
                // Escaped '%' character using "%%". Just print it and we are done
                buf.Append('%');
                return;
            }

            string key = ReadMappingKey();

            opts = new FormatSettings();

            ReadConversionFlags();

            ReadMinimumFieldWidth();

            ReadPrecision();

            ReadLengthModifier();

            // use the key (or lack thereof) to get the value
            object value;

            if (key == null)
            {
                value = GetData(dataIndex++);
            }
            else
            {
                value = GetKey(key);
            }
            opts.Value = value;

            WriteConversion();
        }
Exemplo n.º 12
0
        private void DoFormatCode()
        {
            // we already pulled the first %

            if (_index == _format.Length || _format[_index] == '\n' || _format[_index] == '\0')
            {
                // '%' at the end of the string. Just print it and we are done.
                _buf.Append('%');
                return;
            }

            _curCh = _format[_index++];

            if (_curCh == '%')
            {
                // Escaped '%' character using "%%". Just print it and we are done
                _buf.Append('%');
                return;
            }

            _opts = new FormatSettings();

            ReadConversionFlags();

            ReadArgumentIndex(); // This can be before or after width and precision

            ReadMinimumFieldWidth();

            ReadPrecision();

            ReadArgumentIndex(); // This can be before or after width and precision

            _opts.Value = GetData(_opts.ArgIndex);

            WriteConversion();
        }
Exemplo n.º 13
0
        private void DoFormatCode() {
            // we already pulled the first %

            if (_index == _format.Length) {
                // '%' at the end of the string. Just print it and we are done.
                _buf.Append('%');
                return;
            }

            _curCh = _format[_index++];

            if (_curCh == '%') {
                // Escaped '%' character using "%%". Just print it and we are done
                _buf.Append('%');
                return;
            }

            _opts = new FormatSettings();

            ReadConversionFlags();

            ReadMinimumFieldWidth();

            ReadPrecision();

            _opts.Value = GetData(_opts.ArgIndex);

            WriteConversion();
        }
Exemplo n.º 14
0
 // restricted constructor
 private TradeReportFormatter() : base(FormatSettings.of(FormatCategory.TEXT, ValueFormatters.UNSUPPORTED))
 {
 }
    public void StringToLowerAndContains()
    {
        Expression <Func <TestEntity, bool> > filter = x => x.ProductName.ToLower().Contains("Chai");

        Assert.Equal(FormatSettings.GetContainsFormat("tolower(ProductName)", "Chai"), ODataExpression.FromLinqExpression(filter).AsString(_session));
    }
    public void StringContainedIn()
    {
        Expression <Func <TestEntity, bool> > filter = x => "Chai".Contains(x.ProductName);

        Assert.Equal(FormatSettings.GetContainedInFormat("ProductName", "Chai"), ODataExpression.FromLinqExpression(filter).AsString(_session));
    }
    public void EqualDateTimeOffset()
    {
        Expression <Func <TestEntity, bool> > filter = x => x.Updated == new DateTimeOffset(new DateTime(2013, 1, 1, 0, 0, 0, DateTimeKind.Utc));

        Assert.Equal($"Updated eq {FormatSettings.GetDateTimeOffsetFormat("2013-01-01T00:00:00Z")}", ODataExpression.FromLinqExpression(filter).AsString(_session));
    }
Exemplo n.º 18
0
        public static void SendPage(TSPlayer player, int pageNumber, Dictionary<string, int> dataToPaginate,
			FormatSettings settings = null)
        {
            SendPage(player, pageNumber, dataToPaginate, dataToPaginate.Count, settings);
        }
Exemplo n.º 19
0
        public static void SendPage(
			TSPlayer player, int pageNumber, Dictionary<string, int> dictionary, int dataToPaginateCount,
			FormatSettings settings = null)
        {
            if (settings == null)
                settings = new FormatSettings();

            if (dataToPaginateCount == 0)
            {
                if (settings.NothingToDisplayString != null)
                {
                    if (!player.RealPlayer)
                        player.SendSuccessMessage(settings.NothingToDisplayString);
                    else
                        player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor);
                }
                return;
            }

            var pageCount = ((dataToPaginateCount - 1)/settings.MaxLinesPerPage) + 1;
            if (settings.PageLimit > 0 && pageCount > settings.PageLimit)
                pageCount = settings.PageLimit;
            if (pageNumber > pageCount)
                pageNumber = pageCount;

            if (settings.IncludeHeader)
            {
                if (!player.RealPlayer)
                    player.SendSuccessMessage(string.Format(settings.HeaderFormat, pageNumber, pageCount));
                else
                    player.SendMessage(string.Format(settings.HeaderFormat, pageNumber, pageCount),
                        settings.HeaderTextColor);
            }

            var listOffset = (pageNumber - 1)*settings.MaxLinesPerPage;
            var offsetCounter = 0;
            var lineCounter = 0;

            foreach (var lineData in dictionary)
            {
                if (offsetCounter++ < listOffset)
                    continue;
                if (lineCounter++ == settings.MaxLinesPerPage)
                    break;

                var lineColor = Color.Yellow;
                var hsName = lineData.Key;
                var hsScore = lineData.Value;
                var index = dictionary.Keys.ToList().IndexOf(hsName) + 1;

                if (index == 1)
                    lineColor = Color.Cyan;
                if (index == 2)
                    lineColor = Color.ForestGreen;
                if (index == 3)
                    lineColor = Color.OrangeRed;

                if (string.Equals(hsName, player.UserAccountName, StringComparison.CurrentCultureIgnoreCase))
                    lineColor = Color.White;

                if (!string.IsNullOrEmpty(hsName))
                {
                    if (!player.RealPlayer)
                        player.SendInfoMessage("{0}. {1} with {2} point{3}",
                            index, hsName, hsScore, hsScore.Suffix());
                    else
                        player.SendMessage(string.Format("{0}. {1} with {2} point{3}",
                            index, hsName, hsScore, hsScore.Suffix()), lineColor);
                }
            }

            if (lineCounter == 0)
            {
                if (settings.NothingToDisplayString != null)
                {
                    if (!player.RealPlayer)
                        player.SendSuccessMessage(settings.NothingToDisplayString);
                    else
                        player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor);
                }
            }
            else if (settings.IncludeFooter && pageNumber + 1 <= pageCount)
            {
                if (!player.RealPlayer)
                    player.SendInfoMessage(string.Format(settings.FooterFormat, pageNumber + 1, pageNumber, pageCount));
                else
                    player.SendMessage(string.Format(settings.FooterFormat, pageNumber + 1, pageNumber, pageCount),
                        settings.FooterTextColor);
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Private copy constructor
 /// </summary>
 /// <param name="format">Format settings object</param>
 private FormatSettings(FormatSettings format)
 {
     FontFamily = format.FontFamily;
     FontSize = format.FontSize;
     Color = format.Color;
     Bold = format.Bold;
     Italic = format.Italic;
     Underline = format.Underline;
     Smallcaps = format.Smallcaps;
 }
Exemplo n.º 21
0
        /// <summary>
        /// Return current formatting to previous state.
        /// </summary>
        public void RollBackFormat()
        {
            if(_settingsStack.Count > 0)
                _currentSettings = _settingsStack.Pop();

            _changed = true;
        }
Exemplo n.º 22
0
        public override IList <SettingItem> GetOrderSettings(OrderRequestParameters parameters, FormatSettings formatSettings)
        {
            var settings = base.GetOrderSettings(parameters, formatSettings);

            if (parameters.Type == RequestType.PlaceOrder)
            {
                if (parameters.Symbol.SymbolType != SymbolType.Options)
                {
                    OKExOrderTypeHelper.AddTradeMode(parameters, settings);

                    if (parameters.Symbol.SymbolType == SymbolType.Crypto)
                    {
                        OKExOrderTypeHelper.AddReduceOnly(settings);
                    }
                    else if (parameters.Symbol.SymbolType != SymbolType.Options)
                    {
                        OKExOrderTypeHelper.AddOrderBehaviour(settings);
                    }
                }

                OKExOrderTypeHelper.AddComment(settings, string.Empty);
            }

            return(settings);
        }
Exemplo n.º 23
0
        public void StringContainsEqualTrue()
        {
            Expression <Func <TestEntity, bool> > filter = x => x.ProductName.Contains("ai") == true;

            Assert.Equal(string.Format("{0} eq true", FormatSettings.GetContainsFormat("ProductName", "ai")), ODataExpression.FromLinqExpression(filter).AsString(_session));
        }
    public void EqualGuid()
    {
        Expression <Func <TestEntity, bool> > filter = x => x.LinkID == Guid.Empty;

        Assert.Equal($"LinkID eq {FormatSettings.GetGuidFormat("00000000-0000-0000-0000-000000000000")}", ODataExpression.FromLinqExpression(filter).AsString(_session));
    }
Exemplo n.º 25
0
        private void DoFormatCode() {
            // we already pulled the first %
            if (_index == _str.Length)
                throw PythonOps.ValueError("incomplete format, expected format character at index {0}", _index);

            // Index is placed right after the %.
            Debug.Assert(_str[_index - 1] == '%');

            _curCh = _str[_index++];

            if (_curCh == '%') {
                // Escaped '%' character using "%%". Just print it and we are done
                _buf.Append('%');
                return;
            }

            string key = ReadMappingKey();

            _opts = new FormatSettings();

            ReadConversionFlags();

            ReadMinimumFieldWidth();

            ReadPrecision();

            ReadLengthModifier();

            // use the key (or lack thereof) to get the value
            object value;
            if (key == null) {
                value = GetData(_dataIndex++);
            } else {
                value = GetKey(key);
            }
            _opts.Value = value;

            WriteConversion();
        }
    public void StringContainsEqualFalse()
    {
        Expression <Func <TestEntity, bool> > filter = x => x.ProductName.Contains("ai") == false;

        Assert.Equal($"{FormatSettings.GetContainsFormat("ProductName", "ai")} eq false", ODataExpression.FromLinqExpression(filter).AsString(_session));
    }
Exemplo n.º 27
0
 public override string GetCancelConfirmMessage(CancelOrderRequestParameters cancelRequest, FormatSettings formatSettings)
 {
     return(string.Empty);
 }
    public void StringNotContains()
    {
        Expression <Func <TestEntity, bool> > filter = x => !x.ProductName.Contains("ai");

        Assert.Equal($"not {FormatSettings.GetContainsFormat("ProductName", "ai")}", ODataExpression.FromLinqExpression(filter).AsString(_session));
    }
Exemplo n.º 29
0
        public static void SendPage(
            TSPlayer player, int pageNumber, Dictionary <string, int> dictionary, int dataToPaginateCount,
            FormatSettings settings = null)
        {
            if (settings == null)
            {
                settings = new FormatSettings();
            }

            if (dataToPaginateCount == 0)
            {
                if (settings.NothingToDisplayString != null)
                {
                    if (!player.RealPlayer)
                    {
                        player.SendSuccessMessage(settings.NothingToDisplayString);
                    }
                    else
                    {
                        player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor);
                    }
                }
                return;
            }

            var pageCount = ((dataToPaginateCount - 1) / settings.MaxLinesPerPage) + 1;

            if (settings.PageLimit > 0 && pageCount > settings.PageLimit)
            {
                pageCount = settings.PageLimit;
            }
            if (pageNumber > pageCount)
            {
                pageNumber = pageCount;
            }

            if (settings.IncludeHeader)
            {
                if (!player.RealPlayer)
                {
                    player.SendSuccessMessage(string.Format(settings.HeaderFormat, pageNumber, pageCount));
                }
                else
                {
                    player.SendMessage(string.Format(settings.HeaderFormat, pageNumber, pageCount),
                                       settings.HeaderTextColor);
                }
            }

            var listOffset    = (pageNumber - 1) * settings.MaxLinesPerPage;
            var offsetCounter = 0;
            var lineCounter   = 0;

            foreach (var lineData in dictionary)
            {
                if (offsetCounter++ < listOffset)
                {
                    continue;
                }
                if (lineCounter++ == settings.MaxLinesPerPage)
                {
                    break;
                }

                var lineColor = Color.Yellow;
                var hsName    = lineData.Key;
                var hsScore   = lineData.Value;
                var index     = dictionary.Keys.ToList().IndexOf(hsName) + 1;

                if (index == 1)
                {
                    lineColor = Color.Cyan;
                }
                if (index == 2)
                {
                    lineColor = Color.ForestGreen;
                }
                if (index == 3)
                {
                    lineColor = Color.OrangeRed;
                }

                if (string.Equals(hsName, player.User.Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    lineColor = Color.White;
                }

                if (!string.IsNullOrEmpty(hsName))
                {
                    if (!player.RealPlayer)
                    {
                        player.SendInfoMessage("{0}. {1} with {2} point{3}",
                                               index, hsName, hsScore, hsScore.Suffix());
                    }
                    else
                    {
                        player.SendMessage(string.Format("{0}. {1} with {2} point{3}",
                                                         index, hsName, hsScore, hsScore.Suffix()), lineColor);
                    }
                }
            }

            if (lineCounter == 0)
            {
                if (settings.NothingToDisplayString != null)
                {
                    if (!player.RealPlayer)
                    {
                        player.SendSuccessMessage(settings.NothingToDisplayString);
                    }
                    else
                    {
                        player.SendMessage(settings.NothingToDisplayString, settings.HeaderTextColor);
                    }
                }
            }
            else if (settings.IncludeFooter && pageNumber + 1 <= pageCount)
            {
                if (!player.RealPlayer)
                {
                    player.SendInfoMessage(string.Format(settings.FooterFormat, pageNumber + 1, pageNumber, pageCount));
                }
                else
                {
                    player.SendMessage(string.Format(settings.FooterFormat, pageNumber + 1, pageNumber, pageCount),
                                       settings.FooterTextColor);
                }
            }
        }
Exemplo n.º 30
0
 public static void SendPage(TSPlayer player, int pageNumber, Dictionary <string, int> dataToPaginate,
                             FormatSettings settings = null)
 {
     SendPage(player, pageNumber, dataToPaginate, dataToPaginate.Count, settings);
 }
Exemplo n.º 31
0
 // restricted constructor
 private CashFlowReportFormatter() : base(FormatSettings.of(FormatCategory.TEXT, ValueFormatters.TO_STRING))
 {
 }