/**
             *@brief handle connects and disconnects
             */
            private void Run()
            {
                byte[] data = new byte[native.Networking.kPacketSize];
                native.Networking.ErrorMessage msg = 0;
                Message message = new Message();
                UInt32  id      = 0;

                while (run_)
                {
                    if (native.Networking.SNetIsConnected() == false)
                    {
                        msg = native.Networking.SNetEditorConnect("localhost", 8008);
                        native.Networking.SNetRetrievePacket(ref id, data, (uint)data.Length);
                    }
                    else
                    {
                        NotificationEventArgs args = new NotificationEventArgs(message,
                                                                               (uint)Notifications.kConnected,
                                                                               id <MessageHandler> .type_id_);
                        OnNotification handler = notify_subscribers;
                        handler?.Invoke(this, args);
                        ProcessMessages();
                    }
                    Thread.Sleep(1000 / 30);
                }
            }
Beispiel #2
0
        public async void Start()
        {
            client = new HttpClient();
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);

            var stream = await client.GetStreamAsync(url);

            var reader = new StreamReader(stream);

            string eventName = null;
            string data      = null;

            while (client != null)
            {
                var line = reader.ReadLine();


                if (string.IsNullOrEmpty(line) || line.StartsWith(":"))
                {
                    eventName = data = null;
                    continue;
                }

                if (line.StartsWith("event: "))
                {
                    eventName = line.Substring("event: ".Length).Trim();
                }
                else if (line.StartsWith("data: "))
                {
                    data = line.Substring("data: ".Length);

                    switch (eventName)
                    {
                    case "update":
                        var status = JsonConvert.DeserializeObject <Status>(data);
                        OnUpdate?.Invoke(this, new StreamUpdateEventArgs()
                        {
                            Status = status
                        });
                        break;

                    case "notification":
                        var notification = JsonConvert.DeserializeObject <Notification>(data);
                        OnNotification?.Invoke(this, new StreamNotificationEventArgs()
                        {
                            Notification = notification
                        });
                        break;

                    case "delete":
                        var statusId = int.Parse(data);
                        OnDelete?.Invoke(this, new StreamDeleteEventArgs()
                        {
                            StatusId = statusId
                        });
                        break;
                    }
                }
            }
        }
Beispiel #3
0
        protected void SendEvent(string eventName, string data)
        {
            switch (eventName)
            {
            case "update":
                var status = JsonConvert.DeserializeObject <Status>(data);
                OnUpdate?.Invoke(this, new StreamUpdateEventArgs(status));
                break;

            case "notification":
                var notification = JsonConvert.DeserializeObject <Notification>(data);
                OnNotification?.Invoke(this, new StreamNotificationEventArgs(notification));
                break;

            case "delete":
                var statusId = (data);
                OnDelete?.Invoke(this, new StreamDeleteEventArgs(statusId));
                break;

            case "filters_changed":
                OnFiltersChanged?.Invoke(this, new StreamFiltersChangedEventArgs());
                break;

            case "conversation":
                var conversation = JsonConvert.DeserializeObject <Conversation>(data);
                OnConversation?.Invoke(this, new StreamConversationEvenTargs(conversation));
                break;
            }
        }
        /**
         * @brief Sends an notification that the window was dragged.
         */
        private void Dragged()
        {
            OnNotification        handler = notify_subscribers_;
            NotificationEventArgs args    = new NotificationEventArgs(null, (uint)Notifications.kDragMove, id <TabItem> .type_id_);

            handler?.Invoke(this, args);
        }
Beispiel #5
0
        private async void DataSourceCharacteristicOnValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            var stream = args.CharacteristicValue.AsStream();
            var br     = new BinaryReader(stream);

            var cmdId    = br.ReadByte();
            var notUid   = br.ReadUInt32();
            var attr1    = (NotificationAttribute)br.ReadByte();
            var attr1len = br.ReadUInt16();
            var attr1val = br.ReadChars(attr1len);
            var attr2    = (NotificationAttribute)br.ReadByte();
            var attr2len = br.ReadUInt16();
            var attr2val = br.ReadChars(attr2len);

            EventFlags?flags = null;

            if (FlagCache.ContainsKey(notUid))
            {
                flags = FlagCache[notUid];
            }

            var not = new PlainNotification()
            {
                EventFlags = flags,
                Uid        = notUid,
                Title      = new string(attr1val),
                Message    = new string(attr2val)
            };

            OnNotification?.Invoke(not);
        }
Beispiel #6
0
        private void ProcessMessage(string sBody)
        {
            // Check if this is sensort notification
            if (NotificationEventSchema.IsValid(sBody))
            {
                OnNotificationEventArgs eventData = JsonConvert.DeserializeObject <OnNotificationEventArgs>(sBody);

                if (eventData != null && OnNotification != null)
                {
                    OnNotification.Invoke(sBody, eventData);
                }
            }
            else if (ScheduleUpdateEventSchema.IsValid(sBody))
            {
                OnScheduleUpdateEventArgs eventData = JsonConvert.DeserializeObject <OnScheduleUpdateEventArgs>(sBody);

                eventData.Schedule = this.FilterAppointments(eventData);
                if (eventData != null && OnScheduleUpdate != null)
                {
                    OnScheduleUpdate.Invoke(sBody, eventData);
                }
            }
            else
            {
                /// Unknow schema - probably an error
                this.LogEvent(EventTypeConsts.Error, "Unknown json format", sBody);
            }
        }
Beispiel #7
0
 //注册事件
 public void AddEventListener(string eventName, OnNotification notific)
 {
     if (!eventListener.ContainsKey(eventName))
     {
         eventListener.Add(eventName, notific);
     }
 }
Beispiel #8
0
            /**
             *@brief handle the GotKeyboardFocus event by handling the file_queue. The file queue is build up when the editor lost focus and file operations are done in the workspace.
             *@param[in] sender (object) original object that fired the event
             *@param[in] e (KeyboardFocusChangedEventArgs) argumants passed when the event was fired
             *@remark this event can be fired by any control in the editor but the queue is only handled if the old focus was outside the editor
             *@remark for every file in the file queue an event is fired to notify subscribers
             *@see sulphur.editor.Workspace.Notifications
             *@see sulphur.editor.Workspace.FileWatcherChanged
             *@see sulphur.editor.Workspace.FileWatcherCreated
             *@see sulphur.editor.Workspace.OnFileWatcherRenamed
             */
            private void OnMainWindowFocus(object sender, KeyboardFocusChangedEventArgs e)
            {
                if (e.OldFocus != null)
                {
                    return;
                }
                file_watcher_.EnableRaisingEvents = false;

                while (file_queue_.Count > 0)
                {
                    for (int i = 0; i < file_queue_.Count; ++i)
                    {
                        string                file    = file_queue_[i].path;
                        OnNotification        handler = notify_subscribers_;
                        FileInfo              info    = new FileInfo(file);
                        NotificationEventArgs args    =
                            new NotificationEventArgs(info,
                                                      (uint)file_queue_[i].file_operation,
                                                      id <Workspace> .type_id_);

                        if (file_queue_[i].file_operation == Notifications.kFileRemoved)
                        {
                            handler?.Invoke(this, args);
                            file_queue_.RemoveAt(i);
                        }
                        else if (file_queue_[i].file_operation != Notifications.kFileRemoved && FileArrived(file) == true)
                        {
                            handler?.Invoke(this, args);
                            file_queue_.RemoveAt(i);
                        }
                    }
                }
                e.Handled = true;
            }
Beispiel #9
0
            /**
             * @brief Implementation of the new_root_entity_cmd_ and new_entity_cmd_ commands
             * @param[in] obj (WorldObject) The entity to add to the hierarchy.
             * @param[in] parent (sulphur.editor.WorldObject) The parameter passed to the
             *   command. This parameter will become the parent for the newly created
             *   entity.
             * @remarks Passing null for the parent will parent the entity to the root.
             * @remarks This function is mainly used to construct an entity before adding it to the hierarchy. this way all components can be added to the entity up front.
             */
            public void AddEntity(WorldObject obj, WorldObject parent)
            {
                WorldObject new_object = hierarchy.Add(obj, parent);

                OnNotification        handler = notify_subscribers_;
                NotificationEventArgs args    = new NotificationEventArgs(
                    new_object,
                    (uint)Notifications.kEntityAdded,
                    id <WorldHierarchy> .type_id_);

                handler?.Invoke(this, args);

                // Notify the engine
                native.messages.EntityCreatedMessage msg = new native.messages.EntityCreatedMessage();
                msg.entity_index  = (UInt64)new_object.GetIndex();
                msg.sibling_index = (UInt64)new_object.GetSiblingIndex();
                msg.parent_index  = parent != null ? (UInt64)parent.GetIndex() : UInt64.MaxValue;

                msg.position = new float[3] {
                    0.0f, 0.0f, 0.0f
                };
                msg.rotation = new float[4] {
                    0.0f, 0.0f, 0.0f, 0.0f
                };
                msg.scale = new float[3] {
                    1.0f, 1.0f, 1.0f
                };

                byte[] data = Utils.StructToBytes(msg);
                native.Networking.SNetSendData(
                    (uint)native.NetworkMessages.kEntityCreated,
                    data,
                    (uint)data.Length);
            }
Beispiel #10
0
 /// <summary>
 /// 注册事件
 /// </summary>
 /// <param name="eventKey">事件key</param>
 /// <param name="eventListener">事件监听器</param>
 public void AddListener(string eventKey, OnNotification eventListener)
 {
     if (!eventListners.ContainsKey(eventKey))
     {
         eventListners.Add(eventKey, eventListener);
     }
 }
Beispiel #11
0
        public void Receive(object obj, BasicDeliverEventArgs args)
        {
            var jsonData   = Encoding.UTF8.GetString(args.Body);
            var jsonObject = JsonConvert.DeserializeObject <OutputMessage>(jsonData);

            OnNotification?.Invoke(jsonObject);
        }
Beispiel #12
0
 /// <summary>
 /// Notice that the warehouse is full
 /// </summary>
 public void WarehouseFull()
 {
     OnNotification += () =>
     {
         MessageBox.Show("There is no space in the warehouse.");
     };
     OnNotification.Invoke();
 }
 public void WarehouseFull(string article)
 {
     OnNotification += () =>
     {
         MessageBox.Show("Article '" + article + "' can not be stored because the amount is over 100");
     };
     OnNotification.Invoke();
 }
Beispiel #14
0
 protected override void InsertItem(int index, Notification item)
 {
     base.InsertItem(index, item);
     if (IsInitialFetchDone)
     {
         OnNotification?.Invoke(this, item);
     }
 }
 /// <summary>
 /// 移除系统事件监听
 /// </summary>
 /// <param name="type"></param>
 /// <param name="listener"></param>
 public void RemoveListener(SFSEvent type, OnNotification listener)
 {
     if (eventListeners.ContainsKey(type.Type))
     {
         return;
     }
     eventListeners[type.Type] -= listener;
 }
Beispiel #16
0
 public void NoRemainingSpace()
 {
     OnNotification = () =>
     {
         MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Product did not store. Reason: Missing available space.", "Notification");
     };
     OnNotification.Invoke();
 }
Beispiel #17
0
 public void ProductAlreadyStored()
 {
     OnNotification = () =>
     {
         MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Product did not store. Reason: Product is already stored.", "Notification");
     };
     OnNotification.Invoke();
 }
Beispiel #18
0
 public void StoreSuccessfull()
 {
     OnNotification = () =>
     {
         MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Product successfully stored.", "Notification");
     };
     OnNotification.Invoke();
 }
Beispiel #19
0
 //Event that will be raised when product is stored succsesfuly
 public void ProductStored()
 {
     OnNotification += () =>
     {
         MessageBox.Show("Product is stored in the warehouse");
     };
     OnNotification.Invoke();
 }
Beispiel #20
0
 public static T Show <T>(T notification) where T : Notification
 {
     if (OnNotification != null)
     {
         OnNotification.Invoke(notification);
     }
     return(notification);
 }
Beispiel #21
0
 public Task NotifyUsers <TNotificationBase>(TNotificationBase notification, IEnumerable <Guid> userIds) where TNotificationBase : INotification
 {
     foreach (var userId in userIds)
     {
         OnNotification?.Invoke(notification, userId);
     }
     return(Task.CompletedTask);
 }
Beispiel #22
0
 //Event that will be raised when warehouse capacity is full
 public void WarehouseFull()
 {
     OnNotification += () =>
     {
         MessageBox.Show("Warehouse capacity is 100. There is not enough free space");
     };
     OnNotification.Invoke();
 }
 /// <summary>
 /// 添加系统事件监听
 /// </summary>
 /// <param name="type">事件类型</param>
 /// <param name="listener">委托函数</param>
 public void AddEventListener(SFSEvent type, OnNotification listener)
 {
     if (!eventListeners.ContainsKey(type.Type))
     {
         OnNotification onNote = null;
         eventListeners[type.Type] = onNote;
     }
     eventListeners[type.Type] += listener;
 }
Beispiel #24
0
                /**
                 *@brief Handle the Drop event on the tree view (hierarchy explorer)
                 *@param[in] sender (object) the original sender of the event
                 *@param[in] e (System.Windows.DragEventArgs) event arguments passed when the event was fired
                 */
                private void HierarchyExplorerDrop(object sender, DragEventArgs e)
                {
                    NotificationEventArgs args = new NotificationEventArgs(
                        e.Data.GetData(typeof(WorldObject)) as WorldObject,
                        (int)Notifications.kExplorerDrop,
                        id <HierarchyViewerControl> .type_id_);
                    OnNotification handler = notify_subscribers_;

                    handler?.Invoke(this, args);
                }
 private void _notify(string message)
 {
     if (OnNotification != null)
     {
         OnNotification.Invoke(this, new NotificationEventArg
         {
             Message = message
         });
     }
 }
Beispiel #26
0
        public void JsOnNotify(Notification notification)
        {
            var deviceObj = connectedDevices.SingleOrDefault(d => d.Id == notification.Device.Id);

            if (deviceObj != null)
            {
                notification.Device = deviceObj;
                OnNotification?.Invoke(notification);
            }
        }
 /// <summary>
 /// 取消监听
 /// </summary>
 /// <param name="eventKey"></param>
 /// <param name="eventListener"></param>
 public void RemoveEventListener(string eventKey, OnNotification <T> eventListener)
 {
     if (!eventListeners.ContainsKey(eventKey))
     {
         return;
     }
     else
     {
         eventListeners[eventKey] -= eventListener;
     }
 }
 /// <summary>
 /// 注册事件
 /// </summary>
 /// <param name="eventKey">事件Key</param>
 /// <param name="eventListener">事件监听器</param>
 public void AddEventListener(string eventKey, OnNotification <T> eventListener)
 {
     if (!eventListeners.ContainsKey(eventKey))
     {
         eventListeners.Add(eventKey, eventListener);
     }
     else
     {
         eventListeners[eventKey] += eventListener;
     }
 }
Beispiel #29
0
        public void SendNotification2(Object Context)
        {
            UpdateEVSEStatusTimer.Change(Timeout.Infinite, Timeout.Infinite);

            List <T> NewListOfT = null;

            lock (ListOfT)
            {
                NewListOfT = new List <T>(ListOfT);
                ListOfT.Clear();
            }

            OnNotification?.Invoke(DateTime.Now, NewListOfT);
        }
            /// <summary>
            /// Event will be raies when new product is deleted; writes action to the file
            /// </summary>
            /// <param name="material"></param>
            public void MenagerDeleting(string material)
            {
                string path = @"../../Loger.txt";

                OnNotification += () =>
                {
                    StreamWriter sw = new StreamWriter(path, true);

                    sw.WriteLine("[" + DateTime.Now.ToString("dd-MM-yyyy, H:mm:ss") + "] " + "Manager deleted product: {0}", material);

                    sw.Close();
                };
                OnNotification.Invoke();
            }
 /// <summary>
 /// 注册事件
 /// </summary>
 /// <param name="eventKey">事件Key</param>
 /// <param name="eventListener">事件监听器</param>
 public void AddEventListener(string eventKey,OnNotification eventListener)
 {
     if(!eventListeners.ContainsKey(eventKey)){
         eventListeners.Add(eventKey,eventListener);
     }
 }