Beispiel #1
0
        private void Notify(WebSocketConnectionBase connection, Guid subscriptionId, DeviceNotification notification, Device device,
                            bool isInitialNotification = false)
        {
            if (!isInitialNotification)
            {
                var initialNotificationList = GetInitialNotificationList(connection, subscriptionId);
                lock (initialNotificationList) // wait until all initial notifications are sent
                {
                    if (initialNotificationList.Contains(notification.ID))
                    {
                        return;
                    }
                }

                if (!IsDeviceAccessible(connection, device, "GetDeviceNotification"))
                {
                    return;
                }
            }

            connection.SendResponse("notification/insert",
                                    new JProperty("subscriptionId", subscriptionId),
                                    new JProperty("deviceGuid", device.GUID),
                                    new JProperty("notification", GetMapper <DeviceNotification>().Map(notification)));
        }
Beispiel #2
0
        /// <summary>
        /// 通用
        /// </summary>
        /// <param name="deviceNotification"></param>
        /// <returns></returns>
        public async Task SendToDevice(DeviceNotification deviceNotification)
        {
            try
            {
                if (deviceNotification == null)
                {
                    return;
                }

                if (!_onlineManager.IsDeviceOnline(deviceNotification.DeviceId))
                {
                    return;
                }

                if (_options.SignalrBus.UserSignalrBus)
                {
                    await SendAgent(deviceNotification);
                }
                else
                {
                    await _mediator.Publish(deviceNotification);
                }
            }
            catch (Exception ex) {
                _logger.LogWarning($"SendToDevicen2错误:{ JsonHelper.ToJson( deviceNotification )}, {ex}.");
            }
        }
Beispiel #3
0
        public List <DeviceNotification> GetDeviceNotification()
        {
            List <DeviceNotification> savedItems = new List <DeviceNotification>();

            using (var conn = new SQLiteConnection(_connectionString))
                using (var cmd = conn.CreateCommand())
                {
                    conn.Open();
                    cmd.CommandText = "SELECT * FROM DeviceNotifications order by TimeStamp desc";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DeviceNotification text = new DeviceNotification();
                            text.Id        = Convert.ToInt32(reader["ID"].ToString());
                            text.DeviceId  = Convert.ToInt32(reader["DeviceId"].ToString());
                            text.InfoMsg   = (string)reader["InfoMsg"];
                            text.Status    = (string)reader["Status"];
                            text.TimeStamp = Convert.ToDateTime(reader["TimeStamp"]);
                            savedItems.Add(text);
                        }
                    }
                }
            return(savedItems);
        }
Beispiel #4
0
 private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (notificationHandle != IntPtr.Zero)
     {
         DeviceNotification.Unregister(notificationHandle);
     }
 }
Beispiel #5
0
 private void OnShirtRecievedNotification(DeviceNotification notification)
 {
     if (notification == DeviceNotification.ResetOrientation)
     {
         AlignBodyWithHmd();
     }
 }
Beispiel #6
0
        /// <summary>
        /// Notifies the user about new device notification.
        /// </summary>
        /// <action>notification/insert</action>
        /// <response>
        ///     <parameter name="subscriptionId" type="guid">Identifier of the associated subscription.</parameter>
        ///     <parameter name="deviceGuid" type="string">Device unique identifier.</parameter>
        ///     <parameter name="notification" cref="DeviceNotification">A <see cref="DeviceNotification"/> resource representing the notification.</parameter>
        /// </response>
        public void HandleDeviceNotification(int deviceId, int notificationId, string name)
        {
            var subscriptions = _deviceSubscriptionManagerForNotifications.GetSubscriptions(deviceId);

            if (subscriptions.Any())
            {
                Device             device       = null;
                DeviceNotification notification = null;
                foreach (var subscription in subscriptions)
                {
                    var names = (string[])subscription.Data;
                    if (names != null && !names.Contains(name))
                    {
                        continue;
                    }

                    if (notification == null)
                    {
                        notification = DataContext.DeviceNotification.Get(notificationId);
                    }

                    if (device == null)
                    {
                        device = DataContext.Device.Get(deviceId);
                    }

                    Notify(subscription.Connection, subscription.Id, notification, device);
                }
            }
        }
 private void EnfluxManagerOnShirtReceivedNotification(DeviceNotification deviceNotification)
 {
     if (deviceNotification == DeviceNotification.ResetOrientation)
     {
         DoResetOrientationAnimation(false);
     }
 }
 void Windows10_SendSuccessed(object sender, DeviceNotification e)
 {
     lock (db)
     {
         db.DeviceNotifications.DeleteOnSubmit(e);
     }
 }
Beispiel #9
0
        private static void NotificationMarshaler(object o, EventArgs a)
        {
            if (m_currentEvent != null)
            {
                m_currentEvent();

                m_currentEvent = null;
            }
        }
Beispiel #10
0
        protected void RaisePantsNotificationEvent(DeviceNotification pantsNotification)
        {
            var handler = PantsReceivedNotification;

            if (handler != null)
            {
                handler(pantsNotification);
            }
        }
Beispiel #11
0
        protected void RaiseShirtNotificationEvent(DeviceNotification shirtNotification)
        {
            var handler = ShirtReceivedNotification;

            if (handler != null)
            {
                handler(shirtNotification);
            }
        }
 /// <summary>
 /// Creates a device notification by a specified specified message string
 /// </summary>
 /// <param name="status">Message string for notification</param>
 /// <remarks>
 /// This class can be used by implementers to effectively construct device notifications.
 /// Implementers should create instances of this class to pass to <see cref="DeviceEngine.SendNotification">DeviceEngine.SendNotification</see> function.
 /// </remarks>
 /// <example>
 /// The following example shows how to send a device status notification.
 /// <code>
 /// public class SampleDevice : DeviceEngine
 /// {
 ///     public SampleDevice()
 ///     {
 ///         // Perfdorm initialization here
 ///         // ... 
 ///         DeviceCommand += new CommandResultEventHandler(OnDeviceCommand);
 ///     }
 ///     
 ///     // ... 
 ///     
 ///     bool ThemoCloudDevice_DeviceCommand(object sender, CommandEventArgs e)
 ///     {
 ///         DeviceStatusNotification dn = new DeviceStatusNotification("test status notification");
 ///         return SendNotification(dn);
 ///     }
 /// }
 /// </code>
 /// </example>
 public DeviceStatusNotification(string status)
 {
     Data = new DeviceNotification()
     {
         notification = CommandName,
         timestamp = null,
         parameters = new System.Collections.Hashtable()
     };
     Data.parameters.Add(StatusParameter, status);
 }
        /// <summary>
        /// Default constructor for notification messages
        /// </summary>
        /// <param name="notification">Associated DeviceNotification object</param>
        /// <param name="user">Associated User object</param>
        public MessageHandlerContext(DeviceNotification notification, User user = null)
        {
            if (notification == null)
            {
                throw new ArgumentNullException("notification");
            }

            Device       = notification.Device;
            Notification = notification;
            User         = user;
        }
Beispiel #14
0
        public MainForm()
        {
            InitializeComponent();

            inBuffer      = new byte[0];
            outBuffer     = new byte[0];
            featureBuffer = new byte[0];

            //GUID_DEVINTERFACE_HID
            this.notificationHandle = DeviceNotification.Register(this.Handle, new Guid(0x4D1E55B2, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30), DeviceNotificationFlags.WindowHandle);
        }
 private void RenderBlinkStickCell(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
 {
     if (model.GetValue(iter, 0) is DeviceNotification)
     {
         DeviceNotification notification = (DeviceNotification)model.GetValue(iter, 0);
         (cell as Gtk.CellRendererText).Text = notification.BlinkStickSerial;
     }
     else
     {
         (cell as Gtk.CellRendererText).Text = "";
     }
 }
 public DeviceNotification Put(DeviceNotification deviceNotification)
 {
     try
     {
         return(context.PutDeviceNotification(deviceNotification));
     }
     catch (Exception ex)
     {
         logger.Error("Error in Put deviceNotification " + ex.Message);
         return(null);
     }
 }
        private void Notify(WebSocketConnectionBase connection, DeviceNotification notification, Device device)
        {
            var user = (User)connection.Session["user"];

            if (user == null || !IsNetworkAccessible(device.NetworkID, user))
            {
                return;
            }

            connection.SendResponse("notification/insert",
                                    new JProperty("deviceGuid", device.GUID),
                                    new JProperty("notification", NotificationMapper.Map(notification)));
        }
Beispiel #18
0
        /// <summary>
        /// 通用
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task SendToDevice(int deviceId, NotificationObject data)
        {
            try {
                var deviceNotification = new DeviceNotification {
                    DeviceId     = deviceId,
                    Notification = data
                };

                await SendToDevice(deviceNotification);
            }
            catch (Exception ex) {
                _logger.LogWarning($"SendToDevicen2错误:{deviceId},{ JsonHelper.ToJson( data )}, {ex}.");
            }
        }
Beispiel #19
0
        public JObject MapDeviceNotification(DeviceNotification notification, Device device = null)
        {
            var json = GetMapper <DeviceNotification>().Map(notification);

            if (notification.Device != null)
            {
                json["deviceGuid"] = notification.Device.GUID;
            }
            else if (device != null)
            {
                json["deviceGuid"] = device.GUID;
            }
            return(json);
        }
        public void DeviceNotification()
        {
            var network = new Network("N1");

            DataContext.Network.Save(network);
            RegisterTearDown(() => DataContext.Network.Delete(network.ID));

            var deviceClass = new DeviceClass("D1", "V1");

            DataContext.DeviceClass.Save(deviceClass);
            RegisterTearDown(() => DataContext.DeviceClass.Delete(deviceClass.ID));

            var device = new Device(Guid.NewGuid().ToString(), "Test", network, deviceClass);

            DataContext.Device.Save(device);
            RegisterTearDown(() => DataContext.Device.Delete(device.ID));

            var notification = new DeviceNotification("Test", device);

            DataContext.DeviceNotification.Save(notification);
            RegisterTearDown(() => DataContext.DeviceNotification.Delete(notification.ID));

            // test GetByDevice
            var notifications = DataContext.DeviceNotification.GetByDevice(device.ID);

            Assert.Greater(notifications.Count, 0);

            // test Get(id)
            var notification1 = DataContext.DeviceNotification.Get(notification.ID);

            Assert.IsNotNull(notification1);
            Assert.AreEqual("Test", notification1.Notification);
            Assert.AreEqual(device.ID, notification1.DeviceID);

            // test Save
            notification.Notification = "Test2";
            notification.Parameters   = "{ }";
            DataContext.DeviceNotification.Save(notification);
            var notification2 = DataContext.DeviceNotification.Get(notification.ID);

            Assert.AreEqual("Test2", notification2.Notification);
            Assert.AreEqual("{ }", notification2.Parameters);

            // test Delete
            DataContext.DeviceNotification.Delete(notification.ID);
            var notification3 = DataContext.DeviceNotification.Get(notification.ID);

            Assert.IsNull(notification3);
        }
Beispiel #21
0
        /// <summary>
        /// Handles a device notification
        /// </summary>
        /// <param name="notification">DeviceNotification object</param>
        public void Handle(DeviceNotification notification)
        {
            var parameters   = JObject.Parse(notification.Parameters);
            var deviceStatus = (string)parameters["status"];

            if (string.IsNullOrEmpty(deviceStatus))
            {
                throw new Exception("Device status notification is missing required 'status' parameter");
            }

            var device = _deviceRepository.Get(notification.Device.ID);

            device.Status = deviceStatus;
            _deviceRepository.Save(device);
        }
        public Form1()
        {
            InitializeComponent();
            DeviceNotification.RegisterDeviceNotification(this.Handle);
            string[] message = null;
            Thread   t       = new Thread(new ThreadStart(() =>
            {
                message = getDisplays();
            }));

            t.Start();
            t.Join();
            messageListBox.Items.Add(message[0]);
            messageListBox.Items.Add(message[1]);
        }
Beispiel #23
0
        public void RefreshDeviceStatus()
        {
            var devices = DataContext.Device.GetDisconnectedDevices(OFFLINE_STATUS);

            foreach (var device in devices)
            {
                // update device status
                device.Status = OFFLINE_STATUS;
                DataContext.Device.Save(device);

                // save the status diff notification
                var notification = new DeviceNotification(SpecialNotifications.DEVICE_UPDATE, device);
                notification.Parameters = new JObject(new JProperty("status", OFFLINE_STATUS)).ToString();
                DataContext.DeviceNotification.Save(notification);
                _messageBus.Notify(new DeviceNotificationAddedMessage(device.ID, notification.ID, notification.Notification));
            }
        }
Beispiel #24
0
        private static void HandleNotification(DeviceNotification deviceNotification)
        {
            // get the notification object
            var notification = deviceNotification.Notification;

            if (notification.Name == "equipment" && notification.GetParameter <string>("equipment") == LED_CODE)
            {
                // output the current LED state
                var message = "Device sent LED state change notification, new state: {0}";
                Console.WriteLine(string.Format(message, notification.GetParameter <int>("state")));
            }
            else if (notification.Name == "$device-update" && notification.GetParameter <string>("status") != null)
            {
                var message = "Device changed the status, new status: {0}";
                Console.WriteLine(string.Format(message, notification.GetParameter <string>("status")));
            }
        }
Beispiel #25
0
        public void DeviceNotificationTest()
        {
            var network = new Network("N1");

            NetworkRepository.Save(network);

            var deviceClass = new DeviceClass("D1", "V1");

            DeviceClassRepository.Save(deviceClass);

            var device = new Device(Guid.NewGuid(), "key", "Test", network, deviceClass);

            DeviceRepository.Save(device);

            var notification = new DeviceNotification("Test", device);

            DeviceNotificationRepository.Save(notification);

            // test GetByDevice
            var notifications = DeviceNotificationRepository.GetByDevice(device.ID, null, null);

            Assert.Greater(notifications.Count, 0);

            // test Get(id)
            var notification1 = DeviceNotificationRepository.Get(notification.ID);

            Assert.IsNotNull(notification1);
            Assert.AreEqual("Test", notification1.Notification);
            Assert.AreEqual(device.ID, notification1.DeviceID);

            // test Save
            notification.Notification = "Test2";
            notification.Parameters   = "{}";
            DeviceNotificationRepository.Save(notification);
            var notification2 = DeviceNotificationRepository.Get(notification.ID);

            Assert.AreEqual("Test2", notification2.Notification);
            Assert.AreEqual("{}", notification2.Parameters);

            // test Delete
            DeviceNotificationRepository.Delete(notification.ID);
            var notification3 = DeviceNotificationRepository.Get(notification.ID);

            Assert.IsNull(notification3);
        }
Beispiel #26
0
        /// <summary>
        /// Constructor for the Hotplugger class. Requires an initial method to which send messages when a device is
        /// connected or disconencted.
        /// </summary>
        /// <param name="methodDelegate">The method to be executed when a new controller is connected or disconnected.</param>
        public Hotplugger(Delegate methodDelegate)
        {
            // Create a new CreateParameters object.
            CreateParams cp = new CreateParams
            {
                // Specify HWND_MESSAGE in the hwndParent parameter such that the window only receives messages, no rendering, etc.
                Parent = (IntPtr)HWND_MESSAGE
            };

            // Create the handle for the message only window.
            CreateHandle(cp);

            // Adds the specific delegate such that it is ran upon connecting a controller.
            _controllerConnectDelegate += (GetConnectedControllersDelegate)methodDelegate;

            // Register this window to receive controller connect and disconnect notifications.
            _deviceNotificationDispatcher = new DeviceNotification(Handle, false);
        }
Beispiel #27
0
        public void Save(DeviceNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException("notification");
            }

            using (var context = new DeviceHiveContext())
            {
                context.Devices.Attach(notification.Device);
                context.DeviceNotifications.Add(notification);
                if (notification.ID > 0)
                {
                    context.Entry(notification).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Beispiel #28
0
        /// <summary>
        /// Register new or update existing device
        /// </summary>
        public JObject SaveDevice(Device device, JObject deviceJson,
                                  bool verifyNetworkKey = true)
        {
            // load original device for comparison
            var sourceDevice = device.ID > 0 ? DataContext.Device.Get(device.ID) : null;

            // map and validate the device object
            var deviceMapper = GetMapper <Device>();

            ResolveNetwork(deviceJson, verifyNetworkKey);
            ResolveDeviceClass(deviceJson, device.ID == 0);
            deviceMapper.Apply(device, deviceJson);
            Validate(device);

            // save device object
            DataContext.Device.Save(device);

            // replace equipments for the corresponding device class
            if (!device.DeviceClass.IsPermanent && deviceJson["equipment"] is JArray)
            {
                foreach (var equipment in DataContext.Equipment.GetByDeviceClass(device.DeviceClass.ID))
                {
                    DataContext.Equipment.Delete(equipment.ID);
                }
                foreach (JObject jEquipment in (JArray)deviceJson["equipment"])
                {
                    var equipment = GetMapper <Equipment>().Map(jEquipment);
                    equipment.DeviceClass = device.DeviceClass;
                    Validate(equipment);
                    DataContext.Equipment.Save(equipment);
                }
            }

            // save the device diff notification
            var diff             = deviceMapper.Diff(sourceDevice, device);
            var notificationName = sourceDevice == null ? SpecialNotifications.DEVICE_ADD : SpecialNotifications.DEVICE_UPDATE;
            var notification     = new DeviceNotification(notificationName, device);

            notification.Parameters = diff.ToString();
            DataContext.DeviceNotification.Save(notification);
            _messageBus.Notify(new DeviceNotificationAddedMessage(device.ID, notification.ID));

            return(deviceMapper.Map(device));
        }
        /// <summary>
        /// Register new or update existing device.
        /// </summary>
        /// <param name="device">Source device to update.</param>
        /// <param name="deviceJson">A JSON object with device properties.</param>
        /// <param name="verifyNetworkKey">Whether to verify if a correct network key is passed.</param>
        /// <param name="networkAccessCheck">An optional delegate to verify network access control.</param>
        public JObject SaveDevice(Device device, JObject deviceJson,
                                  bool verifyNetworkKey = true, Func <Network, bool> networkAccessCheck = null)
        {
            // load original device for comparison
            var sourceDevice = device.ID > 0 ? DataContext.Device.Get(device.ID) : null;

            // map and validate the device object
            var deviceMapper = GetMapper <Device>();

            deviceMapper.Apply(device, deviceJson);
            Validate(device);

            // resolve and verify associated objects
            ResolveNetwork(device, verifyNetworkKey, networkAccessCheck);
            ResolveDeviceClass(device);

            // save device object
            DataContext.Device.Save(device);

            // backward compatibility with 1.2 - equipment was passed on device level
            if (!device.DeviceClass.IsPermanent && deviceJson["equipment"] is JArray)
            {
                device.DeviceClass.Equipment = new List <Equipment>();
                foreach (JObject jEquipment in (JArray)deviceJson["equipment"])
                {
                    var equipment = GetMapper <Equipment>().Map(jEquipment);
                    Validate(equipment);
                    device.DeviceClass.Equipment.Add(equipment);
                }
                DataContext.DeviceClass.Save(device.DeviceClass);
            }

            // save the device diff notification
            var diff             = deviceMapper.Diff(sourceDevice, device);
            var notificationName = sourceDevice == null ? SpecialNotifications.DEVICE_ADD : SpecialNotifications.DEVICE_UPDATE;
            var notification     = new DeviceNotification(notificationName, device);

            notification.Parameters = diff.ToString();
            DataContext.DeviceNotification.Save(notification);
            _messageBus.Notify(new DeviceNotificationAddedMessage(device.ID, notification.ID, notification.Notification));

            return(deviceMapper.Map(device));
        }
Beispiel #30
0
        /// <summary>
        /// Processes income notificaton
        /// </summary>
        /// <param name="notification">DeviceNotification object</param>
        public void ProcessNotification(DeviceNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException("notification");
            }

            foreach (var handler in _notificationHandlers[notification.Notification])
            {
                try
                {
                    handler.Handle(notification);
                }
                catch (Exception ex)
                {
                    LogManager.GetLogger(GetType()).Error("Notification handler generated exception!", ex);
                }
            }
        }
Beispiel #31
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == 0x0219)                //WM_DEVICECHANGE
            {
                switch (m.WParam.ToInt32())
                {
                case 0x8000:                            //DBT_DEVICEARRIVAL
                    Thread.Sleep(100);
                    UsbAttach(DeviceNotification.GetDeviceName(m.LParam));
                    break;

                case 0x8004:                            //DBT_DEVICEREMOVECOMPLETE
                    UsbDetatch(DeviceNotification.GetDeviceName(m.LParam));
                    break;
                }
            }
        }
Beispiel #32
0
        public void SetUpWorkings()
        {
            descriptionUpdater = new VoidDelegate(UpdateServerDescription);
             connectionHandler = new DeviceNotification(DeviceManagement_NetworkConnected);

             InitialiseWiFi();

             log.Name = "log";
             log.LogMessage += new LogMessageEventHandler(log_LogMessage);
             log.Start();

             #region Regestry data setup

             RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(SensorShareConfig.ConfigKeyName);

             bool createNewConfig = true;

             object regKey = registryKey.GetValue("ServerID");

             if (regKey != null)
             {
            Guid serverID = new Guid((string)regKey);
            CurrentServerData = DatabaseHelper.GetServerByID(database, serverID);
            if (CurrentServerData != null)
            {
               createNewConfig = false;
            }
            else
            {
               log.Append("Server ID saved in Registry not found");
            }
             }

            #endregion

             #region Server Configuration Setup

             if (createNewConfig)
             {
            log.Append("Need to create a new server configuration");
            // Show server config before starting server (which is automatically done when config box is closed)
            Bitmap serverPic = new Bitmap(Application2.StartupPath + "/defaultImage.jpg");
            CurrentServerData = new ServerData(Guid.Empty, "New Server", "Location", "Description", new SensorDescriptionsData(), JpegImage.GetBytes(serverPic));
            configMenuItem_Click(this, new EventArgs());
             }
             else
             {
            //If config isn't needed, start now
            registryKey.Close();
            log.Append("Starting with server: " + CurrentServerData.id.ToString() + " " + CurrentServerData.name);

            // Save sensor data laoded from database (past session)
            SensorDescriptionsData loadedSensors = new SensorDescriptionsData();
            foreach (SensorDefinition sensor in CurrentServerData.sensors)
            {
               loadedSensors.Add(sensor);
            }
            //Clear current data as logbook isn't connected yet so sensors are unknown
            CurrentServerData.sensors.Clear();
            InitialiseLogbook(); // Set up logbook data

            // Connect Logbook and send identify commands (reply comes on other threads
            ConnectLogbookAndIdentifySensors();
            // Should have done Thread.Sleep in above method to allow reply to have come by now
            // Check sensors match the database version
            ConfirmSensors();

            bool sensorSelectionNotCompleted = true;
            while (sensorSelectionNotCompleted)
            {
               // check that the sensors connected are the same
               bool sameSensorsConnected = true;
               lock (CurrentServerData.sensors)
               {
                  if (loadedSensors.Count != CurrentServerData.sensors.Count)
                  {
                     sameSensorsConnected = false;
                  }
                  else
                  {

                     for (int s = 0; s < loadedSensors.Count; s++)
                     {
                        if ((loadedSensors[s].ID != CurrentServerData.sensors[s].ID) || (loadedSensors[s].Range != CurrentServerData.sensors[s].Range))
                        {
                           sameSensorsConnected = false;
                        }
                     }

                  }
               }
               if (!sameSensorsConnected)
               {
                  DialogResult result = MessageBox.Show("The sensors currently attached to the Logbook do not match the previously saved sensors.  Click Retry to change the sensors, or Cancel to create a new server configuration.", "Different Sensors Connected",
                  MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                  if (result == DialogResult.Retry)
                  {
                     disconnectLogbook();
                     StringBuilder sb = new StringBuilder();
                     sb.Append("You need to connect the following sensors:\r\n");
                     foreach (SensorDefinition sensor in loadedSensors)
                     {
                        sb.AppendFormat("{0}\r\n", sensor.Description);
                     }
                     MessageBox.Show(sb.ToString(), "Sensors Required", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                     CurrentServerData.sensors.Clear();
                     ConnectLogbookAndIdentifySensors();
                     ConfirmSensors();
                  }
                  else
                  {
                     if (result == DialogResult.Cancel)
                     {
                        CurrentServerData.id = Guid.NewGuid();
                        DatabaseHelper.SaveServerConfigData(database, CurrentServerData);
                        sensorSelectionNotCompleted = false;
                     }
                  }
               }
               else
               {
                  sensorSelectionNotCompleted = false;
               }
            }
            StartServer();
             }
             #endregion

             DeviceManagement.NetworkConnected += connectionHandler;
        }
Beispiel #33
0
 internal static extern IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr notificationFilter, DeviceNotification flags);
Beispiel #34
0
 public static extern HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient,
     LPVOID NotificationFilter, DeviceNotification Flags);
 public void SendNotification(DeviceNotification notification)
 {
     _host.SendNotification(_device, notification);
 }
Beispiel #36
0
 public static IntPtr RegisterDeviceNotification(IntPtr hRecipient, IntPtr NotificationFilter, DeviceNotification Flags);
Beispiel #37
0
        private void SetUpWorkings()
        {
            closeDelegate = new VoidDelegate(this.Close);
             connectionHandler = new DeviceNotification(DeviceManagement_NetworkConnected);

             InitialiseWiFi();

             log.Name = "log";
             log.LogMessage += new LogMessageEventHandler(log_LogMessage);
             log.Start();

             DeviceManagement.NetworkConnected += connectionHandler;

             aliveServers = new ObjectCache(7000);
             receiveHandler = new MessageEventHandler(networkNode_MessageReceived);
             aliveServers.ItemExpired += new ItemExpiredEventHandler(aliveServers_ItemExpired);

             ClientID = Guid.NewGuid();
             networkNode = new NetworkNode(ClientID, IPAddress.Any, SensorShareConfig.CommunicationPort);
             networkNode.MessageReceived += receiveHandler;
        }
        /// <summary>
        /// Sends a notification on behalf of the specified device.
        /// </summary>
        /// <param name="sender">Sender <see cref="DeviceBase"/> object.</param>
        /// <param name="notification"><see cref="DeviceNotification"/> object to send.</param>
        public void SendNotification(DeviceBase sender, DeviceNotification notification)
        {
            if (sender == null)
                throw new ArgumentNullException("sender");
            if (notification == null)
                throw new ArgumentNullException("notification");

            Logger.InfoFormat("Sending notification '{0}' from device {1} ({2})", notification.Name, sender.ID, sender.Name);

            try
            {
                var cNotification = new Notification(notification.Name.Trim(),
                    notification.Parameters == null ? null : notification.Parameters.DeepClone());
                DeviceClient.SendNotification(sender.ID, sender.Key, cNotification);
            }
            catch (Exception ex)
            {
                // critical error - log and fault the service
                Logger.Error(string.Format("Exception while sending notification '{0}' from device {1} ({2})", notification.Name, sender.ID, sender.Name), ex);
                throw;
            }
        }
Beispiel #39
0
            public void SendNotification(DeviceNotification notification)
            {
                if (notification == null)
                    throw new ArgumentNullException("notification");

                _host.SendNotification(_device, notification);
            }