public override void OnReceive(Context context, Intent intent)
            {
                BarrierStatus   barrierStatus        = BarrierStatus.Extract(intent);
                string          label                = barrierStatus.BarrierLabel;
                int             barrierPresentStatus = barrierStatus.PresentStatus;
                Action <string> ShowLog              = ((LocationBarrierActivity)context).log.ShowLog;

                switch (label)
                {
                case EnterBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("You are entering the area set by locationBarrier.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("You are not entering the area set by locationBarrier.");
                    }
                    else
                    {
                        ShowLog("The location status is unknown.");
                    }
                    break;

                case StayBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog($"You have stayed in the area set by locationBarrier for {mTimeOfDuration}ms");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("You are not staying in the area set by locationBarrier or the time of duration is not enough.");
                    }
                    else
                    {
                        ShowLog("The location status is unknown.");
                    }
                    break;

                case ExitBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("You are exiting the area set by locationBarrier.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("You are not exiting the area set by locationBarrier.");
                    }
                    else
                    {
                        ShowLog("The location status is unknown.");
                    }
                    break;

                default:
                    break;
                }
            }
            public override void OnReceive(Context context, Intent intent)
            {
                BarrierStatus   barrierStatus        = BarrierStatus.Extract(intent);
                string          label                = barrierStatus.BarrierLabel;
                int             barrierPresentStatus = barrierStatus.PresentStatus;
                Action <string> ShowLog              = ((BehaviorBarrierActivity)context).log.ShowLog;

                switch (label)
                {
                case KeepingBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The user is still.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The user is not still.");
                    }
                    else
                    {
                        ShowLog("The user behavior status is unknown.");
                    }
                    break;

                case BeginningBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The user begins to walk.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The beginning barrier status is false.");
                    }
                    else
                    {
                        ShowLog("The user behavior status is unknown.");
                    }
                    break;

                case EndingBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The user stops cycling.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The ending barrier status is false.");
                    }
                    else
                    {
                        ShowLog("The user behavior status is unknown.");
                    }
                    break;

                default:
                    break;
                }
            }
            public override void OnReceive(Context context, Intent intent)
            {
                BarrierStatus   barrierStatus        = BarrierStatus.Extract(intent);
                string          label                = barrierStatus.BarrierLabel;
                int             barrierPresentStatus = barrierStatus.PresentStatus;
                Action <string> ShowLog              = ((AmbientLightBarrierActivity)context).log.ShowLog;

                switch (label)
                {
                case RangeBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog($"Ambient light intensity is in the range of {LowLuxValue} to {HighLuxValue} lux");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog($"Ambient light intensity is not in the range of {LowLuxValue} to {HighLuxValue} lux");
                    }
                    else
                    {
                        ShowLog("Ambient light status is unknown.");
                    }
                    break;

                case AboveBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog($"Ambient light intensity is above {HighLuxValue} lux");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog($"Ambient light intensity is not above {HighLuxValue} lux");
                    }
                    else
                    {
                        ShowLog("Ambient light status is unknown.");
                    }
                    break;

                case BelowBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog($"Ambient light intensity is below {LowLuxValue} lux");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog($"Ambient light intensity is not below {LowLuxValue} lux");
                    }
                    else
                    {
                        ShowLog("Ambient light status is unknown.");
                    }
                    break;

                default:
                    break;
                }
            }
            public override void OnReceive(Context context, Intent intent)
            {
                BarrierStatus   barrierStatus        = BarrierStatus.Extract(intent);
                string          label                = barrierStatus.BarrierLabel;
                int             barrierPresentStatus = barrierStatus.PresentStatus;
                Action <string> ShowLog              = ((BeaconBarrierActivity)context).log.ShowLog;

                switch (label)
                {
                case DiscoverBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("A beacon matching the filters is found.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The discover beacon barrier status is false.");
                    }
                    else
                    {
                        ShowLog("The beacon status is unknown.");
                    }
                    break;

                case KeepBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("A beacon matching the filters is found but not missed.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("No beacon matching the filters is found.");
                    }
                    else
                    {
                        ShowLog("The beacon status is unknown.");
                    }
                    break;

                case MissedBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("A beacon matching the filters is missed.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The missed beacon barrier status is false.");
                    }
                    else
                    {
                        ShowLog("The beacon status is unknown.");
                    }
                    break;

                default:
                    break;
                }
            }
Exemple #5
0
            public override void OnReceive(Context context, Intent intent)
            {
                BarrierStatus   barrierStatus        = BarrierStatus.Extract(intent);
                string          label                = barrierStatus.BarrierLabel;
                int             barrierPresentStatus = barrierStatus.PresentStatus;
                Action <string> ShowLog              = ((BluetoothBarrierActivity)context).log.ShowLog;

                switch (label)
                {
                case KeepBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The Bluetooth car stereo is connected.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The Bluetooth car stereo is disconnected.");
                    }
                    else
                    {
                        ShowLog("The Bluetooth car stereo status is unknown.");
                    }
                    break;

                case ConnectiongBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The Bluetooth car stereo is connecting.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The Bluetooth car stereo is not connecting.");
                    }
                    else
                    {
                        ShowLog("The Bluetooth car stereo status is unknown.");
                    }
                    break;

                case DisconnectiongBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The Bluetooth car stereo is disconnecting.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The Bluetooth car stereo is not disconnecting.");
                    }
                    else
                    {
                        ShowLog("The Bluetooth car stereo status is unknown.");
                    }
                    break;

                default:
                    break;
                }
            }
Exemple #6
0
 /// <summary>
 /// Updates a barrier to the preferred status
 /// </summary>
 /// <param name="lightName">Ex. vessel/warning_light</param>
 /// <param name="status">Status of the barrier</param>
 public void UpdateBarriers(BarrierStatus status, string laneType)
 {
     if (laneType == LaneType.Vessel)
     {
         VesselBarriers.Status         = status;
         VesselBarriers.UpdateRequired = true;
     }
     if (laneType == LaneType.Track)
     {
         TrackBarriers.Status         = status;
         TrackBarriers.UpdateRequired = true;
     }
 }
Exemple #7
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="startDate">开始日</param>
 /// <param name="maturityDate">到期日</param>
 /// <param name="exercise">行权方式</param>
 /// <param name="optionType">看涨看跌</param>
 /// <param name="strike">行权价</param>
 /// <param name="rebate">敲出补偿收益</param>
 /// <param name="coupon">敲出额外收益</param>
 /// <param name="participationRate">名义本金有效比例</param>
 /// <param name="barrierType">障碍类型</param>
 /// <param name="lowerBarrier">障碍价格下限</param>
 /// <param name="upperBarrier">障碍价格上限</param>
 /// <param name="isDiscreteMonitored">是否离散观察</param>
 /// <param name="underlyingType">标的资产类型</param>
 /// <param name="calendar">交易日历</param>
 /// <param name="dayCount">日期规则</param>
 /// <param name="payoffCcy">收益计算币种</param>
 /// <param name="settlementCcy">结算币种</param>
 /// <param name="exerciseDates">行权日</param>
 /// <param name="observationDates">观察日</param>
 /// <param name="fixings">观察价格序列</param>
 /// <param name="notional">名义本金</param>
 /// <param name="settlementGap">结算日规则</param>
 /// <param name="optionPremiumPaymentDate">权利金支付日</param>
 /// <param name="optionPremium">权利金</param>
 /// <param name="isMoneynessOption">是否为相对行权价期权</param>
 /// <param name="initialSpotPrice">标的资产期初价格</param>
 /// <param name="dividends">标的资产分红</param>
 /// <param name="position">持仓方向</param>
 /// <param name="barrierShift">障碍价格偏移</param>
 /// <param name="barrierStatus">敲入敲出状态</param>
 /// <param name="hasNightMarket">标的资产是否有夜盘交易</param>
 /// <param name="commodityFuturesPreciseTimeMode">是否启用精确时间模式</param>
 public BarrierOption(Date startDate,
                      Date maturityDate,
                      OptionExercise exercise,
                      OptionType optionType,
                      double strike,
                      double rebate,
                      double coupon,
                      double participationRate,
                      BarrierType barrierType,
                      double lowerBarrier,
                      double upperBarrier,
                      bool isDiscreteMonitored,
                      InstrumentType underlyingType,
                      ICalendar calendar,
                      IDayCount dayCount,
                      CurrencyCode payoffCcy,
                      CurrencyCode settlementCcy,
                      Date[] exerciseDates,
                      Date[] observationDates,
                      Dictionary <Date, double> fixings,
                      double notional                      = 1,
                      DayGap settlementGap                 = null,
                      Date optionPremiumPaymentDate        = null,
                      double optionPremium                 = 0,
                      bool isMoneynessOption               = false,
                      double initialSpotPrice              = 0.0,
                      Dictionary <Date, double> dividends  = null,
                      Position position                    = Position.Buy,
                      double barrierShift                  = 0.0,
                      BarrierStatus barrierStatus          = BarrierStatus.Monitoring,
                      bool hasNightMarket                  = false,
                      bool commodityFuturesPreciseTimeMode = false
                      )
     : base(startDate, maturityDate, exercise, optionType, new double[] { strike }, underlyingType, calendar, dayCount,
            payoffCcy, settlementCcy, exerciseDates, observationDates, notional, settlementGap,
            optionPremiumPaymentDate, optionPremium,
            isMoneynessOption: isMoneynessOption, initialSpotPrice: initialSpotPrice, dividends: dividends, hasNightMarket: hasNightMarket,
            commodityFuturesPreciseTimeMode: commodityFuturesPreciseTimeMode)
 {
     Rebate              = rebate;
     Coupon              = coupon;
     ParticipationRate   = participationRate;
     BarrierType         = barrierType;
     Barrier             = lowerBarrier;
     IsDiscreteMonitored = isDiscreteMonitored;
     UpperBarrier        = upperBarrier;
     Fixings             = fixings;
     Position            = position;
     BarrierShift        = barrierShift;
     BarrierStatus       = barrierStatus;
 }
            public override void OnReceive(Context context, Intent intent)
            {
                BarrierStatus   barrierStatus        = BarrierStatus.Extract(intent);
                string          label                = barrierStatus.BarrierLabel;
                int             barrierPresentStatus = barrierStatus.PresentStatus;
                Action <string> ShowLog              = ((BarrierCombinationActivity)context).log.ShowLog;

                switch (label)
                {
                case CombinedBehaviorHeadsetBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The user is taking exercise and the headset is connected.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("The user is not taking exercise or the headset is not connected.");
                    }
                    else
                    {
                        ShowLog("The combined barrier status is unknown.");
                    }
                    break;

                case CombinedTimeBlueToothBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("Bluetooth car stereo is connected on a weekend.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("Bluetooth car stereo is not connected or the current day is not a weekend.");
                    }
                    else
                    {
                        ShowLog("The combined barrier status is unknown.");
                    }
                    break;

                default:
                    break;
                }
            }
        public async static void QueryBarrier(Context context, params string[] labels)
        {
            string MethodName           = "QueryBarrier";
            BarrierQueryRequest request = BarrierQueryRequest.ForBarriers(labels);
            var barrierTask             = Awareness.GetBarrierClient(context).QueryBarriersAsync(request);

            try
            {
                await barrierTask;

                if (barrierTask.IsCompleted)
                {
                    IBarrierStatusMap statusMap     = barrierTask.Result.BarrierStatusMap;
                    string            barrierLabel  = "target barrier label";
                    BarrierStatus     barrierStatus = statusMap.GetBarrierStatus(barrierLabel);
                    if (barrierStatus != null)
                    {
                        string logMessage = $"Target barrier status is {barrierStatus.PresentStatus}";
                        ShowToast(context, logMessage);
                        Log.Info(MethodName, logMessage);
                    }
                    else
                    {
                        Log.Info(MethodName, $"{MethodName} is success but there is no barrier.");
                    }
                }
                else
                {
                    string logMessage = "Query barrier failed";
                    ShowToast(context, logMessage);
                    Log.Error(MethodName, logMessage, barrierTask.Exception);
                }
            }
            catch (Exception ex)
            {
                string logMessage = "Query barrier failed";
                ShowToast(context, logMessage);
                Log.Error(MethodName, logMessage, ex.Message);
            }
        }
            public override void OnReceive(Context context, Intent intent)
            {
                BarrierStatus   barrierStatus        = BarrierStatus.Extract(intent);
                string          label                = barrierStatus.BarrierLabel;
                int             barrierPresentStatus = barrierStatus.PresentStatus;
                Action <string> ShowLog              = ((TimeBarrierActivity)context).log.ShowLog;

                switch (label)
                {
                case InSunriseOrSunsetPeriodBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("It's around sunset time.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("It's not around sunset time.");
                    }
                    else
                    {
                        ShowLog("The time status is unknown.");
                    }
                    break;

                case DuringPeriodOfDayBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("It's between 11 am and 12 am.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("It's not between 11 am and 12 am.");
                    }
                    else
                    {
                        ShowLog("The time status is unknown.");
                    }
                    break;

                case DuringTimePeriodBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("The barrier was added no more than 10 seconds ago.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("10 seconds have passed after adding the duringTimePeriod barrier.");
                    }
                    else
                    {
                        ShowLog("The time status is unknown.");
                    }
                    break;

                case DuringPeriodOfWeekBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("It's between 9 am and 10 am on Monday.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("It's not between 9 am and 10 am on Monday.");
                    }
                    else
                    {
                        ShowLog("The time status is unknown.");
                    }
                    break;

                case InTimeCategoryBarrierLabel:
                    if (barrierPresentStatus == BarrierStatus.True)
                    {
                        ShowLog("Today is a weekend.");
                    }
                    else if (barrierPresentStatus == BarrierStatus.False)
                    {
                        ShowLog("Today is not a weekend.");
                    }
                    else
                    {
                        ShowLog("The time status is unknown.");
                    }
                    break;

                default:
                    break;
                }
            }
 public void Lower()
 {
     _status = BarrierStatus.Warning;
     _timer  = 0.0f;
 }
 public void Raise()
 {
     _status = BarrierStatus.Rising;
 }
        void Update()
        {
            // Movement
            if (_status == BarrierStatus.Warning)
            {
                _timer += Time.deltaTime;
                if (_timer >= 3.0f)
                {
                    _status = BarrierStatus.Lowering;
                }
            }
            if (_status == BarrierStatus.Rising)
            {
                if (_barrierAngle < _barrierTargetAngle)
                {
                    _barrierAngle += 30.0f * Time.deltaTime;
                    _pivot.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, _barrierAngle);
                }
                else
                {
                    _status = BarrierStatus.Up;
                }
            }
            if (_status == BarrierStatus.Lowering)
            {
                if (_barrierAngle > _barrierTargetAngle)
                {
                    _barrierAngle -= 30.0f * Time.deltaTime;
                    _pivot.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, _barrierAngle);
                }
                else
                {
                    _status = BarrierStatus.Down;
                }
            }

            // Lights
            bool blink = (Time.time % 1.0f) < 0.5f;

            if (_status == BarrierStatus.Up)
            {
                if (blink)
                {
                    _lightWhiteMaterial.EnableKeyword("_EMISSION");
                }
                else
                {
                    _lightWhiteMaterial.DisableKeyword("_EMISSION");
                }

                _lightRedLMaterial.DisableKeyword("_EMISSION");
                _lightRedRMaterial.DisableKeyword("_EMISSION");
                _lightBarrierMaterial.DisableKeyword("_EMISSION");
            }
            else
            {
                if (blink)
                {
                    _lightRedLMaterial.EnableKeyword("_EMISSION");
                    _lightRedRMaterial.DisableKeyword("_EMISSION");
                    _lightBarrierMaterial.EnableKeyword("_EMISSION");
                }
                else
                {
                    _lightRedLMaterial.DisableKeyword("_EMISSION");
                    _lightRedRMaterial.EnableKeyword("_EMISSION");
                    _lightBarrierMaterial.DisableKeyword("_EMISSION");
                }

                _lightWhiteMaterial.DisableKeyword("_EMISSION");
            }

            // Sounds
            if ((_status == BarrierStatus.Lowering || _status == BarrierStatus.Rising) && _soundEnabled)
            {
                if (!_motorSound.isPlaying)
                {
                    _motorSound.Play();
                }
            }
            else if (_motorSound.isPlaying)
            {
                _motorSound.Stop();
            }

            if ((_status == BarrierStatus.Lowering || _status == BarrierStatus.Warning) && !_bellLoopSound.isPlaying && _soundEnabled)
            {
                _bellLoopSound.Play();
            }

            if (!(_status == BarrierStatus.Lowering || _status == BarrierStatus.Warning) && _bellLoopSound.isPlaying)
            {
                _bellLoopSound.Stop();
                if (_soundEnabled)
                {
                    _bellSound.Play();
                }
            }
        }