Esempio n. 1
0
        //private void ApplyLayerTransperancyBasedOfGeometryType(GraphicsLayer glayer, GeometryType geometryType)
        //{
        //    if (glayer != null)
        //    {
        //        switch (geometryType)
        //        {
        //            case GeometryType.Point:
        //                glayer.Opacity = 1.0;
        //                break;
        //            case GeometryType.Polyline:
        //                glayer.Opacity = 1.0;
        //                break;
        //            case GeometryType.Polygon:
        //                glayer.Opacity = 0.5; // for polygons, we make it semi-transparent
        //                break;
        //        }
        //    }
        //}
        private void ApplyDefaultRenderer(GraphicsLayer gLayer, GeometryType geometryType)
        {
            if (gLayer == null && Symbology == null)
            {
                return;
            }

            SymbolDescription desc = null;

            if (geometryType == GeometryType.MultiPoint) // Treat MultiPoint as point for looking up default symbol
            {
                geometryType = GeometryType.Point;
            }
            if (Symbology.DefaultSymbols.TryGetValue(geometryType, out desc))
            {
                if (desc != null && desc.Symbol != null)
                {
                    Symbol symbol = desc.Symbol.CloneSymbol();
                    if (symbol != null)
                    {
                        gLayer.ChangeRenderer(symbol);
                    }
                }
            }
        }
Esempio n. 2
0
        private void GenerateSymbolVertices(int symbolIndex, SymbolDescription symbol)
        {
            var verticesStartIndex = symbolIndex * 4;

            _vertices[verticesStartIndex]     = new Vector3(_horizontalOffset, _verticalOffset - symbol.VerticalOffset);
            _vertices[verticesStartIndex + 1] = new Vector3(_horizontalOffset, _verticalOffset + symbol.Height - symbol.VerticalOffset);
            _vertices[verticesStartIndex + 2] = new Vector3(_horizontalOffset + symbol.Width, _verticalOffset + symbol.Height - symbol.VerticalOffset);
            _vertices[verticesStartIndex + 3] = new Vector3(_horizontalOffset + symbol.Width, _verticalOffset - symbol.VerticalOffset);

            _uv[verticesStartIndex]     = new Vector2(symbol.UV.X, symbol.UV.Y);
            _uv[verticesStartIndex + 1] = new Vector2(symbol.UV.X, symbol.UV.MaxY);
            _uv[verticesStartIndex + 2] = new Vector2(symbol.UV.MaxX, symbol.UV.MaxY);
            _uv[verticesStartIndex + 3] = new Vector2(symbol.UV.MaxX, symbol.UV.Y);

            var triangleStartIndex = symbolIndex * 6;

            _triangles[triangleStartIndex]     = verticesStartIndex;
            _triangles[triangleStartIndex + 1] = verticesStartIndex + 1;
            _triangles[triangleStartIndex + 2] = verticesStartIndex + 2;
            _triangles[triangleStartIndex + 3] = verticesStartIndex;
            _triangles[triangleStartIndex + 4] = verticesStartIndex + 2;
            _triangles[triangleStartIndex + 5] = verticesStartIndex + 3;

            GenerateColors(verticesStartIndex, GetAlphaByIndex(symbolIndex));
        }
Esempio n. 3
0
        private void ApplyMousePositionToVerticalOffset(SymbolDescription symbol)
        {
            var pos = GetMouseSpriteTexturePosition();

            pos.y -= symbol.Sprite.VerticalOffset;
            symbol.PixelsVerticalOffset = Mathf.FloorToInt(pos.y);
        }
Esempio n. 4
0
        private void ApplyMousePositionToSecondPoint(SymbolDescription symbol)
        {
            var pos = GetMouseSpriteTexturePosition() - new Vector2(symbol.Sprite.HorizontalOffset, symbol.Sprite.VerticalOffset);

            symbol.Sprite.Width  = (int)pos.x;
            symbol.Sprite.Height = (int)pos.y;
        }
Esempio n. 5
0
        private void ApplyMousePositionToFirstPoint(SymbolDescription symbol)
        {
            var pos = GetMouseSpriteTexturePosition();

            symbol.Sprite.HorizontalOffset = (int)pos.x;
            symbol.Sprite.VerticalOffset   = (int)pos.y;
        }
Esempio n. 6
0
        public override DataSource CreateDataSource()
        {
            DataSource dataSource = new DataSource(this);

            dataSource.BarDataScale = _newDSScale;
            dataSource.DSString     = SymbolDescription.SerializeList(_newDSSymbols);

            return(dataSource);
        }
Esempio n. 7
0
 private Rect GetVerticalOffsetRect(SymbolDescription symbol, bool applyValues)
 {
     if (_verticalOffsetPointModified && applyValues)
     {
         ApplyMousePositionToVerticalOffset(symbol);
         return(GetMouseBoundsRect());
     }
     return(GetActualVerticalOffsetRect(symbol));
 }
Esempio n. 8
0
 private Rect GetRightTopBoundsRect(SymbolDescription symbol, bool applyValues)
 {
     if (_secondBoundsPointModified && applyValues)
     {
         ApplyMousePositionToSecondPoint(symbol);
         return(GetMouseBoundsRect());
     }
     return(GetActualRightTopBoundsRect(symbol));
 }
Esempio n. 9
0
 private Rect GetLeftBottomBoundsRect(SymbolDescription symbol, bool applyValues)
 {
     if (_firstBoundsPointModified && applyValues)
     {
         ApplyMousePositionToFirstPoint(symbol);
         return(GetMouseBoundsRect());
     }
     return(GetActualLeftBottomBoundsRect(symbol));
 }
Esempio n. 10
0
        private static ClassifiedTextElement ToClassifiedTextElement(SymbolDescription symbolDescription)
        {
            var list = new List <ClassifiedTextRun>();

            foreach (var item in symbolDescription.TaggedParts)
            {
                list.Add(new ClassifiedTextRun(item.Tag, item.Text));
            }
            return(new ClassifiedTextElement(list));
        }
Esempio n. 11
0
        private void DrawVerticalOffset(Rect point0, Rect point1, SymbolDescription symbol, bool drawButtons)
        {
            var rect = GetVerticalOffsetRect(symbol, drawButtons);

            if (drawButtons)
            {
                _verticalOffsetPointModified = GUI.Toggle(rect, _verticalOffsetPointModified, string.Empty, GUI.skin.button);
            }
            GUI.DrawTexture(new Rect(point0.center, new Vector2(point1.x - point0.x, GetActualVerticalOffsetRect(symbol).y - point0.y)), _verticalOffsetTexture);
        }
Esempio n. 12
0
        public override void RequestUpdates(List <string> symbols, DateTime startDate, DateTime endDate, BarScale scale, int barInterval, IUpdateRequestCompleted requestCompleted)
        {
            List <Task> tasks = new List <Task>();

            BarDataScale dataScale = new BarDataScale(scale, barInterval);

            foreach (string updSymbol in symbols)
            {
                SymbolDescription symbolDescription = GetSymbolDescription(updSymbol);

                if (symbolDescription != null)
                {
                    tasks.Add(Task.Factory.StartNew((object updateRequiredSymbol) =>
                    {
                        string symbol = (string)updateRequiredSymbol;

                        DateTime currentDate = DateTime.Now;

                        Bars bars = new Bars(symbol, scale, barInterval);

                        try
                        {
                            string suffix = GetSuffix(dataScale);

                            int corrections = 0;
                            bars.AppendWithCorrections(GetHistory(dataScale, symbol, suffix), out corrections);

                            if (bars.Count > 0 && bars.Date[bars.Count - 1] > currentDate)
                            {
                                bars.Delete(bars.Count - 1);
                            }

                            requestCompleted.UpdateCompleted(bars);
                        }
                        catch (Exception exception)
                        {
                            logger.Error(exception);
                            requestCompleted.UpdateError(symbol, exception);
                        }
                    }, updSymbol));
                }
                else
                {
                    requestCompleted.UpdateError(updSymbol, new Exception("В формате имени инструмента была допущена ошибка"));
                }
            }

            if (tasks.Count > 0)
            {
                Task.WaitAll(tasks.ToArray());
            }

            requestCompleted.ProcessingCompleted();
        }
Esempio n. 13
0
        public override void PopulateSymbols(DataSource ds, List <string> symbols)
        {
            if (string.IsNullOrEmpty(ds.Name))
            {
                return;
            }

            List <SymbolDescription> symbolsDescription = SymbolDescription.DeserializeList(ds.DSString);

            var query = from description in symbolsDescription
                        select description.FullCode;

            symbols.AddRange(query);
        }
Esempio n. 14
0
        private SymbolDescription GetSymbolDescription(string symbol)
        {
            try
            {
                SymbolDescription description = new SymbolDescription();

                description.MarketCode = symbol.Substring(0, symbol.IndexOf("."));
                description.SymbolCode = symbol.Substring(symbol.IndexOf(".") + 1, symbol.Length - symbol.IndexOf(".") - 1);

                return(description);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(null);
            }
        }
Esempio n. 15
0
        public override string ModifySymbols(DataSource ds, List <string> symbols)
        {
            List <SymbolDescription> symbolsDescription = SymbolDescription.DeserializeList(ds.DSString);

            // Удаление инструментов
            //
            List <SymbolDescription> removeQuery = (from description in symbolsDescription
                                                    where !symbols.Exists(x => x == description.FullCode)
                                                    select description).ToList();

            foreach (SymbolDescription description in removeQuery)
            {
                symbolsDescription.Remove(description);
            }

            // Добавление инструментов
            //
            var addQuery = from symbol in symbols
                           where !symbolsDescription.Exists(x => x.FullCode == symbol)
                           select symbol;

            int errorsCount = 0;

            foreach (string symbol in addQuery)
            {
                SymbolDescription description = GetSymbolDescription(symbol);

                if (description != null)
                {
                    symbolsDescription.Add(description);
                }
                else
                {
                    errorsCount++;
                }
            }

            if (errorsCount > 0)
            {
                MessageBox.Show(string.Format("В формате имени одного или нескольких инструментов была допущена ошибка. Всего ошибок: {0}.", errorsCount),
                                "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(SymbolDescription.SerializeList(symbolsDescription));
        }
Esempio n. 16
0
        public override Bars RequestData(DataSource ds, string symbol, DateTime startDate, DateTime endDate, int maxBars, bool includePartialBar)
        {
            Bars bars = new Bars(symbol, ds.Scale, ds.BarInterval);

            List <SymbolDescription> symbolDescriptions = SymbolDescription.DeserializeList(ds.DSString);
            SymbolDescription        description        = symbolDescriptions.Find(x => x.FullCode == symbol);

            if (description != null && OnDemandUpdate)
            {
                _dataStore.LoadBarsObject(bars);

                DateTime currentDate = DateTime.Now;

                try
                {
                    string suffix = GetSuffix(ds.BarDataScale);

                    int correction = 0;
                    bars.AppendWithCorrections(GetHistory(ds.BarDataScale, description.FullCode, suffix), out correction);
                }
                catch (Exception exception)
                {
                    logger.Error(exception);
                    MessageBox.Show(string.Format("[{0}] {1}", symbol, exception.Message), "Внимание! Произошла ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (bars.Count > 0 && bars.Date[bars.Count - 1] > currentDate && !includePartialBar)
                {
                    bars.Delete(bars.Count - 1);
                }

                if (!base.IsStreamingRequest)
                {
                    lock (_locker)
                        _dataStore.SaveBarsObject(bars);
                }
            }
            else
            {
                _dataStore.LoadBarsObject(bars, startDate, endDate, maxBars);
            }

            return(bars);
        }
Esempio n. 17
0
        private TextBlock ToTextBlock(SymbolDescription symbolDescription)
        {
            var formatMapService     = ServicesProvider.Instance.FormatMapService;
            var tooltipFormatMap     = formatMapService.GetClassificationFormatMap("tooltip");
            var textFormatMap        = formatMapService.GetClassificationFormatMap("text");
            var defaultRunProperties = tooltipFormatMap.DefaultTextProperties;
            var registryService      = ServicesProvider.Instance.RegistryService;

            var textBlock = new TextBlock();
            var builder   = StringBuilderCache.Acquire();

            foreach (var classifiedText in symbolDescription.TaggedParts)
            {
                var textRunProperties  = defaultRunProperties;
                var classificationType = registryService.GetClassificationType(classifiedText.Tag);
                if (!(classificationType is null))
                {
                    // TODO: compare classification with known CoCo classifications
                    textRunProperties = classificationType.Classification.StartsWith("CoCo")
                        ? textFormatMap.GetExplicitTextProperties(classificationType)
                        : tooltipFormatMap.GetTextProperties(classificationType);
                }

                textBlock.Inlines.Add(new Run
                {
                    Background        = textRunProperties.BackgroundBrush,
                    BaselineAlignment = textRunProperties.BaselineAlignment,
                    Foreground        = textRunProperties.ForegroundBrush,
                    Text            = classifiedText.Text,
                    TextDecorations = textRunProperties.TextDecorations,
                    TextEffects     = textRunProperties.TextEffects,
                    FontSize        = defaultRunProperties.FontRenderingEmSize,
                    FontFamily      = defaultRunProperties.Typeface.FontFamily,
                    FontStretch     = defaultRunProperties.Typeface.Stretch,
                    FontStyle       = defaultRunProperties.Typeface.Style,
                    FontWeight      = defaultRunProperties.Typeface.Weight
                });
                builder.Append(classifiedText.Text);
            }

            textBlock.SetValue(AutomationProperties.NameProperty, StringBuilderCache.Release(builder));
            textBlock.TextWrapping = TextWrapping.Wrap;
            return(textBlock);
        }
Esempio n. 18
0
        private void DrawSymbolBounds(SymbolDescription symbol, bool drawButtons = true)
        {
            var point0  = GetLeftBottomBoundsRect(symbol, drawButtons);
            var point1  = GetRightTopBoundsRect(symbol, drawButtons);
            var boxRect = new Rect(GetActualLeftBottomBoundsRect(symbol).center, GetActualRightTopBoundsRect(symbol).center - GetActualLeftBottomBoundsRect(symbol).center);

            DrawBox(boxRect, symbol.Symbol);
            if (drawButtons)
            {
                DrawSelectedMark(boxRect);
            }
            DrawVerticalOffset(GetActualLeftBottomBoundsRect(symbol), GetActualRightTopBoundsRect(symbol), symbol, drawButtons);
            if (!drawButtons)
            {
                return;
            }
            _firstBoundsPointModified  = GUI.Toggle(point0, _firstBoundsPointModified, string.Empty, GUI.skin.button);
            _secondBoundsPointModified = GUI.Toggle(point1, _secondBoundsPointModified, string.Empty, GUI.skin.button);
        }
Esempio n. 19
0
        protected IEnumerable <SymbolDescription> GetSymbolDescriptionsForJsonSymbolSet(string jsonSymbolSet)
        {
            try
            {
                string    json                = jsonSymbolSet;
                JsonArray jsarray             = (JsonArray)JsonArray.Parse(json);
                List <SymbolDescription> list = new List <SymbolDescription>();

                var jsymbols = from jsymbol in jsarray
                               select jsymbol;
                foreach (JsonObject j in jsymbols)
                {
                    SymbolDescription description = new SymbolDescription();
                    JsonObject        symb        = j["symbol"] as JsonObject;
                    description.Symbol      = SymbolJsonHelper.SymbolFromJson(symb);
                    description.DisplayName = j["id"];
                    list.Add(description);
                }
                return(list);
            }
            catch {}
            return(null);
        }
Esempio n. 20
0
        public List <SymbolDescription> GetSymbolsDescription(ref int errorsCount)
        {
            string buffer = rtbSymbols.Text;

            string[] symbols = buffer.Split(new string[] { ",", "\r\n", " " }, StringSplitOptions.RemoveEmptyEntries);

            List <SymbolDescription> descriptions = new List <SymbolDescription>();

            foreach (string symbol in symbols)
            {
                SymbolDescription description = GetSymbolDescription(symbol);

                if (description != null)
                {
                    descriptions.Add(description);
                }
                else
                {
                    errorsCount++;
                }
            }

            return(descriptions);
        }
Esempio n. 21
0
        private bool UpdateRequired(SymbolDescription description, BarDataScale barDataScale)
        {
            if (!_dataStore.ContainsSymbol(description.FullCode, barDataScale.Scale, barDataScale.BarInterval))
            {
                return(true);
            }

            MarketHours mktHours = new MarketHours();

            mktHours.Market = GetMarketInfo(description.FullCode);
            DateTime updateTime = _dataStore.SymbolLastUpdated(description.FullCode, barDataScale.Scale, barDataScale.BarInterval);

            if (!barDataScale.IsIntraday)
            {
                if ((DateTime.Now.Date >= updateTime.Date.AddDays(1)) ||
                    (updateTime.Date < mktHours.LastTradingSessionEndedNative.Date))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (mktHours.IsMarketOpenNow || (updateTime < mktHours.LastTradingSessionEndedNative))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 22
0
 private Rect GetActualRightTopBoundsRect(SymbolDescription symbol)
 {
     return(new Rect((float)(symbol.Sprite.HorizontalOffset + symbol.Sprite.Width) / _font.Texture.width * TextureEditorWidth - BoundsButtonSize / 2,
                     (1 - (float)(symbol.Sprite.VerticalOffset + symbol.Sprite.Height) / _font.Texture.height) * TextureEditorHeight - BoundsButtonSize / 2, BoundsButtonSize, BoundsButtonSize));
 }
Esempio n. 23
0
        public override void UpdateProvider(IDataUpdateMessage dataUpdateMsg, List <DataSource> dataSources, bool updateNonDSSymbols, bool deleteNonDSSymbols)
        {
            foreach (BarDataScale scale in this._dataStore.GetExistingBarScales())
            {
                if (_cancelTokenSource != null && _cancelTokenSource.IsCancellationRequested)
                {
                    dataUpdateMsg.DisplayUpdateMessage("Обновление провайдера отменено");
                    break;
                }

                dataUpdateMsg.DisplayUpdateMessage("Обновление таймфрейма " + scale.ToString());

                var visibleSymbols = from dataSource in dataSources
                                     where dataSource.BarDataScale == scale
                                     select SymbolDescription.DeserializeList(dataSource.DSString);

                List <SymbolDescription> symbols = new List <SymbolDescription>();

                foreach (List <SymbolDescription> visibleSymbol in visibleSymbols)
                {
                    symbols.AddRange(visibleSymbol);
                }

                if (updateNonDSSymbols)
                {
                    var nonDSSymbols = from symbol in _dataStore.GetExistingSymbols(scale.Scale, scale.BarInterval)
                                       where !symbols.Exists(x => x.FullCode == symbol)
                                       select GetSymbolDescription(symbol);

                    symbols.AddRange(nonDSSymbols);
                }

                DataSource dsVirtual = new DataSource(this);

                dsVirtual.Name         = "VirtualDSr";
                dsVirtual.BarDataScale = scale;

                dsVirtual.DSString = SymbolDescription.SerializeList(symbols);

                UpdateDataSource(dsVirtual, dataUpdateMsg);

                if (deleteNonDSSymbols)
                {
                    dataUpdateMsg.DisplayUpdateMessage("--------------");
                    dataUpdateMsg.DisplayUpdateMessage("Удаление истории инструментов не входящих ни в один набор данных данного таймфрейма:");

                    var nonDSSymbols = from symbol in _dataStore.GetExistingSymbols(scale.Scale, scale.BarInterval)
                                       where !symbols.Exists(x => x.FullCode == symbol)
                                       select symbol;

                    foreach (string symbol in nonDSSymbols)
                    {
                        lock (_locker)
                            _dataStore.RemoveFile(symbol, scale.Scale, scale.BarInterval);
                        dataUpdateMsg.DisplayUpdateMessage(string.Format("[DELETED] Инструмент {0} - История удалена", symbol));
                    }

                    if (nonDSSymbols.Count() == 0)
                    {
                        dataUpdateMsg.DisplayUpdateMessage(string.Format("[NA] Инструменты для удаления не найдены"));
                    }
                }

                dataUpdateMsg.DisplayUpdateMessage("--------------");
            }
        }
Esempio n. 24
0
        public override void UpdateDataSource(DataSource ds, IDataUpdateMessage dataUpdateMsg)
        {
            _cancelTokenSource = new CancellationTokenSource();

            dataUpdateMsg.ReportUpdateProgress(0);

            if (string.IsNullOrWhiteSpace(ds.DSString))
            {
                List <SymbolDescription> symbolDescriptions = (from symbol in ds.Symbols
                                                               select GetSymbolDescription(symbol)).ToList();

                ds.DSString = SymbolDescription.SerializeList(symbolDescriptions);
            }

            List <SymbolDescription> updateRequired = (from description in SymbolDescription.DeserializeList(ds.DSString)
                                                       where UpdateRequired(description, ds.BarDataScale)
                                                       select description).ToList();

            dataUpdateMsg.DisplayUpdateMessage(string.Format("Количество инструментов требующих обновления: {0}", updateRequired.Count));

            if (updateRequired.Count > 0)
            {
                dataUpdateMsg.DisplayUpdateMessage("Запуск обновления инструментов:");

                Task[] tasks = new Task[updateRequired.Count];

                for (int i = 0; i < updateRequired.Count; i++)
                {
                    dataUpdateMsg.DisplayUpdateMessage(string.Format("[START] Инструмент: {0} - Обновление запущено", updateRequired[i].FullCode));

                    tasks[i] = Task.Factory.StartNew((object updateRequiredSymbol) =>
                    {
                        string symbol = (string)updateRequiredSymbol;

                        DateTime currentDate = DateTime.Now;

                        Bars bars = new Bars(symbol, ds.Scale, ds.BarInterval);

                        _dataStore.LoadBarsObject(bars);

                        try
                        {
                            string suffix = GetSuffix(ds.BarDataScale);

                            int corrections = 0;
                            bars.AppendWithCorrections(GetHistory(ds.BarDataScale, symbol, suffix), out corrections);

                            if (bars.Count > 0 && bars.Date[bars.Count - 1] > currentDate)
                            {
                                bars.Delete(bars.Count - 1);
                            }

                            lock (_locker)
                                _dataStore.SaveBarsObject(bars);

                            dataUpdateMsg.DisplayUpdateMessage(string.Format("[COMPLETE] Инструмент: {0} - Обновление завершено", symbol));
                        }
                        catch (Exception exception)
                        {
                            logger.Error(exception);
                            dataUpdateMsg.DisplayUpdateMessage(string.Format("[ERROR] Инструмент {0} - {1}", symbol, exception.Message));
                        }
                    }, updateRequired[i].FullCode);
                }

                try
                {
                    Task.WaitAll(tasks);
                }
                catch (AggregateException exception)
                {
                    exception.Handle((inner) =>
                    {
                        if (inner is OperationCanceledException)
                        {
                            return(true);
                        }
                        else
                        {
                            logger.Error(inner);
                            return(false);
                        }
                    });
                }
            }
        }