Пример #1
0
        private void InitializeCommands()
        {
            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            cmdSvc.Register <OpenMarketDataSettingsCommand>(this, true, cmd => OpenMarketDataPanel(cmd.Settings));

            cmdSvc.Register <RefreshSecurities>(this, false, cmd => ThreadingHelper
                                                .Thread(() =>
            {
                var entityRegistry = ConfigManager.GetService <IEntityRegistry>();
                var count          = 0;
                var progress       = 0;

                try
                {
                    using (var client = new RemoteStorageClient(new Uri(cmd.Settings.Path)))
                    {
                        var credentials = cmd.Settings.Credentials;

                        client.Credentials.Login    = credentials.Login;
                        client.Credentials.Password = credentials.Password;

                        foreach (var secType in cmd.Types.TakeWhile(secType => !cmd.IsCancelled()))
                        {
                            if (secType == SecurityTypes.Future)
                            {
                                var from        = DateTime.Today.AddMonths(-4);
                                var to          = DateTime.Today.AddMonths(4);
                                var expiryDates = from.GetExpiryDates(to);

                                foreach (var expiryDate in expiryDates.TakeWhile(d => !cmd.IsCancelled()))
                                {
                                    client.Refresh(entityRegistry.Securities, new Security {
                                        Type = secType, ExpiryDate = expiryDate
                                    }, s =>
                                    {
                                        entityRegistry.Securities.Save(s);
                                        _connector.SendOutMessage(s.ToMessage());
                                        count++;
                                    }, cmd.IsCancelled);
                                }
                            }
                            else
                            {
                                // для акций передаем фиктивное значение ExpiryDate, чтобы получить инструменты без даты экспирации
                                var expiryDate = secType == SecurityTypes.Stock ? DateTime.Today : (DateTime?)null;

                                client.Refresh(entityRegistry.Securities, new Security {
                                    Type = secType, ExpiryDate = expiryDate
                                }, s =>
                                {
                                    entityRegistry.Securities.Save(s);
                                    _connector.SendOutMessage(s.ToMessage());
                                    count++;
                                }, cmd.IsCancelled);
                            }

                            cmd.ProgressChanged(++progress);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.LogError();
                }

                if (cmd.IsCancelled())
                {
                    return;
                }

                try
                {
                    cmd.WhenFinished(count);
                }
                catch (Exception ex)
                {
                    ex.LogError();
                }
            })
                                                .Launch());

            cmdSvc.Register <CreateSecurityCommand>(this, true, cmd =>
            {
                var entityRegistry = ConfigManager.GetService <IEntityRegistry>();

                ISecurityWindow wnd;

                if (cmd.SecurityType == typeof(Security))
                {
                    wnd = new SecurityCreateWindow();
                }
                else
                {
                    throw new InvalidOperationException(LocalizedStrings.Str2140Params.Put(cmd.SecurityType));
                }

                wnd.ValidateId = id =>
                {
                    if (entityRegistry.Securities.ReadById(id) != null)
                    {
                        return(LocalizedStrings.Str2927Params.Put(id));
                    }

                    return(null);
                };

                if (!((Window)wnd).ShowModal(Application.Current.GetActiveOrMainWindow()))
                {
                    return;
                }

                entityRegistry.Securities.Save(wnd.Security);
                _connector.SendOutMessage(wnd.Security.ToMessage());
                cmd.Security = wnd.Security;
            });

            cmdSvc.Register <SetDefaultEmulationSettingsCommand>(this, false, cmd =>
            {
                _emulationSettings.Load(cmd.Settings.Save());
                _layoutManager.FlushSettings();
            });
        }
Пример #2
0
        private void InitializeCommands()
        {
            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            cmdSvc.Register <OpenMarketDataSettingsCommand>(this, true, cmd => OpenMarketDataPanel(cmd.Settings));

            cmdSvc.Register <RefreshSecurities>(this, false, cmd => ThreadingHelper
                                                .Thread(() =>
            {
                var entityRegistry = ConfigManager.GetService <IEntityRegistry>();
                var count          = 0;
                var progress       = 0;

                try
                {
                    using (var client = new RemoteStorageClient(new Uri(cmd.Settings.Path)))
                    {
                        var credentials = cmd.Settings.Credentials;

                        client.Credentials.Login    = credentials.Login;
                        client.Credentials.Password = credentials.Password;

                        foreach (var secType in cmd.Types.TakeWhile(secType => !cmd.IsCancelled()))
                        {
                            if (secType == SecurityTypes.Future)
                            {
                                var from        = DateTime.Today.AddMonths(-4);
                                var to          = DateTime.Today.AddMonths(4);
                                var expiryDates = from.GetExpiryDates(to);

                                foreach (var expiryDate in expiryDates.TakeWhile(d => !cmd.IsCancelled()))
                                {
                                    client.Refresh(entityRegistry.Securities, new Security {
                                        Type = secType, ExpiryDate = expiryDate
                                    }, s =>
                                    {
                                        entityRegistry.Securities.Save(s);
                                        _connector.SendOutMessage(s.ToMessage());
                                        count++;
                                    }, cmd.IsCancelled);
                                }
                            }
                            else
                            {
                                // для акций передаем фиктивное значение ExpiryDate, чтобы получить инструменты без даты экспирации
                                var expiryDate = secType == SecurityTypes.Stock ? DateTime.Today : (DateTime?)null;

                                client.Refresh(entityRegistry.Securities, new Security {
                                    Type = secType, ExpiryDate = expiryDate
                                }, s =>
                                {
                                    entityRegistry.Securities.Save(s);
                                    _connector.SendOutMessage(s.ToMessage());
                                    count++;
                                }, cmd.IsCancelled);
                            }

                            cmd.ProgressChanged(++progress);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.LogError();
                }

                if (cmd.IsCancelled())
                {
                    return;
                }

                try
                {
                    cmd.WhenFinished(count);
                }
                catch (Exception ex)
                {
                    ex.LogError();
                }
            })
                                                .Launch());
        }