示例#1
0
 void Client_OnDeviceStateChanged(object sender, GuruxAMI.Common.GXAmiDevice[] devices)
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new DeviceStateChangedEventHandler(OnDeviceStateChanged), sender, devices);
     }
     else
     {
         OnDeviceStateChanged(sender, devices);
     }  
 }
		private void CreateDeviceGroupTree(GuruxAMI.Common.GXAmiDevice[] devices, TreeNode rootNode)
		{
            List<TreeNode> nodes = new List<TreeNode>();
			foreach (GuruxAMI.Common.GXAmiDevice device in devices)
			{
                TreeNode node = new TreeNode(device.Name);
                node.Tag = device;
                node.SelectedImageIndex = node.ImageIndex = 2;
                if (IsChecked(device.Id))
                {
                    node.Checked = true;
                }
                nodes.Add(node);
			}
            rootNode.Nodes.AddRange(nodes.ToArray());
		}
示例#3
0
 void OnDeviceStateChanged(object sender, GuruxAMI.Common.GXAmiDevice[] devices)
 {
     try
     {
         foreach (GuruxAMI.Common.GXAmiDevice it in devices)
         {
             ListViewItem node = DeviceToListItem[it.Id] as ListViewItem;
             if (node != null)
             {
                 node.SubItems[1].Text = it.State.ToString();
             }
         }
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, ex);
     }
 }
示例#4
0
 void OnDevicesAdded(object sender, object target, GuruxAMI.Common.GXAmiDevice[] devices)
 {
     try
     {
         List<ListViewItem> list = new List<ListViewItem>();
         foreach (GuruxAMI.Common.GXAmiDevice it in devices)
         {
             string info;
             if (string.IsNullOrEmpty(it.Manufacturer))
             {
                 info = it.Protocol + " " + it.Profile;
             }
             else
             {
                 info = it.Manufacturer + " " + it.Model + " " + it.Version + " " + it.PresetName;
             }
             ListViewItem node = new ListViewItem(new string[] { it.Name, it.State.ToString(), info});
             DeviceToListItem.Add(it.Id, node);
             list.Add(node);
             node.Tag = it;
         }
         DevicesList.Items.AddRange(list.ToArray());                
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, ex);
     }
 }
示例#5
0
 void OnDevicesRemoved(object sender, GuruxAMI.Common.GXAmiDevice[] devices)
 {
     try
     {
         foreach (GuruxAMI.Common.GXAmiDevice it in devices)
         {
             DevicesList.Items.Remove(DeviceToListItem[it.Id] as ListViewItem);
             DeviceToListItem.Remove(it);                    
         }
     }
     catch (Exception ex)
     {
         GXCommon.ShowError(this.ParentComponent, Gurux.DeviceSuite.Properties.Resources.GuruxDeviceSuiteTxt, ex);
     }
 }
        bool IsDBCreated(out GuruxAMI.Client.GXAmiClient cl)
        {
            if (!Gurux.DeviceSuite.Properties.Settings.Default.AmiEnabled)
            {
                Gurux.DeviceSuite.Properties.Settings.Default.AmiHostName = "http://" + AddressTB.Text;
                //Start AMI Server.
                AmiForm.Start(true, true);
            }
            string baseUr = "http://" + AddressTB.Text;
            if (baseUr.Contains('*'))
            {
                baseUr = baseUr.Replace("*", "localhost");
            }
            cl = new GuruxAMI.Client.GXAmiClient(baseUr, 
                Gurux.DeviceSuite.Properties.Settings.Default.AmiUserName, 
                Gurux.DeviceSuite.Properties.Settings.Default.AmiPassword);
            bool created = false;
            try
            {
                created = cl.IsDatabaseCreated();
            }
            catch (System.Net.WebException ex)
            {
                if (ex.Status == System.Net.WebExceptionStatus.ConnectFailure ||
                    ex.Status == System.Net.WebExceptionStatus.ConnectionClosed)
                {
                    created = false;
                }
                else
                {
                    throw ex;
                }
            }
            if (!created)
            {
                if ((DialogResult)this.Invoke(new ShowQuestionEventHandler(OnShowQuestion), "GuruxAMI Database is not created. Do you want to create it?") != DialogResult.Yes)
                {
                    return false;
                }
                if ((DialogResult)this.Invoke(new ShowQuestionEventHandler(OnShowQuestion2), "") == DialogResult.OK)
                {
                    //Close AMI Server and start again.
                    AmiForm.ClosingApplication.Set();
                    AmiForm.ServerThreadClosed.WaitOne();

                    string connStr = string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}",
                        Gurux.DeviceSuite.Properties.Settings.Default.AmiDatabaseHostName, Gurux.DeviceSuite.Properties.Settings.Default.AmiDatabaseName,
                        Gurux.DeviceSuite.Properties.Settings.Default.AmiDBUserName, Gurux.DeviceSuite.Properties.Settings.Default.AmiDBPassword);
                    GXAmiDataCollector dc;
                    using (IDbConnection Db = new OrmLiteConnectionFactory(connStr, true, ServiceStack.OrmLite.MySql.MySqlDialectProvider.Instance).OpenDbConnection())
                    {
                        GXDBService.CreateTables(Db, OnProgress, "gurux", "gurux");
                        dc = GXDBService.AddDataCollector(Db);
                    }
                    dc.Internal = true;
                    AmiForm.Start(true, false);
                    AmiForm.AddDataCollector(new GXAmiDataCollector[] {dc});
                    if (cl.IsDatabaseCreated())
                    {
                        this.Invoke(new ShowQuestionEventHandler(OnMessage), "Database created successfully.");
                    }
                }
            }
            return created;
        }
 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);
 }