예제 #1
0
파일: Cache.cs 프로젝트: Codex04/AREA
        public static HttpEventAnswer AddToken(Event e)
        {
            User user = null;

            try
            {
                user = e.OwnerInfos;
            }
            catch (Exception err)
            {
                Console.Error.WriteLine(err.Message);
                return(HttpEventAnswer.Error(e, 502, "Invalid data argument for event"));
            }

            bool found = false;

            for (int i = 0; i < UserList.Count; i++)
            {
                if (UserList[i].Email == user.Email)
                {
                    UserList[i] = user;
                    found       = true;
                }
            }

            if (!found)
            {
                UserList.Add(user);
            }

            return(HttpEventAnswer.Success(e, "Tree successfully added for tree"));
        }
예제 #2
0
파일: Cache.cs 프로젝트: Codex04/AREA
        /// <summary>
        /// Add an <see cref="User"/> to the user list
        /// </summary>
        /// <param name="e">An <see cref="Event"/></param>
        /// <returns>An <see cref="HttpEventAnswer"/></returns>
        public static HttpEventAnswer AddUser(Event e)
        {
            User user = null;

            try
            {
                user = e.Data as User;
            }
            catch (Exception err)
            {
                Console.Error.WriteLine(err.Message);
                return(HttpEventAnswer.Error(e, 502, "Invalid data argument for event"));
            }

            if (user == null)
            {
                return(HttpEventAnswer.Error(e, 502, "Invalid data argument for event"));
            }

            foreach (var item in UserList)
            {
                if (item.Email == user.Email)
                {
                    return(HttpEventAnswer.Error(e, 501, "Can't add " + item.Email + ", user already exist"));
                }
            }

            UserList.Add(user);

            return(HttpEventAnswer.Success(e, "User successfully added"));
        }
예제 #3
0
파일: Cache.cs 프로젝트: Codex04/AREA
        /// <summary>
        /// Add a tree to the tree list
        /// </summary>
        /// <param name="e">An <see cref="Event"/></param>
        /// <returns>An <see cref="HttpEventAnswer"/></returns>
        public static HttpEventAnswer AddTree(Event e)
        {
            ATreeRoot tree = null;
            User      user = null;

            try
            {
                KeyValuePair <User, ATreeRoot> kvp = (KeyValuePair <User, ATreeRoot>)e.Data;
                tree = kvp.Value;
                user = kvp.Key;
            }
            catch (Exception err)
            {
                Console.Error.WriteLine(err.Message);
                return(HttpEventAnswer.Error(e, 502, "Invalid data argument for event"));
            }

            MessageBus.RegisterReactionForUser(GetUserByMail(user.Email), tree.root.data.serviceName, tree.root.data.eventName);

            AreaTree atr = new AreaTree(user.Email);

            atr.AreasList = new List <ATreeRoot> {
                tree
            };
            TreeList.Add(atr);

            return(HttpEventAnswer.Success(e, "Tree successfully added for tree"));
        }
예제 #4
0
 /// <summary>
 /// ProcessEvent
 /// </summary>
 /// <param name="e">The event to be added</param>
 /// <returns>An <see cref="HttpEventAnswer"/></returns>
 public static HttpEventAnswer ProcessEvent(Event e)
 {
     foreach (var route in Routes)
     {
         if (route.Key == e.GetType())
         {
             return(route.Value(e));
         }
     }
     return(HttpEventAnswer.Error(e, 501, "Event not found"));
 }