private void ReadingChangedforVibrator(object sender, AccelerometerReadingChangedEventArgs e) { AccelerometerReading reading = e.Reading; string sMessage = ""; if (Math.Abs(reading.AccelerationX - 0.09) > 0.07 || Math.Abs(reading.AccelerationY - 0.01) > 0.05 || Math.Abs(Math.Abs(reading.AccelerationZ) - 0.96) > 0.4) { sMessage = ""; sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice Success."; sMessage += "\r\n"; Vlog.WriteText(sMessage); } else { sMessage = ""; sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice Failed."; sMessage += "\r\n"; Vlog.WriteText(sMessage); } _accelerometer.ReportInterval = 0; _accelerometer.ReadingChanged -= new Windows.Foundation.TypedEventHandler <Windows.Devices.Sensors.Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChangedforVibrator); if (TestCount >= TestMaxCount) { Vtimer.Cancel(); TestCount = 0; Gtimer = ThreadPoolTimer.CreatePeriodicTimer(Gyrometer_Timer_Tick, TimeSpan.FromMilliseconds(2000)); } }
public async Task <IManagerActionResultModel <Vlog> > UpdateVlogTranslation(IUpdateTranslationVlogModel model) { var result = new ManagerActionResultModel <Vlog>(); Vlog entity = await this.GetByIdAsync(model.Id); if (entity == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(string.Empty, "Vlog not found!")); } if (model.Language == this.settings.DefaultLanguage) { model.Name = model.Name; } VlogTranslation translation = entity.Translations.Where(t => t.Language == model.Language).FirstOrDefault(); if (translation == null) { translation = new VlogTranslation() { Vlog = entity, VlogId = entity.Id, Language = model.Language }; entity.Translations.Add(translation); } translation.Name = model.Name; await this.repository.SaveAsync(); return(result); }
/// <summary> /// Called when a vlog has been uploaded. This will /// publish the vlog and notify all followers. /// </summary> /// <remarks> /// <para> /// The vlog will be owned by the current user. /// </para> /// <para> /// If the video file or thumbnail file does not /// exist in our blob storage this throws a /// <see cref="FileNotFoundException"/>. /// </para> /// </remarks> /// <param name="context">Context for posting the vlog.</param> public async Task PostVlogAsync(PostVlogContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (!await _blobStorageService.FileExistsAsync(StorageConstants.VlogStorageFolderName, StorageHelper.GetVideoFileName(context.VlogId))) { throw new FileNotFoundException(); } if (!await _blobStorageService.FileExistsAsync(StorageConstants.VlogStorageFolderName, StorageHelper.GetThumbnailFileName(context.VlogId))) { throw new FileNotFoundException(); } var vlog = new Vlog { Id = context.VlogId, IsPrivate = context.IsPrivate, UserId = context.UserId, }; await _vlogRepository.CreateAsync(vlog); // TODO AppContext.UserId returned Guid.Empty. Why? --> context.UserId will work. // This function will dispatch a notification for each follower. await _notificationService.NotifyFollowersVlogPostedAsync(context.UserId, context.VlogId); }
public async void DeleteVlogWorks() { DbContextOptions <JamesAmosDbContext> options = new DbContextOptionsBuilder <JamesAmosDbContext> ().UseInMemoryDatabase("DeleteVlog").Options; using (JamesAmosDbContext context = new JamesAmosDbContext(options)) { // arrange Vlog vlog = new Vlog(); vlog.ID = 1; vlog.Subject = "stuff"; vlog.VideoUrl = "URL"; // Act context.Vlogs.Add(vlog); context.SaveChanges(); var toDelete = await context.Vlogs.FirstOrDefaultAsync(v => v.ID == vlog.ID); context.Remove(toDelete); context.SaveChanges(); var deleted = await context.Vlogs.FirstOrDefaultAsync(v => v.ID == vlog.ID); // Assert Assert.Null(deleted); } }
public async Task <IManagerActionResultModel <Vlog> > CreateVlogAsync(ICreateVlogModel model) { var result = new ManagerActionResultModel <Vlog>(); try { string alias = model.Alias.ToLowerInvariant(); bool isExisting = this.repository.All().Where(v => v.Alias == alias).Any(); if (isExisting) { result.Errors.Add(new ErrorResultModel() { Code = nameof(model.Name), Message = $"Vlog with alias {model.Alias} already exists!" }); return(result); } var entity = new Vlog() { Alias = alias, Name = model.Name, EmbededVideo = model.EmbededVideo, ThumbnailId = model.ThumbImageId }; entity.Translations.Add(new VlogTranslation() { Vlog = entity, Language = this.settings.DefaultLanguage, Name = model.Name }); await this.repository.AddAsync(entity); await this.repository.SaveAsync(); result.Succeeded = true; result.Model = entity; } catch (Exception ex) { result.Errors.Add(new ErrorResultModel(ex)); if (ex.InnerException != null) { result.Errors.Add(new ErrorResultModel(ex.InnerException)); } } return(result); }
private async Task GetVbrationDevice() { if (await VibrationDevice.RequestAccessAsync() != VibrationAccessStatus.Allowed) { Vlog.WriteText("VibrationAccessStatus failed."); return; } VibrationDevice = await VibrationDevice.GetDefaultAsync(); if (VibrationDevice != null) { BuzzFeedback = FindFeedback(); } }
public IActionResult Create(string Subject, string VideoUrl) { Vlog vlog = new Vlog(); vlog.DateCreated = DateTime.Now; vlog.Subject = Subject; vlog.VideoUrl = VideoUrl; _context.Vlogs.Add(vlog); _context.SaveChanges(); return(RedirectToAction("Index")); }
private void Vibrator_Timer_Tick(ThreadPoolTimer timer) { TestCount++; string sMessage = ""; if (VibrationDevice == null) { sMessage += "Round" + TestRound + "->" + TestCount + ":VibrationDevice is null.\r\n"; Vlog.WriteText(sMessage); return; } VibrationDevice.SimpleHapticsController.SendHapticFeedbackForDuration(BuzzFeedback, 1, TimeSpan.FromMilliseconds(4000)); //Use Accelerometer value to check vibrator have vibrated or not uint minReportIntervalMsecs = _accelerometer.MinimumReportInterval; _accelerometer.ReportInterval = minReportIntervalMsecs > 16 ? minReportIntervalMsecs : 16; _accelerometer.ReadingChanged += new Windows.Foundation.TypedEventHandler <Windows.Devices.Sensors.Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChangedforVibrator); }
public async Task <IManagerActionResultModel <Vlog> > UpdateVlogAsync(IUpdateVlogModel model) { var result = new ManagerActionResultModel <Vlog>(); try { Vlog entity = await this.GetByIdAsync(model.Id); if (entity == null) { result.Succeeded = false; result.Errors.Add(new ErrorResultModel(string.Empty, "Vlog not found!")); } VlogTranslation translation = entity.Translations.Where(t => t.Language == this.settings.DefaultLanguage).FirstOrDefault(); entity.Name = model.Name; entity.Alias = model.Alias; entity.EmbededVideo = model.EmbededVideo; entity.ThumbnailId = model.ThumbImageId; translation.Name = model.Name; await this.repository.SaveAsync(); result.Succeeded = true; result.Model = entity; } catch (Exception ex) { result.Errors.Add(new ErrorResultModel(ex)); if (ex.InnerException != null) { result.Errors.Add(new ErrorResultModel(ex.InnerException)); } } return(result); }
/// <summary> /// Updates a vlog in our data store. /// </summary> /// <remarks> /// This expects the current user to own the vlog. /// </remarks> /// <param name="vlog">The vlog with updates properties.</param> public Task UpdateAsync(Vlog vlog) => _vlogRepository.UpdateAsync(vlog);