示例#1
0
 public RaceProcessor(string raceId)
 {
     RaceId = raceId;
     Race = null;
     _RaceSpotHistory = new Dictionary<string, Stack<RaceSpot>>();
     _RaceSpots = new Dictionary<string, RaceSpot>();
     _virtualRiders = new List<VirtualRider>();
     _Spots = new Dictionary<string, Spot>();
     _RaceSpotLock = new ReaderWriterLockSlim();
     _SpotLock = new ReaderWriterLockSlim();
     _RaceProfile = null;
     _CountdownTimer = null;
     _StartTimer = null;
     _RaceCloseTimer = null;
 }
示例#2
0
文件: Profile.cs 项目: Cycli/Cycli
 public static Profile Load(string profileId)
 {
     Profile profile = null;
       string sql = "select p.UserId, p.ProfileId, p.Name, p.Description, p.Favourite, p.CreatedOn, p.ModifiedOn, s.X, s.Y " +
     "from cycli_profiles p, cycli_profile_spots s " +
     "where " +
     "s.ProfileId = p.ProfileId " +
     "and p.ProfileId = '" + profileId + "' " +
     "order by s.PointOrder";
       SQLiteDatabase db = new SQLiteDatabase();
       DataTable dt = db.GetDataTable(sql);
       foreach (DataRow dr in dt.Rows)
       {
     if (profile == null)
     {
       // New profile
       profile = new Profile();
       profileId = (string)dr["ProfileId"];
       profile.UserId = (string)dr["ProfileId"];
       profile.ProfileId = profileId;
       profile.Favourite = ((string)dr["Favourite"] == bool.TrueString);
       profile.Name = (string)dr["Name"];
       profile.Description = (string)dr["Description"];
     }
     float[] pt = { (float)(long)dr["X"], (float)(long)dr["Y"] };
     profile.data.Add(pt);
       }
       db.Close();
       return profile;
 }
示例#3
0
文件: Profile.cs 项目: Cycli/Cycli
        public static Profile New(string userId)
        {
            Profile p = new Profile();

              long timeNowDb = Utilities.DbTime.ToDbSecs(DateTime.UtcNow);
              p.ProfileId = Guid.NewGuid().ToString();
              p.UserId = userId;
              p.Name = "New Profile";
              p.Description = "";
              p.Favourite = false;
              // It's a new profile
              string sqlProfile = @"insert into cycli_profiles (ProfileId, UserId, Name, Description, Favourite, CreatedOn, ModifiedOn) " +
                          "values (@p, @u, @n, @d, @f, @c, @m)";
              string sqlSpot = @"insert into cycli_profile_spots (ProfileId, X, Y) values (@p, @x, @y)";
              SQLiteDatabase db = new SQLiteDatabase(true);
              try
              {
            db.ExecuteNonQuery(sqlProfile,
                                "@p", p.ProfileId,
                                "@u", p.UserId,
                                "@n", p.Name,
                                "@d", p.Description,
                                "@f", p.Favourite.ToString(),
                                "@c", timeNowDb,
                                "@m", timeNowDb);
            db.ExecuteNonQuery(sqlSpot,
                                "@p", p.ProfileId,
                                "@x", 0,
                                "@y", 50);
            db.ExecuteNonQuery(sqlSpot,
                                "@p", p.ProfileId,
                                "@x", 100,
                                "@y", 50);

            db.CommitTransaction();
              }
              catch (Exception ex)
              {
            try
            {
              db.RollbackTransaction();
            }
            catch(Exception ex1)
            {
            }
              }
              finally
              {
              }
              return p;
        }
示例#4
0
文件: Profile.cs 项目: Cycli/Cycli
 public static Profile[] LoadAll(string userId)
 {
     List<Profile> profiles = new List<Profile>();
       string sql = "select p.UserId, p.ProfileId, p.Name, p.Description, p.Favourite, p.CreatedOn, p.ModifiedOn, s.X, s.Y " +
     "from cycli_profiles p, cycli_profile_spots s " +
     "where " +
     "s.ProfileId = p.ProfileId " +
     "and p.UserId = '"+userId+"' order by p.ProfileId, s.PointOrder";
       SQLiteDatabase db = new SQLiteDatabase();
       DataTable dt = db.GetDataTable(sql);
       string profileId = "";
       Profile thisProfile = null;
       foreach (DataRow dr in dt.Rows)
       {
     if (profileId !=  (string)dr["ProfileId"])
     {
       // New profile
       profileId = (string)dr["ProfileId"];
       Profile p = new Profile();
       p.UserId = userId;
       p.ProfileId = profileId;
       p.Favourite = ((string)dr["Favourite"] == bool.TrueString);
       p.Name = (string)dr["Name"];
       p.Description = (string)dr["Description"];
       profiles.Add(p);
       thisProfile = p;
     }
     float[] pt = {(float)(long)dr["X"], (float)(long)dr["Y"]};
     thisProfile.data.Add(pt);
       }
       db.Close();
       return profiles.ToArray();
 }
示例#5
0
文件: DataHub.cs 项目: Cycli/Cycli
 // PROFILES //
 public void SaveProfile(Profile profile)
 {
     string userId = Context.User.Identity.Name;
       profile.Save(userId);
 }
示例#6
0
        private void CloseRace(object state)
        {
            string raceId = (string)state;
            // Do a final check  - has the race been moved back? (only back outside the scheduling range is allowed
            // At this point we can save a reference to a race object for use by the scheduler - the
            // race properties are not going to change, only the status
            Race = Race.Load(raceId);

            if (Race != null && Race.StartDateTime == _StartDateTime)
            {
                _RaceSpotLock.EnterWriteLock();
                if (Race.ProfileId != null)
                {
                    _RaceProfile = Profile.Load(Race.ProfileId);
                }
                else
                {
                    _RaceProfile = null;
                }
                // Load up the virtual riders and get them pedalling
                foreach (Race.Participant p in Race.VirtualParticipants)
                {
                    // create a new virtual rider and pass the Race Processor so the virtual rider can sniff the race
                    VirtualRider vr = VirtualRider.Load(p.UserId);
                    if (vr != null)
                    {
                        // Race is only closed once, so no need to check that it's already added
                        _virtualRiders.Add(vr);
                        vr.StartRiding(Race, this);
                    }
                }

                // tell the db
                Race.Schedule();

                CycliManager.Instance.SendCloseRace(Race);
                // Start the countdown timer and start timer - At this point, the race object
                // cannot change, so we can pass it to the timer threads
                _StartTimer = new Timer(Start, null, 1000 * CLOSE_RACE_SECS, Timeout.Infinite);
                _CountdownTimer = new Timer(StartCountdown, null, 0, 1000);

                _RaceSpotLock.ExitWriteLock();
            }
            else
            {
                CycliManager.Instance.Reschedule(Race);
            }
            // If we've skipped this stage, then the race won't start
        }