Пример #1
0
        public void TestMethod1()
        {
            var user = new User("[email protected]@192.168.0.10") { Description = "Adminstrator", AccessLevel = AccessLevel.Admin };

            GenericIdentity identity = new GenericIdentity(user.Host.Nick);
            GenericPrincipal principal = new GenericPrincipal(identity, new[] { user.AccessLevel.ToString() });
            Thread.CurrentPrincipal = principal;
        }
Пример #2
0
        /// <summary>
        /// Gets the users asynchronous.
        /// </summary>
        /// <returns>
        /// The <see cref="Task" />.
        /// </returns>
        public async Task<IEnumerable<IUser>> GetUsersAsync()
        {
            var user1 = new User("[email protected]");
            var user2 = new User("[email protected]");

            var users = new[] { user1, user2 };

            return await Task.FromResult(users);
        }
Пример #3
0
        public void Start()
        {
            this.tokenSource = new CancellationTokenSource();

            Task.Factory.StartNew(() =>
                {
                    while (true)
                    {
                        if (this.isConnected)
                        {
                            var user = new User("[email protected]");
                            var channel = new Channel { Name = "#fake", Network = this.network as Network };

                            this.OnPrivateMessageReceived(new PrivateMessageReceivedEventArgs(user, this.server, MessageFormat.Message, MessageBroadcast.Private, "fake message"));
                            this.OnPublicMessageReceived(new PublicMessageReceivedEventArgs(user, this.server, channel, MessageFormat.Message, MessageBroadcast.Public, "fake message"));
                        }

                        Thread.Sleep(TimeSpan.FromSeconds(20));
                    }
                }, this.tokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current);
        }
Пример #4
0
        /// <summary>
        /// Gets the or create by hostmask asynchronous.
        /// </summary>
        /// <param name="hostmask">
        /// The hostmask.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task<IUser> GetOrCreateByHostmaskAsync(string hostmask)
        {
            Contract.Requires<ArgumentNullException>(hostmask != null, "hostmask");

            Task<User> user =
                this.databaseContext.Users.FirstOrDefaultAsync(
                    u => u.KnownHosts.Any(kh => this.hostMatcher.IsMatch(kh, hostmask)));

            if (user == null)
            {
                var guestUser = new User(hostmask);
                var item = new CacheItem(hostmask, guestUser);

                this.cache.Add(item, 
                    new CacheItemPolicy
                        {
                            SlidingExpiration = TimeSpan.FromMinutes(30), 
                            Priority = CacheItemPriority.Default
                        });
            }

            return this.cache[hostmask] as IUser;
        }