Skip to content

Commit

Permalink
[client] 사용자의 클라이언트 연결을 볼 수 있는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
powerumc committed Aug 8, 2019
1 parent 25690e0 commit dffafce
Show file tree
Hide file tree
Showing 14 changed files with 403 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using Ntreev.Crema.ServiceModel;
using Ntreev.Crema.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ntreev.Crema.Client.Framework
{
public interface IUserAuthenticationDescriptor : IDescriptorBase
{
string DisplayName { get; }

UserInfo UserInfo { get; }

bool IsOnline { get; }

IUser User { get; }

new IUserAuthentication Target { get; }
}
}
2 changes: 2 additions & 0 deletions client/Ntreev.Crema.Client.Framework/IUserDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace Ntreev.Crema.Client.Framework
{
public interface IUserDescriptor : IDescriptorBase
{
IUserAuthenticationCollection Authentications { get; }

string UserID { get; }

string DisplayName { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="IUserAuthenticationDescriptor.cs" />
<Compile Include="ListBoxBase.cs" />
<Compile Include="TreeViewBase.cs" />
<Compile Include="Controls\PropertyListBox.cs" />
Expand Down Expand Up @@ -116,6 +117,8 @@
<Compile Include="TableContentDescriptorUtility.cs" />
<Compile Include="TableContentListItemBase.cs" />
<Compile Include="TableItemDescriptorUtility.cs" />
<Compile Include="UserAuthenticationDescriptor.cs" />
<Compile Include="UserAuthenticationTreeItemBase.cs" />
<Compile Include="UserCategoryTreeItemBase.cs" />
<Compile Include="UserTreeItemBase.cs" />
<None Include="Converters\DataBaseDescriptorToPropertyConverter.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ntreev.Crema.ServiceModel;
using Ntreev.Crema.Services;

namespace Ntreev.Crema.Client.Framework
{
public class UserAuthenticationDescriptor : DescriptorBase, IUserAuthenticationDescriptor
{
private readonly IUserAuthentication userAuthentication;

public UserAuthenticationDescriptor(Authentication authentication, IUserAuthentication userAuthentication, DescriptorTypes descriptorTypes, object owner)
: base(authentication, userAuthentication, descriptorTypes)
{
this.userAuthentication = userAuthentication;
}

public string DisplayName
{
get
{
var name = "";
if (this.authentication.Token == this.userAuthentication.Authentication.Token)
{
name += "* ";
}

name += this.userAuthentication.Authentication.Token.ToString();
return name;
}
}

public UserInfo UserInfo => this.User.UserInfo;

public bool IsOnline { get; } = true;

public IUser User => this.userAuthentication.User;

IUserAuthentication IUserAuthenticationDescriptor.Target => this.userAuthentication;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//Released under the MIT License.
//
//Copyright (c) 2018 Ntreev Soft co., Ltd.
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
//persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
//Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ntreev.Crema.ServiceModel;
using Ntreev.Crema.Services;

namespace Ntreev.Crema.Client.Framework
{
public class UserAuthenticationTreeItemBase : DescriptorTreeItemBase<UserAuthenticationDescriptor>, IUserAuthenticationDescriptor
{
public UserAuthenticationTreeItemBase(Authentication authentication, IUserAuthentication userAuthentication, bool isSubscriptable, object owner)
: base(authentication, new UserAuthenticationDescriptor(authentication, userAuthentication, isSubscriptable ? DescriptorTypes.All : DescriptorTypes.IsRecursive, owner), owner)
{

}

internal protected UserAuthenticationTreeItemBase(Authentication authentication, UserAuthenticationDescriptor descriptor, object owner)
: base(authentication, descriptor, owner)
{
}

public UserInfo UserInfo => this.Descriptor.UserInfo;

public bool IsOnline => this.Descriptor.IsOnline;

public IUser User => this.Descriptor.User;

IUserAuthentication IUserAuthenticationDescriptor.Target => this.Descriptor.Target as IUserAuthentication;
}
}
84 changes: 84 additions & 0 deletions client/Ntreev.Crema.Client.Framework/UserDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ public class UserDescriptor : DescriptorBase, IUserDescriptor, IUserItemDescript
private UserState userState;
private BanInfo banInfo = BanInfo.Empty;

private readonly ObservableCollection<UserAuthenticationDescriptor> userAuthentications = new ObservableCollection<UserAuthenticationDescriptor>();
private readonly ReadOnlyObservableCollection<UserAuthenticationDescriptor> userAuthenticationsReadonly;

public ReadOnlyObservableCollection<UserAuthenticationDescriptor> UserAuthentications => this.userAuthenticationsReadonly;

public UserDescriptor(Authentication authentication, IUserDescriptor descriptor, bool isSubscriptable, object owner)
: base(authentication, descriptor.Target, descriptor, isSubscriptable)
{
this.user = descriptor.Target;
this.owner = owner ?? this;

this.userAuthenticationsReadonly = new ReadOnlyObservableCollection<UserAuthenticationDescriptor>(this.userAuthentications);
}

public UserDescriptor(Authentication authentication, IUser user, DescriptorTypes descriptorTypes, object owner)
Expand All @@ -60,12 +67,22 @@ public UserDescriptor(Authentication authentication, IUser user, DescriptorTypes
this.userState = this.user.UserState;
this.banInfo = this.user.BanInfo;

this.userAuthenticationsReadonly = new ReadOnlyObservableCollection<UserAuthenticationDescriptor>(this.userAuthentications);

if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true)
{
this.user.Deleted += User_Deleted;
this.user.UserInfoChanged += User_UserInfoChanged;
this.user.UserStateChanged += User_UserStateChanged;
this.user.UserBanInfoChanged += User_UserBanInfoChanged;
this.user.Authentications.CollectionChanged += Authentications_CollectionChanged;
}

foreach (var userAutentication in this.user.Authentications.Values)
{
var userAuthenticationDescriptor = new UserAuthenticationDescriptor(this.authentication, userAutentication, this.descriptorTypes, this.owner);
userAutentication.ExtendedProperties[this.owner] = userAuthenticationDescriptor;
this.userAuthentications.Add(userAuthenticationDescriptor);
}
}

Expand Down Expand Up @@ -111,6 +128,7 @@ await this.user.Dispatcher.InvokeAsync(() =>
this.user.UserInfoChanged -= User_UserInfoChanged;
this.user.UserStateChanged -= User_UserStateChanged;
this.user.UserBanInfoChanged -= User_UserBanInfoChanged;
this.user.Authentications.CollectionChanged -= Authentications_CollectionChanged;
}
});
}
Expand Down Expand Up @@ -144,6 +162,70 @@ private async void User_UserBanInfoChanged(object sender, EventArgs e)
await this.RefreshAsync();
}

private void Authentications_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
{
var descriptorList = new List<UserAuthenticationDescriptor>(e.NewItems.Count);
foreach (IUserAuthentication item in e.NewItems)
{
if (item.ExtendedProperties.ContainsKey(this.owner) == true)
{
var descriptor = item.ExtendedProperties[this.owner] as UserAuthenticationDescriptor;
descriptorList.Add(descriptor);
}
else
{
var descriptor = new UserAuthenticationDescriptor(this.authentication, item, this.descriptorTypes, this.owner);
item.ExtendedProperties[this.owner] = descriptor;
descriptorList.Add(descriptor);
}

}
this.Dispatcher.InvokeAsync(() =>
{
foreach (var item in descriptorList)
{
this.userAuthentications.Add(item);
}
});
}
break;
case NotifyCollectionChangedAction.Remove:
{
var descriptorList = new List<UserAuthenticationDescriptor>(e.OldItems.Count);
foreach (IUserAuthentication item in e.OldItems)
{
var descriptor = item.ExtendedProperties[this.owner] as UserAuthenticationDescriptor;
descriptorList.Add(descriptor);
}
this.Dispatcher.InvokeAsync(() =>
{
foreach (var item in descriptorList)
{
this.userAuthentications.Remove(item);
}
});
}
break;
case NotifyCollectionChangedAction.Move:
{

}
break;
case NotifyCollectionChangedAction.Reset:
{
this.Dispatcher.InvokeAsync(() =>
{
this.userAuthentications.Clear();
});
}
break;
}
}

#region IUserItemDescriptor

IUserItem IUserItemDescriptor.Target => this.user as IUserItem;
Expand All @@ -158,6 +240,8 @@ private async void User_UserBanInfoChanged(object sender, EventArgs e)

IUser IUserDescriptor.Target => this.user;

public IUserAuthenticationCollection Authentications => this.user.Authentications;

#endregion
}
}
Loading

0 comments on commit dffafce

Please sign in to comment.