예제 #1
0
 public bool DeviceCreate(Device device, Guid session)
 {
     ClientSession _session = ClientSession.Get(session);
     if (_session == null) return false;
     if (!_session.UserHasAdminPermission) return false;
     return DeviceManager.Instance.Create(device, _session.Connection);
 }
예제 #2
0
파일: Driver.cs 프로젝트: ziyan/reactivity
 void client_DeviceUpdated(object source, Device device)
 {
     // Device updated
     if (!client.DeviceIsRegistered(device.Guid)) return;
     Console.WriteLine("[Server] Device updated: " + device.Guid.ToString());
     //Util.DeviceConfigurationAdapter adapter = Util.DeviceConfigurationAdapter.CreateAdapter(client.DeviceGet(device).Configuration);
 }
예제 #3
0
 public bool Create(Device device, Data.Connection connection)
 {
     if (device == null || device.Guid == Guid.Empty) return false;
     devices_mutex.WaitOne();
     if (devices.ContainsKey(device.Guid))
     {
         devices_mutex.ReleaseMutex();
         return false;
     }
     if (Data.StoredProcedure.DeviceCreate(device.Guid, device.Name, device.Description, device.Type, device.Profile, device.Configuration, connection))
     {
         device.Status = DeviceStatus.Offline;
         devices[device.Guid] = device;
         devices_mutex.ReleaseMutex();
         Clients.ClientSession.Notify(new ClientEvent { Type = ClientEventType.DeviceCreation, Device = device, Timestamp = DateTime.Now });
         return true;
     }
     devices_mutex.ReleaseMutex();
     return false;
 }
예제 #4
0
 public static Device DeviceGetByGuid(Guid guid, Connection connection)
 {
     SqlCommand cmd = _setup("r_device_get_by_guid", connection);
     _param(cmd, "@guid", SqlDbType.VarChar, guid.ToString());
     Device device = null;
     SqlDataReader reader = cmd.ExecuteReader();
     if (reader.Read())
         device = new Device
         {
             Guid = new Guid(reader["r_guid"].ToString()),
             Name = reader["r_name"].ToString(),
             Description = reader["r_description"].ToString(),
             Type = new Guid(reader["r_type"].ToString()),
             Profile = reader["r_profile"].ToString(),
             Configuration = reader["r_configuration"].ToString(),
             Status = DeviceStatus.Unknown
         };
     reader.Close();
     reader.Dispose();
     return device;
 }
예제 #5
0
        public DeviceEditDialog(Device device)
        {
            InitializeComponent();

            this.DeviceType.Items.Add(new ComboBoxItem { Content = "Temperature Sensor {" + Util.DeviceType.TemperatureSensor.ToString() + "}" });
            this.DeviceType.Items.Add(new ComboBoxItem { Content = "Luminosity Sensor {" + Util.DeviceType.LuminositySensor.ToString() + "}" });
            this.DeviceType.Items.Add(new ComboBoxItem { Content = "AC Node {" + Util.DeviceType.ACNode.ToString() + "}" });
            this.DeviceType.Items.Add(new ComboBoxItem { Content = "Motion Sensor {" + Util.DeviceType.MotionSensor.ToString() + "}" });
            this.DeviceType.Items.Add(new ComboBoxItem { Content = "RFID Reader {" + Util.DeviceType.RFIDReader.ToString() + "}" });
            this.DeviceType.Items.Add(new ComboBoxItem { Content = "Computer Node {" + Util.DeviceType.ComputerNode.ToString() + "}" });
            this.DeviceType.Items.Add(new ComboBoxItem { Content = "Acceleration Sensor {" + Util.DeviceType.AccelerationSensor.ToString() + "}" });

            this.backgroundWorker = new BackgroundWorker();
            this.backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
            this.backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

            this.indexBackgroundWorker = new BackgroundWorker();
            this.indexBackgroundWorker.DoWork += new DoWorkEventHandler(indexBackgroundWorker_DoWork);
            this.indexBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(indexBackgroundWorker_RunWorkerCompleted);

            this.resourceBackgroundWorker = new BackgroundWorker();
            this.resourceBackgroundWorker.DoWork += new DoWorkEventHandler(resourceBackgroundWorker_DoWork);
            this.resourceBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(resourceBackgroundWorker_RunWorkerCompleted);

            if (device != null)
                this.device = (Device)device.Clone();
            else
            {
                this.device = new Device { Guid = Guid.NewGuid(),
                    Name = "<New Device>", Description = "",
                    Type = Guid.Empty, Configuration = "",
                    Profile = "<profile>\n<building id=\"10000000-0000-0000-0000-000000000000\">\n<floor level=\"0\">\n<position x=\"0\" y=\"0\" z=\"0\" />\n</floor></building></profile>",
                    Status = DeviceStatus.Unknown };
                modification = false;
            }
            //Initialize
            this.profile = Util.DeviceProfileAdapter.CreateAdapter(this.device.Profile);
            this.configuration = Util.DeviceConfigurationAdapter.CreateAdapter(this.device.Configuration);

            this.DeviceGuid.Text = this.device.Guid.ToString();
            this.DeviceGuid.IsReadOnly = modification;
            this.DeviceName.Text = this.device.Name;
            this.DeviceDescription.Text = this.device.Description;
            this.DeviceProfileX.Text = profile.X.ToString();
            this.DeviceProfileY.Text = profile.Y.ToString();
            this.DeviceProfileZ.Text = profile.Z.ToString();
            this.DeviceType.Text = this.device.Type.ToString();

            foreach (string key in configuration.Settings.Keys)
                configurations.Add(new Configuration { Key = key, Value = configuration.Settings[key] });

            // set up bindings
            FloorsBinding = new Binding();
            FloorsBinding.Source = floors;
            DeviceProfileFloor.SetBinding(ComboBox.ItemsSourceProperty, FloorsBinding);

            BuildingsBinding = new Binding();
            BuildingsBinding.Source = buildings;
            DeviceProfileBuilding.SetBinding(ComboBox.ItemsSourceProperty, BuildingsBinding);

            ConfigurationListBinding = new Binding();
            ConfigurationListBinding.Source = configurations;
            ConfigurationListView.SetBinding(ListView.ItemsSourceProperty, ConfigurationListBinding);

            // get index
            this.indexBackgroundWorker.RunWorkerAsync();
        }
예제 #6
0
 public bool Update(Device device, Data.Connection connection)
 {
     if (device == null || device.Guid == Guid.Empty) return false;
     devices_mutex.WaitOne();
     if (!devices.ContainsKey(device.Guid))
     {
         devices_mutex.ReleaseMutex();
         return false;
     }
     if (Data.StoredProcedure.DeviceUpdateByGuid(device.Guid, device.Name, device.Description, device.Type, device.Profile, device.Configuration, connection))
     {
         devices[device.Guid].Name = device.Name;
         devices[device.Guid].Description = device.Description;
         devices[device.Guid].Type = device.Type;
         devices[device.Guid].Profile = device.Profile;
         devices[device.Guid].Configuration = device.Configuration;
         device = devices[device.Guid];
         devices_mutex.ReleaseMutex();
         Nodes.NodeSession.Notify(new NodeEvent { Type = NodeEventType.DeviceUpdate, Device = device, Timestamp = DateTime.Now });
         Clients.ClientSession.Notify(new ClientEvent { Type = ClientEventType.DeviceUpdate, Device = device, Timestamp = DateTime.Now });
         return true;
     }
     devices_mutex.ReleaseMutex();
     return false;
 }
예제 #7
0
파일: Client.cs 프로젝트: ziyan/reactivity
 private void DeviceUpdatedHandler(Device device)
 {
     if (!UserIsLoggedIn) return;
     devices_mutex.WaitOne();
     if (devices != null)
         foreach (Device d in devices)
             if (d.Guid == device.Guid)
             {
                 d.Description = device.Description;
                 d.Name = device.Name;
                 d.Status = device.Status;
                 d.Profile = device.Profile;
                 d.Type = device.Type;
                 d.Configuration = device.Configuration;
                 int index = devices.IndexOf(d);
                 devices.Remove(d);
                 devices.Insert(index, d);
                 break;
             }
     devices_mutex.ReleaseMutex();
 }
예제 #8
0
파일: Client.cs 프로젝트: ziyan/reactivity
 private void DeviceCreatedHandler(Device device)
 {
     if (!UserIsLoggedIn) return;
     if (devices != null)
     {
         devices_mutex.WaitOne();
         bool exists_in_devices = false;
         foreach (Device d in devices)
             if (d.Guid == device.Guid)
             {
                 exists_in_devices = true;
                 break;
             }
         if (!exists_in_devices)
             devices.Insert(0, device);
         devices_mutex.ReleaseMutex();
     }
 }
예제 #9
0
파일: Client.cs 프로젝트: ziyan/reactivity
 private void DeviceUpdatedHandler(Device device)
 {
     devices_mutex.WaitOne();
     if (!devices.ContainsKey(device.Guid))
     {
         devices_mutex.ReleaseMutex();
         return;
     }
     devices[device.Guid].Name = device.Name;
     devices[device.Guid].Description = device.Description;
     devices[device.Guid].Profile = device.Profile;
     devices[device.Guid].Configuration = device.Configuration;
     devices[device.Guid].Status = device.Status;
     device = devices[device.Guid];
     devices_mutex.ReleaseMutex();
     if (DeviceUpdated != null)
         DeviceUpdated(this, device);
 }
예제 #10
0
 public void TryConnect()
 {
     try
     {
         //make sure client is connected
         if (client == null || !client.IsOpen)
         {
             client = new Client(System.Configuration.ConfigurationManager.AppSettings["Reactivity.Nodes.Computer.ServiceUri"]);
             client.DeviceUpdated += new DeviceUpdateHandler(client_DeviceUpdated);
             client.DeviceDeregistered += new DeviceDeregisteredHandler(client_DeviceDeregistered);
             client.DataReceived += new DataReceptionHandler(client_DataReceived);
         }
     }
     catch
     {
         if (client != null) client.Close();
         client = null;
         return;
     }
     try
     {
         //make sure device is registered
         Guid device_guid = new Guid(System.Configuration.ConfigurationManager.AppSettings["Reactivity.Nodes.Computer.Device"]);
         if (!client.DeviceIsRegistered(device_guid))
         {
             if (device_timer.Enabled)
                 device_timer.Stop();
             device = null;
             if (!client.DeviceRegister(device_guid))
                 return;
             device = client.DeviceGet(device_guid);
             if (device == null) return;
             Util.DeviceConfigurationAdapter adapter = Util.DeviceConfigurationAdapter.CreateAdapter(device.Configuration);
             if (adapter.Settings.ContainsKey("Interval"))
                 device_timer.Interval = Convert.ToDouble(adapter.Settings["Interval"]);
             device_timer.Start();
         }
     }
     catch { TryReset(); }
 }
예제 #11
0
 void client_DeviceUpdated(object source, Reactivity.Objects.Device device)
 {
     if (this.device == null || device == null) return;
     if (device.Guid != this.device.Guid) return;
     if (device_timer.Enabled)
         device_timer.Stop();
     this.device = device;
     device_timer.Interval = 1000;
     try
     {
         Util.DeviceConfigurationAdapter adapter = Util.DeviceConfigurationAdapter.CreateAdapter(this.device.Configuration);
         device_timer.Interval = Convert.ToDouble(adapter.Settings["Interval"]);
     }
     catch { }
     device_timer.Start();
 }
예제 #12
0
 void client_DeviceDeregistered(object source, Guid device)
 {
     if (device_timer.Enabled)
         device_timer.Stop();
     this.device = null;
     TryConnect();
 }
예제 #13
0
파일: Client.cs 프로젝트: ziyan/reactivity
 public bool DeviceUpdate(Device device)
 {
     if (device == null || device.Guid == Guid.Empty || device.Type == Guid.Empty)
         throw new ArgumentException();
     SessionCheck();
     if (!UserHasAdminPermission) throw new PermissionDeniedException();
     return service.DeviceUpdate(device, session);
 }