public void Import(bool fromDataCollector) { try { //Ask save settings if device template is dirty. if (Device != null && Device.Dirty) { DialogResult ret = MessageBox.Show(ParentComponent, Gurux.DeviceSuite.Properties.Resources.SaveChangesQuestionTxt, Gurux.DeviceSuite.Properties.Resources.DeviceEditorTxt, MessageBoxButtons.YesNoCancel); if (ret == DialogResult.Cancel) { return; } else if (ret == DialogResult.Yes) { Save(); } } GXDevice tmpDev = Device.Clone(); tmpDev.Categories.Clear(); tmpDev.Tables.Clear(); GXImportDlg dlg = new GXImportDlg(TraceLevel, tmpDev.AddIn, tmpDev, fromDataCollector); dlg.OnTrace += new TraceEventHandler(OnTrace); if (dlg.ShowDialog(ParentComponent) != DialogResult.OK) { dlg.OnTrace -= new TraceEventHandler(OnTrace); tmpDev.Dispose(); return; } //Copy device properties from temp device to original device because they might change on import. PropertyDescriptorCollection Props = TypeDescriptor.GetProperties(Device); foreach (PropertyDescriptor it in Props) { try { if (!it.IsReadOnly && it.SerializationVisibility != DesignerSerializationVisibility.Hidden) { object value = it.GetValue(tmpDev); object orig = it.GetValue(Device); if (!object.Equals(value, orig)) { it.SetValue(Device, value); } } } catch { continue; } } Device.Keepalive.Ignore = tmpDev.Keepalive.Ignore; Device.Keepalive.Interval = tmpDev.Keepalive.Interval; Device.Keepalive.Target = tmpDev.Keepalive.Target; dlg.OnTrace -= new TraceEventHandler(OnTrace); //Add device description Device.Dirty = true; Device.Description = tmpDev.Description; //Add new categories foreach (GXCategory cat in tmpDev.Categories) { if (Device.Categories.Find(cat.Name) == null) { Device.Categories.Add(cat); } else { GXCategory TargetCat = (GXCategory)Device.Categories.Find(cat.Name); foreach (GXProperty prop in cat.Properties) { if (TargetCat.Properties.Find(prop.Name, null) == null) { TargetCat.Properties.Add(prop); } } } } //Add new notify categories if (tmpDev.Events != null) { foreach (GXCategory cat in tmpDev.Events.Categories) { if (Device.Events.Categories.Find(cat.Name) == null) { Device.Events.Categories.Add(cat); } else { GXCategory TargetCat = (GXCategory)Device.Events.Categories.Find(cat.Name); foreach (GXProperty prop in cat.Properties) { if (TargetCat.Properties.Find(prop.Name, null) == null) { TargetCat.Properties.Add(prop); } } } } } //Add new tables foreach (GXTable table in tmpDev.Tables) { if (Device.Tables.Find(table.Name) == null) { Device.Tables.Add(table); } } if (tmpDev.Events != null) { //Add new notify tables foreach (GXTable table in tmpDev.Events.Tables) { if (Device.Events.Tables.Find(table.Name) == null) { Device.Events.Tables.Add(table); } } } //Update view. ShowProperties(Device); ValidateTasks(); } catch (Exception Ex) { GXCommon.ShowError(ParentComponent, Ex); } }
public GXThread(GXImportDlg parent) { m_Parent = parent; }