public GXDeviceProfilesForm(GXPublishedDeviceProfile target)
        {
            InitializeComponent();
            Target = target;
            NameTB.Text = Target.PresetName;

            bool installed = target.Versions.Count != 0;
            NameTB.ReadOnly = installed;
            AddBtn.Enabled = OKBtn.Enabled = !installed;
            List<int> items = new List<int>(target.Versions.Count);
            //Show selected templates
            if(!string.IsNullOrEmpty(target.PresetName))
            {
                string str = target.Protocol + target.Name;
                UpdateTarget(target);
                items.Add(str.GetHashCode());
                AddBtn.Enabled = false;
            }
            //Show available templates.
            foreach (GXDeviceProfile it in GXDeviceList.GetDeviceTypes(false, null))
            {
                string str = it.Protocol + it.Name;
                if (!items.Contains(str.GetHashCode()))
                {
                    AvailableTemplates.Items.Add(it);
                }
            }
        }
 /// <summary>
 /// Add new device template and select it.
 /// </summary>
 private void AddTemplate(GXDeviceVersion version)
 {
     try
     {
         GXPublishedDeviceProfile type = new GXPublishedDeviceProfile();
         type.Status = DownloadStates.Add;
         GXDeviceProfilesForm dlg = new GXDeviceProfilesForm(type);
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             type = dlg.Target;
             type.Status = DownloadStates.Add;
             version.Templates.Add(type);
             //Add list item.
             ListViewItem li = PresetList.Items.Add(type.PresetName);
             li.Tag = type;
             ItemToListItem[type] = li;
         }
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this.Parent, ex);
     }
 }
 /// <summary>
 /// Edit selected device template.
 /// </summary>
 private void EditTemplate(GXPublishedDeviceProfile type)
 {
     try
     {
         GXDeviceProfilesForm dlg = new GXDeviceProfilesForm(type);
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             TreeNode node = ItemToTreeNode[type] as TreeNode;
             if (node != null)
             {
                 node.Text = type.PresetName;
             }
         }
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this.Parent, ex);
     }
 }
 void UpdateTarget(GXPublishedDeviceProfile item)
 {
     SelectedTemplateTB.Text = item.Name;
     ProtocolTB.Text = item.Protocol;
 }
 private void AddBtn_Click(object sender, EventArgs e)
 {
     try
     {                
         if (AddBtn.Enabled && AvailableTemplates.SelectedItems.Count != 0)
         {
             if (Target != null)
             {
                 AvailableTemplates.Items.Add(Target);
             }
             ListBox.SelectedObjectCollection items = AvailableTemplates.SelectedItems;
             GXPublishedDeviceProfile item = new GXPublishedDeviceProfile(AvailableTemplates.SelectedItems[0] as GXDeviceProfile);
             AvailableTemplates.Items.Remove(items[0]);                    
             Target = item;
             UpdateTarget(item);
         }
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this, ex);
     }
 }