Exemplo n.º 1
0
 internal static extern int VibrateGetDeviceCaps(Vibrate.VibrationCapabilities caps);
Exemplo n.º 2
0
        private void CheckStation()
        {
            Logger.Log("CheckStation - Start");

            double _AlertDistance = m_Options.AlertDistance;

            foreach (Station _Station in m_ItemsControl.Items)
            {
                //m_Latitude = 48.323644;
                //m_Longitude = 10.050087;

                //Have to check dinamically of any changes made on the options dialog
                var _StationChanges = from _StationChange in m_Options.GetStations()
                                      where _StationChange.StationID == _Station.StationID
                                      select _StationChange;

                if (null != _StationChanges.SingleOrDefault())
                {
                    _Station.PerformAlert = _StationChanges.SingleOrDefault().PerformAlert;
                }
                else
                {
                    _Station.PerformAlert = false;
                }

                _Station.RefreshDistanceTo(m_Latitude, m_Longitude);
                _Station.AlertDistance = _AlertDistance;

                m_ItemsControl.Items.GetContentPresenter(_Station).RefreshContent();

                Application.DoEvents();

                if (_Station.PerformAlert && _AlertDistance > 0 && _Station.DistanceToDestination < _AlertDistance)
                {
                    if (m_Options.SmsActive && !m_SMSSent)
                    {
                        //TODO : Calculate speed without GPS information, only with distance.
                        //if (m_GpsPosition.SpeedValid)
                        //{
                        //    _EstimatedTime = Utils.ETAString(", estaria llegando en {0} {1}", Utils.EstimatedTimeOfArrival(m_GpsPosition.Speed, _Distance));
                        //}

                        //TODO : Multilanguage
                        DistanceTypes _DistanceType       = _Station.DistanceType;
                        string        _DistanceTypeFormat = "I'm {0:0.00} km from {1}";
                        if (_DistanceType == DistanceTypes.Meters)
                        {
                            _DistanceTypeFormat = "I'm {0:0.00} meters from {1}";
                        }

                        string _SMSMessage = string.Format(_DistanceTypeFormat,
                                                           (_DistanceType == DistanceTypes.Meters ? Convert.ToInt32(_Station.DistanceToDestination) : _Station.DistanceToDestination),
                                                           _Station.Name);

                        SendSMS(_SMSMessage);
                    }

                    Logger.Log("Video Power on");

                    //Power on the device if stand by
                    if (NativeMethods.GetVideoPowerState() != NativeMethods.VideoPowerState.VideoPowerOn)
                    {
                        NativeMethods.SetVideoPowerState(NativeMethods.VideoPowerState.VideoPowerOn);
                    }

                    //Doesnt matter if the Ringer is on/off,
                    //when off it will vibrates when on will do both.
                    Vibrate.PlaySync(150, 150, 150, 150);
                    Vibrate.PlaySnd();

                    Logger.Log("Vibrate and Sound played");
                }
            }

            NativeMethods.PowerPolicyNotify(NativeMethods.PPNMessage.PPN_UNATTENDEDMODE, 0);

            Logger.Log("CheckStation - Finished");

            //string _Message = string.Empty;
            //string _EstimatedTime = string.Empty;
            //Color _Color = Color.Green;
            //double _Distance = 0;
            //double _AlertInstance = m_Options.GetAlert();
            //bool _Alert = false;

            //try
            //{
            //    Station _Station = m_Options.GetStation();
            //    if (null != _Station)
            //    {
            //        //TEST
            //        //_Station.Latitude = 48.323644;
            //        //_Station.Longitude = 10.050087;

            //        txtStatus.Text = string.Format("{0} Lat:{1}-Long:{2} <-> Current Lat:{3}-Lon:{4}", _Station.Name, _Station.Latitude, _Station.Longitude, m_Latitude, m_Longitude);

            //        _Distance = _Station.DistanceTo(m_Latitude, m_Longitude);

            //        if (_AlertInstance > 0 && _Distance < _AlertInstance)
            //        {
            //            _Color = Color.Red;
            //            _Alert = true;
            //        }

            //        //if (m_GpsPosition.SpeedValid)
            //        //{
            //        //    _EstimatedTime = Utils.ETAString("ETA: {0} {1}", Utils.EstimatedTimeOfArrival(m_GpsPosition.Speed, _Distance));
            //        //}

            //        //"{0} in {1:0.00} km. {2}"
            //        _Message = string.Format("{0} in {1:0.00} km", _Station.Name, _Distance/*, _EstimatedTime*/);
            //    }
            //    else
            //    {
            //        txtStatus.Text = "Station cannot be found";
            //    }
            //}
            //catch (Exception ex)
            //{
            //    _Color = Color.Red;
            //    _Message = ex.Message;
            //}

            //lblAlert.ForeColor = _Color;
            //lblAlert.Text = _Message;

            //if (_Alert)
            //{
            //    //TODO : Recheck this option.
            //    //if (chkSendSMS.Checked && !m_SMSSent)
            //    //{
            //    //    if (m_GpsPosition.SpeedValid)
            //    //    {
            //    //        _EstimatedTime = Utils.ETAString(", estaria llegando en {0} {1}", Utils.EstimatedTimeOfArrival(m_GpsPosition.Speed, _Distance));
            //    //    }

            //    //    //TODO : Multilanguage
            //    //    string _DistanceType = (((_Distance * 1000) < 1000) ? "metros" : "km");
            //    //    string _SMSMessage = string.Format("Estoy a {0} {1} de {2}", _Distance, _DistanceType, _Station, _EstimatedTime);
            //    //    SendSMS(_SMSMessage);
            //    //}

            //    //Doesnt matter if the Ringer is on/off,
            //    //when off it will vibrates when on will do both.
            //    //m_Vibrate.Play();
            //    //Application.DoEvents();
            //    //m_Vibrate.Play();
            //    //Application.DoEvents();
            //    //m_Vibrate.Play();

            //    Vibrate.PlaySync(300, 300, 300, 300);
            //    Vibrate.PlaySnd();
            //}
        }