/// <summary>
        /// 
        /// </summary>
        public ExpertHostControl(LocalExpertHost expertHost)
            : base(expertHost)
        {
            InitializeComponent();

            Initialize(expertHost);
        }
        private void runStandaloneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listViewExperts.SelectedItems.Count != 1)
            {
                return;
            }

            ExpertInformation info = (ExpertInformation)listViewExperts.SelectedItems[0].Tag;

            string operationMessage = string.Empty;
            Type expertType = info.GetExpertType(ref operationMessage);
            if (expertType == null)
            {
                MessageBox.Show("Failed to create expert [" + operationMessage + "]", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            LocalExpertHost expertHost = new LocalExpertHost(info.Name, expertType);
            expertHost.Name = expertHost.Name;
            ExpertManager.Platform.RegisterComponent(expertHost);
        }
        void createItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            Type componentType = (Type)item.Tag;

            PlatformComponent component = null;

            bool showPropertiesForm = ComponentManagementAttribute.GetTypeAttribute(componentType).RequestPreStartSetup;

            if (ComponentManagementAttribute.GetTypeAttribute(componentType).IsMandatory)
            {// Mandatory components we do not create, only show / hide.
                component = _platform.GetFirstComponent(componentType);
                component.UISerializationInfo.AddValue("componentVisible", true);

                platform_ActiveComponentAddedEvent(component, false);
                return;
            }

            if (componentType.IsSubclassOf(typeof(Expert)))
            {
                component = new LocalExpertHost(UserFriendlyNameAttribute.GetTypeAttributeName(componentType), componentType);
                showPropertiesForm = ComponentManagementAttribute.GetTypeAttribute(typeof(LocalExpertHost)).RequestPreStartSetup;
            }
            else if (componentType.IsSubclassOf(typeof(WizardControl)))
            {// Wizards are run in Hosting forms.

                ConstructorInfo info = componentType.GetConstructor(new Type[] { typeof(Platform) });

                if (info != null)
                {
                    WizardControl wizardControl = (WizardControl)info.Invoke(new object[] { _platform });
                    HostingForm hostingForm = new HostingForm(UserFriendlyNameAttribute.GetTypeAttributeName(componentType), wizardControl);
                    hostingForm.Icon = Resources.magic_wand1;
                    hostingForm.Show();
                    return;
                }
            }
            else if (componentType.IsSubclassOf(typeof(CommonBaseControl)))
            {// Tester/editor etc. controls have no components, they are standalone UI components.
                ConstructorInfo info = componentType.GetConstructor(new Type[] { });
                // If failed to find orderInfo, just fall trough to failed to create component (which remains null).
                if (info != null)
                {// Since this is a UI only component, just create and return.
                    CommonBaseControl testerControl = (CommonBaseControl)info.Invoke(new object[] { });
                    /*tabControl.SelectedTab = */AddComponentControl(testerControl, true);

                    return;
                }
            }
            else
            {
                ConstructorInfo info = componentType.GetConstructor(new Type[] { });
                if (info != null)
                {
                    component = (PlatformComponent)info.Invoke(new object[] { });
                }
            }

            // ...
            if (component == null)
            {
                MessageBox.Show("Failed to create component.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Set settings for component.
            if (component.SetInitialState(_platform.Settings) == false)
            {
                MessageBox.Show("Component failed to initialize from initial state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (showPropertiesForm)
            {
                // Show properties for the user to configure.
                PropertiesForm form = new PropertiesForm("Properties", component);
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            // Register to platform.
            _platform.RegisterComponent(component);
        }
 void SetControlFloat(LocalExpertHost host)
 {
     CommonBaseControl control = MasterForm.combinedContainerControl.GetControlByTag(host);
     if (control != null)
     {
         MasterForm.combinedContainerControl.SetControlFloating(control);
     }
     else
     {
         SystemMonitor.Error("Failed to find host control to float.");
     }
 }
        void CreateSessionPane(bool trading)
        {
            if (listViewQuotes.SelectedItems.Count < 1 || Component.Delivery == null || Component.DataSourceId.HasValue == false)
            {
                return;
            }

            ListViewItem item = listViewQuotes.SelectedItems[0];
            LocalExpertHost host = new LocalExpertHost(item.Text, typeof(ManualTradeExpert));
            Component.Platform.RegisterComponent(host);

            RuntimeDataSessionInformation info = Component.Delivery.GetSymbolRuntimeSessionInformation((Symbol)item.Tag);

            if (info == null)
            {
                SystemMonitor.OperationError("Failed to obtain symbol session, operation can not be performed.");
                MessageBox.Show("Failed to obtain symbol session, operation can not be performed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string operationResultMessage;

            ComponentId? tradeSourceId = null;
            if (trading)
            {
                SortedDictionary<int, List<ComponentId>> compatibleExecutioners =
                    Component.GetCompatibleOrderExecutionSources(Component.DataSourceId.Value, info.Info.Symbol, SourceTypeEnum.Live | SourceTypeEnum.OrderExecution);

                if (compatibleExecutioners.Count == 0 ||
                        compatibleExecutioners[GeneralHelper.EnumerableFirstThrows<int>(compatibleExecutioners.Keys)].Count == 0)
                {
                    MessageBox.Show("Failed to find order execution source for this symbol. Trading can not be initiated.");
                    return;
                }

                tradeSourceId = compatibleExecutioners[GeneralHelper.EnumerableFirstThrows<int>(compatibleExecutioners.Keys)][0];
            }

            PlatformExpertSession session = host.CreateExpertSession(info.Info, Component.DataSourceId.Value,
                tradeSourceId, false, out operationResultMessage);

            if (session == null)
            {
                SystemMonitor.OperationError(operationResultMessage);
                MessageBox.Show(operationResultMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (host.RegisterExpertSession(session))
            {
                // Try to run a 1hour chart, or if not, any chart available.
                bool oneHourFound = false;
                foreach (TimeSpan span in session.DataProvider.AvailableDataBarProviderPeriods)
                {
                    if (span == TimeSpan.FromHours(1))
                    {
                        session.DataProvider.ObtainDataBarProvider(TimeSpan.FromHours(1));
                        oneHourFound = true;
                        break;
                    }
                }

                if (oneHourFound == false && session.DataProvider.AvailableDataBarProviderPeriods.Length > 0)
                {
                    session.DataProvider.ObtainDataBarProvider(session.DataProvider.AvailableDataBarProviderPeriods[0]);
                }

                // Allow the pending control requests to be created and performed before floating it.
                this.BeginInvoke(new GeneralHelper.GenericDelegate<LocalExpertHost>(SetControlFloat), host);
            }
            else
            {
                SystemMonitor.OperationError("Failed to register session.");
                MessageBox.Show("Failed to register session.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="manager"></param>
 public CreateExpertSessionForm(LocalExpertHost host)
 {
     InitializeComponent();
     this.createExpertSessionControl.Host = host;
     this.createExpertSessionControl.SessionCreatedEvent += new CreateExpertSessionControl2.SessionCreatedDelegate(createExpertSessionControl1_SessionCreatedEvent);
 }