private SuperColumn BuildFolderIndexEntry(InventoryFolderBase folder, byte[] folderIdBytes, FolderMutationSelector mutationTypes, Guid newParent, long timeStamp) { SuperColumn indexColumn = new SuperColumn(); indexColumn.Name = folderIdBytes; List<Column> columns = new List<Column>(); if (mutationTypes == FolderMutationSelector.All || mutationTypes == FolderMutationSelector.AllButParent) { columns.Add(new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("name"), Value = ByteEncoderHelper.UTF8Encoder.ToByteArray(folder.Name), Timestamp = timeStamp }); columns.Add(new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("type"), Value = ByteEncoderHelper.Int32Encoder.ToByteArray((int)folder.Type), Timestamp = timeStamp }); columns.Add(new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("level"), Value = new byte[] { (byte)folder.Level }, Timestamp = timeStamp }); } if (mutationTypes == FolderMutationSelector.All || mutationTypes == FolderMutationSelector.ParentOnly) { columns.Add(new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("parent_folder"), Value = ByteEncoderHelper.GuidEncoder.ToByteArray(newParent), Timestamp = timeStamp }); } indexColumn.Columns = columns; return indexColumn; }
private void GetFolderStorageMutations(InventoryFolderBase folder, byte[] folderIdBytes, byte[] userIdBytes, FolderMutationSelector mutationTypes, Dictionary<byte[], Dictionary<string, List<Mutation>>> outMuts, Guid newParent, long timeStamp) { //Folder CF mutations List<Mutation> folderMutList = new List<Mutation>(); Mutation propertiesMut = new Mutation(); propertiesMut.Column_or_supercolumn = new ColumnOrSuperColumn(); propertiesMut.Column_or_supercolumn.Super_column = new SuperColumn(); propertiesMut.Column_or_supercolumn.Super_column.Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("properties"); List<Column> propertiesColumns = new List<Column>(); if (mutationTypes == FolderMutationSelector.All || mutationTypes == FolderMutationSelector.AllButParent) { Column nameCol = new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("name"), Value = ByteEncoderHelper.UTF8Encoder.ToByteArray(folder.Name), Timestamp = timeStamp, }; Column typeCol = new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("type"), Value = ByteEncoderHelper.LittleEndianInt32Encoder.ToByteArray(folder.Type), Timestamp = timeStamp, }; Column userIdCol = new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("user_id"), Value = ByteEncoderHelper.GuidEncoder.ToByteArray(folder.Owner.Guid), Timestamp = timeStamp, }; Column levelCol = new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("level"), Value = new byte[] { (byte)folder.Level }, Timestamp = timeStamp, }; propertiesColumns.Add(nameCol); propertiesColumns.Add(typeCol); propertiesColumns.Add(userIdCol); propertiesColumns.Add(levelCol); } if (mutationTypes == FolderMutationSelector.All || mutationTypes == FolderMutationSelector.ParentOnly) { Column parentIdCol = new Column { Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("parent"), Value = ByteEncoderHelper.GuidEncoder.ToByteArray(newParent), Timestamp = timeStamp, }; propertiesColumns.Add(parentIdCol); } propertiesMut.Column_or_supercolumn.Super_column.Columns = propertiesColumns; folderMutList.Add(propertiesMut); Dictionary<string, List<Mutation>> folderKeyMuts = new Dictionary<string, List<Mutation>>(); folderKeyMuts[FOLDERS_CF] = folderMutList; //version increment Mutation versionMut = VersionIncrement(); folderKeyMuts[FOLDERVERSIONS_CF] = new List<Mutation> { versionMut }; outMuts[folderIdBytes] = folderKeyMuts; //UserFolder CF mutations if (!outMuts.ContainsKey(userIdBytes)) { outMuts[userIdBytes] = new Dictionary<string, List<Mutation>>(); } if (!outMuts[userIdBytes].ContainsKey(USERFOLDERS_CF)) { outMuts[userIdBytes].Add(USERFOLDERS_CF, new List<Mutation>()); } List<Mutation> userKeyMuts = outMuts[userIdBytes][USERFOLDERS_CF]; List<Mutation> userFolderMutList = new List<Mutation>(); //userfolders index, the list of all folders per user Mutation userFolderPropertiesMut = new Mutation(); userFolderPropertiesMut.Column_or_supercolumn = new ColumnOrSuperColumn(); userFolderPropertiesMut.Column_or_supercolumn.Super_column = this.BuildFolderIndexEntry(folder, folderIdBytes, mutationTypes, newParent, timeStamp); userKeyMuts.Add(userFolderPropertiesMut); }