Пример #1
0
        public List <Task> ProcessNodes(
            Func <ChirperUserInfo, Task> action,
            Action <long> intervalAction = null,
            AsyncPipeline pipeline       = null)
        {
            List <Task> promises = new List <Task>();
            long        i        = 0;

            foreach (XElement nodeData in Nodes)
            {
                ChirperUserInfo userData = ParseUserInfo(nodeData);

                // Call main processing action
                Task n = action(userData);
                if (n != null)
                {
                    if (pipeline != null)
                    {
                        pipeline.Add(n);
                    }
                    promises.Add(n);
                }
                // else skip this node

                if (intervalAction != null && ProgressInterval != 0)
                {
                    if ((++i % ProgressInterval) == 0)
                    {
                        // Call progress interval action
                        intervalAction(i);
                    }
                }
            }
            return(promises);
        }
Пример #2
0
        public ChirperUserInfo ParseUserInfo(XElement nodeData)
        {
            var state = ChirperUserInfo.GetUserInfo(
                Int64.Parse(nodeData.Attribute("id").Value),
                nodeData.Elements(ns + "data").Single(e => e.Attribute("key").Value == customDataUserAliasValue).Value);

            return(state);
        }
Пример #3
0
        public Task RemoveFollower(string alias, IChirperSubscriber follower)
        {
            IEnumerable <KeyValuePair <ChirperUserInfo, IChirperSubscriber> > found = State.Followers.Where(f => f.Key.UserAlias == alias).ToList();

            if (found.Any())
            {
                ChirperUserInfo userInfo = found.FirstOrDefault().Key;
                State.Followers.Remove(userInfo);
            }
            return(TaskDone.Done);
        }
Пример #4
0
        public Task AddFollower(string alias, long userId, IChirperSubscriber follower)
        {
            ChirperUserInfo userInfo = ChirperUserInfo.GetUserInfo(userId, alias);

            if (State.Followers.ContainsKey(userInfo))
            {
                State.Followers.Remove(userInfo);
            }
            State.Followers[userInfo] = follower;
            return(TaskDone.Done);
        }
Пример #5
0
        private async Task UnfollowUser(long userId, string userAlias, IChirperPublisher userToUnfollow)
        {
            await userToUnfollow.RemoveFollower(State.UserAlias, this);

            ChirperUserInfo userInfo = ChirperUserInfo.GetUserInfo(userId, userAlias);

            State.Subscriptions.Remove(userInfo);

            // Notify any viewers that a subscription has been removed for this user
            viewers.Notify(
                v => v.SubscriptionRemoved(userInfo)
                );
        }
Пример #6
0
        public Task SetUserDetails(ChirperUserInfo userInfo)
        {
            string alias = userInfo.UserAlias;

            if (alias != null)
            {
                if (logger.IsVerbose)
                {
                    logger.Verbose("{0} Setting UserAlias = {1}.", Me, alias);
                }
                State.UserAlias = alias;
            }
            return(TaskDone.Done);
        }
Пример #7
0
        public async Task SetUserDetails(ChirperUserInfo userInfo)
        {
            string alias = userInfo.UserAlias;

            if (alias != null)
            {
                if (logger.IsVerbose)
                {
                    logger.Verbose("{0} Setting UserAlias = {1}.", Me, alias);
                }
                State.UserAlias = alias;
                await WriteStateAsync();
            }
        }
Пример #8
0
        private async Task FollowUser(long userId, string userAlias, IChirperPublisher userToFollow)
        {
            if (logger.IsVerbose)
            {
                logger.Verbose("{0} FollowUser({1}).", Me, userAlias);
            }
            await userToFollow.AddFollower(State.UserAlias, State.UserId, this);

            ChirperUserInfo userInfo = ChirperUserInfo.GetUserInfo(userId, userAlias);

            State.Subscriptions[userInfo] = userToFollow;

            // Notify any viewers that a subscription has been added for this user
            viewers.Notify(
                v => v.SubscriptionAdded(userInfo)
                );
        }
        private async Task AddChirperUser(ChirperUserInfo userData)
        {
            // Create Chirper account grain for this user
            long            userId    = userData.UserId;
            string          userAlias = userData.UserAlias;
            IChirperAccount grain     = GrainClient.GrainFactory.GetGrain <IChirperAccount>(userId);

            this.Users[userId] = grain;
            try
            {
                // Force creation of the grain by sending it a first message to set user alias
                ChirperUserInfo userInfo = ChirperUserInfo.GetUserInfo(userId, userAlias);
                await grain.SetUserDetails(userInfo);

                Interlocked.Increment(ref numUsers);
            }
            catch (Exception exc)
            {
                ReportError("Error creating user id " + userId, exc);
                throw exc.GetBaseException();
            }
        }
Пример #10
0
        private async Task AddChirperUser(ChirperUserInfo userData)
        {
            // Create Chirper account grain for this user
            long userId = userData.UserId;
            string userAlias = userData.UserAlias;
            IChirperAccount grain = ChirperAccountFactory.GetGrain(userId);
            this.Users[userId] = grain;
            try
            {
                // Force creation of the grain by sending it a first message to set user alias
                ChirperUserInfo userInfo = ChirperUserInfo.GetUserInfo(userId, userAlias);
                await grain.SetUserDetails(userInfo);

                Interlocked.Increment(ref numUsers);
            }
            catch (Exception exc)
            {
                ReportError("Error creating user id " + userId, exc);
                throw exc.GetBaseException();
            }
        }
Пример #11
0
 public void SubscriptionRemoved(ChirperUserInfo notFollowing)
 {
     Console.WriteLine(
         @"Removed subscription to {0}",
         notFollowing);
 }
Пример #12
0
 public void SubscriptionAdded(ChirperUserInfo following)
 {
     Console.WriteLine(
         @"Added subscription to {0}",
         following);
 }
Пример #13
0
 public void SubscriptionRemoved(ChirperUserInfo notFollowing)
 {
     Console.WriteLine(
         @"Removed subscription to {0}",
         notFollowing);
 }
Пример #14
0
 public void SubscriptionAdded(ChirperUserInfo following)
 {
     Console.WriteLine(
         @"Added subscription to {0}",
         following);
 }