public void RegisterSession(ISession session) { var mutex = new Mutex(false, session.Id.ToString()); try { mutex.WaitOne(); var existingSession = _repository.GetSession(session.Id); //Thread.Sleep(ThreadTestDelay); if (existingSession == null) { _repository.AddSession(session); _coutnerBusiness.UpdateSessionCounters(); } else { if (session.ApplicationVersionId != existingSession.ApplicationVersionId) { var ex = new ArgumentException("The session belongs to a different application version."); ex.Data.Add("SessionId", session.Id); ex.Data.Add("ApplicationVersionId", session.ApplicationVersionId); ex.Data.Add("ExistingApplicationVersionId", existingSession.ApplicationVersionId); throw ex; } _repository.UpdateSessionUsage(session.Id, DateTime.UtcNow); } } finally { mutex.ReleaseMutex(); } }
public static void SpawnExternalCrawl(IRepository repo, int sessionId, int crawlerId, Uri externalUri) { //if we are less than max concurrent crawls //and this crawl is not defined //spawn the process int inProgress = repo.GetCountOfCrawlsInProgress(sessionId); if (inProgress < repo.GetSession(sessionId).MaxConcurrentCrawls) { int nextCrawlerId = -1; bool alreadyDefined = false; do { nextCrawlerId = repo.GetNextCrawlerId(sessionId); alreadyDefined = repo.GetCrawl(sessionId, nextCrawlerId) != null; } while (alreadyDefined || nextCrawlerId <= crawlerId); //Spawn { string args = string.Format("{0} {1} {2}", sessionId, nextCrawlerId, externalUri.AbsoluteUri); ProcessStartInfo psi = new ProcessStartInfo("ThrongBot.CrawlRunner.exe", args); Process p = Process.Start(psi); Console.WriteLine("Process {0} spawned, crawlerId: {1}, seedUrl: {1}", p.Id, nextCrawlerId, externalUri.AbsoluteUri); } } }
public Session GetById(int sessionId) { var session = _repository.GetSession(sessionId); if (session == null) { return(null); } return(session); }
public async Task <Action> Post(string sessionId, [FromBody] MoveMoneyTransaction moveMoneyTransaction) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var sessionModel = await _repository.GetSession(sessionId); var actionModel = _moneyMover.CreateMoveMoneyTransaction(sessionModel, moveMoneyTransaction); return(await _repository.UpdateAction(sessionId, actionModel)); }
public static bool CanExternalCrawlBeSpawned(IRepository repo, int sessionId) { // check config canSpawnCrawlsConfigSetting first bool canSpawn = false; int inProgress = repo.GetCountOfCrawlsInProgress(sessionId); if (inProgress < repo.GetSession(sessionId).MaxConcurrentCrawls) { canSpawn = true; } return(canSpawn); }
// GET api/debts public async Task <IEnumerable <Debt> > Get(string id) { var sessionModel = await _repository.GetSession(id); var actionModels = await _repository.GetSessionActions(id); var actions = _actionsProvider.GetSessionActions(sessionModel, actionModels); return(_debtService.GetDebts(actions).Select(d => new Debt { Debtor = d.Debtor, Creditor = d.Creditor, Transactions = d.Transactions.OrderByDescending(t => t.Date).ToList() }) .OrderBy(d => d.Debtor) .ThenBy(d => d.Creditor)); }
FullScheduleSessionGroup CreateFullScheduleSessionGroup(Slot slot, Agenda agenda) { var group = new FullScheduleSessionGroup(slot); group.StartTime = slot.StartTime; var sessions = slot.SessionIds.Select(sessionId => _repository.GetSession(sessionId)); if (_trackFilters.Any()) { sessions = sessions.Where(session => IsInFilter(session)); } group.AddRange(sessions.Select(session => new FullScheduleCellViewModel( _repository, session, agenda, slot, _trackFilters))); return(group); }
/// <summary> /// TODO : Not working as expected /// </summary> /// <param name="orders"></param> /// <returns></returns> public async Task InsertBulkAsync(IList <Order> orders) { var session = _repository.GetSession(); session.StartTransaction(); var collection = _repository.GetCollection("orders"); try { foreach (var order in orders) { await collection.InsertOneAsync(session, order); } await session.CommitTransactionAsync(); } catch (Exception ex) { await session.AbortTransactionAsync(); } }
public static bool CanExternalCrawlBeSpawned(IRepository repo, int sessionId) { // check config canSpawnCrawlsConfigSetting first bool canSpawn = false; int inProgress = repo.GetCountOfCrawlsInProgress(sessionId); if (inProgress < repo.GetSession(sessionId).MaxConcurrentCrawls) { canSpawn = true; } return canSpawn; }
// GET: api/Sessions/5 public async Task <Session> Get(string id) => await _repository.GetSession(id);
private ISession GetSession(Guid id) { return(_repository.GetSession(id)); }