void ProcessRequests()
        {
            InvocationData data = null;

            do
            {
                lock (this)
                {
                    if (_pendingInvokes.Count > 0)
                    {
                        data = _pendingInvokes[0];
                        _pendingInvokes.RemoveAt(0);
                    }
                    else
                    {
                        data = null;
                        break;
                    }
                }

                try
                {
                    if (data != null)
                    {
                        //TracerHelper.Trace("Performing request.");
                        data.Perform();
                    }
                }
                catch (Exception ex)
                {
                    SystemMonitor.Error("Pending operation caused an exception [" + ex.Message + "].");
                }
            }while (_keepRunning && data != null);
        }
        /// <summary>
        ///
        /// </summary>
        public bool RegisterOperation(OperationInformation operationInfo, bool assignId)
        {
            if (assignId && string.IsNullOrEmpty(operationInfo.Id) == false)
            {
                SystemMonitor.Warning("Id of operation already assigned.");
                return(false);
            }

            if (assignId)
            {
                operationInfo.Id = GetNextOperationCustomID().ToString();
            }

            lock (this)
            {
                if (_pendingOperations.ContainsKey(operationInfo.Id))
                {
                    SystemMonitor.Error("An operation for this order id already running.");
                    return(false);
                }

                // Register now to be sure, that whenever responce and OrderResponce come they will be handled OK.
                _pendingOperations.Add(operationInfo.Id, operationInfo);
                operationInfo.OperationCompleteEvent += new OperationInformation.OperationUpdateDelegate(operationInfo_OperationCompleteEvent);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Update user interface based on the underlying information.
        /// </summary>
        void DoUpdateUI()
        {
            try
            {
                if (this.Tracer == null || _itemKeeperSink == null || this.DesignMode)
                {
                    return;
                }

                if (_priorityFilter == null || _priorityFilter.MinimumPriority == TracerItem.PriorityEnum.Minimum)
                {
                    toolStripComboBoxPriority.Text = "Priority [All]";
                }
                else
                {
                    toolStripComboBoxPriority.Text = "Priority [+" + GeneralHelper.SplitCapitalLetters(_priorityFilter.MinimumPriority.ToString()) + "]";
                }

                toolStripDropDownButtonTimeDisplay.Text = "Time [" + GeneralHelper.SplitCapitalLetters(_tracer.TimeDisplayFormat.ToString()) + "]";
                this.toolStripButtonEnabled.Checked     = this.Tracer.Enabled;

                // Give some slack for the vlist, since it has problems due to Microsoft List implementation.
                listView.VirtualListSize = _itemKeeperSink.FilteredItemsCount + CleanVirtualItemsCount;
            }
            catch (Exception ex)
            {
                SystemMonitor.Error("UI Logic Error [" + ex.Message + "]");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Helper.
        /// </summary>
        void SetObjectPropertyValueByTag(object tag, object value)
        {
            if (tag is string)
            {// This is a dynamic generic property.
                SystemMonitor.CheckThrow(SelectedContainerObject != null);
                SelectedContainerObject.SetGenericDynamicPropertyValue(tag as string, value);
            }
            else if (tag is PropertyInfo)
            {// Direct property of the indicator.
                PropertyInfo info = (PropertyInfo)tag;
                if (info.CanWrite)
                {
                    info.SetValue(_selectedObject, value, null);
                }
                else
                {
                    SystemMonitor.OperationError("Property set method not found [" + info.DeclaringType.Name + ":" + info.Name + "].");
                }
            }
            else
            {
                SystemMonitor.Error("Unrecognized tag type for indicator property.");
            }

            if (SelectedContainerObject != null)
            {
                SelectedContainerObject.PropertyChanged();
            }
        }
        /// <summary>
        /// Update user interface based on the underlying information.
        /// </summary>
        void DoUpdateUI()
        {
            try
            {
                if (this.Tracer == null || _itemKeeperSink == null || this.DesignMode)
                {
                    return;
                }

                if (_priorityFilter == null || _priorityFilter.MinimumPriority == TracerItem.PriorityEnum.Minimum)
                {
                    toolStripComboBoxPriority.Text = "Priority [All]";
                }
                else
                {
                    toolStripComboBoxPriority.Text = "Priority [+" + _priorityFilter.MinimumPriority.ToString() + "]";
                }

                this.toolStripButtonEnabled.Checked = this.Tracer.Enabled;
                //toolStripButtonDetails.Checked = panelSelected.Visible;

                //_itemKeeperSink.ReFilterItems();

                // Give some slack for the vlist, since it has problems due to Microsoft List implementation.
                listView.VirtualListSize = _itemKeeperSink.FilteredItemsCount + CleanVirtualItemsCount;

                //ListViewItem item = listView.TopItem;
                // Needed to update scroll state and evade a bug in the list control (problem in any win list control).
                //this.listView.Scrollable = false;
                //this.listView.Scrollable = true;
                //if (_itemKeeperSink.FilteredItemsCount < 30 && listView.VirtualListSize > 0)
                //{
                //    //listView.EnsureVisible(0);
                //}

                //if (toolStripButtonAutoScroll.Checked && listView.VirtualListSize > 0)
                //{
                //    // Selection update is needed, since on size change the virtual list redraws also where the selected indeces are
                //    // and this causes massive flicker on auto update and auto scroll - the scroll skipping back and forth (since selection is somewhere back).
                //    listView.SelectedIndices.Clear();
                //    listView.SelectedIndices.Add(listView.VirtualListSize - 1);
                //    //listView.EnsureVisible(listView.VirtualListSize - 1);
                //}
            }
            catch (Exception ex)
            {
                SystemMonitor.Error("UI Logic Error [" + ex.Message + "]");
            }
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        public virtual bool Start()
        {
            lock (this)
            {
                if (_isStarted)
                {
                    SystemMonitor.Error("Operation already complete.");
                    return(false);
                }

                _isStarted = true;
            }

            return(true);
        }
        /// <summary>
        /// This only applies the simples baseMethod of looking for a web site shortcut icon - the "favicon.ico" image.
        /// </summary>
        /// <param name="websiteUri"></param>
        /// <returns></returns>
        public static Image GetWebSiteShortcutIcon(Uri websiteUri)
        {
            Image  result = null;
            string host   = websiteUri.Host;


            WebRequest requestImg = WebRequest.Create("http://" + websiteUri.Host + "/favicon.ico");

            requestImg.Timeout = 10000;

            WebResponse response = requestImg.GetResponse();

            if (response.ContentLength > 0)
            {
                try
                {
                    result = Image.FromStream(response.GetResponseStream());
                }
                catch (Exception ex)
                {
                    SystemMonitor.Error("Failed to get image [" + ex.Message + "]");
                    return(null);
                }
            }

            //else
            //{
            //    HtmlDocument doc = webBrowser1.Document;
            //    HtmlElementCollection collect = doc.GetElementsByTagName("link");

            //    foreach (HtmlElement element in collect)
            //    {
            //        if (element.GetAttribute("rel").ToLower() == "shortcut icon"
            //        || element.GetAttribute("rel").ToLower() == "icon" || element.GetAttribute("type").ToLower() == "image/x-icon")
            //            iconPath = element.GetAttribute("href");
            //    }

            //    this.Text = doc.Title;

            //    requestImg = WebRequest.Create("http://" + e.Url.Host + iconPath);

            //    response = requestImg.GetResponse();

            //    myStream = response.GetResponseStream();
            //}

            return(result);
        }
        /// <summary>
        /// Perform deserialization of an object from a stream.
        /// </summary>
        public static bool DeSerialize(MemoryStream stream, out object value)
        {
            try
            {
                IFormatter formatter = GenerateFormatter();
                value = formatter.Deserialize(stream);
            }
            catch (Exception ex)
            {
                SystemMonitor.Error("Failed to deserialize object.", ex);
                value = null;
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
 /// <summary>
 /// Main operation thread.
 /// </summary>
 protected void Run()
 {
     while (_keepRunning)
     {
         try
         {
             Application.DoEvents();
             ProcessRequests();
             Thread.Sleep(16);
         }
         catch (Exception ex)
         {
             SystemMonitor.Error("Exception in messages processing thread [" + ex.Message + "]");
         }
     }
 }
        public static bool Serialize(MemoryStream stream, object p)
        {
            try
            {
                IFormatter formatter = GenerateFormatter();
                formatter.Serialize(stream, p);
                if (stream.Position > SerializationWarningLimit)
                {
                    SystemMonitor.Warning("Serialialization of object [" + p.GetType().Name + "] has grown above the default serialization limit to [" + stream.Position.ToString() + "] bytes.");
                }

                return(true);
            }
            catch (Exception ex)
            {
                SystemMonitor.Error("Failed to serialize object [" + p.GetType().Name + "," + ex.Message + "].");
                return(false);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Complete the operation and set the result.
        /// </summary>
        public virtual void Complete(object response)
        {
            lock (this)
            {
                if (_isComplete)
                {
                    SystemMonitor.Error("Operation already complete.");
                    return;
                }

                _isComplete = true;
                _response   = response;
                _event.Set();
            }

            if (OperationCompleteEvent != null)
            {
                OperationCompleteEvent(this);
            }
        }
Esempio n. 12
0
        void propertyValue_ValueChanged(object sender, EventArgs e)
        {
            NumericUpDown propertyValueNumeric = (NumericUpDown)sender;
            Type          propertyType         = GetPropertyTypeByTag(propertyValueNumeric.Tag);

            // Since numeric may display different types of values, and the type info is lost in entering,
            // now extract it back to pass properly to the indicator.

            object value = null;

            if (propertyType == typeof(int))
            {
                value = (int)propertyValueNumeric.Value;
            }
            else if (propertyType == typeof(double))
            {
                value = (double)propertyValueNumeric.Value;
            }
            else if (propertyType == typeof(Single))
            {
                value = (Single)propertyValueNumeric.Value;
            }
            else if (propertyType == typeof(long))
            {
                value = (long)propertyValueNumeric.Value;
            }
            else if (propertyType == typeof(decimal))
            {
                value = (decimal)propertyValueNumeric.Value;
            }
            else if (propertyType == typeof(short))
            {
                value = (short)propertyValueNumeric.Value;
            }
            else
            {
                SystemMonitor.Error("Unsupported input type in numeric box.");
            }

            SetObjectPropertyValueByTag(propertyValueNumeric.Tag, value);
        }
Esempio n. 13
0
        void ProcessUpdate(WatcherChangeTypes changeType)
        {
            lock (_syncRoot)
            {
                // File created, deleted, or first call, setup the reader.
                if (_fileStream == null ||
                    changeType == WatcherChangeTypes.Deleted ||
                    changeType == WatcherChangeTypes.Created)
                {
                    if (_reader != null)
                    {
                        _reader.Dispose();
                        _reader = null;
                    }

                    if (_fileStream != null)
                    {
                        _fileStream.Dispose();
                        _fileStream = null;
                    }

                    if (changeType == WatcherChangeTypes.Deleted)
                    {
                        return;
                    }

                    try
                    {
                        _fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        _reader     = new StreamReader(_fileStream);
                    }
                    catch (Exception ex)
                    {
                        SystemMonitor.Error(ex.Message);

                        _reader = null;
                        _fileStream.Dispose();
                        _fileStream = null;
                    }
                }

                if (_fileStream == null || _fileStream.CanRead == false)
                {
                    return;
                }

                if (_fileStream.Length < _lastFilePos - 10)
                {// File was rewritten start from beggining.
                    _lastFilePos = 0;
                }

                try
                {
                    _fileStream.Seek(_lastFilePos, SeekOrigin.Begin);

                    string line = _reader.ReadLine();
                    while (line != null)
                    {
                        DataUpdateDelegate delegateInstance = NewLineReadEvent;
                        if (delegateInstance != null)
                        {
                            delegateInstance(this, line);
                        }

                        line = _reader.ReadLine();
                    }
                }
                catch (Exception ex)
                {
                    SystemMonitor.OperationError("Failed to read file", ex);
                }

                _lastFilePos = _fileStream.Position;
            }
        }
        /// <summary>
        /// Add a control to the tabbed controls list.
        /// </summary>
        public void AddTabbedControl(CommonBaseControl control)
        {
            if (_tabbedButtonsControls.ContainsValue(control))
            {
                SystemMonitor.Error("Control already added.");
                return;
            }

            #region Establish Index
            // Since the components enter one by one, it will happen that the index of the incoming control
            // is beyond the current maximum, so we look for the existing controls, one by one, and see where
            // the current one fits - this way they are restored places one by one and everyone is properly placed.

            int?index = null;
            if (control.PersistenceData.ContainsValue("combinedContainer.TabIndex"))
            {
                index = control.PersistenceData.GetValue <int>("combinedContainer.TabIndex");
            }

            int?actualIndex = null;
            if (index.HasValue)
            {
                foreach (ToolStripItem item in toolStripMain.Items)
                {
                    int itemIndex = 0;
                    if (item is ToolStripButton)
                    {
                        if (_tabbedButtonsControls.ContainsKey(item as ToolStripButton))
                        {
                            CommonBaseControl itemControl = _tabbedButtonsControls[item as ToolStripButton];
                            if (itemControl != null && itemControl.PersistenceData.ContainsValue("combinedContainer.TabIndex"))
                            {
                                itemIndex = itemControl.PersistenceData.GetValue <int>("combinedContainer.TabIndex");
                            }
                        }
                    }

                    if (index.Value <= itemIndex)
                    {
                        actualIndex = toolStripMain.Items.IndexOf(item);
                        break;
                    }
                }
            }
            #endregion

            string nameRepaired = control.Name.Replace("&", "&&");

            ToolStripButton controlButton = new ToolStripButton(nameRepaired);
            Image           image         = GetControlImage(control);
            if (image == null)
            {
                image = Resources.dot;
            }

            controlButton.ToolTipText  = control.Text;
            controlButton.Image        = image;
            controlButton.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
            controlButton.CheckOnClick = false;
            controlButton.Checked      = false;
            controlButton.MouseDown   += new MouseEventHandler(controlButton_MouseDown);
            controlButton.MouseUp     += new MouseEventHandler(controlButton_MouseUp);
            controlButton.MouseMove   += new MouseEventHandler(controlButton_MouseMove);

            if (actualIndex.HasValue)
            {
                toolStripMain.Items.Insert(actualIndex.Value, controlButton);
            }
            else
            {
                toolStripMain.Items.Add(controlButton);
            }

            _tabbedButtonsControls.Add(controlButton, control);

            bool isChecked = false;
            if (control.PersistenceData != null && control.PersistenceData.ContainsValue("combinedContainer.Checked"))
            {
                isChecked = control.PersistenceData.GetBoolean("combinedContainer.Checked");
            }

            if (_checkedControl == null || isChecked)
            {
                ChangeCheckedControl(control);
            }

            UpdateUI();
        }
Esempio n. 15
0
 /// <summary>
 /// Report an serious error. Those errors are usually a sign something in the work
 /// of the application has gone seriously wrong, and operation can not continue
 /// properly (for ex. unexpected exception, access to critical resources etc.)
 /// </summary>
 /// <param name="errorMessage"></param>
 public void Error(string errorMessage)
 {
     SystemMonitor.Error(errorMessage);
 }