コード例 #1
0
        public async void recordTrack()
        {
            string query    = "SELECT * FROM Vehicles";
            var    vehicles = SqlDataAccess.LoadData <VehicleModel>(query);
            int    count    = 0;
            Random rand     = new Random();

            while (true)
            {
                Debug.WriteLine($@"Record Track {count} Start: {DateTime.Now}");
                for (int i = 0; i < vehicles.Count; i++)
                {
                    var    vehicle = vehicles[i];
                    double la      = 13.706555 + rand.NextDouble();
                    double lo      = 100.597545 + rand.NextDouble();
                    var    track   = new RegisterTrackViewModel()
                    {
                        VehicleSeqID = vehicle.VehicleSeqID,
                        Latitude     = Math.Round(la, 6),
                        Longitude    = Math.Round(lo, 6)
                    };

                    _ = await TrackProcessor.RegisterTrackAsync(track);
                }
                Debug.WriteLine($@"Record Track {count} End: {DateTime.Now}");
                await Task.Delay(30000);

                count++;
            }
        }
コード例 #2
0
        public async Task <ActionResult> RegisterTrackPost(RegisterTrackViewModel registerModel)
        {
            if (registerModel.Secret != null)
            {
                string userId = this.User.Identity.GetUserId();

                TracksRepository <Track> tracksRepo = new TracksRepository <Track>();
                IEnumerable <Track>      tracks     = tracksRepo.GetFor(registerModel.Secret);
                Track track = tracks.FirstOrDefault() as Track;
                if (track != null)
                {
                    EntityState state = await tracksRepo.RegisterUser(track.Id, userId);

                    if (state == EntityState.Modified)
                    {
                        return(RedirectToAction("Index", "Garage"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Sorry, something went wrong - please try again.");
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "That track secret was not found, try again.");
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #3
0
        public ActionResult RegisterTrack()
        {
            string          userId = this.User.Identity.GetUserId();
            ApplicationUser user   = Request.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(userId);

            RegisterTrackViewModel registerModel = new RegisterTrackViewModel();

            registerModel.User = user;
            return(View(registerModel));
        }
コード例 #4
0
ファイル: TrackController.cs プロジェクト: nfskis/VehicleAPI
        public async Task <ActionResult> RegisterTrackAsync([FromForm] RegisterTrackViewModel value)
        {
            // current user allows to add tracking record.
            // doens't allows to add tracking record for other vehicle.
            string userId        = User.Claims.First().Value;
            bool   IsUserVehicle = TrackProcessor.IsUserVehicle(userId, value.VehicleSeqID);

            if (User.IsInRole("Admin") || IsUserVehicle)
            {
                _ = await TrackProcessor.RegisterTrackAsync(value);
            }
            else
            {
                return(BadRequest("Logined user is not Admin or vehicle user."));
            }

            return(Ok("Track data has been registed"));
        }
コード例 #5
0
        /// <summary>
        /// Основной конструктор.
        /// </summary>
        /// <param name="registerType">Тип регистрации трека.</param>
        /// <param name="group">Группа, если имеется.</param>
        /// <param name="track">Трек, если имеется.</param>
        private RegisterTrackPage(LyricsSiteParser parser, IRepository <Track, Guid> tracksStore, IRepository <Group, Guid> groupsStore, IPath path, ILogManager logManager, TrackRegisterType registerType, Group group = null, Track track = null)
        {
            RegisterTrackViewModel GetViewModel(TrackRegisterType type)
            {
                switch (type)
                {
                case TrackRegisterType.AddFromGroups:
                    return(new NewTrackViewModel(parser, tracksStore, groupsStore, path, logManager));

                case TrackRegisterType.AddFromTracks:
                    return(new NewTrackViewModel(parser, tracksStore, groupsStore, path, logManager, group));

                case TrackRegisterType.Update:
                    return(new UpdateTrackViewModel(parser, tracksStore, groupsStore, path, logManager, track));

                default:
                    _logger.Error($"View model of type {type} not found in {typeof(RegisterTrackPage)}.{nameof(GetViewModel)}");
                    return(null);
                }
            }

            InitializeComponent();

            _logger    = logManager.GetLog();
            _viewModel = GetViewModel(registerType);

            BindingContext = _viewModel;
            _viewModel.FocusInvalidField += OnFocusInvalidField;
            _viewModel.ClosePage         += async() => await Navigation.PopAsync();

            _viewModel.GetTextFromBuffer += async() => Clipboard.HasText ? await Clipboard.GetTextAsync() : string.Empty;

            _viewModel.ConfirmPaste += async() => await DisplayAlert(Resource.ConfirmPasteTitle, Resource.ConfirmPasteQuestion, Resource.AnswerYes, Resource.AnswerNo);

            if (group != null || track != null)
            {
                groupEntry.IsReadOnly = true;
            }

            var grayColor = Color.FromHex("aeaeae");

            groupEntry.Unfocused += (sender, args) => groupEntry.PlaceholderColor = grayColor;
            trackEntry.Unfocused += (sender, args) => trackEntry.PlaceholderColor = grayColor;
        }
コード例 #6
0
        /// <summary>
        /// return Current Vehicle location
        /// </summary>
        /// <param name="vehicleSeqID">Target vehicle sequense ID</param>
        /// <returns></returns>
        public async Task <int> RegisterTrackAsync(RegisterTrackViewModel value)
        {
            // Check to eixted Vehicle ID
            bool isExisted = VehicleProcessor.FindVehicleByVehicleID(value.VehicleSeqID) != null ? true : false;

            if (!isExisted)
            {
                throw new Exception($"the givens VehicleID is not existed in DataBase: '{value.VehicleSeqID}'");
            }

            #region Compare current location and previous position
            // compare current position and previous position.
            var current = GetCurrentLocationByVehicleSeqID(value.VehicleSeqID);
            if (current != null)
            {
                if (Math.Abs(current.Longitude - value.Longitude) <= 0.000001 &&
                    Math.Abs(current.Latitude - value.Latitude) <= 0.000001)
                {
                    // Vehicle stpped at somewhere in 30sec. so, It waste keep recored location.
                    // So, update current record renewal for time
                    return(UpdateTrack(new UpdateTrackViewModel()
                    {
                        TrackSeqID = current.TrackSeqID,
                        Latitude = current.Latitude,
                        Longitude = current.Longitude,
                    })); //return -1;
                }
            }
            #endregion

            return(await SqlDataAccess.SaveDataAsync <TrackModel, dynamic>("dbo.Track_RegisterTrack",
                                                                           new
            {
                TrackSeqID = Guid.NewGuid().ToString(),
                VehicleSeqID = value.VehicleSeqID,
                Latitude = value.Latitude,
                Longitude = value.Longitude
            }));
        }