Esempio n. 1
0
        public async Task InitializeAsync(string id)
        {
            if (RootContainer == null)
            {
                IUserProfileDataManagement userManager = ServiceRegistration.Get <IUserProfileDataManagement>();
                ClientName = $"DLNA ({id})";
                var profile = await userManager.GetProfileByNameAsync(ClientName);

                if (profile.Success)
                {
                    ClientId = profile.Result.ProfileId;
                }
                else
                {
                    ClientId = await userManager.CreateProfileAsync(ClientName, UserProfileType.ClientProfile, "");
                }
                await userManager.LoginProfileAsync(ClientId);

                if (UserId.HasValue)
                {
                    await InitializeUserAsync();
                }

                InitialiseContainerTree();
            }
        }
Esempio n. 2
0
        public async Task <UserProfile> GetOrCreateDefaultUser()
        {
            await _lock.WaitAsync();

            try
            {
                Guid systemId = Guid.Parse(ServiceRegistration.Get <ISystemResolver>().LocalSystemId);
                IUserProfileDataManagement updm = UserProfileDataManagement;
                if (updm == null)
                {
                    return(null);
                }

                var result = await updm.GetProfileAsync(systemId);

                if (result.Success)
                {
                    return(result.Result);
                }

                // First check if there is an "old" client profile with same name but different ID. This happens only for older versions.
                // This needs to be done to avoid unique constraint violations when creating the new profile by name.
                // If client profile exists rename it and convert it to a user profile so it can be deleted or used otherwise.
                string profileName     = SystemInformation.ComputerName;
                var    existingProfile = await updm.GetProfileByNameAsync(profileName);

                if (existingProfile.Success && existingProfile.Result.ProfileId != systemId)
                {
                    if (await updm.ChangeProfileIdAsync(existingProfile.Result.ProfileId, systemId))
                    {
                        result = await updm.GetProfileAsync(systemId);

                        if (result.Success)
                        {
                            return(result.Result);
                        }
                    }
                }

                // Create a login profile which uses the LocalSystemId and the associated ComputerName
                Guid profileId = await updm.CreateClientProfileAsync(systemId, profileName);

                result = await updm.GetProfileAsync(profileId);

                if (result.Success)
                {
                    return(result.Result);
                }
                return(null);
            }
            finally
            {
                _lock.Release();
            }
        }