Ejemplo n.º 1
0
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (!isLoaded)
            {
                Constant.Loader(this.resourceLoader.GetString("GlobalLoading"), true);
                this.DefaultViewModel["Title"] = "Route";
                await Task.Run(() => LoadRoute());

                isLoaded = true;
                Constant.Loader(this.resourceLoader.GetString("GlobalLoadingSuccess"), false);
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                            async() =>
                {
                    while (true)
                    {
                        await Task.Delay(10000);
                        foreach (var item in Buses)
                        {
                            Buses.Where(d => d.d_id == item.d_id).First().Next_Bus = time.getNextBusTime(item.schedule, item.days);
                        }
                        foreach (var item in Trolls)
                        {
                            Trolls.Where(d => d.d_id == item.d_id).First().Next_Bus = time.getNextBusTime(item.schedule, item.days);
                        }
                        foreach (var item in Tramms)
                        {
                            Tramms.Where(d => d.d_id == item.d_id).First().Next_Bus = time.getNextBusTime(item.schedule, item.days);
                        }
                    }
                }
                                                                                                            );
            }
        }
Ejemplo n.º 2
0
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (!isLoaded)
            {
                Constant.Loader(this.resourceLoader.GetString("GlobalLoading"), true);
                param = JsonConvert.DeserializeObject <StopNameAllSQL>(e.NavigationParameter.ToString());
                this.DefaultViewModel["Title"]    = param.name;
                this.DefaultViewModel["Favorite"] = Database.IfAllStopsAreFavorite(Int32.Parse(param.id)) ? Constant.FavoriteStar : Constant.UnFavoriteStar;
                await Task.Run(() => LoadRoutes(param));

                isLoaded = true;
                Constant.Loader(this.resourceLoader.GetString("GlobalLoadingSuccess"), false);
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                            async() =>
                {
                    while (true)
                    {
                        await Task.Delay(10000);
                        foreach (var item in Buses)
                        {
                            Buses.Where(d => d.d_id == item.d_id).First().Next_Bus = time.getNextBusTime(item.schedule, item.days);
                        }
                        foreach (var item in Trolls)
                        {
                            Trolls.Where(d => d.d_id == item.d_id).First().Next_Bus = time.getNextBusTime(item.schedule, item.days);
                        }
                        foreach (var item in Tramms)
                        {
                            Tramms.Where(d => d.d_id == item.d_id).First().Next_Bus = time.getNextBusTime(item.schedule, item.days);
                        }
                    }
                }
                                                                                                            );
            }
        }
Ejemplo n.º 3
0
        //Executes the event and returns true if the execution should halt
        private bool ExecuteScriptedEvent(ScriptedEvent ev)
        {
            Module source = Modules.Where(m => m.Name.Equals(ev.Module)).FirstOrDefault();

            //Send packet with given data size from source to target over target bus
            if (ev.Command == ModuleCommand.SEND || ev.Command == ModuleCommand.PING)
            {
                //Parse parameters
                byte dest_address;
                if (!byte.TryParse(ev.Parameters[0], out dest_address))
                {
                    MessageBox.Show("An event in your script has an invalid parameter. This simulation will now abort.", "Parameter Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    abort = true;
                    return(true);
                }
                Bus   targetBus = Buses.Where(b => b.Name.Equals(ev.Parameters[1])).FirstOrDefault();
                short dataSize;
                if (!short.TryParse(ev.Parameters[2], out dataSize))
                {
                    dataSize = 1;
                }

                //Check source module exists
                if (source == null)
                {
                    if (!scriptWarningShown)
                    {
                        scriptWarningShown = true;
                        if (MessageBox.Show("A scripted event cannot be run because the source module does not exist. Continue the simulation?", "Script Error", MessageBoxButton.YesNo, MessageBoxImage.Warning)
                            == MessageBoxResult.No)
                        {
                            abort = true;
                            return(true);
                        }
                    }
                    return(true);
                }

                //Send a packet
                if (targetBus is CSPBus)
                {
                    source.SendCSPPacket((CSPBus)targetBus, dest_address, 0, 0, (byte)source.Priority, dataSize, ev.Command);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public void InitializeBigTransportMap(int startTime)//Генерация полной карты переездов
        {
            BigTransportMap = new List <Transaction>();
            var transportMap = GetTransportMap(Buses, Moves);
            int period;
            int iteration;

            foreach (var transact in transportMap)
            {
                iteration = 0;
                period    = Buses.Where(x => x.Id == transact.BusId).Select(x => x.Period).FirstOrDefault();
                while (transact.EndTime + period * iteration <= 1440)
                {
                    if ((transact.StartTime + period * iteration) >= startTime)
                    {
                        BigTransportMap.Add(new Transaction(transact, period * iteration));
                    }
                    iteration++;
                }
            }
            BigTransportMap = BigTransportMap.OrderBy(x => x.StartTime).ToList();
        }