Пример #1
0
        /// <summary>
        /// Loads the rule file.
        /// </summary>
        /// <returns></returns>
        internal static FormatRules LoadRuleFile(string iniFilePath)
        {
            //default xml path is at the same location as the assembly
            string assemblyPath = Assembly.GetAssembly(typeof(ConfigurationHelper)).Location;

            assemblyPath = assemblyPath.Substring(0, assemblyPath.LastIndexOf(@"\"));
            string      ruleFile = assemblyPath + @"\MRIFormatRules.xml";
            FormatRules rules    = new FormatRules();

            if (iniFilePath != null)
            {
                StringBuilder filePathBuffer = new StringBuilder(Win32.MAX_PATH);
                Win32.GetPrivateProfileString("Format Rules", "RuleFileName", string.Empty, filePathBuffer, Win32.MAX_PATH, iniFilePath);
                if (!string.IsNullOrEmpty(filePathBuffer.ToString().Trim()))
                {
                    ruleFile = filePathBuffer.ToString().Trim();
                }

                try
                {
                    rules.LoadRules(ruleFile);
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Rules could not be loaded.\n\n{0}", e.Message), "Error indenting code");
                }
            }

            return(rules);
        }
Пример #2
0
 public CppThreeTextController()
 {
     FormatRules.Add(new NodeTextFormatRule(NodeType.FOR, new EditTokensFilter(FormatCommonFor)));
     FormatRules.Add(new NodeTextFormatRule(NodeType.ANY, new RemoveTokensFilter(new SingleTokenPattern(TokenType.LINE_END))));
     FormatRules.Add(new NodeTextFormatRule(NodeType.ANY, new RemoveTokensFilter(new SingleTokenPattern(TokenType.INPUT_OPERATOR))));
     FormatRules.Add(new NodeTextFormatRule(NodeType.ANY, new RemoveTokensFilter(new SingleTokenPattern(TokenType.OUTPUT_OPERATOR))));
 }
Пример #3
0
        public Func <Binding, DataTemplate> GetFormatter(Column column)
        {
            if (formatters != null && formatters.TryGetValue(column.Name, out Func <Binding, DataTemplate> cf))
            {
                return(cf);
            }

            PropertyRoute route = column.Token.GetPropertyRoute();

            if (route != null)
            {
                var formatter = QuerySettings.PropertyFormatters.TryGetC(route);
                if (formatter != null)
                {
                    return(formatter);
                }
            }

            FormatterRule fr = FormatRules.Last(cfr => cfr.IsApplicable(column));

            return(fr.Formatter(column));
        }
Пример #4
0
        public CellFormatter GetFormatter(Column column)
        {
            CellFormatter cf;

            if (formatters != null && formatters.TryGetValue(column.Name, out cf))
            {
                return(cf);
            }

            PropertyRoute route = column.Token.GetPropertyRoute();

            if (route != null)
            {
                var formatter = QuerySettings.PropertyFormatters.TryGetC(route);
                if (formatter != null)
                {
                    return(formatter);
                }
            }

            var last = FormatRules.Last(cfr => cfr.IsApplyable(column));

            return(last.Formatter(column));
        }
Пример #5
0
        /// <summary>
        /// Создать <see cref="OptionDesk"/>.
        /// </summary>
        public OptionDesk()
        {
            InitializeComponent();

            #region Format rules

            var callColor = Color.FromArgb(255, 190, 224, 189);
            var putColor  = Color.FromArgb(255, 255, 190, 189);

            FormatRules.Add(CallRho, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallTheta, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallVega, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallGamma, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallDelta, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallBid, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallAsk, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallTheorPrice, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallVolume, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallOpenInterest, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(CallSecCode, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(callColor),
            });
            FormatRules.Add(Strike, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = Brushes.LightGray,
                Font       = { Weight = System.Windows.FontWeights.Bold }
            });
            FormatRules.Add(ImpliedVolatility, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = Brushes.LightGray,
            });
            FormatRules.Add(HistoricalVolatility, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = Brushes.LightGray,
            });
            FormatRules.Add(PnL, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = Brushes.LightGray,
            });
            FormatRules.Add(PutSecCode, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutOpenInterest, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutVolume, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutTheorPrice, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutBid, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutAsk, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutDelta, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutGamma, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutVega, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutTheta, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });
            FormatRules.Add(PutRho, new FormatRule
            {
                Condition  = ComparisonOperator.Any,
                Background = new SolidColorBrush(putColor),
            });

            #endregion

            Options = Enumerable.Empty <Security>();
        }
Пример #6
0
        private void Process(IStorageRegistry storageRegistry, Security security, StorageFormats format, IMarketDataDrive drive)
        {
            this.GuiSync(() =>
            {
                _visibleEntries.Clear();

                Columns.RemoveRange(_candleColumns.Values);
                _candleColumns.Values.ForEach(c => FormatRules.Remove(c));
                _candleColumns.Clear();
            });

            if (security == null)
            {
                return;
            }

            var dict = new Dictionary <DateTime, MarketDataEntry>();

            drive = drive ?? storageRegistry.DefaultDrive;

            var candles = new Dictionary <string, Tuple <Type, object> >();

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            foreach (var tuple in drive.GetCandleTypes(security.ToSecurityId(), format))
            {
                foreach (var arg in tuple.Item2)
                {
                    var key = tuple.Item1.Name.Replace("CandleMessage", string.Empty) + " " + arg;
                    candles.Add(key, Tuple.Create(tuple.Item1, arg));
                }
            }

            var candleNames = candles.Keys.ToArray();

            if (candleNames.Length > 0)
            {
                this.GuiSync(() =>
                {
                    foreach (var candleName in candleNames)
                    {
                        var column = new DataGridTextColumn
                        {
                            Header  = candleName,
                            Binding = new Binding
                            {
                                Path      = new PropertyPath("Candles[{0}]".Put(candleName)),
                                Converter = new BoolToCheckMarkConverter()
                            }
                        };
                        //var cbElement = new FrameworkElementFactory(typeof(CheckBox));

                        //var column = new DataGridTemplateColumn
                        //{
                        //	Header = candle,
                        //	CellStyle = new Style(),
                        //	//SortMemberPath = "Candles[{0}]".Put(key)
                        //	CellTemplate = new DataTemplate(typeof(CheckBox))
                        //	{
                        //		VisualTree = cbElement,
                        //	}
                        //};

                        //var bind = new Binding { Path = new PropertyPath("Candles[{0}]".Put(candle)) };

                        //cbElement.SetBinding(ToggleButton.IsCheckedProperty, bind);
                        //cbElement.SetValue(IsHitTestVisibleProperty, false);
                        //cbElement.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);

                        Columns.Add(column);
                        _candleColumns.Add(candleName, column);

                        //ApplyFormatRules(column);
                    }

                    //ApplyFormatRules();
                });
            }

            Add(dict, storageRegistry.GetTickMessageStorage(security, drive, format).Dates, candleNames, e => e.IsTick         = true);
            Add(dict, storageRegistry.GetQuoteMessageStorage(security, drive, format).Dates, candleNames, e => e.IsDepth       = true);
            Add(dict, storageRegistry.GetLevel1MessageStorage(security, drive, format).Dates, candleNames, e => e.IsLevel1     = true);
            Add(dict, storageRegistry.GetOrderLogMessageStorage(security, drive, format).Dates, candleNames, e => e.IsOrderLog = true);

            foreach (var c in candleNames)
            {
                var candleName = c;

                lock (_syncObject)
                {
                    if (_isChanged)
                    {
                        return;
                    }
                }

                var tuple = candles[candleName];
                Add(dict, storageRegistry.GetCandleMessageStorage(tuple.Item1, security, tuple.Item2, drive, format).Dates, candleNames, e => e.Candles[candleName] = true);
            }

            if (dict.Count > 0)
            {
                // add gaps by working days
                var emptyDays = dict.Keys.Min().Range(dict.Keys.Max(), TimeSpan.FromDays(1))
                                .Where(d => !dict.ContainsKey(d) /* && security.Board.WorkingTime.IsTradeDate(d, true)*/)
                                .OrderBy()
                                .ToList();

                foreach (var monthGroup in emptyDays.ToArray().GroupBy(d => new DateTime(d.Year, d.Month, 1)))
                {
                    var firstDay = monthGroup.First();
                    var lastDay  = monthGroup.Last();

                    // whole month do not have any values
                    if (firstDay.Day == 1 && lastDay.Day == monthGroup.Key.DaysInMonth())
                    {
                        emptyDays.RemoveRange(monthGroup);
                    }
                }

                Add(dict, emptyDays, candleNames, e => { });
            }

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            this.GuiSync(RefreshSort);
        }
Пример #7
0
        private void Process(IStorageRegistry storageRegistry, Security security, StorageFormats format, IMarketDataDrive drive)
        {
            this.GuiSync(() =>
            {
                _visibleEntries.Clear();

                Columns.RemoveRange(_candleColumns.Values);
                _candleColumns.Values.ForEach(c => FormatRules.Remove(c));
                _candleColumns.Clear();
            });

            if (security == null)
            {
                return;
            }

            var dict = new Dictionary <DateTime, MarketDataEntry>();

            drive = drive ?? storageRegistry.DefaultDrive;

            var candles = new Dictionary <string, Tuple <Type, object> >();

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            foreach (var tuple in drive.GetCandleTypes(security.ToSecurityId(), format))
            {
                foreach (var arg in tuple.Item2)
                {
                    var key = tuple.Item1.Name.Replace("Candle", string.Empty) + " " + arg;
                    candles.Add(key, Tuple.Create(tuple.Item1, arg));
                }
            }

            var candleKeys = candles.Keys.ToArray();

            if (candleKeys.Length > 0)
            {
                this.GuiSync(() =>
                {
                    foreach (var candle in candleKeys)
                    {
                        var column = new DataGridTextColumn
                        {
                            Header  = candle,
                            Binding = new Binding
                            {
                                Path      = new PropertyPath("Candles[{0}]".Put(candle)),
                                Converter = new BoolToCheckMarkConverter()
                            }
                        };
                        //var cbElement = new FrameworkElementFactory(typeof(CheckBox));

                        //var column = new DataGridTemplateColumn
                        //{
                        //	Header = candle,
                        //	CellStyle = new Style(),
                        //	//SortMemberPath = "Candles[{0}]".Put(key)
                        //	CellTemplate = new DataTemplate(typeof(CheckBox))
                        //	{
                        //		VisualTree = cbElement,
                        //	}
                        //};

                        //var bind = new Binding { Path = new PropertyPath("Candles[{0}]".Put(candle)) };

                        //cbElement.SetBinding(ToggleButton.IsCheckedProperty, bind);
                        //cbElement.SetValue(IsHitTestVisibleProperty, false);
                        //cbElement.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);

                        Columns.Add(column);
                        _candleColumns.Add(candle, column);

                        //ApplyFormatRules(column);
                    }

                    //ApplyFormatRules();
                });
            }

            Add(dict, storageRegistry.GetTradeStorage(security, drive, format), candleKeys, e => e.IsTick           = true);
            Add(dict, storageRegistry.GetMarketDepthStorage(security, drive, format), candleKeys, e => e.IsDepth    = true);
            Add(dict, storageRegistry.GetLevel1MessageStorage(security, drive, format), candleKeys, e => e.IsLevel1 = true);
            Add(dict, storageRegistry.GetOrderLogStorage(security, drive, format), candleKeys, e => e.IsOrderLog    = true);

            foreach (var candle in candleKeys)
            {
                lock (_syncObject)
                {
                    if (_isChanged)
                    {
                        return;
                    }
                }

                var tuple = candles[candle];
                Add(dict, storageRegistry.GetCandleStorage(tuple.Item1, security, tuple.Item2, drive, format), candleKeys, e => e.Candles[candle] = true);
            }

            if (dict.Count > 0)
            {
                // добавляем рабочие дни, которые отсутствуют в данных
                var emptyDays = dict.Keys.Min().Range(dict.Keys.Max(), TimeSpan.FromDays(1))
                                .Where(d => security.Board.WorkingTime.IsTradeDate(d, true) && !dict.ContainsKey(d));

                foreach (var batch in emptyDays.Batch(10))
                {
                    lock (_syncObject)
                    {
                        if (_isChanged)
                        {
                            return;
                        }
                    }

                    TryAddEntries(dict, batch, candleKeys, e => {});
                }
            }

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            this.GuiSync(RefreshSort);
        }