示例#1
0
        public ChannelService(IChannelConnectionRepository channelConnRepo,
                              IChannelMessageRepository channelMessageRepo,
                              IChannelRepository channelRepo)
        {
            _channelConnRepo = (ChannelConnectionRepository)channelConnRepo;

            _channelMessageRepo = channelMessageRepo;

            _channelRepo = channelRepo;
        }
        public void SetUsersIfCanMansge(IDbConnection connection, IChannelConnectionRepository repository)
        {
            if (!CanManage)
            {
                return;
            }
            var provider   = repository.Provider;
            var chTbName   = repository.SchemeTableName;//channel_connection
            var userTbName = provider.GetTableName(nameof(user));
            var sql        = $"SELECT c.*, u.nickname AS UserName FROM {chTbName} AS c " +
                             $"LEFT JOIN {userTbName} AS u ON c.userId =u.Id " +
                             $"WHERE c.channelId={ChannelId} AND c.channelType={(byte)ChannelType} ";

            Users = provider.Text <dynamic>(connection, sql).Select(i =>
            {
                var d = ((object)i).ToSerealizeString().ToSpecificModel <channel_connection>();
                var r = new ChannelConnectionUserOut(repository.ConvertToWorkModel(d), (string)i.UserName, _data.Password);
                return(r);
            }).ToDictionary(i => i.Id, i => i);
            CreatorConnection = Users.First(i => i.Value.UserId == _data.CreatorId).Value;
            Users.Remove(CreatorConnection.Id);
        }
        public void SetChannelsTabsData(IDbConnection connection, IChannelRepository channelR, IChannelMessageRepository mesR, IChannelConnectionRepository conR, int userId, int allianceId,
                                        bool allianceRoleMessageSend)
        {
            var privateCollection = new Dictionary <int, IBaseChannelOut>();
            var groupCollection   = new Dictionary <int, IBaseChannelOut>();
            Dictionary <int, IBaseChannelOut> allianceCollection = null;
            var provider = channelR.Provider;
            var channelConnectionTbName = conR.SchemeTableName;
            var channelTableName        = channelR.SchemeTableName;
            var ch          = ChannelExtensions.SqlAliaceChannel;
            var chCon       = ChannelExtensions.SqlAliaceChannelConnection;
            var sqlChannels = $"SELECT {chCon}.messageSend as messageSend, {ch}.* FROM {channelConnectionTbName} AS {chCon} " +
                              $"JOIN {channelTableName} AS {ch} ON {ch}.Id = {chCon}.channelId " +
                              $"WHERE {chCon}.userId={userId} AND {chCon}.messageRead=1 AND {ch}.password={chCon}.password";

            var channelData = provider.Text <dynamic>(connection, sqlChannels);
            var channels    = channelData.Select(i => new {
                channelData = channelR.ConvertToWorkModel(((object)i).ToSerealizeString().ToSpecificModel <channel>()),
                messageSend = (bool)i.messageSend
            }
                                                 );

            foreach (var channel in channels)
            {
                switch (channel.channelData.ChannelType)
                {
                case ChannelTypes.Group:
                    var gChOut = new GroupChannelOut(channel.channelData, userId);
                    gChOut.SetMessages(connection, mesR);
                    gChOut.SetComplexButtonView();
                    gChOut.SetBtnSend(channel.messageSend);
                    gChOut.SetUsersIfCanMansge(connection, conR);
                    groupCollection.Add(gChOut.ChannelId, gChOut);


                    break;

                case ChannelTypes.Private:
                    var pChOut = new PrivateChannelOut(channel.channelData);
                    pChOut.SetMessages(connection, mesR);
                    pChOut.SetComplexButtonView();
                    pChOut.SetBtnSend(channel.messageSend);

                    privateCollection.Add(pChOut.ChannelId, pChOut);
                    break;

                case ChannelTypes.Alliance:
                    if (allianceCollection != null)
                    {
                        throw new NotImplementedException("AllianceChannel !=null");
                    }
                    var allianceChannel = new AllianceChannelOut(channel.channelData);
                    allianceChannel.SetMessages(connection, mesR);
                    allianceChannel.SetComplexButtonView();
                    allianceChannel.SetBtnSend(allianceRoleMessageSend);

                    allianceCollection = new Dictionary <int, IBaseChannelOut>(1)
                    {
                        { allianceChannel.ChannelId, allianceChannel }
                    };
                    break;

                default:
                    throw new NotImplementedException();
                }
            }


            Private = new ChannelTab(privateCollection);
            Group   = new ChannelTab(groupCollection)
            {
                MaxChannelsLimit = (int)MaxLenghtConsts.GroupChannelsLimit
            };
            Alliance = new ChannelTab(allianceCollection);
        }
示例#4
0
 public ChannelConnectionLocalStorageCache(IChannelConnectionRepository repository)
     : base(repository)
 {
     throw new NotImplementedException(Error.NotUsedServerMethod);
 }