示例#1
0
        public async Task <List <WifiInformation> > ScanForWifi()
        {
            var appContext = Application.Context.ApplicationContext;
            ConnectivityManager manager = (ConnectivityManager)appContext.GetSystemService(Context.ConnectivityService);
            var wifiManager             = (WifiManager)appContext.GetSystemService(Context.WifiService);

            var activity = CrossCurrentActivity.Current.Activity;

            //if (ContextCompat.CheckSelfPermission(activity, Manifest.Permission.AccessFineLocation) != Android.Content.PM.Permission.Granted &&
            //    ContextCompat.CheckSelfPermission(activity, Manifest.Permission.AccessCoarseLocation) != Android.Content.PM.Permission.Granted &&
            //    ContextCompat.CheckSelfPermission(activity, Manifest.Permission.AccessWifiState) != Android.Content.PM.Permission.Granted &&
            //    ContextCompat.CheckSelfPermission(activity, Manifest.Permission.ChangeWifiState) != Android.Content.PM.Permission.Granted)
            //{
            var permissions = PermissionContainer.WaitForPermission(9002);

            ActivityCompat.RequestPermissions(activity, new[] { Manifest.Permission.AccessFineLocation, Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessWifiState, Manifest.Permission.ChangeWifiState }, 9002);

            var result = await permissions;

            Console.WriteLine($"Permission request result : {result}");
            //}

            var tcs = new TaskCompletionSource <List <WifiInformation> >();

            activity.RegisterReceiver(new WifiReceiver(tcs), new IntentFilter(WifiManager.ScanResultsAvailableAction));

            var ret = wifiManager.StartScan();

            Console.WriteLine($"Start scan results : {ret}");

            return(await tcs.Task);
        }
        public ActionResult GetPermissions(ODataActionParameters parameters)
        {
            ActionResult result = NoContent();

            if (parameters.ContainsKey("keys") && parameters.ContainsKey("typeName"))
            {
                List <string> keys     = new List <string>(parameters["keys"] as IEnumerable <string>);
                string        typeName = parameters["typeName"].ToString();
                List <PermissionContainer> permissionContainerList = new List <PermissionContainer>();
                ITypeInfo typeInfo = ObjectSpace.TypesInfo.PersistentTypes.FirstOrDefault(t => t.Name == typeName);
                if (typeInfo != null)
                {
                    Type  type       = typeInfo.Type;
                    IList entityList = ObjectSpace.GetObjects(type, new InOperator(typeInfo.KeyMember.Name, keys));
                    foreach (var entity in entityList)
                    {
                        PermissionContainer permissionContainer = new PermissionContainer();
                        permissionContainer.Key = typeInfo.KeyMember.GetValue(entity).ToString();
                        IEnumerable <IMemberInfo> memberList = GetPersistentMembers(typeInfo);
                        foreach (IMemberInfo member in memberList)
                        {
                            bool permission = Security.IsGranted(new PermissionRequest(ObjectSpace, type, SecurityOperations.Read, entity, member.Name));
                            permissionContainer.Data.Add(member.Name, permission);
                        }
                        permissionContainerList.Add(permissionContainer);
                    }
                    result = Ok(permissionContainerList.AsQueryable());
                }
            }
            return(result);
        }
        public void InitiatePermissionContainer()
        {
            var permissions = Permissions.Permissions.All();

            foreach (var permission in Permissions.Permissions.All())
            {
                PermissionContainer.Add(permission, false);
            }
            PermissionContainer.OrderBy(k => k.Key);
        }
        public async Task EditUser()
        {
            try
            {
                var user = await _userManager.FindByIdAsync(Id);

                user.Email = this.Email;

                user.UserName = this.UserName;
                //   user.PhoneNumber = this.PhoneNumber;

                IdentityResult result = await _userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    var roles = await _userManager.GetRolesAsync(user);

                    await _userManager.RemoveFromRolesAsync(user, roles);

                    var roleResult = await _userManager.AddToRoleAsync(user, Role);

                    if (roleResult.Succeeded)
                    {
                        var role = await _roleManager.FindByNameAsync(this.Role);

                        var roleClaims = await _roleManager.GetClaimsAsync(role);

                        foreach (var claim in roleClaims)
                        {
                            await _roleManager.RemoveClaimAsync(role, claim);
                        }
                        foreach (var permission in PermissionContainer)
                        {
                            await _roleManager.AddClaimAsync(role, new Claim(CustomClaimsTypes.Permission, permission.Key));
                        }
                        foreach (var permission in Permissions.Permissions.All())
                        {
                            if (!PermissionContainer.ContainsKey(permission))
                            {
                                PermissionContainer.Add(permission, false);
                            }
                        }
                        Notification = new NotificationModel("Success !!", "Successfully Edited User", NotificationModel.NotificationType.Success);
                        PermissionContainer.OrderBy(k => k.Key);
                    }
                }
            }
            catch (Exception e)
            {
                Notification = new NotificationModel("Failed !!", "Failed to Add User", NotificationModel.NotificationType.Fail);
                throw e;
            }
        }
        public async Task <IdentityResult> AddUser()
        {
            try
            {
                var user = new IdentityUser
                {
                    UserName    = this.UserName,
                    Email       = this.Email,
                    PhoneNumber = this.PhoneNumber
                };
                var result = await _userManager.CreateAsync(user, this.Password);

                if (result.Succeeded)
                {
                    var role = await _roleManager.FindByIdAsync(this.Role);

                    var roleResult = await _userManager.AddToRoleAsync(user, role.Name);

                    if (roleResult.Succeeded)
                    {
                        var roleClaims = await _roleManager.GetClaimsAsync(role);

                        foreach (var claim in roleClaims)
                        {
                            await _roleManager.RemoveClaimAsync(role, claim);
                        }
                        foreach (var permission in PermissionContainer)
                        {
                            await _roleManager.AddClaimAsync(role, new Claim(CustomClaimsTypes.Permission, permission.Key));
                        }
                        foreach (var permission in Permissions.Permissions.All())
                        {
                            if (!PermissionContainer.ContainsKey(permission))
                            {
                                PermissionContainer.Add(permission, false);
                            }
                        }
                        // await _roleManager.AddClaimAsync(adminRole, new Claim(CustomClaimsTypes.Permission, Permissions.Permissions.Create));
                        Notification = new NotificationModel("Success !!", "Successfully Added User", NotificationModel.NotificationType.Success);
                        return(result);
                    }
                }
            }
            catch (Exception e)
            {
                Notification = new NotificationModel("Failed !!", "Failed to Add User", NotificationModel.NotificationType.Fail);
                throw e;
            }
            Notification = new NotificationModel("Failed !!", "Already registered", NotificationModel.NotificationType.Fail);
            return(null);
        }
        public async Task LoadPermission(string id)
        {
            // var user = await _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User);
            var user = await _userManager.FindByIdAsync(id);

            var userRoleNames = await _userManager.GetRolesAsync(user);

            var userRoles = await _roleManager.Roles.Where(x => userRoleNames.Contains(x.Name)).ToListAsync();

            foreach (var role in userRoles)
            {
                var roleClaims = await _roleManager.GetClaimsAsync(role);

                var permissionsofRole = roleClaims.Where(x => x.Type == CustomClaimsType.CustomClaimsTypes.Permission)
                                        .Select(x => x.Value);
                foreach (var permission in permissionsofRole)
                {
                    PermissionContainer[permission] = true;
                }
                PermissionContainer.OrderBy(k => k.Key);
            }
        }
示例#7
0
 public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
 {
     Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
     PermissionContainer.OnResult(requestCode, grantResults);
     base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
 }