public void Subscriber()
        {
            Task.Factory.StartNew(() =>
            {
                //	int i = 1;
                while (true)
                {
                    byte[] buffer  = new byte[1024];
                    string MsgT    = SubData.Receive(Encoding.Unicode);
                    int bufferSize = SubData.Receive(buffer);
                    buffer         = buffer.Skip(0).Take(bufferSize).ToArray();
                    Console.WriteLine(MsgT);
                    if (bufferSize > 0)
                    {
                        //Add rawdeserialize here after unpacking send data using invoke written below
                        // this.OnDataArrived.Invoke()

                        FinalPrice FP = (FinalPrice)DataPacket.RawDeserialize(buffer, typeof(FinalPrice));
                        Holder.holderData.TryAdd(FP.Token, FP);
                        OnDataUpdate.Raise(OnDataUpdate, OnDataUpdate.CreateReadOnlyArgs(FP));
                    }
                }
            }
                                  );
        }
Beispiel #2
0
        public void UpdateProc(float delta)
        {
            if (disconnected)
            {
                ScreenMessages.Add("disconnected");
                return;
            }

            // we want to update the previous buttons outside the update restriction so,
            // we only get one button event pr. unity update frame
            prevButtons = currentButtons;

            timeElapsed += timeElapsed + delta;


            // Here we manually enforce updates only every updateRate amount of time
            // The reason we don't just do this in FixedUpdate is so the main program's FixedUpdate rate
            // can be set independently of the controllers' update rate.

            if (timeElapsed < updateRate)
            {
                return;
            }
            else
            {
                timeElapsed = 0.0f;
            }
            //Console.WriteLine("Update");
            uint buttons = 0;

            // NOTE! There is potentially data waiting in queue.
            // We need to poll *all* of it by calling psmove_poll() until the queue is empty. Otherwise, data might begin to build up.
            while (psmove_poll(handle) > 0)
            {
                // We are interested in every button press between the last update and this one:
                buttons = buttons | psmove_get_buttons(handle);

                // The events are not really working from the PS Move Api. So we do our own with the prevButtons
                //psmove_get_button_events(handle, ref pressed, ref released);
                currentButtons = buttons;
            }


            // For acceleration, gyroscope, and magnetometer values, we look at only the last value in the queue.
            // We could in theory average all the acceleration (and other) values in the queue for a "smoothing" effect, but we've chosen not to.
            ProcessData();

            // Send a report to the controller to update the LEDs and rumble.
            if (psmove_update_leds(handle) == 0)
            {
                // If it returns zero, the controller must have disconnected (i.e. out of battery or out of range),
                // so we should fire off any events and disconnect it.
                OnControllerDisconnected(this, new EventArgs());
                Disconnect();
                return;
            }

            OnDataUpdate?.Invoke(0, this);
        }
Beispiel #3
0
        private async Task RunEventMethod()
        {
            await Task.Delay(500);

            var trade = new TradeData(Exchange.Binance, _rnd.Next(1, 10), _rnd.Next(0, 10), _rnd.Next(0, 20), SideType.Buy, DateTime.UtcNow, "XBTUSD");

            OnDataUpdate.Invoke(this, new WebSocketMessage(trade));
        }
        public void AddToHistory(DateTime dateTime)
        {
            // add entry to th history
            historyDates.Add(dateTime);

            ValidateNotifications();

            OnDataUpdate?.Invoke(this);
        }
Beispiel #5
0
        private void UpdateItems()
        {
            if (ItemsSource.Count == 0 && (EmptyTextTemplate != null || !string.IsNullOrEmpty(EmptyText)))
            {
                BuildEmptyText();
            }
            else
            {
                BuildItems(ItemsSource);
            }

            OnDataUpdate?.Invoke(this, new EventArgs());
        }
        public void ChangeRepeatInterval(eNotificationRepeatInterval repeatInterval, bool isFortnight = false)
        {
            if (this.repeatInterval == repeatInterval)
            {
                Debug.LogWarning("Trying to change notification with a same repeat interval! Return.");
                return;
            }

            this.repeatInterval = repeatInterval;
            TryFixInterval();

            RemoveAllNotifications();
            SetNotification();

            OnDataUpdate?.Invoke();
        }
        public void CheckReminderData()
        {
            Debug.Log($"Reminder with title {title} has been loaded. Notifications count: {notifications.Count}, mode: {appMode}");

            // check, is there any updates for completedDates
            // set yesterday by default
            DateTime lastCompletedDate = DateTime.Today.AddDays(-1);

            // if value is not > 0, that means nothing to check
            int daysToCheck = DateTime.Today.Subtract(lastCompletedDate).Days;

            for (int i = 0; i < daysToCheck; i++)
            {
                DateTime dateTime = lastCompletedDate.AddDays(i + 1);

                // if there are some notifications which could be triggered these period
                if (HasNotificationByDate(dateTime))
                {
                    // inform user
                    // TODO - not needed for now
                }
            }

            // probably not needed because that can be triggered from ReminderManager in OnLocalNotificationReceived callback and now we need it only for tests in editor
            if (Application.isEditor)
            {
                // also check for outdated notification and reschedule some if needed
                for (int i = 0; i < notifications.Count; i++)
                {
                    // try to find outdated notifications to add to history
                    List <NotificationInfo> infos = notifications[i].GetPassedNotifications();
                    if (infos != null)
                    {
                        for (int j = 0; j < infos.Count; j++)
                        {
                            AddToHistory(infos[j].fireDate);
                        }
                    }
                }

                ValidateNotifications();

                OnDataUpdate?.Invoke(this);
            }
        }
Beispiel #8
0
        private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            var items = ItemsSource.Cast <object>().ToList();

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:

                var index = e.NewStartingIndex;

                foreach (var newItem in e.NewItems)
                {
                    Children.Insert(index++, GetItemView(newItem));
                }
                break;

            case NotifyCollectionChangedAction.Move:

                var moveItem = items[e.OldStartingIndex];

                Children.RemoveAt(e.OldStartingIndex);
                Children.Insert(e.NewStartingIndex, GetItemView(moveItem));
                break;

            case NotifyCollectionChangedAction.Remove:

                Children.RemoveAt(e.OldStartingIndex);
                break;

            case NotifyCollectionChangedAction.Replace:

                Children.RemoveAt(e.OldStartingIndex);
                Children.Insert(e.NewStartingIndex, GetItemView(items[e.NewStartingIndex]));
                break;

            case NotifyCollectionChangedAction.Reset:

                BuildItems(ItemsSource);
                break;
            }

            OnDataUpdate?.Invoke(this, new EventArgs());
        }
    public void SetProperty(string _key, object _data, bool _useUpdate = true)
    {
        Player _playerData = GetValue <Player>(CustomPropertyCode.PLAYER);

        if (playerProperty.ContainsKey(_key))
        {
            playerProperty[_key] = _data;
            Debug.Log("set " + _key + " " + _data);
        }
        else
        {
            playerProperty.Add(_key, _data);
            Debug.Log("add " + _key + " " + _data);
        }
        if (_useUpdate)
        {
            OnDataUpdate?.Invoke(_key, _data, _playerData);
        }
    }
        /// <summary>
        /// Set notification using all local data.
        /// </summary>
        private void SetNotification()
        {
            TryFixInterval();

            // when we reschedule or change existing notification, fireDate can be in a past already, so each time we need to find next date when notification should be called
            DateTime nextFireDate = fireDate;

            // get start date diff in secs
            long startInSecs = (long)this.fireDate.Subtract(DateTime.Now).TotalSeconds;

            Debug.Log($"Set notification: title: {title}, parent id: {parentGroupId}. fireDate: {fireDate}, nextFireDate: {nextFireDate}, startInSecs: {startInSecs}");

            // if fireDate is in a past (past will return always 0, not -value)
            if (startInSecs <= 0)
            {
                nextFireDate = FindNextFireDate();
                startInSecs  = (long)nextFireDate.Subtract(DateTime.Now).TotalSeconds;
            }

            // schedule 2 notifications upfront for each week, so 4 totally
            if (this.isFortnight)
            {
                long twoWeeksToSeconds = 2 * 7 * 24 * 60 * 60;
                int  notificationCount = notificationsDict.Count;

                for (int i = notificationCount; i < 4; i++)
                {
                    Debug.Log($"Start in secs: {startInSecs}, twoWeeksToSeconds {twoWeeksToSeconds}, partial: {twoWeeksToSeconds * i}, total: {startInSecs + twoWeeksToSeconds * i}, and date format: {new TimeSpan(0, 0, (int)(startInSecs + twoWeeksToSeconds * i))}");
                    RegisterNotification(startInSecs + twoWeeksToSeconds * i, repeatInterval);
                }
            }
            else
            {
                RegisterNotification(startInSecs, this.repeatInterval);
            }

            OnDataUpdate?.Invoke();
        }
Beispiel #11
0
 private void ExchangeTradeDataRecieved(TradeData obj)
 {
     OnDataUpdate.Invoke(this, new WebSocketMessage(obj));
 }
        /// <summary>
        /// Important to call to save Reminder changes and write data.
        /// </summary>
        public void SetupReminder()
        {
            RemoveAllNotifications();

            NotificationData data;

            eNotificationRepeatInterval notificationRepeatInterval = eNotificationRepeatInterval.NONE;

            // covert to VoxelBuster plugin data format
            switch (this.repeatInterval)
            {
            case RepeatInterval.ONCE:
                notificationRepeatInterval = eNotificationRepeatInterval.NONE;
                break;

            case RepeatInterval.DAY:
                notificationRepeatInterval = eNotificationRepeatInterval.DAY;
                break;

            case RepeatInterval.WEEK:
                notificationRepeatInterval = eNotificationRepeatInterval.WEEK;
                break;

            case RepeatInterval.FORTNIGHT:
                notificationRepeatInterval = eNotificationRepeatInterval.NONE;
                break;

            case RepeatInterval.MONTH:
                notificationRepeatInterval = eNotificationRepeatInterval.MONTH;
                break;
            }

            // when user set multiple days of week, need to add notification for each of the day
            if (daysOfWeek != null && daysOfWeek.Length > 1)
            {
                int fireDateIndex = (int)fireDate.DayOfWeek;

                for (int i = 0; i < daysOfWeek.Length; i++)
                {
                    data = new NotificationData();
                    int index = (int)daysOfWeek[i];

                    DateTime notificationFireDate = fireDate.AddDays(index - fireDateIndex);

                    data.SetNotification(notificationFireDate, notificationRepeatInterval, id,
                                         this.repeatInterval == RepeatInterval.FORTNIGHT, title, message);

                    // cache it
                    notifications.Add(data);
                }
            }
            //  set new notification - in most cases use simple logic
            else
            {
                data = new NotificationData();
                data.SetNotification(fireDate, notificationRepeatInterval, id,
                                     this.repeatInterval == RepeatInterval.FORTNIGHT, title, message);

                // cache it
                notifications.Add(data);
            }

            OnDataUpdate?.Invoke(this);
        }
 private void UpdateData(DataType dataType)
 {
     OnDataUpdate?.Invoke(this, new UpdateDataEventArgs((int)dataType));
 }
 public void registerOnData(OnDataUpdate listener)
 {
     _onDataUpdateDelegates.Add(listener);
 }