示例#1
0
        public ControllerService()
        {
            var bsRepo       = new BaseStationRepository();
            var baseStations = new TelecommunicationNetworkSimulatorContext().BaseStations.ToList();

            foreach (var bs in baseStations)
            {
                baseStationCapacity.Add(bs.Id, 0);
            }
        }
示例#2
0
        // user statuses:
        // 0 - free
        // 1 - talking
        // 2 - in queue

        public static void StartChanceCalculation(this User user, ControllerService controllerService)
        {
            int chance    = 30; // in percents
            int callDelay = 60; // in seconds

            using (var dbContext = new TelecommunicationNetworkSimulatorContext())
            {
                var rnd = new Random();

                while (true)
                {
                    int chanceGenerated = rnd.Next(100);
                    if (
                        dbContext.BaseStations
                        .Where(bs => bs.Id == user.BaseStationId)
                        .FirstOrDefault()
                        .BaseStationStatusId == 1
                        )
                    {
                        if (chanceGenerated > chance)
                        {
                            Thread.Sleep(callDelay * 1000);
                        }
                        else
                        {
                            User otherUser = dbContext.Users.ToList()[rnd.Next(dbContext.Users.Count())];
                            while (otherUser == user)
                            {
                                otherUser = dbContext.Users.ToList()[rnd.Next(dbContext.Users.Count())];
                            }
                            user.Call(otherUser, controllerService);
                        }
                    }
                }
            }
        }
示例#3
0
文件: Program.cs 项目: osgoth/TNS
        static void Main(string[] args)
        {
            ControllerService controllerService = new ControllerService();

            using (var dbContext = new TelecommunicationNetworkSimulatorContext())
            {
                List <Thread> threads = new List <Thread>();
                foreach (var user in dbContext.Users)
                {
                    threads.Add(
                        new Thread(
                            new ThreadStart(
                                () => user.StartChanceCalculation(controllerService)
                                )
                            )
                        );
                }

                foreach (var thr in threads)
                {
                    thr.Start();
                }
            }
        }
示例#4
0
 //TODO: remove after DI install
 public BaseStationRepository()
 {
     _context = new TelecommunicationNetworkSimulatorContext();
 }
示例#5
0
 //TODO: for DI
 public BaseStationRepository(TelecommunicationNetworkSimulatorContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }