Esempio n. 1
0
        /// <summary>
        /// An order has been received an update containing critical modification of its information,
        /// so handle this here and show to user.
        /// </summary>
        void management_OrdersCriticalInformationChangedEvent(ITradeEntityManagement provider, AccountInfo account, Order order, OrderInfo updateInfo)
        {
            // Compose the critical update message instantly, as otherwise it is wrong since the order gets instantly updated after this call.
            string criticalUpdateMessage = string.Empty;

            if (order.OpenPrice.HasValue && updateInfo.OpenPrice.HasValue && order.OpenPrice.Value != updateInfo.OpenPrice.Value)
            {
                criticalUpdateMessage = string.Format("Open Price Difference [{0}], Existing [{1}], New [{2}].", order.OpenPrice - updateInfo.OpenPrice, order.OpenPrice.ToString(), updateInfo.OpenPrice) + Environment.NewLine;
            }

            if (order.ClosePrice.HasValue && updateInfo.ClosePrice.HasValue && order.ClosePrice.Value != updateInfo.ClosePrice.Value)
            {
                criticalUpdateMessage += string.Format("Close Price Difference [{0}], Existing [{1}], New [{2}].", order.ClosePrice - updateInfo.ClosePrice, order.ClosePrice.ToString(), updateInfo.ClosePrice) + Environment.NewLine;
            }

            WinFormsHelper.BeginManagedInvoke(this, delegate()
            {
                if (toolStripButtonPopupNotifications.Checked == false)
                {
                    return;
                }

                if (string.IsNullOrEmpty(criticalUpdateMessage) == false)
                {
                    MessageBox.Show("Account [" + account.Name + "] Order Id[" + order.Id + "] Critical Information Updated" + Environment.NewLine + criticalUpdateMessage, "Critical Order Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            });
        }
        /// <summary>
        /// Non UI thread.
        /// </summary>
        void UpdateMasterChart()
        {
            this.chartControl.Visible         = _session != null;
            toolStripButtonIndicators.Visible = _session != null;

            if (_session == null || _session.DataProvider == null)
            {
                return;
            }

            string name = _session.Info.Symbol.Name;

            if (CurrentDataBarProvider != null && CurrentDataBarProvider.Period.HasValue)
            {
                name += " [M" + CurrentDataBarProvider.Period.Value.TotalMinutes.ToString() + "]";
            }

            if (_session.DataProvider != null && _session.DataProvider.Quotes != null &&
                _session.DataProvider.Quotes.OperationalState == OperationalStateEnum.Operational)
            {
                name += ", " + GeneralHelper.ToString(_session.DataProvider.Quotes.Bid, _session.Info.ValueFormat) + " / " + GeneralHelper.ToString(_session.DataProvider.Quotes.Ask, _session.Info.ValueFormat);
                name += ", " + _session.DataProvider.DataBars.BarCount.ToString() + " bars";
            }
            else
            {
                name = name + ", " + _session.OperationalState.ToString();
            }

            if (_session.OperationalState != OperationalStateEnum.Operational)
            {
                name = name + ", " + _session.OperationalState.ToString();
            }

            WinFormsHelper.BeginFilteredManagedInvoke(this, new GeneralHelper.GenericDelegate <string>(chartControl.MasterPane.SetChartName), name);
        }
        private void toolStripButtonStartAdapter_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listViewIntegrations.SelectedItems)
            {
                GeneralHelper.FireAndForget(delegate(ListViewItem itemValue)
                {
                    string operationMessage = string.Empty;

                    IIntegrationAdapter adapter = (IIntegrationAdapter)itemValue.Tag;
                    string operationResultMessage;

                    if (adapter.Start(out operationResultMessage) == false)
                    {
                        operationMessage += "Adapter [" + adapter.Name + "] failed to start [" + operationResultMessage + "]." + Environment.NewLine;
                    }

                    WinFormsHelper.BeginManagedInvoke(this, delegate()
                    {
                        if (string.IsNullOrEmpty(operationMessage) == false)
                        {
                            MessageBox.Show(operationMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        UpdateUI();
                    });
                }, item);
            }
        }
        void source_DataDownloadedEventToDataStore(OnlineEntrySource source)
        {
            source.DataDownloadedEvent -= new OnlineEntrySource.EntrySourceUpdateDelegate(source_DataDownloadedEventToDataStore);

            if (source.DownloadSucceeded)
            {
                foreach (string filePath in source.DownloadedTempFilesPaths)
                {
                    Manager.AddEntryFromLocalFile(filePath);
                }

                WinFormsHelper.BeginManagedInvoke(this, delegate()
                {
                    toolStripStatusLabel1.DisplayStyle = ToolStripItemDisplayStyle.Text;
                    toolStripStatusLabel1.Text         = "Download of [" + source.Uri.ToString() + "] successful.";
                });
            }
            else
            {
                WinFormsHelper.BeginManagedInvoke(this, delegate()
                {
                    toolStripStatusLabel1.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                    toolStripStatusLabel1.Text         = "Download of [" + source.Uri.ToString() + "] failed.";
                });
            }

            source.EndDownload(true);
            WinFormsHelper.BeginFilteredManagedInvoke(this, UpdateUI);
        }
        private void toolStripMenuItemFromFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "All supported|*.csv;*.hst|CSV (*.csv)|*.csv|HST (*.hst)|*.hst";
            ofd.Multiselect = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                _waitControl.Message = "Importing data, please wait.";
                _waitControl.SetActiveState(true);

                GeneralHelper.FireAndForget(delegate()
                {
                    string errors = string.Empty;

                    foreach (string filePath in ofd.FileNames)
                    {
                        if (DataStoreComponent.DataStore.AddEntryFromLocalFile(filePath) == null)
                        {
                            errors += "Failed to create entry from file [" + filePath + "]." + Environment.NewLine;
                        }
                    }

                    _waitControl.SetActiveState(false);
                    WinFormsHelper.BeginFilteredManagedInvoke(this, UpdateUI);

                    if (string.IsNullOrEmpty(errors) == false)
                    {
                        MessageBox.Show(errors, "Error(s) in Importing Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                });
            }
        }
 void DataBarHistory_DataBarHistoryUpdateEvent(IDataBarHistoryProvider provider, DataBarUpdateType updateType, int updatedBarsCount)
 {
     if (updateType == DataBarUpdateType.Initial)
     {// Only executes on initial adding of many items.
         WinFormsHelper.BeginFilteredManagedInvoke(this, new GeneralHelper.GenericDelegate <bool, bool>(chartControl.MasterPane.FitDrawingSpaceToScreen), true, true);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// NON UI Thread.
 /// </summary>
 public void SelectOrder(Order order)
 {
     if (this.IsHandleCreated)
     {
         WinFormsHelper.BeginFilteredManagedInvoke(this, new GeneralHelper.GenericDelegate <Order>(DoSelectOrder), order);
     }
 }
Esempio n. 8
0
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // copying the currently selected row in the currently selected ListView here:
            var grid = ActiveControl as DataGridView;

            WinFormsHelper.CopySelectedDataGridRowsToClipboard(grid);
        }
 /// <summary>
 ///
 /// </summary>
 /// <see cref="WinFormsHelper.InvokeSafe{TCtrl, TState, TResult}(TCtrl, Func{TCtrl, TState, TResult}, Func{TCtrl, TState})" />
 public static TResult InvokeSafe <TCtrl, TState, TResult>(this TCtrl ctrl,
                                                           Func <TCtrl, TState, TResult> func,
                                                           Func <TCtrl, TState> funcStateFactory) where TCtrl : global::System.Windows.Forms.Control
 {
     return(WinFormsHelper.InvokeSafe <TCtrl, TState, TResult>(ctrl,
                                                               func, funcStateFactory));
 }
 /// <summary>
 ///
 /// </summary>
 /// <see cref="WinFormsHelper.InvokeSafe{TCtrl, TState}(TCtrl, Action{TCtrl, TState}, Func{TCtrl, TState})" />
 public static void InvokeSafe <TCtrl, TState>(this TCtrl ctrl,
                                               Action <TCtrl, TState> action,
                                               Func <TCtrl, TState> actionStateFactory) where TCtrl : global::System.Windows.Forms.Control
 {
     WinFormsHelper.InvokeSafe <TCtrl, TState>(ctrl,
                                               action, actionStateFactory);
 }
Esempio n. 11
0
        public void SynchronizeWithMasterPane()
        {
            if (_masterPane == null || _masterPaneSynchronizationMode == MasterPaneSynchronizationModeEnum.None)
            {
                return;
            }

            SystemMonitor.CheckThrow(_masterPaneSynchronizationMode == MasterPaneSynchronizationModeEnum.XAxis, "Mode not supported.");
            GraphicsWrapper.SynchronizeDrawingSpaceXAxis(_masterPane.GraphicsWrapper);

            this.YAxisLabelsPosition = _masterPane.YAxisLabelsPosition;

            //this.AutoScrollToEnd = _masterPane.AutoScrollToEnd;
            this.LimitedView = _masterPane.LimitedView;

            Crosshair.Visible = _masterPane.Crosshair.Visible;

            RectangleF screen = GraphicsWrapper.ActualSpaceToDrawingSpace(ActualDrawingSpaceArea);

            FitHorizontalAreaToScreen(screen);

            UpdateMasterSynchronizationState(true);

            WinFormsHelper.BeginFilteredManagedInvoke(this, TimeSpan.FromMilliseconds(100), Refresh);
            //this.Invalidate();
        }
Esempio n. 12
0
        private void LoadSelectedList()
        {
            FormLoadList loadList = new FormLoadList();

            if (loadList.ShowDialog() == DialogResult.OK)
            {
                dataGridViewEdit.Columns.Clear();
                dataGridViewEdit.Rows.Clear();

                string selection = loadList.SelectedList;

                foreach (string language in WinFormsHelper.Languages(selection))
                {
                    dataGridViewEdit.Columns.Add(language, language.ToUpper());
                }

                foreach (string[] words in WinFormsHelper.AllWords(selection))
                {
                    dataGridViewEdit.Rows.Add(words);
                }

                EditButtonsSwitch();
                buttonAddWord.Enabled = true;

                labelCurrentWordList.Text = $"Current list: {loadList.SelectedList}";

                CurrentList = loadList.SelectedList;
            }
        }
 private void uiThread_ComponentDeSerializationFailed(long componentId, string componentTypeName)
 {
     if (WinFormsHelper.ShowMessageBox("A component [id " + componentId.ToString() + ", type " + componentTypeName + "] has failed on deserialization or initialization, " + System.Environment.NewLine + "would you like to remove it?",
                                       "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
     {
         _platform.RemovePersistedComponentById(componentId);
     }
 }
 void _component_OperationalStateChangedEvent(IOperational operational, OperationalStateEnum previousOperationState)
 {
     WinFormsHelper.BeginManagedInvoke(this,
                                       delegate
     {
         labelStatus.Text = UserFriendlyNameAttribute.GetTypeAttributeName(operational.GetType()) + " is " + operational.OperationalState.ToString();
     });
 }
        public override void UnInitializeControl()
        {
            UnInitialize();

            WinFormsHelper.BeginFilteredManagedInvoke(this, TimeSpan.FromMilliseconds(250), UpdateUI);

            base.UnInitializeControl();
        }
Esempio n. 16
0
        //void ParseLine(string line)
        //{
        //if (string.IsNullOrEmpty(line))
        //{
        //    return;
        //}

        //try
        //{
        //    string[] substrings = line.Split('|');

        //    if (substrings.Length < 4)
        //    {
        //        SystemMonitor.OperationError("Failed to parse tracer item line [" + line + ", Not enough substrings generated].");
        //        return;
        //    }

        //    TracerItem.TypeEnum type = (TracerItem.TypeEnum)Enum.Parse(typeof(TracerItem.TypeEnum), substrings[0]);

        //    long index = 0;
        //    long.TryParse(substrings[1], out index);

        //    DateTime time;
        //    try
        //    {
        //        string dateTime = substrings[2];
        //        string[] dateTimeParts = dateTime.Split('/');
        //        string[] subParts = dateTimeParts[2].Split(' ');
        //        TimeSpan timeSpan = TimeSpan.Parse(subParts[1]);

        //        time = new DateTime(int.Parse(subParts[0]), int.Parse(dateTimeParts[0]),
        //            int.Parse(dateTimeParts[1]), timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds);
        //    }
        //    catch(Exception ex2)
        //    {
        //        SystemMonitor.OperationError("Failed to parse tracer item line [" + line + ", " + ex2.Message + "].");
        //        time = DateTime.MinValue;
        //    }

        //    //if (DateTime.TryParse(substrings[2], out time) == false)
        //    //{
        //    //    time = DateTime.MinValue;
        //    //}

        //    TracerItem item = new TracerItem(type, time, index.ToString() + "  " + substrings[substrings.Length - 1]);
        //    _tracer.Add(item);

        //}
        //catch(Exception ex)
        //{
        //    SystemMonitor.OperationError("Failed to parse tracer item line [" + line + ", " + ex.Message + "].");
        //}
        //}

        private void toolStripButtonUpdate_Click(object sender, EventArgs e)
        {
            GeneralHelper.FireAndForget(delegate()
            {
                _watcher_Changed(null, new FileSystemEventArgs(WatcherChangeTypes.Created, _watcher.Path, _watcher.Filter));
                WinFormsHelper.BeginFilteredManagedInvoke(tracerControl1, tracerControl1.UpdateUI);
            });
        }
Esempio n. 17
0
        public void UpdateUI()
        {
            ListView listView = _listView;

            if (listView != null)
            {
                WinFormsHelper.BeginManagedInvoke(_listView, DoUpdateUI);
            }
        }
        void _account_UpdateEvent(Account account)
        {
            if (this.DesignMode)
            {
                return;
            }

            WinFormsHelper.BeginFilteredManagedInvoke(this, TimeSpan.FromMilliseconds(250), UpdateUI);
        }
        /// <inheriteddoc />
        protected sealed override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            WinFormsHelper.MakeMoveable(this,
                                        this.SetupMoveableForm);

            this.OnLoad();
        }
Esempio n. 20
0
        private void InitView()
        {
            oldSettings = new ObsData(settings);

            // force double buffering on to eliminate control flickering during refresh
            WinFormsHelper.DoubleBufferControl(panel);

            ReloadProperties();
        }
Esempio n. 21
0
        void _provider_AccountInfoUpdateEvent(IOrderSink provider, AccountInfo accountInfo)
        {
            if (((ISourceOrderExecution)provider).DefaultAccount != Account)
            {
                Account = ((ISourceOrderExecution)provider).DefaultAccount;
            }

            WinFormsHelper.BeginFilteredManagedInvoke(this, UpdateUI);
        }
Esempio n. 22
0
        private void DeleteListPrompt()
        {
            if (MessageBox.Show(this, "Are you sure you want to permanently delete this list?",
                                "Delete list", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                WinFormsHelper.DeleteList(listBoxList.GetItemText(listBoxList.SelectedItem));

                RefreshListBoxLists();
            }
        }
Esempio n. 23
0
 void _ownerControl_Paint(object sender, PaintEventArgs e)
 {
     if (e.ClipRectangle.Width >= _ownerControl.Width &&
         e.ClipRectangle.Height >= _ownerControl.Height)
     {
         _drawnHorizontal = false;
         _drawnVertical   = false;
         WinFormsHelper.BeginManagedInvoke(_ownerControl, delegate() { Redraw(); });
     }
 }
Esempio n. 24
0
        private bool AddWord()
        {
            List <string> wordsToAdd = new List <string>();

            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (cell.ColumnIndex == 0)
                    {
                        if (!string.IsNullOrEmpty((string)cell.Value))
                        {
                            cell.Value = cell.Value.ToString().Trim();

                            if (string.IsNullOrEmpty((string)cell.Value))
                            {
                                MessageBox.Show(this, "Enter one translation for every language.", "Error",
                                                MessageBoxButtons.OK, MessageBoxIcon.Warning);

                                return(false);
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "Enter one translation for every language.", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);

                            return(false);
                        }


                        wordsToAdd.Add(cell.Value.ToString().ToLower());
                    }
                }
            }

            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cell.Value = null;
                }
            }

            WinFormsHelper.Add(parentFormWordList.CurrentList, wordsToAdd.ToArray());

            parentFormWordList.RefreshLoadedList();

            dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0];
            dataGridView.BeginEdit(true);

            wordAdded = true;

            return(true);
        }
Esempio n. 25
0
 private void toolStripButtonRemoveAdapter_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in listViewIntegrations.SelectedItems)
     {
         IIntegrationAdapter adapter = (IIntegrationAdapter)item.Tag;
         if (WinFormsHelper.ShowMessageBox(string.Format("Remove adapter [{0}]?", adapter.Name), string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
         {
             Operator.Adapters.Remove(adapter);
         }
     }
 }
 void _controller_CurrentPeriodChangedEvent(ITimeControl control)
 {
     if (InvokeRequired)
     {
         WinFormsHelper.BeginFilteredManagedInvoke(this, UpdateUI);
     }
     else
     {
         UpdateUI();
     }
 }
Esempio n. 27
0
        private void listBoxLanguages_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBoxWord.Items.Clear();

            foreach (string word in WinFormsHelper.SelectLanguageWords(
                         listBoxList.GetItemText(listBoxList.SelectedItem),
                         listBoxLanguage.GetItemText(listBoxLanguage.SelectedItem)))
            {
                listBoxWord.Items.Add(word.Capitalize());
            }
        }
Esempio n. 28
0
		/// <summary>
		/// Selects or unselects all files in the file list.
		/// </summary>
		/// <param name="doSelect">True to select the files, false to unselect them.</param>
		public void ToggleSelectAllFiles(bool doSelect)
		{
			using (WinFormsHelper.BeginUiUpdate(View.fileGrid))
			{
				if (doSelect)
					View.fileGrid.SelectAll();
				else
				{
					View.fileGrid.ClearSelection();
				}
			}
		}
Esempio n. 29
0
        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            textBoxListName.Text = textBoxListName.Text.Trim();

            if (!string.IsNullOrEmpty(textBoxListName.Text))
            {
                if (textBoxListLanguages.Lines.Length > 1)
                {
                    if (!string.IsNullOrEmpty(textBoxListLanguages.Lines[0]) &&
                        !string.IsNullOrEmpty(textBoxListLanguages.Lines[1]))
                    {
                        string[] language = textBoxListLanguages.Lines;

                        for (int i = 0; i < language.Length; i++)
                        {
                            language[i] = language[i].Trim();
                        }

                        WinFormsHelper.New(textBoxListName.Text, language);

                        buttonConfirm.DialogResult = DialogResult.OK;

                        if (parentLoadList != null)
                        {
                            parentLoadList.RefreshListBoxLists();
                        }
                        else
                        {
                            parentWordList.LoadNewList(this);
                        }

                        Close();
                    }
                    else
                    {
                        MessageBox.Show(this, "Enter at least two languages.", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show(this, "Enter at least two languages.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show(this, "Enter a list name.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 30
0
        public void RefreshLoadedList()
        {
            dataGridViewEdit.Columns.Clear();
            dataGridViewEdit.Rows.Clear();

            foreach (string language in WinFormsHelper.Languages(CurrentList))
            {
                dataGridViewEdit.Columns.Add(language, language.ToUpper());
            }

            foreach (string[] words in WinFormsHelper.AllWords(CurrentList))
            {
                dataGridViewEdit.Rows.Add(words);
            }
        }