private void TableChanged(object sender, GXItemEventArgs e)
 {
     try
     {
         GXTable table = e.Item as GXTable;
         TreeNode node = (TreeNode)DeviceToTreeNode[table];
         if (node != null)
         {
             node.Text = table.DisplayName;
         }
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
     }
 }
        private void TableRemoved(object sender, GXItemEventArgs e)
        {
            try
            {
                GXTable table = e.Item as GXTable;
#if DEBUG
                m_ObjectIDs.Remove(table.ID);
#endif //DEBUG
                TreeNode Parent = (TreeNode)DeviceToTreeNode[table];
                if (Parent != null)
                {
                    Parent.Remove();
                    DeviceToTreeNode.Remove(table);
                }
            }
            catch (Exception Ex)
            {
                GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
            }
        }
 private void DeviceStateChanged(object sender, GXItemEventArgs e)
 {
     GXDevice device = e.Item as GXDevice;
     GXDeviceEventArgs t = e as GXDeviceEventArgs;
     DeviceStates state = t.Status;
     GXDevice SelDevice = Director.m_DeviceList.SelectedItem is GXDevice ? (GXDevice)Director.m_DeviceList.SelectedItem : null;
     if (SelDevice == null)
     {
         SelDevice = Director.m_DeviceList.SelectedItem is GXProperty ? ((GXProperty)Director.m_DeviceList.SelectedItem).Device : null;
     }
     if (SelDevice == null)
     {
         SelDevice = Director.m_DeviceList.SelectedItem is GXCategory ? ((GXCategory)Director.m_DeviceList.SelectedItem).Device : null;
     }
     if (SelDevice == null)
     {
         SelDevice = Director.m_DeviceList.SelectedItem is GXTable ? (GXDevice)((GXTable)Director.m_DeviceList.SelectedItem).Device : null;
     }
     if (SelDevice == null)
     {
         SelDevice = Director.m_DeviceList.SelectedItem is GXTableCollection ? (GXDevice)((GXTableCollection)Director.m_DeviceList.SelectedItem).Parent : null;
     }
     if (SelDevice == null)
     {
         SelDevice = Director.m_DeviceList.SelectedItem is GXCategoryCollection ? (GXDevice)((GXCategoryCollection)Director.m_DeviceList.SelectedItem).Parent : null;
     }
     if (SelDevice == device)
     {
         if ((state & DeviceStates.Connected | DeviceStates.Disconnected) != 0)
         {
             UpdateUIState(Director.m_DeviceList.SelectedItem);
         }
     }
 }        
Exemple #4
0
		internal virtual void NotifyUpdated(object sender, GXItemEventArgs e)
		{
			if (FreezeEvents == 0 && OnUpdated != null)
			{
				OnUpdated(sender, e);
			}
			if (this.DeviceList != null)
			{
				this.DeviceList.NotifyUpdated(sender, e);
			}
		}
 /// <summary>
 /// Update readed values to the DB.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void DeviceList_OnUpdated(object sender, GXItemEventArgs e)
 {
     if (e.Item is GXProperty)
     {
         GXPropertyEventArgs t = e as GXPropertyEventArgs;
         //Notify if property read or write is started or ended.
         if ((t.Status & PropertyStates.ValueChanged) == 0)
         {
             return;
         }
         m_Updated(new GXAmiDataValue[] { new GXAmiDataValue(t.Item.ID, Convert.ToString(t.Item.GetValue(true)), t.Item.ReadTime) });
     }
     else if (e.Item is GXTable)
     {
         GXTableEventArgs t = e as GXTableEventArgs;
         //Notify if property read or write is started or ended.
         if ((t.Status & (TableStates.RowsAdded | TableStates.RowsUpdated)) == 0)
         {
             return;
         }
         List<GXAmiDataRow> values = new List<GXAmiDataRow>();
         foreach (object[] row in t.Rows)
         {
             int col = -1;
             foreach (object value in row)
             {
                 ++col;
                 values.Add(new GXAmiDataRow(t.Item.ID, t.Item.Columns[col].ID, Convert.ToString(value), 0, (uint)col));
             }
         }
         m_Updated(values.ToArray());
     }
     else if (e.Item is GXDevice)
     {
         GXDeviceEventArgs t = e as GXDeviceEventArgs;
         if ((t.Status & (DeviceStates.Disconnected | DeviceStates.Connected)) == 0)
         {
             return;
         }
         //Set only monitoring flag. There is no need to show all flags.
         if ((t.Status & (DeviceStates.Monitoring)) != 0)
         {
             m_StateChange(ExecutedTask.Device.Id, DeviceStates.Monitoring);
         }
         else
         {
             m_StateChange(ExecutedTask.Device.Id, t.Status);
         }
     }
 }
 internal virtual void NotifyUpdated(object sender, GXItemEventArgs e)
 {
     if (this.FreezeEvents == 0)
     {
         bool dirty = false;
         GXPropertyEventArgs p = e as GXPropertyEventArgs;
         GXCategoryEventArgs c = e as GXCategoryEventArgs;
         GXTableEventArgs t = e as GXTableEventArgs;
         GXDeviceEventArgs d = e as GXDeviceEventArgs;
         if (e.Item is GXDeviceGroup || e.Item is GXDeviceList)
         {
             dirty = true;
         }
         else if (p != null)
         {
             dirty = (p.Status & PropertyStates.Updated) != 0;
         }
         else if (c != null)
         {
             dirty = (c.Status & CategoryStates.Updated) != 0;
         }
         else if (t != null)
         {
             dirty = (t.Status & TableStates.Updated) != 0;
         }
         else if (d != null)
         {
             dirty = (d.Status & DeviceStates.Updated) != 0;
         }
         if (dirty)
         {
             this.NotifyDirty(sender);
         }
         if (this.FreezeEvents == 0 && OnUpdated != null)
         {
             OnUpdated(sender, e);
         }
     }
 }
        private void OnClear(object sender, GXItemEventArgs e)
        {
            try
            {
                if (e.Item is GXDeviceList)
                {
                    UpdateTree(true);
                    return;
                }
                GXDeviceCollection devices = e.Item as GXDeviceCollection;
                if (devices != null)
                {
                    foreach (GXDevice it in devices)
                    {
                        OnRemoved(e.Item, new GXItemEventArgs(it));
                    }
                    return;
                }

                GXDeviceGroupCollection deviceGroups = e.Item as GXDeviceGroupCollection;
                if (deviceGroups != null)
                {
                    foreach (GXDeviceGroup it in deviceGroups)
                    {
                        this.OnRemoved(e.Item, new GXItemEventArgs(it));
                    }
                    return;
                }
                GXTableCollection tables = e.Item as GXTableCollection;
                if (tables != null)
                {
                    foreach (GXTable it in tables)
                    {
                        this.OnRemoved(e.Item, new GXItemEventArgs(it));
                    }
                    return;
                }

                GXCategoryCollection categories = e.Item as GXCategoryCollection;
                if (categories != null)
                {
                    foreach (GXCategory it in categories)
                    {
                        this.OnRemoved(e.Item, new GXItemEventArgs(it));
                    }
                    return;
                }

                GXPropertyCollection properties = e.Item as GXPropertyCollection;
                if (properties != null)
                {
                    if (categories != null)
                    {
                        foreach (GXProperty it in properties)
                        {
                            this.OnRemoved(e.Item, new GXItemEventArgs(it));
                        }
                    }
                    return;
                }
            }
            catch (Exception Ex)
            {
                GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
            }
        }
 private void Updated(object sender, GXItemEventArgs e)
 {
     if (e.Item is GXDeviceList)
     {
         GXDeviceList list = e.Item as GXDeviceList;
         TreeNode node = DeviceToTreeNode[list] as TreeNode;
         node.Text = list.Name;
         return;
     }
     if (e.Item is GXCategory)
     {
         GXCategory cat = e.Item as GXCategory;
         TreeNode node = DeviceToTreeNode[cat] as TreeNode;
         if (node != null)
         {
             node.Text = cat.DisplayName;
         }
         GXCategoryEventArgs t = e as GXCategoryEventArgs;
         //Ignore if category read or write is started or ended.
         if ((t.Status & (CategoryStates.ReadStart | CategoryStates.ReadEnd | CategoryStates.WriteStart | CategoryStates.WriteEnd)) != 0)
         {
             return;
         }
     }
     if (e.Item is GXTable)
     {
         GXTableEventArgs t = e as GXTableEventArgs;
         //Ignore if table read or write is started or ended.
         if ((t.Status & (TableStates.ReadStart | TableStates.ReadEnd | TableStates.WriteStart | TableStates.WriteEnd)) != 0)
         {
             return;
         }
         if (this.InvokeRequired)
         {
             this.BeginInvoke(new ItemUpdatedEventHandler(UpdatedTableData), new object[] { sender, e });
         }
         else
         {
             UpdatedTableData(sender, e);
         }
         return;
     }
     if (e.Item is GXDeviceGroup)
     {
         GXDeviceGroup group = e.Item as GXDeviceGroup;
         TreeNode node = DeviceToTreeNode[group] as TreeNode;
         node.Text = group.Name;
         return;
     }
     if (e.Item is GXProperty)
     {
         GXPropertyEventArgs t = e as GXPropertyEventArgs;
         //Notify if property read or write is started or ended.
         if ((t.Status & (PropertyStates.ReadStart | PropertyStates.ReadEnd | PropertyStates.WriteStart | PropertyStates.WriteEnd)) == 0)
         {
             return;
         }
         if (this.InvokeRequired)
         {
             this.BeginInvoke(new ItemUpdatedEventHandler(PropertyChanged), new object[] { sender, e });
         }
         else
         {
             PropertyChanged(sender, e);
         }
     }
     if (e.Item is GXDevice)
     {
         GXDeviceEventArgs t = e as GXDeviceEventArgs;
         if ((t.Status & (DeviceStates.Connecting | DeviceStates.Disconnecting | DeviceStates.Disconnecting | DeviceStates.ReadStart | DeviceStates.ReadEnd | DeviceStates.WriteStart | DeviceStates.WriteEnd)) != 0)
         {
             return;
         }
         if (this.InvokeRequired)
         {
             this.BeginInvoke(new ItemUpdatedEventHandler(DeviceStateChange), new object[] { sender, e });
         }
         else
         {
             DeviceStateChange(sender, e);
         }
         return;
     }
     if (e.Item is GXSchedule)
     {
         UpdateScheduleItem(sender, e);
         return;
     }
 }
        private void PropertyChanged(object sender, GXItemEventArgs e)
        {
            try
            {
                GXPropertyEventArgs t = e as GXPropertyEventArgs;
                TreeNode node = (TreeNode)DeviceToTreeNode[t.Item];
                GXProperty p = e.Item as GXProperty;
                if (node != null)
                {                    
                    if (Gurux.DeviceSuite.Properties.Settings.Default.DeviceTreeShowPropertyValue && 
                        (t.Status & (PropertyStates.ValueChangedByDevice | PropertyStates.ValueChangedByUser)) != 0)
                    {
                        node.Text = p.DisplayName + " " + p.GetValue(true);
                    }
                    if ((t.Status & PropertyStates.ValueChangedByUser) != 0)
                    {
                        node.SelectedImageIndex = node.ImageIndex = (int)DeviceImageType.DevicePropertyChanged;
                    }
                    else if ((t.Status & PropertyStates.Error) != 0)
                    {
                        node.SelectedImageIndex = node.ImageIndex = (int)DeviceImageType.DevicePropertyError;
                    }
                    else
                    {
                        node.SelectedImageIndex = node.ImageIndex = (int)DeviceImageType.DeviceProperty;
                    }
                }
                //If property value has changed
                if ((t.Status & (Gurux.Device.PropertyStates.ValueReset | Gurux.Device.PropertyStates.ValueChangedByDevice | Gurux.Device.PropertyStates.ValueChangedByUser)) != 0)
                {                    
                    if (p.Parent.Parent == m_DeviceList.SelectedItem)
                    {
                        ListViewItem item = PropertyToListItem[p] as ListViewItem;
                        if (item == null) //It item not found.
                        {
                            return;
                        }
                        string type = p.ValueType == null ? "" : p.ValueType.Name;
                        string tm = p.ReadTime == DateTime.MinValue ? "" : p.ReadTime.ToString();
                        string unit = p.Unit == null ? "" : Convert.ToString(p.Unit);

                        object value = p.GetValue(true);
                        if (value is Array || value is IList)
                        {
                            StringBuilder sb = new StringBuilder();
                            if (value is Array)
                            {
                                Array arr = value as Array;
                                foreach (object it2 in arr)
                                {
                                    sb.Append(it2);
                                    sb.Append(", ");
                                }
                            }
                            else
                            {
                                IList list = value as IList;
                                foreach (object it2 in list)
                                {
                                    sb.Append(it2);
                                    sb.Append(", ");
                                }
                            }
                            //Remove extra data.
                            if (sb.Length > 2)
                            {
                                sb.Remove(sb.Length - 2, 2);
                            }
                            value = sb.ToString();
                        }
                        item.SubItems[1].Text = Convert.ToString(value);
                        item.SubItems[4].Text = tm;
                        item.SubItems[5].Text = string.Format("{0:#,0}/{1:#,0}", p.Statistics.ReadCount, p.Statistics.ReadFailCount);
                        item.SubItems[6].Text = string.Format("{0:#,0}/{1:#,0}", p.Statistics.WriteCount, p.Statistics.WriteFailCount);
                        item.SubItems[7].Text = string.Format("{0:#,0}/{1:#,0}", p.Statistics.ExecutionTime, p.Statistics.ExecutionAverage);
                    }
                    if (p == m_DeviceList.SelectedItem)
                    {
                        string tm = p.ReadTime == DateTime.MinValue ? "" : p.ReadTime.ToString();
                        TimeStampTB.Text = tm;
                        if ((t.Status & Gurux.Device.PropertyStates.ValueChanged) != 0)
                        {
                            string str = Convert.ToString(p.GetValue(true));
                            if (UseCombobox)
                            {
                                this.ValueCB.SelectedIndexChanged -= new System.EventHandler(this.ValueCB_SelectedIndexChanged);
                                ValueCB.Text = str;
                                this.ValueCB.SelectedIndexChanged += new System.EventHandler(this.ValueCB_SelectedIndexChanged);
                            }
                            else
                            {
                                ValueTB.Text = str;
                                if (UseBitMask)
                                {
                                    ulong val = Convert.ToUInt64(p.GetValue(true));
                                    this.ValueLB.ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.ValueLB_ItemCheck);
                                    foreach (ListViewItem it in ValueLB.Items)
                                    {
                                        it.Checked = (val & Convert.ToUInt64(it.Tag)) != 0;
                                    }
                                    this.ValueLB.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.ValueLB_ItemCheck);
                                }
                                if (UseBitMask)
                                {
                                    ValueLB.Text = str;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
            }
        }
 /// <summary>
 /// Content of the table is changed.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void UpdatedTableData(object sender, GXItemEventArgs e)
 {
     if (e.Item is GXTable)
     {
         GXTableEventArgs t = e as GXTableEventArgs;
         //If other table is selected.
         if (m_DeviceList.SelectedItem != t.Item)
         {
             return;
         }
         if ((t.Status & TableStates.RowsAdded) != 0 && TableData.ColumnCount != 0)
         {
             foreach (object[] it in t.Rows)
             {
                 TableData.Rows.Add(it);
             }
             try
             {
                 IGXPartialRead partialRead = e.Item as IGXPartialRead;
                 if (partialRead.Type != PartialReadType.New || partialRead.Start == null)
                 {
                     LastReadValueTP.Text = "";
                 }
                 else
                 {
                     LastReadValueTP.Text = Convert.ToDateTime(partialRead.Start).ToString();
                 }
             }
             catch
             {
                 LastReadValueTP.Text = "";
             }
         }
         else if ((t.Status & TableStates.RowsClear) != 0)
         {
             TableData.Rows.Clear();
         }
         TableRowCount.Text = "Row count: " + (TableData.RowCount).ToString();
     }
 }
        private void UpdateScheduleItem(object sender, GXItemEventArgs e)
        {
            try
            {
                GXSchedule item = e.Item as GXSchedule;
                ListViewItem it = (ListViewItem)ScheduleToTreeNode[item];
                if (it == null)
                {
                    return;
                }
                GXScheduleEventArgs t = e as GXScheduleEventArgs;
                //If user has updated schedule item.
                if (t.Status == ScheduleState.Updated)
                {
                    it.SubItems[0].Text = item.Name;
                    it.SubItems[1].Text = GXScheduleEditorDlg.ScheduleRepeatToString(item.RepeatMode);
                    DateTime NextDate = item.NextScheduledDate;
                    if (NextDate > DateTime.MinValue)
                    {
                        it.SubItems[2].Text = NextDate.ToString();
                    }
                    else
                    {
                        it.SubItems[2].Text = string.Empty;
                    }

                    if (item.Statistics.LastRunTime > DateTime.MinValue)
                    {
                        it.SubItems[3].Text = item.Statistics.LastRunTime.ToString();
                    }
                    else
                    {
                        it.SubItems[3].Text = string.Empty;
                    }
                    it.SubItems[4].Text = string.Empty;
                    it.ImageIndex = (int)((item.Status & ScheduleState.Run) != 0 ? ScheduleImages.ScheduleItemStart : ScheduleImages.ScheduleItemStop);
                }
                else
                {
                    switch (t.Status)
                    {
                        case ScheduleState.TaskStart:
                            it.ImageIndex = (int)ScheduleImages.ScheduleItemExecute;

                            if (!m_IntervalCntSwapNode.Contains(item))
                            {
                                m_IntervalCntSwapNode[item] = item.Statistics.RunCount;
                            }
                            else
                            {
                                m_IntervalCntSwapNode[item] = ((int)m_IntervalCntSwapNode[item]) + 1;
                            }                            

                            if (item.TransactionCount == 0)
                            {
                                it.SubItems[4].Text = string.Format("{0}/-", (int)m_IntervalCntSwapNode[item]);
                            }
                            else
                            {
                                it.SubItems[4].Text = string.Format("{0}/{1}", (int)m_IntervalCntSwapNode[item], item.TransactionCount);
                            }
                            break;
                        case ScheduleState.TaskFinish:
                            it.ImageIndex = (int)ScheduleImages.ScheduleItemStart;
                            //Update next schedule date.
                            UpdateScheduleItem(this, new GXScheduleEventArgs(item, ScheduleState.Updated));
                            Schedules.Sort();
                            break;
                        case ScheduleState.Start:
                            it.ImageIndex = (int)ScheduleImages.ScheduleItemStart;
                            m_IntervalCntSwapNode[item] = 0;
                            DateTime NextDate = item.NextScheduledDate;
                            if (NextDate > DateTime.MinValue)
                            {
                                it.SubItems[2].Text = NextDate.ToString();
                            }
                            else
                            {
                                it.SubItems[2].Text = string.Empty;
                            }
                            break;
                        case ScheduleState.End:
                            it.ImageIndex = (int)ScheduleImages.ScheduleItemStop;
                            if (item.Statistics.LastRunTime > DateTime.MinValue)
                            {
                                it.SubItems[3].Text = item.Statistics.LastRunTime.ToString();
                            }
                            else
                            {
                                it.SubItems[3].Text = string.Empty;
                            }
                            break;
                        default:
                            //Unknown state.
                            System.Diagnostics.Debug.Assert(false);
                            break;
                    }
                }
            }
            catch (Exception Ex)
            {
                GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
            }
        }
 private void DeviceStateChange(object sender, GXItemEventArgs e)
 {
     TreeNode it = (TreeNode)DeviceToTreeNode[e.Item];
     ListViewItem item = DeviceToListItem[e.Item] as ListViewItem;
     if (it == null || item == null)
     {
         return;
     }
     GXDeviceEventArgs t = e as GXDeviceEventArgs;
     GXDevice device = e.Item as GXDevice;
     DeviceStates state = t.Status;
     // Devices name or type has changed.
     if (state == 0)
     {
         it.Text = device.Name;                
         item.Text = device.Name;
         return;
     }
     //Update device state.
     if ((device.Status & Gurux.Device.DeviceStates.Connected) != 0)
     {
         if ((device.Status & DeviceStates.Error) != 0)
         {
             item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.DeviceError;
         }
         else if ((device.Status & DeviceStates.PropertyChanged) != 0)
         {
             item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.DeviceChanged;
         }
         else if ((state & (DeviceStates.Reading | DeviceStates.ReadStart)) != 0)
         {
             item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.DeviceReading;
         }
         else if ((state & DeviceStates.Writing) != 0)
         {
             item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.DeviceWriting;
         }
         else if ((device.Status & DeviceStates.Monitoring) != 0)
         {
             item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.DeviceMonitoring;
         }
         else
         {
             item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.DeviceConnected;
         }
         //Do nothing if we are starting transaction.
         if ((state & (DeviceStates.ReadStart | DeviceStates.WriteStart)) != 0)
         {
             return;
         }
     }
     else if ((device.Status & Gurux.Device.DeviceStates.MediaConnected) != 0)
     {
         item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.MediaConnected;
     }
     else //Device is disconnected.
     {
         item.ImageIndex = it.SelectedImageIndex = it.ImageIndex = (int)DeviceImageType.DeviceDisconnected;
     }
 }
        /// <summary>
        /// A device is removed from the device list.
        /// </summary>
        /// <param name="sender">A GXDevice that was removed from the list.</param>
        /// <param name="index"></param>
        public virtual void OnRemoved(object sender, GXItemEventArgs e)
        {
            try
            {
                GXDevice device = e.Item as GXDevice;
                if (device != null)
                {
#if DEBUG
                    m_ObjectIDs.Remove(device.ID);
#endif //DEBUG
                    TreeNode node = (TreeNode)DeviceToTreeNode[device];
                    if (node != null)
                    {
                        foreach (GXTable table in device.Tables)
                        {
                            TableRemoved(sender, new GXItemEventArgs(table));
                        }
                        foreach (GXCategory cat in device.Categories)
                        {
                            CategoryRemoved(sender, new GXItemEventArgs(cat));
                        }
                        DeviceToTreeNode.Remove(device);
                        node.Remove();
                    }                    
                }                
                else if (e.Item is GXDeviceGroup)
                {
                    GXDeviceGroup deviceGroup = e.Item as GXDeviceGroup;
#if DEBUG
                    m_ObjectIDs.Remove(deviceGroup.ID);
#endif //DEBUG
                    TreeNode node = (TreeNode)DeviceToTreeNode[deviceGroup];
                    if (node != null)
                    {
                        foreach (GXDevice dev in deviceGroup.Devices)
                        {
                            OnRemoved(sender, new GXItemEventArgs(dev));
                        }
                        DeviceToTreeNode.Remove(deviceGroup);
                        node.Remove();
                    }                    
                }
                else if (e.Item is GXProperty)
                {
                    this.BeginInvoke(new ItemRemovedEventHandler(PropertyRemoved), new object[] { sender, e });
                }
                else if (e.Item is GXCategory)
                {
                    this.BeginInvoke(new ItemRemovedEventHandler(CategoryRemoved), new object[] { sender, e });
                }
                else if (e.Item is GXTable)
                {
                    this.BeginInvoke(new ItemRemovedEventHandler(TableRemoved), new object[] { sender, e });                
                }
                else if (e.Item is GXSchedule)
                {
                    GXSchedule item = e.Item as GXSchedule;
                    ListViewItem it = ScheduleToTreeNode[item] as ListViewItem;
                    ScheduleToTreeNode.Remove(item);
                    m_IntervalCntSwapNode.Remove(item);
                    if (it != null)
                    {
                        it.Remove();
                    }
                }
            }
            catch (Exception Ex)
            {
                GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
            }
        }
 /// <summary>
 /// New device added to the device list.
 /// </summary>
 /// <param name="sender">A GXDevice that was added to the list.</param>
 /// <param name="index"></param>
 public virtual void OnAdded(object sender, GXItemEventArgs e)
 {
     try
     {
         if (!this.Created)
         {
             return;
         }
         if (e.Item is GXProperty)
         {
             if (this.InvokeRequired)
             {
                 this.BeginInvoke(new ItemAddedEventHandler(PropertyAdded), new object[] { sender, e });
             }
             else
             {
                 PropertyAdded(sender, e);
             }
             return;
         }
         else if (e.Item is GXCategory)
         {
             if (this.InvokeRequired)
             {
                 this.BeginInvoke(new ItemAddedEventHandler(CategoryAdded), new object[] { sender, e });
             }
             CategoryAdded(sender, e);
             return;
         }
         else if (e.Item is GXTable)
         {
             if (this.InvokeRequired)
             {
                 this.BeginInvoke(new ItemAddedEventHandler(TableAdded), new object[] { sender, e });
             }
             TableAdded(sender, e);
             return;
         }
         GXDevice device = e.Item as GXDevice;
         if (device != null)
         {
             //If trace level is used update it.
             if (TraceLevel != System.Diagnostics.TraceLevel.Off)
             {
                 device.Trace = TraceLevel;
             }
             //Find parent node.
             TreeNode parent = DeviceToTreeNode[device.Parent.Parent] as TreeNode;
             System.Diagnostics.Debug.Assert(parent != null);
             ShowAvailableDevice(device, parent);
             return;
         }
         GXDeviceGroup deviceGroup = e.Item as GXDeviceGroup;
         if (deviceGroup != null)
         {
             GXDeviceGroupCollection groups = deviceGroup.Parent;
             TreeNode DeviceNode = (TreeNode)DeviceToTreeNode[groups.Parent];
             TreeNodeCollection nodes = null;
             if (DeviceNode != null)
             {
                 nodes = DeviceNode.Nodes;
             }
             else
             {
                 nodes = DeviceListTree.Nodes;
             }
             TreeNode node = ShowAvailableDeviceGroup(deviceGroup, nodes, false);
             DeviceListTree.SelectedNode = node;
             node.EnsureVisible();
             return;
         }
         if (e.Item is GXSchedule)
         {
             AddScheduleItem(e.Item as GXSchedule);                    
         }
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
     }
 }
 private void OnPropertyChanged(object sender, GXItemEventArgs e)
 {
     try
     {
         if (e.Item is GXProperty)
         {
             GXPropertyEventArgs t = e as GXPropertyEventArgs;
             //Ignore transaction start and end notify.
             if ((t.Status & (PropertyStates.ReadEnd | PropertyStates.ReadStart | PropertyStates.WriteStart | PropertyStates.WriteEnd)) != 0)
             {
                 return;
             }
             // Update UI if window has created.
             if (this.InvokeRequired)
             {
                 this.BeginInvoke(new Gurux.Device.ItemUpdatedEventHandler(PropertyChanged), sender, e);
             }
             else
             {
                 PropertyChanged(sender, e);
             }
         }
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
     }
 }
 private void OnUpdated(object sender, GXItemEventArgs e)
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new ItemUpdatedEventHandler(Updated), new object[] { sender, e });
     }
     else
     {
         Updated(sender, e);
     }
 }
 private void CategoryAdded(object sender, GXItemEventArgs e)
 {
     try
     {
         GXCategory category = e.Item as GXCategory;
         TreeNode Parent = (TreeNode)DeviceToTreeNode[category.Device];
         ShowAvailableCategory(category, Parent);
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
     }
 }
Exemple #18
0
 internal virtual void NotifyUpdated(object sender, GXItemEventArgs e)
 {
     if (OnUpdated != null)
     {
         OnUpdated(sender, e);
     }
     if (this.Device != null)
     {
         this.Device.NotifyUpdated(sender, e);
     }
 }
        private void CategoryRemoved(object sender, GXItemEventArgs e)
        {
            try
            {
                GXCategory category = e.Item as GXCategory;
#if DEBUG
                m_ObjectIDs.Remove(category.ID);
#endif //DEBUG
                TreeNode Parent = (TreeNode)DeviceToTreeNode[category];
                if (Parent != null)
                {
                    foreach (GXProperty prop in category.Properties)
                    {
                        PropertyRemoved(sender, new GXItemEventArgs(prop));
                    }
                    Parent.Remove();
                    DeviceToTreeNode.Remove(category);
                }
            }
            catch (Exception Ex)
            {
                GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
            }
        }
 internal virtual void NotifyClear(object sender, GXItemEventArgs e)
 {
     if (!IsLoading)
     {
         this.NotifyDirty(sender);
         if (this.FreezeEvents == 0 && OnClear != null)
         {
             OnClear(sender, e);
         }
     }
 }
 private void TableAdded(object sender, GXItemEventArgs e)
 {
     try
     {
         GXTable table = e.Item as GXTable;
         TreeNode Parent = (TreeNode)DeviceToTreeNode[table.Device];
         ShowAvailableTable(table, Parent);
     }
     catch (Exception Ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, Ex);
     }
 }
 internal virtual void NotifyDeviceGroupUpdated(GXItemEventArgs e)
 {
     if (DeviceGroupUpdated != null)
     {
         DeviceGroupUpdated(this, e);
     }
     if (Parent != null)
     {
         Parent.OnDeviceGroupUpdated(this, e);
     }
 }
 private void OnTableChanged(object sender, GXItemEventArgs e)
 {
     if (e.Item is GXTable)
     {
         GXTableEventArgs t = e as GXTableEventArgs;
         // Update UI if window has created.
         if (this.IsHandleCreated && (t.Status & TableStates.Updated) != 0)
         {
             this.BeginInvoke(new ItemUpdatedEventHandler(TableChanged), new object[] { sender, e });
         }
     }
 }
 /// <summary>
 /// Update memus when device state changes.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void OnUpdated(object sender, GXItemEventArgs e)
 {
     if (e.Item is GXDevice)
     {
         GXDeviceEventArgs t = e as GXDeviceEventArgs;
         if ((t.Status & (DeviceStates.Connected | DeviceStates.Disconnected)) != 0)
         {
             if (this.InvokeRequired)
             {
                 this.BeginInvoke(new Gurux.Device.ItemUpdatedEventHandler(DeviceStateChanged), new object[] { sender, e });
             }
             else
             {
                 DeviceStateChanged(sender, e);
             }
         }                
     }            
 }
Exemple #25
0
		internal virtual void NotifyClear(object sender, GXItemEventArgs e)
		{
			if (FreezeEvents == 0 && OnClear != null)
			{
				OnClear(sender, e);
				if (this.DeviceList != null)
				{
					this.DeviceList.NotifyClear(sender, e);
				}
			}
		}