Exemple #1
0
        private async Task OnUserNotificationsBackgroundTaskActivated(IBackgroundTaskInstance backgroundTaskInstance)
        {
            var applicationsService = new ApplicationsService();

            var errorMessage = await DeviceManager.ConnectAsync(isBackgroundActivity : true);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                return;
            }

            var characteristic = await DeviceManager.GetGattCharacteristicAsync(Asteroid.NotificationUpdateCharacteristicUuid);

            if (characteristic == null)
            {
                return;
            }

            var userNotifications = await NotificationsManager.RetriveNotificationsAsync();

            if (userNotifications.IsNullOrEmpty())
            {
                return;
            }

            foreach (var userNotification in userNotifications)
            {
                var application = applicationsService.GetApplicationPreferenceByAppId(userNotification.AppInfo.PackageFamilyName);
                await DeviceManager.InsertNotificationAsync(characteristic, userNotification, application);
            }

            await applicationsService.UpsertFoundApplicationsAsync(userNotifications);

            await DeviceManager.DisconnectAsync(removeLastDeviceInfo : false);
        }
Exemple #2
0
        private async Task OnTimeBatteryLevelBackgroundTaskActivated(IBackgroundTaskInstance backgroundTaskInstance)
        {
            if (!TilesHelper.BatteryTileExists())
            {
                return;
            }

            var applicationsService = new ApplicationsService();

            var errorMessage = await DeviceManager.ConnectAsync(isBackgroundActivity : true);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                return;
            }

            var percentage = await DeviceManager.GetBatteryPercentageAsync();

            if (percentage > 0)
            {
                TilesHelper.UpdateBatteryTile(percentage);
            }
            else
            {
                TilesHelper.ResetBatteryTile();
            }
        }
Exemple #3
0
        public MainPageViewModel(
            ApplicationsService applicationsService,
            IDialogService dialogService,
            INavigationService navigationService) : base(dialogService, navigationService)
        {
            this.ApplicationsService = applicationsService ?? throw new ArgumentNullException(nameof(applicationsService));

            this.Initialize();
        }
Exemple #4
0
        public IHttpActionResult Get(string id)
        {
            ApplicationDTO appDTO = ApplicationsService.Get(id);

            if (appDTO == null)
            {
                return(NotFound());
            }
            return(Ok(appDTO));
        }
Exemple #5
0
 public IHttpActionResult DeleteApplication(string id)
 {
     try
     {
         ApplicationsService.Delete(id);
     }
     catch (Exception exception)
     {
         return(BadRequest(exception.Message));
     }
     return(Ok());
 }
Exemple #6
0
        public IHttpActionResult CreateApplication(ApplicationCreateModel app)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ApplicationDTO newApp = new ApplicationDTO()
            {
                ApplicationName = app.ApplicationName,
                UserOwnerId     = app.UserOwnerId
            };

            try
            {
                ApplicationsService.Create(newApp);
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
            return(CreatedAtRoute("DefaultApi", new { id = newApp.Id }, newApp));
        }
Exemple #7
0
 public IHttpActionResult GetAllApplications()
 {
     if (User.IsInRole("admin"))
     {
         var resultList = CollectInfoAboutApplications(ApplicationsService.GetAll());
         return(Ok(resultList));
     }
     if (User.IsInRole("manager"))
     {
         var currentUser = UserService.GetAll().Where(x => x.UserName == User.Identity.Name).First();
         var statusOfApplicationToShow        = StatusService.Find(y => y.Name == "new").First();
         IEnumerable <ApplicationDTO> appList = ApplicationsService.Find(x => x.StatusId == statusOfApplicationToShow.Id || x.ExecutorId == currentUser.Id);
         var resultList = CollectInfoAboutApplications(appList);
         return(Ok(resultList));
     }
     if (User.IsInRole("user"))
     {
         var currentUser = UserService.GetAll().Where(x => x.UserName == User.Identity.Name).First();
         IEnumerable <ApplicationDTO> appList = ApplicationsService.Find(x => x.UserOwnerId == currentUser.Id);
         var resultList = CollectInfoAboutApplications(appList);
         return(Ok(resultList));
     }
     return(Content(HttpStatusCode.Forbidden, "You have no rights for this content"));
 }
Exemple #8
0
        public IHttpActionResult EditApplication(ApplicationEditModel app)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ApplicationDTO editedApp = new ApplicationDTO()
            {
                Id = app.Id,
                ApplicationName = app.ApplicationName,
                StatusId        = app.StatusId,
                ExecutorId      = app.ExecutorId
            };

            try
            {
                ApplicationsService.Edit(editedApp);
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
            return(Ok(editedApp));
        }
 public ApplicationsServiceTests()
 {
     DatabaseAccessService = Substitute.For <IDatabaseAccessService>();
     ApplicationsService   = new ApplicationsService(DatabaseAccessService);
 }