void HandleRemotelyCreatedGameObject(GameObject gameObject, CreatedObjectMessage message) { // TODO: Many ways through the code in this function that would not result // in us clearing our 'busy' status. bool newAnchor = false; // Do we already know the anchor that the GameObject is associated with? var anchorObject = this.worldAnchorMap.GetById(message.ParentAnchorId); newAnchor = (anchorObject == null); // If we don't have one... if (newAnchor) { // Make one but it's not anchored at this point anchorObject = this.worldAnchorMap.AddAnchorWithExistingIdAtOrigin( message.ParentAnchorId); } // Parent the object off the anchor object, hoping that this // will be ok even if we later go on to import the anchor. gameObject.transform.SetParent(anchorObject.transform, false); gameObject.transform.localPosition = message.LocalPosition; gameObject.transform.localRotation = message.LocalRotation; this.sharedObjectsInSceneMessages.Add(message); this.ConfigureTransformSynchronizer(gameObject); #if !UNITY_EDITOR if (newAnchor) { // We need to go off to the cloud and download that anchor. AzureBlobStorageHelper.DownloadWorldAnchorBlob( this.storageDetails, message.ParentAnchorId, (worked, bits) => { if (worked) { // Having got the bits, we need to import them onto the // game object which means that this object is likely // to change its position and orientation. WorldAnchorImportExportHelper.ImportWorldAnchorToGameObject( anchorObject, bits, imported => { this.FireBusy(false); this.FireHologramCreatedRemotely(new Guid(message.ObjectId)); } ); } } ); } #else this.FireHologramCreatedRemotely(new Guid(message.ObjectId)); #endif }
public void DeleteUser(string userId) { var existingUser = this.GetUserById(userId); AzureBlobStorageHelper.DeleteAvatar(existingUser.Id); this.DbContext.Users.Remove(existingUser); this.DbContext.SaveChanges(); }
public void UpdateMap(Map map) { AzureBlobStorageHelper.UploadMapThumbnail(map.Id.ToString(), MapThumbnailDrawer.Draw(map)); this.DbContext.Maps.Attach(map); this.DbContext.Entry(map).State = EntityState.Modified; this.DbContext.SaveChanges(); }
public void CreateMap(Map map, bool isLocked = false) { AzureBlobStorageHelper.UploadMapThumbnail(map.Id.ToString(), MapThumbnailDrawer.Draw(map)); map.IsLocked = isLocked; this.DbContext.Maps.Add(map); this.DbContext.SaveChanges(); }
public void DeleteMap(Map map) { if (map.IsLocked) { throw HttpResponseExceptionHelper.Create("Cannot delete a locked map, unlock it first", HttpStatusCode.BadRequest); } AzureBlobStorageHelper.DeleteMapThumbnail(map.Id.ToString()); this.DbContext.Maps.Remove(map); this.DbContext.SaveChanges(); }
public CreateExternalUserResult CreateExternalUser(ApplicationUserLogin userLogin) { if (string.IsNullOrEmpty(userLogin.ProviderUserId) || string.IsNullOrEmpty(userLogin.ProviderUsername)) { throw HttpResponseExceptionHelper.Create($"{userLogin.Provider} account login failed", HttpStatusCode.BadRequest); } var result = new CreateExternalUserResult(); // Check if the user login is already in use var existingUserLogin = this.DbContext.UserLogins .FirstOrDefault(x => x.Provider == userLogin.Provider && x.ProviderUserId == userLogin.ProviderUserId); // User already exists if (existingUserLogin != null) { result.User = this.GetUserById(existingUserLogin.UserId); result.UserCreated = false; return(result); } // Take only the first part if email var username = userLogin.ProviderUsername.Split('@').First(); // If username is already in use, tweak it until it's available while (this.DbContext.Users.FirstOrDefault(x => x.Username == username) != null) { username += new Random().Next(0, 9); } userLogin.UserId = ApplicationUserManager.GetUserHash(userLogin.ProviderUsername); var newUser = new ApplicationUser { Username = username, Id = userLogin.UserId, UserLogins = new List <ApplicationUserLogin> { userLogin } }; this.DbContext.Users.Add(newUser); this.DbContext.SaveChanges(); result.User = newUser; result.UserCreated = true; AzureBlobStorageHelper.UploadDefaultAvatar(newUser.Id); return(result); }
public IHttpActionResult UpdateUserProfile(UpdateProfileMessage msg) { var user = this._userRepo.GetUserById(this.UserToken.UserId); // Update modified fields user.Description = msg.Description; // Upload the new avatar if (!string.IsNullOrEmpty(msg.AvatarInBase64)) { AzureBlobStorageHelper.UploadAvatar(user.Id, Convert.FromBase64String(msg.AvatarInBase64)); } this._userRepo.UpdateUser(user); return this.Ok(); }
public ApplicationUser CreateUser(string username, string password) { var existingUser = this.DbContext.Users.SingleOrDefault(x => x.Username == username); if (existingUser != null) { throw HttpResponseExceptionHelper.Create("This username is already taken", HttpStatusCode.BadRequest); } var newUser = new ApplicationUser { Username = username, Id = ApplicationUserManager.GetUserHash(username), Password = ApplicationUserManager.HashUserPassword(password) }; this.DbContext.Users.Add(newUser); this.DbContext.SaveChanges(); AzureBlobStorageHelper.UploadDefaultAvatar(newUser.Id); return(newUser); }
void HandleLocallyCreateGameObject(GameObject gameObject, string gameObjectType, Action <GameObject> callback) { // Do we have a world anchor for this position already? GameObject worldAnchorParent = null; bool addedAnchor = this.worldAnchorMap.GetOrAddWorldAnchorForPosition( gameObject.transform.position, gameObject.transform.forward, out worldAnchorParent); // parent the GameObject off its anchor without moving it, the assumption // being that if didn't already have an anchor then we just created it // at the same place as the object itself and so once we reparent we // are hoping that object and the anchor are identical in placement // (making for a LocalPosition of 0). gameObject.transform.SetParent(worldAnchorParent.transform, true); #if !UNITY_EDITOR // We only do this work with world anchors if we aren't in the editor // as I don't think a WorldAnchor in the editor will ever say that it // isLocated so it'll break our logic. if (addedAnchor) { // Now export that to get a bunch of bytes for it... WorldAnchorImportExportHelper.ExportWorldAnchorFromGameObject( worldAnchorParent, bits => { if (bits != null) { // We now need to send those bits off to the cloud... AzureBlobStorageHelper.UploadWorldAnchorBlob( this.storageDetails, worldAnchorParent.name, bits, (worked, bytes) => { this.ConfigureTransformSynchronizer(gameObject); this.SendCreatedObjectMessage( gameObjectType, gameObject, worldAnchorParent, callback); } ); } else { // TODO: figure what we do here and make sure that if we do it // then we don't forget to clear our busy status too. } } ); } else { this.ConfigureTransformSynchronizer(gameObject); // Send a message to the world telling them about the new object. this.SendCreatedObjectMessage( gameObjectType, gameObject, worldAnchorParent, callback); } #else // Send a message to the world telling them about the new object - it's // important to note that we pass whether we newly created an anchor or // not as that impacts the message that we send. this.ConfigureTransformSynchronizer(gameObject); this.SendCreatedObjectMessage( gameObjectType, gameObject, worldAnchorParent, callback); #endif }