/// <summary>
 /// New custom device type is selected.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CustomDeviceType_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         if (CustomDeviceProfile.SelectedItems.Count == 1)
         {
             PresetList.SelectedItems.Clear();
             GXAmiDeviceProfile type = CustomDeviceProfile.SelectedItems[0] as GXAmiDeviceProfile;
             GXAmiDeviceProfile DeviceProfiles = null;
             if (Device != null)
             {
                 DeviceProfiles = FindDeviceProfiles(Device.ProfileId, Templates.ToArray());            
             }
             if (DeviceProfiles == null || 
                 DeviceProfiles.Protocol != type.Protocol ||
                 DeviceProfiles.Profile != type.Name)
             {
                 Device = Client.CreateDevice(type);
                 UIDevice = GXDevice.Create(Device.Protocol, Device.Profile, "");
                 UpdateMedias(false);
             }                     
         }
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this, ex);
     }
 }
 public GXAmiDeviceSettingsForm(GXAmiClient client, GuruxAMI.Common.GXAmiDevice device, GXAmiDataCollector[] dcs)
 {
     InitializeComponent();            
     DataCollectors = dcs;
     AvailableMedias = new List<string>();                    
     Client = client;
     Device = device;
     ulong id = GetAllAvailableMediasFromDCs();
     if (Device != null)
     {
         MediaConnections.AddRange(Device.Medias);
     }
     this.CollectorsCB.Items.Add("");
     foreach (GXAmiDataCollector it in DataCollectors)
     {
         int pos2 = this.CollectorsCB.Items.Add(it);                
         if (id == it.Id)             
         {
             this.CollectorsCB.SelectedIndex = pos2;
         }
     }
     if (this.CollectorsCB.SelectedIndex == -1)
     {
         this.CollectorsCB.SelectedIndex = 0;
     }
     SettingsPanel.Dock = PropertyGrid.Dock = PresetList.Dock = CustomDeviceProfile.Dock = DockStyle.Fill;
     //GuruxAMI.Common.Device type can not be changed after creation. This is for secure reasons.
     PresetCB.Enabled = CustomRB.Enabled = PresetList.Enabled = CustomDeviceProfile.Enabled = Device == null;                  
     CustomDeviceProfile.Visible = false;            
     if (Device != null)
     {
         //Add redundant conections.
         for (int pos = 1; pos < Device.Medias.Length; ++pos)
         {
             AddConnection(Device.Medias[pos]);
         }            
         NameTB.Text = Device.Name;
         RefreshRateTp.Value = new DateTime(((long)Device.UpdateInterval) * 10000000 + RefreshRateTp.MinDate.Ticks);
         UpdateResendCnt(Device.ResendCount);
         UpdateWaitTime(Device.WaitTime);
         //Create UI Device so all assemblys are loaded.
         string path = Path.Combine(Gurux.Common.GXCommon.ApplicationDataPath, "Gurux");
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
             Gurux.Common.GXFileSystemSecurity.UpdateDirectorySecurity(path);
         }
         path = Path.Combine(path, "Gurux.DeviceSuite");
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
             Gurux.Common.GXFileSystemSecurity.UpdateDirectorySecurity(path);
         }
         path = Path.Combine(path, "DeviceProfiles");
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
             Gurux.Common.GXFileSystemSecurity.UpdateDirectorySecurity(path);
         }
         path = Path.Combine(path, Device.ProfileGuid.ToString());
         //Load Device template if not loaded yet.                                 
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
             Gurux.Common.GXFileSystemSecurity.UpdateDirectorySecurity(path);
             byte[] data = Client.GetDeviceProfilesData(Device.ProfileGuid);
             GXZip.Import(this, data, path + "\\");
         }
         path = Path.Combine(path, Device.ProfileGuid.ToString() + ".gxp");
         UIDevice = GXDevice.Load(path);                
     }
     else
     {
         RefreshRateTp.Value = new DateTime(((long)1) * 10000000 + RefreshRateTp.MinDate.Ticks);                
     }
     //Add disabled actions.
     m_DisActions = new DisabledAction(Device == null ? Gurux.Device.DisabledActions.None : (Gurux.Device.DisabledActions)Device.DisabledActions);
     tabControl1.TabPages.Add(m_DisActions.DisabledActionsTB);
     this.Text = Gurux.DeviceSuite.Properties.Resources.DeviceSettingsTxt;
     this.GeneralTab.Text = Gurux.DeviceSuite.Properties.Resources.GeneralTxt;
     //Update helps from the resources.
     this.helpProvider1.SetHelpString(this.NameTB, Gurux.DeviceSuite.Properties.Resources.DeviceNameHelp);
     this.helpProvider1.SetHelpString(this.MediaCB, Gurux.DeviceSuite.Properties.Resources.MediaListHelp);
     this.helpProvider1.SetHelpString(this.RefreshRateTp, Gurux.DeviceSuite.Properties.Resources.RefreshRateHelp);
     this.helpProvider1.SetHelpString(this.OkBtn, Gurux.DeviceSuite.Properties.Resources.OKHelp);
     this.helpProvider1.SetHelpString(this.CancelBtn, Gurux.DeviceSuite.Properties.Resources.CancelHelp);
 }
 /// <summary>
 /// New preset device is selected.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void PresetList_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         if (PresetList.SelectedIndices.Count == 1)
         {
             CustomDeviceProfile.SelectedItems.Clear();
             GXAmiDeviceProfile template = PresetList.SelectedItems[0].Tag as GXAmiDeviceProfile;
             Device = Client.CreateDevice(template);
             UIDevice = GXDevice.Create(Device.Manufacturer, Device.Model, Device.Version, Device.PresetName, "");
             UpdateMedias(false);
         }
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this, ex);
     }         
 }