/// <summary> /// the expected node for the item xml is the following: /// <item id="1061" name="106" appName="HANGOUT_FAMILY_Application_1" itemTypeName="Room Backdrop" buttonName="Two Fast Two Furious" description="Live life a quarter mile at a time" smallImageUrl="http://s3.amazonaws.com/HangoutDevFileBucket/48141004.jpg" mediumImageUrl="" largeImageUrl="http://s3.amazonaws.com/HangoutDevFileBucket/48141004.jpg" available="-1"> /// <Assets /> /// </item> /// </summary> /// <param name="receivedMessage"></param> private void ChangeBackground(Message receivedMessage) { mRoomBackgroundItemId = CheckType.TryAssignType <ItemId>(receivedMessage.Data[0]); List <ItemId> roomItems = UpdateRoomItems(); XmlDocument updatedRoomDna = RoomXmlUtil.CreateRoomDnaXml(this.RoomName, this.RoomType, roomItems); //update the database with the new items RoomManagerServiceAPI.UpdateRoomDnaService(this.RoomId, updatedRoomDna, delegate(XmlDocument xmlResponse) { XmlNode successNode = xmlResponse.SelectSingleNode("Success"); if (successNode != null && successNode.InnerText == "true") { XmlNode backgroundItemXml = mServerAssetRepository.GetXmlDna(new ItemId[] { mRoomBackgroundItemId }); List <object> backgroundChangeMessageData = new List <object>(); backgroundChangeMessageData.Add(backgroundItemXml.OuterXml); Message broadcastBackgroundChangeMessage = new Message(); broadcastBackgroundChangeMessage.UpdateObjectMessage(true, false, this.DistributedObjectId, (int)MessageSubType.ChangeBackground, backgroundChangeMessageData); BroadcastMessage(broadcastBackgroundChangeMessage); } else { StateServerAssert.Assert(new System.Exception("Error setting background in room on database.")); } } ); }
/// <summary> /// Received a DNA update from the client. Save the DNA via the AvatarManagerServiceAPI and broadcast to other clients /// TODO: Verify the dna is valid /// </summary> /// <param name="message"></param> private void RecvDnaUpdate(Message message) { string newDnaString = CheckType.TryAssignType <string>(message.Data[0]); XmlDocument newDna = new XmlDocument(); newDna.LoadXml(newDnaString); mLogger.Info("RecvDnaUpdate: " + mAvatarId.ToString() + ": " + newDnaString); // Get list of ItemIds from DNA List <ItemId> itemIds; AvatarXmlUtil.GetItemIdsFromAvatarDnaNode(newDna, out itemIds); // Get XML of assets from ItemIds XmlDocument assetXml = mServerAssetRepository.GetXmlDna(itemIds); // Replace the DNA in the message with the asset xml message.Data[0] = assetXml.OuterXml; mObjectData[3] = assetXml.InnerXml; // Broadcast the change out BroadcastMessage(message); // Save the dna to the DB AvatarManagerServiceAPI.UpdateAvatarDna(mAvatarId, newDna, delegate(XmlDocument xmlResponse) { mLogger.Info("RecvDnaUpdate, DNA saved: " + mAvatarId.ToString() + "\n" + xmlResponse.OuterXml); }); }
/// <summary> /// Get a reference system avatar. This avatar is used to fill in missing required info when pulling an avatar from the db /// </summary> private void GetReferenceAvatar(Action <Dna> gotReferenceAvatarFinished) { Action <XmlDocument> systemAvatarCallback = delegate(XmlDocument xmlResponse) { // Get the avatars for the friends without Hangout Avatars XmlNode avatarXmlNode = xmlResponse.SelectSingleNode("/Avatars/Avatar[@AvatarId='1']"); AvatarId avatarId; List <ItemId> itemIds = null; if (AvatarXmlUtil.GetAvatarInfoFromAvatarXmlNode(avatarXmlNode, out avatarId, out itemIds)) { //use the ServerAssetRepo to composite the List<ItemId> into an XmlNode XmlDocument itemsXml = mServerAssetRepository.GetXmlDna(itemIds); // Get a list of AssetInfos from this xml IEnumerable <AssetInfo> assetInfoList = ServerAssetInfo.Parse(itemsXml); // Make dna mReferenceAvatarDna = new Dna(); mReferenceAvatarDna.UpdateDna(assetInfoList); gotReferenceAvatarFinished(mReferenceAvatarDna); mLogger.Debug("System avatar xml = " + xmlResponse.OuterXml); } else { StateServerAssert.Assert(new Exception("Didn't get a valid system avatar for reference avatar, using an empty DNA")); mReferenceAvatarDna = new Dna(); gotReferenceAvatarFinished(mReferenceAvatarDna); } }; if (mReferenceAvatarDna == null) { AvatarManagerServiceAPI.GetSystemAvatars(systemAvatarCallback); } else { gotReferenceAvatarFinished(mReferenceAvatarDna); } }