Пример #1
0
 public StorageUserModel(IStorage storage, StorageContext storageContext, Guid id)
     : base(storage, storageContext, id)
 {
     this.accounts = new StorageEntityCollection <StorageAccountModel, IAccountModel>(storageContext)
     {
         FetchIdCollection = () => storage.User.GetAccounts(id),
         GetId             = account => account.Id,
         GetModel          = storageContext.InternalAccounts.InternalFind,
         ReverseAdd        = account => account.InternalUsers.CacheAdd(this),
         ReverseRemove     = account => account.InternalUsers.CacheRemove(this),
         SaveAdd           = account => storage.Account.Add(account.Id, id),
         SaveRemove        = account => storage.Account.Remove(account.Id, id),
     };
 }
Пример #2
0
        public StorageListModel(IStorage storage, StorageContext storageContext, Guid listId)
            : base(storage, storageContext, listId)
        {
            this.followers = new StorageEntityCollection <StorageAccountModel, IAccountModel>(storageContext)
            {
                FetchIdCollection = () => storage.List.GetFollowingAccounts(listId),
                GetId             = account => account.Id,
                GetModel          = storageContext.InternalAccounts.InternalFind,
                ReverseAdd        = account =>
                {
                    // TODO: this shouldn't involve storage calls
                    account.InternalAllFollowedLists.CacheAdd(this);
                    if (!this.IsPrivate)
                    {
                        account.InternalPublicFollowedLists.CacheAdd(this);
                    }
                },
                ReverseRemove = account =>
                {
                    // TODO: this shouldn't involve storage calls
                    account.InternalAllFollowedLists.CacheRemove(this);
                    if (!this.IsPrivate)
                    {
                        account.InternalPublicFollowedLists.CacheRemove(this);
                    }
                },
                SaveAdd    = account => storage.List.Follow(listId, account.Id),
                SaveRemove = account => storage.List.Unfollow(listId, account.Id)
            };

            this.members = new StorageEntityCollection <StorageAccountModel, IAccountModel>(storageContext)
            {
                FetchIdCollection = () => storage.List.GetAccounts(listId),
                GetId             = account => account.Id,
                GetModel          = storageContext.InternalAccounts.InternalFind,
                ReverseAdd        = account => account.InternalMemberOfLists.CacheAdd(this),
                ReverseRemove     = account => account.InternalMemberOfLists.CacheRemove(this),
                SaveAdd           = account => storage.List.Add(listId, account.Id),
                SaveRemove        = account => storage.List.Remove(listId, account.Id)
            };
        }
Пример #3
0
        public StorageAccountModel(IStorage storage, StorageContext storageContext, Guid accountId)
            : base(storage, storageContext, accountId)
        {
            this.users = new StorageEntityCollection <StorageUserModel, IUserModel>(this.StorageContext)
            {
                FetchIdCollection = () => storage.Account.GetUsers(accountId),
                GetId             = user => user.Id,
                GetModel          = storageContext.InternalUsers.InternalFind,
                ReverseAdd        = user => user.InternalAccounts.CacheAdd(this),
                ReverseRemove     = user => user.InternalAccounts.CacheRemove(this),
                SaveAdd           = user => storage.Account.Add(this.Id, user.Id),
                SaveRemove        = user => storage.Account.Remove(this.Id, user.Id),
            };

            this.memberOfLists = new ListCollectionAdapter(this.StorageContext)
            {
                FetchIdCollection = () => storage.List.GetFollowingLists(accountId),
                GetId             = list => list.Id,
                GetModel          = storageContext.InternalLists.InternalFind,
                ReverseAdd        = list => list.InternalMembers.CacheAdd(this),
                ReverseRemove     = list => list.InternalMembers.CacheRemove(this),
                SaveAdd           = list => storage.List.Add(list.Id, this.Id),
                SaveRemove        = list => storage.List.Remove(list.Id, this.Id),
            };

            this.allFollowedLists =
                new ListCollectionAdapter(storageContext)
            {
                FetchIdCollection = () => storage.List.GetAccountFollowedLists(accountId, true),
                GetId             = list => list.Id,
                GetModel          = storageContext.InternalLists.InternalFind,
                ReverseAdd        = list =>
                {
                    // TODO: shouldn't call storage
                    list.InternalFollowers.CacheAdd(this);
                    if (!list.IsPrivate)
                    {
                        this.InternalPublicFollowedLists.CacheAdd(list);
                    }
                },
                ReverseRemove = list =>
                {
                    // TODO: shouldn't call storage
                    list.InternalFollowers.CacheRemove(this);
                    if (!list.IsPrivate)
                    {
                        this.InternalPublicFollowedLists.CacheRemove(list);
                    }
                },
                SaveAdd    = list => storage.List.Follow(list.Id, this.Id),
                SaveRemove = list => storage.List.Unfollow(list.Id, this.Id),
            };

            this.publicFollowedLists =
                new ListCollectionAdapter(storageContext)
            {
                FetchIdCollection = () => storage.List.GetAccountFollowedLists(accountId, true),
                GetId             = list => list.Id,
                GetModel          = storageContext.InternalLists.InternalFind,
                ReverseAdd        = list => Contract.Assert(false),
                ReverseRemove     = list => Contract.Assert(false),
                SaveAdd           = list => Contract.Assert(false),
                SaveRemove        = list => Contract.Assert(false),
            };

            this.allOwnedLists =
                new ListCollectionAdapter(storageContext)
            {
                FetchIdCollection = () => storage.List.GetAccountOwnedLists(accountId, true),
                GetId             = list => list.Id,
                GetModel          = storageContext.InternalLists.InternalFind,
                ReverseAdd        = list => Contract.Assert(false),
                ReverseRemove     = list => Contract.Assert(false),
                SaveAdd           = list => Contract.Assert(false),
                SaveRemove        = list => Contract.Assert(false),
            };

            this.publicOwnedLists =
                new ListCollectionAdapter(storageContext)
            {
                FetchIdCollection = () => storage.List.GetAccountOwnedLists(accountId, false),
                GetId             = list => list.Id,
                GetModel          = storageContext.InternalLists.InternalFind,
                ReverseAdd        = list => Contract.Assert(false),
                ReverseRemove     = list => Contract.Assert(false),
                SaveAdd           = list => Contract.Assert(false),
                SaveRemove        = list => Contract.Assert(false),
            };
        }