示例#1
0
        /// <summary>
        /// Creates a user ID based on the ID type.
        /// </summary>
        /// <typeparam name="TUser">The type of user.</typeparam>
        /// <param name="user">The user to create the ID for.</param>
        /// <param name="idType">The type of the ID to create.</param>
        /// <param name="db">The Raven document store.</param>
        /// <returns>An initial string ID. Depending on the <paramref name="idType"/>, this may be null or a partial ID that gets assigned by the database upon storing the user.</returns>
        public static string?UserIdFor <TUser>(TUser user, UserIdType idType, IDocumentStore db)
            where TUser : IdentityUser
        {
            // Raven has special handling for consecutive IDs (AppUsers/1)
            if (idType == UserIdType.Consecutive)
            {
                return(CollectionNameFor <TUser>(db) + "|"); // pipe character convention: https://ravendb.net/docs/article-page/4.2/csharp/client-api/document-identifiers/working-with-document-identifiers#identities
            }

            // Raven has special handling for number-tag IDs (AppUsers/1-a)
            if (idType == UserIdType.NumberTag)
            {
                return(null); // null ID for autogenerated IDs: https://ravendb.net/docs/article-page/4.2/csharp/client-api/document-identifiers/working-with-document-identifiers#autogenerated-ids
            }

            // If UserIdType is none, that means we use whatever the user has specified for User.Id
            if (idType == UserIdType.None)
            {
                return(user.Id);
            }

            var userIdPart = idType switch
            {
                UserIdType.Email => user.Email,
                UserIdType.UserName => user.UserName,
                _ => string.Empty // everything else uses empty or has already been handled above.
            };

            return(UserIdWithSuffix <TUser>(userIdPart, db));
        }
示例#2
0
 internal DisboardPlayer(UserIdType id, string name, string nickname, string mention, DisboardChannel channel)
 {
     Id         = id;
     Name       = name;
     Nickname   = nickname;
     Mention    = mention;
     Channel    = channel;
     NextPlayer = this;
 }
示例#3
0
        public UserRights(UserIdType userIdType, string principalId, Collection <string> rights)
        {
            if ((userIdType != UserIdType.Email) &&
                (userIdType != UserIdType.IpcUser))
            {
                throw new ArgumentOutOfRangeException("principalIdType");
            }

            if (principalId == null)
            {
                throw new ArgumentNullException("principalId");
            }

            if (principalId.Trim().Length == 0)
            {
                throw new ArgumentOutOfRangeException("principalId");
            }

            if (userIdType == UserIdType.IpcUser)
            {
                if (string.Compare(principalId, IpcUserIDs.UserIdEveryone, StringComparison.InvariantCultureIgnoreCase) != 0 &&
                    string.Compare(principalId, IpcUserIDs.UserIdNull, StringComparison.InvariantCultureIgnoreCase) != 0 &&
                    string.Compare(principalId, IpcUserIDs.UserIdOwner, StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    throw new ArgumentOutOfRangeException("principalId");
                }
            }

            if (rights == null)
            {
                throw new ArgumentNullException("rights");
            }

            m_rights     = rights;
            m_userId     = principalId;
            m_userIdType = userIdType;
        }
示例#4
0
 /// <summary>
 /// Creates a new ChangeUserIdType migration.
 /// </summary>
 /// <param name="db">The Raven doc store.</param>
 /// <param name="newUserIdType">The type of ID to migrate to.</param>
 public ChangeUserIdType(IDocumentStore db, UserIdType newUserIdType)
     : base(db)
 {
     this.newUserIdType = newUserIdType;
 }
示例#5
0
文件: RMSAPI.cs 项目: LiDamon/ADRMS
 public UserRights SetUserRights(UserIdType userType, string userName, Collection <string> rights)
 {
     return(new UserRights(userType, userName, rights));
 }
示例#6
0
        async Task OnBot(DisboardGame?game, DiscordChannel channel, UserIdType authorId, string content, IEnumerable <DiscordUser> mentionedUsers)
        {
            var         split   = content.Split(" ").ToList();
            GuildIdType guildId = channel.GuildId;

            if (split.Count > 1 && split[1].ToLower() == "start")
            {
                if (game == null)
                {
                    if (mentionedUsers.Count() == split.Count - 2)
                    {
                        await NewGame(channel, mentionedUsers);
                    }
                    else
                    {
                        await channel.SendMessageAsync("`BOT start @참가인원1 @참가인원2... 로 게임을 시작합니다.`");
                    }
                }
                else
                {
                    await channel.SendMessageAsync("`진행중인 게임이 있습니다. BOT restart @참가인원1 @참가인원2...는 어떨까요?`");
                }
            }
            else if (split.Count > 1 && split[1].ToLower() == "restart")
            {
                if (game == null)
                {
                    await channel.SendMessageAsync("`진행중인 게임이 없습니다. BOT start @참가인원1 @참가인원2...는 어떨까요?`");
                }
                else
                {
                    if (mentionedUsers.Count() == split.Count - 2)
                    {
                        await NewGame(channel, mentionedUsers);
                    }
                    else
                    {
                        await channel.SendMessageAsync("`BOT restart @참가인원1 @참가인원2... 로 게임을 시작합니다.`");
                    }
                }
            }
            else if (split.Count == 2 && split[1].ToLower() == "help")
            {
                if (game == null)
                {
                    await channel.SendMessageAsync("`BOT start @참가인원1 @참가인원2...로 게임을 시작합니다.`");
                }
                else
                {
                    var player = game.InitialPlayers.Where(_ => _.Id == authorId).FirstOrDefault();
                    if (player == null)
                    {
                        await channel.SendMessageAsync("`BOT restart @참가인원1 @참가인원2... 로 게임을 시작합니다.`");
                    }
                }

                var messageQueue = new ConcurrentQueue <Func <Task> >();
                void task() => GameFactory.OnHelp(new DisboardChannel(channel, messageQueue, STADispatcher));
                await RunAndProcessMessage(task, messageQueue);
            }
            else if (split.Count > 1 && split[1].ToLower() == "restoredm")
            {
                if (game == null)
                {
                    await channel.SendMessageAsync("`진행중인 게임이 없습니다. BOT start @참가인원1 @참가인원2...는 어떨까요?`");
                }
                else if (false == game is DisboardGameUsingDM)
                {
                    await channel.SendMessageAsync("`DM을 사용하지 않는 게임입니다.`");
                }
                else
                {
                    var player = game.InitialPlayers.Where(_ => _.Id == authorId).FirstOrDefault();
                    if (player == null)
                    {
                        await channel.SendMessageAsync("`게임에 참여하고 있지 않습니다. 게임에 참여하려면 BOT restart @참가인원1 @참가인원2...로 게임을 다시 시작해야 합니다.`");
                    }
                    else
                    {
                        var gameUsesDM = game as DisboardGameUsingDM;
                        var member     = await channel.Guild.GetMemberAsync(authorId);

                        var dMChannel = await member.CreateDmChannelAsync();

                        if (GamesByUsers.GetValueOrDefault(authorId) == game)
                        {
                            await dMChannel.SendMessageAsync("`이곳에 입력하는 메시지는 해당 채널의 게임으로 전달됩니다.`");
                        }
                        else
                        {
                            GamesByUsers.Remove(authorId, out _);
                            GamesByUsers.TryAdd(authorId, gameUsesDM !);
                            await dMChannel.SendMessageAsync("`복원되었습니다. 이제부터 이곳에 입력하는 메시지는 해당 채널의 게임으로 전달됩니다.`");
                        }
                    }
                }
            }
            else
            {
                await channel.SendMessageAsync("`명령어: BOT start, BOT restart, BOT help, BOT restoredm`");
            }
        }
        public UserRights(UserIdType userIdType, string principalId, Collection<string> rights)
        {
            if ((userIdType != UserIdType.Email) &&
                (userIdType != UserIdType.IpcUser))
            {
                throw new ArgumentOutOfRangeException("principalIdType");
            }

            if (principalId == null)
            {
                throw new ArgumentNullException("principalId");
            }

            if (principalId.Trim().Length == 0)
            {
                throw new ArgumentOutOfRangeException("principalId");
            }

            if (userIdType == UserIdType.IpcUser)
            {
                if (string.Compare(principalId, IpcUserIDs.UserIdEveryone, StringComparison.InvariantCultureIgnoreCase) != 0 &&
                    string.Compare(principalId, IpcUserIDs.UserIdNull, StringComparison.InvariantCultureIgnoreCase) != 0 &&
                    string.Compare(principalId, IpcUserIDs.UserIdOwner, StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    throw new ArgumentOutOfRangeException("principalId");
                }
            }

            if (rights == null)
            {
                throw new ArgumentNullException("rights");
            }

            m_rights = rights;
            m_userId = principalId;
            m_userIdType = userIdType;
        }
        /// <summary>
        /// Serializes CommmonPcehrHeader as a PCEHRHeader.
        /// </summary>
        /// <returns>Serialized PCEHRHeader.</returns>
        public XmlDocument Serialize()
        {
            var pcehrHeader = new PCEHRHeader();

            pcehrHeader.ihiNumber = IhiNumber;

            pcehrHeader.User                 = new PCEHRHeaderUser();
            pcehrHeader.User.ID              = UserId;
            pcehrHeader.User.IDType          = (PCEHRHeaderUserIDType)Enum.Parse(typeof(PCEHRHeaderUserIDType), UserIdType.ToString());
            pcehrHeader.User.userName        = UserName;
            pcehrHeader.User.role            = UserRole;
            pcehrHeader.User.useRoleForAudit = UserUseRoleForAudit;

            pcehrHeader.accessingOrganisation = new PCEHRHeaderAccessingOrganisation();
            pcehrHeader.accessingOrganisation.organisationName          = OrganisationName;
            pcehrHeader.accessingOrganisation.organisationID            = OrganisationId;
            pcehrHeader.accessingOrganisation.alternateOrganisationName = AlternateOrganisationName;

            pcehrHeader.clientSystemType = (PCEHRHeaderClientSystemType)Enum.Parse(typeof(PCEHRHeaderClientSystemType), ClientSystemType.ToString());

            pcehrHeader.productType                = new PCEHRHeaderProductType();
            pcehrHeader.productType.platform       = ProductPlatform;
            pcehrHeader.productType.productName    = ProductName;
            pcehrHeader.productType.productVersion = ProductVersion;
            pcehrHeader.productType.vendor         = ProductVendor;

            return(pcehrHeader.SerializeToXml());
        }