Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
        public Session GetById(int sessionId)
        {
            var session = _repository.GetSession(sessionId);

            if (session == null)
            {
                return(null);
            }
            return(session);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        // 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));
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        /// <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();
            }
        }
Exemplo n.º 9
0
        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);
                }
            }
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
 // GET: api/Sessions/5
 public async Task <Session> Get(string id) => await _repository.GetSession(id);
Exemplo n.º 12
0
 private ISession GetSession(Guid id)
 {
     return(_repository.GetSession(id));
 }