/** * Creates all needed Actions for a new collection */ public void AddNewCollectionActions(string collectionName) { if (string.IsNullOrEmpty(collectionName)) { Log($"{nameof(AddNewCollectionActions)}: collectionName is empty"); return; } if (_collectionActions == null) { return; } if (_collectionActions.ContainsKey(collectionName)) { return; } var newActions = new CollectionActions { PlayAction = new JSONStorableAction(GetPlayRandomClipActionName(collectionName), () => PlayRandomClipAction(collectionName)), QueueAction = new JSONStorableAction(GetQueueRandomClipActionName(collectionName), () => QueueRandomClipAction(collectionName)) }; _controller.RegisterAction(newActions.PlayAction); _controller.RegisterAction(newActions.QueueAction); _collectionActions.Add(collectionName, newActions); }
/// <summary> /// Create a member mapping<br/> /// 创建成员映射<br/> /// </summary> public void Map <TMember>( Expression <Func <T, TMember> > memberExpression, EntityMappingOptions options = null) { // Unsupported options: Length, CustomSqlType, CascadeDelete, WithSerialization options = options ?? new EntityMappingOptions(); ordinaryMembers.Add(((MemberExpression)memberExpression.Body).Member); MapActions.Add(m => { var memberMap = m.MapMember(memberExpression); if (!string.IsNullOrEmpty(options.Column)) { memberMap = memberMap.SetElementName(options.Column); } if (options.Nullable == true) { memberMap.SetIsRequired(true); } else if (options.Nullable == false) { memberMap.SetIsRequired(false); } }); if (options.Unique == true || !string.IsNullOrEmpty(options.Index)) { // Create indexes CollectionActions.Add(c => { var keys = new IndexKeysDefinitionBuilder <T>().Ascending( Expression.Lambda <Func <T, object> >( Expression.Convert(memberExpression.Body, typeof(object)), memberExpression.Parameters)); var indexOptions = new CreateIndexOptions() { Background = true, Unique = options.Unique, Sparse = !options.Unique // ignore null member on indexing }; var model = new CreateIndexModel <T>(keys, indexOptions); c.Indexes.CreateOne(model); }); } }