예제 #1
0
        public RideProcessor(string userId)
        {
            _outputLock = new ReaderWriterLockSlim();
            UserId = userId;
            // load the turbo
            _spotData = new Spot();
            _lastSpotData = null;

            // Set-up the lease

            LeaseId = GenerateLease(12);

            // Set the initial timeout
            LastUpdateTimestamp = DateTime.UtcNow;

            _messageQueue = new Queue<InterfaceDatum>(QUEUE_CAPACITY);
            _queueLock = new ReaderWriterLockSlim();
            _zeroingTimer = new Timer(CheckZeroing, null, 1000, 4000);

            _Rider = Rider.LoadAny(userId);

            // will load either a real or virtual rider
            if (_Rider != null)
            {
                _Turbo = TurboTrainer.Load(UserId, _Rider.CurrentTurbo, _Rider.TurboIsCalibrated);
            }
        }
예제 #2
0
파일: Rider.cs 프로젝트: Cycli/Cycli
        public static Rider LoadAny(string userId)
        {
            Rider thisRider = null;
              SQLiteDatabase db = new SQLiteDatabase();
              string sql = @"select r.UserId as UserId, r.Username as Username, r.BikeWheelSizeMm as BikeWheelSizeMm, r.Turbo as Turbo, " +
            "r.TurboIsCalibrated as TurboIsCalibrated, r.EstimatedPower as EstimatedPower " +
            "From cycli_riders r " +
            "where UserId=@u1 and AccountStatus='Active'" +
            "union " +
            "select r.UserId as UserId, r.Username as Username, 700 as BikeWheelSizeMm, null as Turbo, " +
            "'False' as TurboIsCalibrated, 'False' as EstimatedPower " +
            "From cycli_virtual_riders r " +
            "where UserId=@u2 and Status='Active'";

             // Only load active accounts
               DataTable dtUser = db.GetDataTable(sql, "@u1", userId, "@u2",userId);
              if (dtUser.Rows.Count > 0)
              {
            DataRow dr = dtUser.Rows[0];
            thisRider = new Rider();
            thisRider.UserName = dr.Field<string>("Username");
            thisRider.UserId= dr.Field<string>("UserId");
            thisRider.BikeWheelSizeMm = (int)dr.Field<long>("BikeWheelSizeMm");
            thisRider.CurrentTurbo = dr.Field<string>("Turbo");
            thisRider.TurboIsCalibrated = (dr.Field<string>("TurboIsCalibrated") == bool.TrueString);
            thisRider.EstimatedPower = (dr.Field<string>("EstimatedPower") == bool.TrueString);

              }
              db.Close();
              return thisRider;
        }