Example #1
0
        public DeviceRoleViewModel(DeviceRole deviceRole)
        {
            SaveCmd             = new RelayCommand(Save);
            CancelCmd           = new RelayCommand(() => Close(""));
            ViewModelAttachment = new ViewModelAttachment <DeviceRole>();

            var dtos = AuthorizationDevices.Select(x => new ListBoxItem
            {
                ID          = x.DeviceID,
                DisplayName = x.Name,
                IsSelected  = deviceRole.HasDeviceAuthorization(x.DeviceID)
            });

            DeviceDtos = new ObservableCollection <SelectableItem>(dtos);

            CurrentDeviceRole = deviceRole;
            if (deviceRole.DeviceRoleID != 0)
            {
                Name = deviceRole.RoleName;
                if (deviceRole.DeviceRolePermissions.Any())
                {
                    var firstPermission = deviceRole.DeviceRolePermissions.First();
                    SelectedTimezone         = Timezones.FirstOrDefault(x => x.TimeZoneID == firstPermission.AllowedAccessTimeZoneID);
                    SelectedPermissionAction = (int)firstPermission.PermissionAction;
                }
            }
            else
            {
                SelectedTimezone         = Timezones.FirstOrDefault();
                SelectedPermissionAction = PermissionActionDict.FirstOrDefault().ItemID.Value;
            }

            Title = (deviceRole.DeviceRoleID == 0) ? "新增设备角色" : "修改设备角色";
        }
Example #2
0
        public bool GetDeviceTransformByRole(DeviceRole role, out Vector3 position, out Quaternion rotation)
        {
#if MIXCAST_STEAMVR
            if (VRInfo.IsDeviceOpenVR())
            {
                return(GetDeviceTransformByRole_SteamVR(role, out position, out rotation));
            }
#endif
#if MIXCAST_OCULUS
            if (VRInfo.IsDeviceOculus())
            {
                return(GetDeviceTransformByRole_Oculus(role, out position, out rotation));
            }
#endif

            if (Application.isEditor)
            {
                position = Camera.main.transform.localPosition;
                rotation = Camera.main.transform.localRotation;
                return(true);
            }

            position = Vector3.zero;
            rotation = Quaternion.identity;
            return(false);
        }
Example #3
0
        private void UpdateUserMS(User user, DeviceController deviceInfo, DeviceRole role)
        {
            var deviceId         = deviceInfo.DeviceID;
            var devicePermission = role.DeviceRolePermissions.FirstOrDefault(x => x.DeviceID == deviceId);

            var deviceUser = new UserInfo();

            deviceUser.UserId           = user.UserCode.ToInt32();
            deviceUser.Role             = (Rld.DeviceSystem.Contract.Model.UserRole)devicePermission.PermissionAction.GetHashCode();
            deviceUser.AccessTimeZoneId = devicePermission.AllowedAccessTimeZoneID;

            Log.Info("Invoke WebSocketOperation...");
            var operation             = new WebSocketOperation(deviceId);
            var updateUserInfoRequest = new UpdateUserInfoRequest()
            {
                Token = operation.Token, UserInfo = deviceUser
            };
            string rawRequest = DataContractSerializationHelper.Serialize(updateUserInfoRequest);

            Log.DebugFormat("Request: {0}", rawRequest);
            var rawResponse = operation.Execute(rawRequest);

            Log.DebugFormat("Response: {0}", rawResponse);

            var response = DataContractSerializationHelper.Deserialize <UpdateUserInfoResponse>(rawResponse);

            Log.InfoFormat("Update user id:[{0}], device user id:[{1}] to device id:[{2}], result:[{3}]", user.UserID, deviceUser.UserId, deviceId, response.ResultType);

            if (response.ResultType != ResultType.OK)
            {
                throw new Exception(string.Format("Update user id:[{0}], device user id:[{1}] to device id:[{2}] fails]", user.UserID, deviceUser.UserId, deviceId));
            }
        }
        public static void RemoveDeviceIndexChangedListener(DeviceRole role, DeviceIndexChangedHandler handler)
        {
            var index = (int)role;

            if (!ReferenceEquals(indexChangedHandlers[index], null))
            {
                indexChangedHandlers[index] -= handler;
            }
        }
Example #5
0
        public static bool HasDeviceAuthorization(this DeviceRole deviceRole, Int32 deviceId)
        {
            if (deviceRole == null || deviceRole.DeviceRolePermissions == null || deviceRole.DeviceRolePermissions.Count == 0)
            {
                return(false);
            }

            return(deviceRole.DeviceRolePermissions.Any(r => r.DeviceID == deviceId));
        }
Example #6
0
 private DataSample CreateDataSampleFromDevice(GameObject device, DeviceRole role, float currentActualAperture, float intendedAtoSRatio, double elapsedTotalMilliseconds)
 {
     return(new DataSample(role,
                           _currentBlock,
                           (_currentTrial + 1), _shoulderWidth, _hipWidth,
                           currentActualAperture, intendedAtoSRatio, _poleLeft.transform, _poleRight.transform,
                           elapsedTotalMilliseconds,
                           new Pose(device.transform.position, device.transform.rotation)));
 }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RoleInActivity"/> class.
        /// </summary>
        /// <param name="role">
        /// The role during the activity.
        /// </param>
        /// <param name="activity">
        /// The activity during that the role is played.
        /// </param>
        public RoleInActivity(DeviceRole role, ActivityId activity)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }

            Role     = role;
            Activity = activity;
        }
        public static Vector3 GetAngularVelocity(DeviceRole role, Transform origin = null)
        {
            var index    = ViveRole.GetDeviceIndex(role);
            var rawValue = Vector3.zero;

            if (index < rawPoses.Length)
            {
                rawValue = new Vector3(-rawPoses[index].vAngularVelocity.v0, -rawPoses[index].vAngularVelocity.v1, rawPoses[index].vAngularVelocity.v2);
            }

            return(origin == null ? rawValue : origin.TransformVector(rawValue));
        }
        public HttpResponseMessage Put(int id, [FromBody] DeviceRole deviceRoleInfo)
        {
            return(ActionWarpper.Process(deviceRoleInfo, OperationCodes.MDVRL, () =>
            {
                deviceRoleInfo.DeviceRoleID = id;

                var deviceRoleRepo = RepositoryManager.GetRepository <IDeviceRoleRepository>();
                var deviceRolePermissionRepo = RepositoryManager.GetRepository <IDeviceRolePermissionRepository>();
                var userDeviceRoleRepo = RepositoryManager.GetRepository <IUserDeviceRoleRepository>();

                var originalDeviceRoleInfo = deviceRoleRepo.GetByKey(id);
                if (originalDeviceRoleInfo == null)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, string.Format("Device Role Id={0} does not exist.", id));
                }

                var addedPermissions = new List <DeviceRolePermission>();
                var deletedPermissionIds = new List <int>();
                if (deviceRoleInfo.DeviceRolePermissions != null && deviceRoleInfo.DeviceRolePermissions.Any())
                {
                    var originalPermissionIDs = originalDeviceRoleInfo.DeviceRolePermissions.Select(d => d.DeviceRolePermissionID);
                    var currentPermissionIDs = deviceRoleInfo.DeviceRolePermissions.Select(d => d.DeviceRolePermissionID);
                    deletedPermissionIds = originalPermissionIDs.Except(currentPermissionIDs).ToList();

                    addedPermissions = deviceRoleInfo.DeviceRolePermissions.FindAll(d => d.DeviceRolePermissionID == 0);
                }
                else
                {
                    deletedPermissionIds = originalDeviceRoleInfo.DeviceRolePermissions.Select(d => d.DeviceRolePermissionID).ToList();
                }

                if (userDeviceRoleRepo.Query(new Hashtable()
                {
                    { "DeviceRoleID", id }
                }).Any())
                {
                    return new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        Content = new StringContent("设备角色已经绑定人员使用,不能修改。"),
                        ReasonPhrase = ConstStrings.BusinessLogicError,
                    };
                }

                deletedPermissionIds.ForEach(d => deviceRolePermissionRepo.Delete(d));
                addedPermissions.ForEach(d => deviceRolePermissionRepo.Insert(d));
                deviceRoleInfo.DeviceRolePermissions.FindAll(d => d.DeviceRolePermissionID != 0).ForEach(d => deviceRolePermissionRepo.Update(d));

                deviceRoleRepo.Update(deviceRoleInfo);

                return Request.CreateResponse(HttpStatusCode.OK);
            }, this));
        }
        public static void AddDeviceIndexChangedListener(DeviceRole role, DeviceIndexChangedHandler handler)
        {
            var index = (int)role;

            if (ReferenceEquals(indexChangedHandlers[index], null))
            {
                indexChangedHandlers[index] = handler;
            }
            else
            {
                indexChangedHandlers[index] += handler;
            }
        }
 public DataSample(DeviceRole deviceRole, int block, int trial, float shoulderWidth, float hipWidth, float aperture, float aTos,
                   Transform leftPoleTransform, Transform rightPoleTransform, double time,
                   Pose pose) : this()
 {
     DeviceRole         = deviceRole;
     Block              = block;
     Trial              = trial;
     ShoulderWidth      = shoulderWidth;
     HipWidth           = hipWidth;
     ActualAperture     = aperture;
     AtoSRatio          = aTos;
     LeftPoleTransform  = leftPoleTransform;
     RightPoleTransform = rightPoleTransform;
     Time = time;
     Pose = pose;
 }
Example #12
0
        internal unsafe void __MarshalFrom(ref DeviceDetails.__Native @ref)
        {
            fixed(char *ptr = & @ref.DeviceID)
            {
                this.DeviceID = Utilities.PtrToStringUni((IntPtr)((void *)ptr), 256);
            }

            fixed(char *ptr2 = & @ref.DisplayName)
            {
                this.DisplayName = Utilities.PtrToStringUni((IntPtr)((void *)ptr2), 256);
            }

            this.Role         = @ref.Role;
            this.OutputFormat = new WaveFormatExtensible();
            this.OutputFormat.__MarshalFrom(ref @ref.OutputFormat);
        }
Example #13
0
        public static String GetDeviceAssociatedTimezoneList(this DeviceRole deviceRole, List <TimeZone> timeZones)
        {
            if (deviceRole == null || deviceRole.DeviceRolePermissions == null || deviceRole.DeviceRolePermissions.Count == 0)
            {
                return(string.Empty);
            }

            if (timeZones == null || timeZones.Count == 0)
            {
                return(string.Empty);
            }

            var permissions   = deviceRole.DeviceRolePermissions.Where(x => timeZones.Select(d => d.TimeZoneID).Contains(x.AllowedAccessTimeZoneID));
            var timezoneNames = permissions.Select(x => timeZones.First(d => d.TimeZoneID == x.AllowedAccessTimeZoneID).TimeZoneName).Distinct();

            return(string.Join(", ", timezoneNames));
        }
Example #14
0
        public static String GetDeviceAssociatedDeviceList(this DeviceRole deviceRole, List <DeviceController> devices)
        {
            if (deviceRole == null || deviceRole.DeviceRolePermissions == null || deviceRole.DeviceRolePermissions.Count == 0)
            {
                return(string.Empty);
            }

            if (devices == null || devices.Count == 0)
            {
                return(string.Empty);
            }

            var permissions = deviceRole.DeviceRolePermissions.Where(x => devices.Select(d => d.DeviceID).Contains(x.DeviceID));
            var deviceNames = permissions.Select(x => devices.First(d => d.DeviceID == x.DeviceID).Name).Distinct();

            return(string.Join(", ", deviceNames));
        }
Example #15
0
        public static String GetDeviceAssociatedPermissionActionList(this DeviceRole deviceRole, List <SysDictionary> permissionActionDict)
        {
            if (deviceRole == null || deviceRole.DeviceRolePermissions == null || deviceRole.DeviceRolePermissions.Count == 0)
            {
                return(string.Empty);
            }

            if (permissionActionDict == null || permissionActionDict.Count == 0)
            {
                return(string.Empty);
            }

            var permissions           = deviceRole.DeviceRolePermissions.Where(x => permissionActionDict.Select(d => d.ItemID).Contains((int)x.PermissionAction));
            var permissionActionNames = permissions.Select(x => permissionActionDict.First(d => d.ItemID == (int)x.PermissionAction).ItemValue).Distinct();

            return(string.Join(", ", permissionActionNames));
        }
        /// <summary>
        /// Returns tracking pose of the device identified by role
        /// </summary>
        public static Pose GetPose(DeviceRole role, Transform origin = null)
        {
            var index   = ViveRole.GetDeviceIndex(role);
            var rawPose = new Pose();

            if (index < poses.Length)
            {
                rawPose = poses[index];
            }

            if (origin != null)
            {
                rawPose = new Pose(origin) * rawPose;
                rawPose.pos.Scale(origin.localScale);
            }

            return(rawPose);
        }
Example #17
0
        /// <summary>
        /// Returns device index of the device identified by the role
        /// Returns OpenVR.k_unTrackedDeviceIndexInvalid if the role doesn't assign to any device
        /// </summary>
        /// <returns>Current device index assigned to the role, should be tested by ViveRole.IsValidIndex before using it</returns>
        public static uint GetDeviceIndex(DeviceRole role)
        {
            if (role == DeviceRole.Hmd)
            {
                return(OpenVR.k_unTrackedDeviceIndex_Hmd);
            }

            var index = (int)role;

            if (index < 0 || index >= roleIndice.Length)
            {
                return(OpenVR.k_unTrackedDeviceIndexInvalid);
            }
            else
            {
                return(roleIndice[index]);
            }
        }
        public bool GetDeviceTransformByRole_SteamVR(DeviceRole role, out Vector3 position, out Quaternion rotation)
        {
            switch (role)
            {
            case DeviceRole.Head:
                return(GetDeviceTransformByIndex_SteamVR((int)SteamVR_TrackedObject.EIndex.Hmd, out position, out rotation));

            case DeviceRole.LeftHand:
                return(GetDeviceTransformByIndex_SteamVR((int)Valve.VR.OpenVR.System.GetTrackedDeviceIndexForControllerRole(Valve.VR.ETrackedControllerRole.LeftHand), out position, out rotation));

            case DeviceRole.RightHand:
                return(GetDeviceTransformByIndex_SteamVR((int)Valve.VR.OpenVR.System.GetTrackedDeviceIndexForControllerRole(Valve.VR.ETrackedControllerRole.RightHand), out position, out rotation));

            default:
                position = Vector3.zero;
                rotation = Quaternion.identity;
                return(false);
            }
        }
Example #19
0
    public void Devices_XRDeviceRoleDeterminesTypeOfDevice(DeviceRole role, string baseLayoutName, Type expectedType)
    {
        var deviceDescription = CreateSimpleDeviceDescriptionByRole(role);

        testRuntime.ReportNewInputDevice(deviceDescription.ToJson());

        InputSystem.Update();

        Assert.That(InputSystem.devices, Has.Count.EqualTo(1));
        var createdDevice = InputSystem.devices[0];

        Assert.That(createdDevice, Is.TypeOf(expectedType));

        var generatedLayout = InputSystem.TryLoadLayout(string.Format("{0}::{1}::{2}", XRUtilities.kXRInterfaceCurrent,
                                                                      deviceDescription.manufacturer, deviceDescription.product));

        Assert.That(generatedLayout, Is.Not.Null);
        Assert.That(generatedLayout.baseLayouts, Is.EquivalentTo(new[] { new InternedString(baseLayoutName) }));
    }
        public HttpResponseMessage Post([FromBody] DeviceRole deviceRoleInfo)
        {
            return(ActionWarpper.Process(deviceRoleInfo, OperationCodes.ADVRL, () =>
            {
                var deviceRoleRepo = RepositoryManager.GetRepository <IDeviceRoleRepository>();
                var deviceRolePermissionRepo = RepositoryManager.GetRepository <IDeviceRolePermissionRepository>();

                if (deviceRoleInfo == null)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "deviceRoleInfo is null");
                }

                deviceRoleRepo.Insert(deviceRoleInfo);

                deviceRoleInfo.DeviceRolePermissions.ForEach(a => a.DeviceRoleID = deviceRoleInfo.DeviceRoleID);
                deviceRoleInfo.DeviceRolePermissions.ForEach(a => deviceRolePermissionRepo.Insert(a));

                return Request.CreateResponse(HttpStatusCode.OK, deviceRoleInfo);
            }, this));
        }
Example #21
0
 private InputDeviceDescription CreateSimpleDeviceDescriptionByRole(DeviceRole role)
 {
     return(new InputDeviceDescription
     {
         interfaceName = XRUtilities.kXRInterfaceCurrent,
         product = "Device",
         manufacturer = "Manufacturer",
         capabilities = new XRDeviceDescriptor
         {
             deviceRole = role,
             inputFeatures = new List <XRFeatureDescriptor>()
             {
                 new XRFeatureDescriptor()
                 {
                     name = "Filler",
                     featureType = FeatureType.Binary
                 }
             }
         }.ToJson()
     });
 }
        public bool GetDeviceTransformByRole_Oculus(DeviceRole role, out Vector3 position, out Quaternion rotation)
        {
            OVRPlugin.Node node;
            switch (role)
            {
            case DeviceRole.Head:
                node = OVRPlugin.Node.Head;
                break;

            case DeviceRole.LeftHand:
                node = OVRPlugin.Node.HandLeft;
                break;

            case DeviceRole.RightHand:
                node = OVRPlugin.Node.HandRight;
                break;

            default:
                position = Vector3.zero;
                rotation = Quaternion.identity;
                return(false);
            }
            if (OVRPlugin.GetNodePositionTracked(node) && OVRPlugin.GetNodeOrientationTracked(node))
            {
                OVRPlugin.Posef pose = OVRPlugin.GetNodePose(node, OVRPlugin.Step.Render);
                position = new Vector3(pose.Position.x, pose.Position.y, pose.Position.z);
                rotation = new Quaternion(pose.Orientation.x, pose.Orientation.y, pose.Orientation.z, pose.Orientation.w);
                return(true);
            }
            else
            {
                position = Vector3.zero;
                rotation = Quaternion.identity;
                return(false);
            }
        }
Example #23
0
        private bool CheckRoleForUser(DeviceRole role, Dictionary <Int32, UserInfo> userDeviceInfoDict, List <Rld.Acs.Model.TimeZone> timezoneInfos)
        {
            string userDevicePermissionString = string.Empty;
            string rolePermissionString       = string.Empty;

            foreach (KeyValuePair <Int32, UserInfo> item in userDeviceInfoDict)
            {
                var roleid           = item.Value.Role.HasValue ? (int)item.Value.Role.Value : 0;
                var accessTimeZoneId = 1;
                if (item.Value.AccessTimeZoneId.HasValue)
                {
                    accessTimeZoneId = timezoneInfos.First(x => x.TimeZoneCode == item.Value.AccessTimeZoneId.Value.ToString()).TimeZoneID;
                }
                userDevicePermissionString += string.Format("{0}_{1}_{2},", item.Key, roleid, accessTimeZoneId);
            }

            foreach (var permission in role.DeviceRolePermissions.OrderBy(x => x.DeviceID))
            {
                rolePermissionString += string.Format("{0}_{1}_{2},", permission.DeviceID, (int)permission.PermissionAction, permission.AllowedAccessTimeZoneID);
            }

            Log.InfoFormat("Compare permission string {0} == {1}", userDevicePermissionString, rolePermissionString);
            return(userDevicePermissionString == rolePermissionString);
        }
Example #24
0
 public DeviceDefaultChangedEvent(MMDevice device, DeviceRole role) : base(device.ID)
 {
     Device = device;
     Role   = role;
 }
 public static bool IsUninitialized(DeviceRole role)
 {
     return(IsUninitialized(ViveRole.GetDeviceIndexEx(role)));
 }
 public static bool IsCalibrating(DeviceRole role)
 {
     return(IsCalibrating(ViveRole.GetDeviceIndexEx(role)));
 }
 public static bool IsOutOfRange(DeviceRole role)
 {
     return(IsOutOfRange(ViveRole.GetDeviceIndexEx(role)));
 }
 /// <summary>
 /// Returns true if tracking data of the device identified by role has valid value.
 /// </summary>
 public static bool HasTracking(DeviceRole role)
 {
     return(HasTracking(ViveRole.GetDeviceIndexEx(role)));
 }
 /// <summary>
 /// Returns true if the device identified by role is connected.
 /// </summary>
 public static bool IsConnected(DeviceRole role)
 {
     return(IsConnected(ViveRole.GetDeviceIndexEx(role)));
 }
 /// <summary>
 /// Returns device index of the device identified by the role
 /// Returns INVALID_DEVICE_INDEX if the role doesn't assign to any device
 /// </summary>
 /// <returns>Current device index assigned to the role, should be tested by ViveRole.IsValidIndex before using it</returns>
 public static uint GetDeviceIndex(DeviceRole role)
 {
     return(GetDeviceIndexEx(role));
 }
Example #31
0
 internal unsafe void __MarshalFrom(ref DeviceDetails.__Native @ref)
 {
     fixed (char* ptr = &@ref.DeviceID)
     {
         this.DeviceID = Utilities.PtrToStringUni((IntPtr)((void*)ptr), 256);
     }
     fixed (char* ptr2 = &@ref.DisplayName)
     {
         this.DisplayName = Utilities.PtrToStringUni((IntPtr)((void*)ptr2), 256);
     }
     this.Role = @ref.Role;
     this.OutputFormat = new WaveFormatExtensible();
     this.OutputFormat.__MarshalFrom(ref @ref.OutputFormat);
 }