Пример #1
0
        private void getLogic(bool getUsers, string username)
        {
            APICaller caller = new APICaller("getReviews.php").AddParam("privateKey", PrivateKey).AddParam("username", username);

            if (getUsers)
            {
                caller.AddParam("user", "");
            }

            JObject obj = caller.Call();

            //Console.WriteLine(obj);
            if (obj["status"].ToString() == "success")
            {
                List <UserReview>         userReviews = new List <UserReview>();
                Dictionary <string, User> users       = null;
                obj["reviews"].ToList().ForEach((userReview) =>
                {
                    userReviews.Add(new UserReview
                    {
                        Message  = userReview["message"].ToString(),
                        Karma    = userReview["karma"].ToObject <int>(),
                        Username = userReview["username"].ToString(),
                        PostDate = DateTimeOffset.FromUnixTimeSeconds(userReview["postDate"].ToObject <long>()).DateTime
                    });
                });
                if (getUsers)
                {
                    users = new Dictionary <string, User>();
                    obj["users"].ToList().ForEach((user) =>
                    {
                        users[user.First["username"].ToString()] = new User
                        {
                            Username    = user.First["username"].ToString(),
                            FirstName   = user.First["firstName"].ToString(),
                            LastName    = user.First["lastName"].ToString(),
                            KarmaPoints = user.First["karmaPoints"].ToObject <int>(),
                            IsLecturer  = Convert.ToBoolean(user.First["lecturer"].ToObject <int>()),

                            //gender = Convert.ToBoolean(user.First["gender"].ToObject<int>()),
                            ProfilePictureLocation = user.First["profilePicture"].ToString()
                        };
                    });
                }
                GetUserReviewResult(GetStatus.Success, userReviews, users);
            }
            else
            {
                GetStatus status = GetStatus.UnknownError;

                if (!Enum.TryParse <GetStatus>(obj["message"].ToString(), out status))
                {
                    status = GetStatus.UnknownError;
                }

                GetUserReviewResult(status, null, null);
            }
        }
Пример #2
0
        private void getLogic(bool getUsers)
        {
            APICaller caller = new APICaller("getHelpRequests.php").AddParam("privateKey", PrivateKey);

            if (getUsers)
            {
                caller.AddParam("user", "");
            }
            JObject obj = caller.Call();

            //Console.WriteLine(obj);
            if (obj["status"].ToString() == "success")
            {
                List <HelpRequest>        helpRequests = new List <HelpRequest>();
                Dictionary <string, User> users        = null;
                obj["helpRequests"].ToList().ForEach((helpRequest) =>
                {
                    helpRequests.Add(new HelpRequest
                    {
                        Id              = helpRequest["id"].ToObject <int>(),
                        Title           = helpRequest["title"].ToString(),
                        Description     = helpRequest["description"].ToString(),
                        CreatorUsername = helpRequest["username"].ToString(),
                        Category        = helpRequest["category"].ToString(),
                        Timestamp       = DateTimeOffset.FromUnixTimeSeconds(helpRequest["postDate"].ToObject <long>()).DateTime
                    });
                });
                if (getUsers)
                {
                    users = new Dictionary <string, User>();
                    obj["users"].ToList().ForEach((user) =>
                    {
                        users[user.First["username"].ToString()] = new User
                        {
                            Username               = user.First["username"].ToString(),
                            FirstName              = user.First["firstName"].ToString(),
                            LastName               = user.First["lastName"].ToString(),
                            KarmaPoints            = user.First["karmaPoints"].ToObject <int>(),
                            IsLecturer             = Convert.ToBoolean(user.First["lecturer"].ToObject <int>()),
                            ProfilePictureLocation = user.First["profilePicture"].ToString()
                        };
                    });
                }
                GetHelpRequestsResult(GetStatus.Success, helpRequests, users);
            }
            else
            {
                GetStatus status = GetStatus.UnknownError;
                if (!Enum.TryParse <GetStatus>(obj["message"].ToString(), out status))
                {
                    status = GetStatus.UnknownError;
                }
                GetHelpRequestsResult(status, null, null);
            }
        }
Пример #3
0
        private void getLogic(int helpRequestID, bool getUsers)
        {
            var caller = new APICaller("getHelpRequestComments.php").AddParam("privateKey", PrivateKey).
                         AddParam("id", helpRequestID.ToString());

            if (getUsers)
            {
                caller.AddParam("user", "");
            }
            JObject obj = caller.Call();

            if (obj["status"].ToString() == "success")
            {
                List <Comment>            comments = new List <Comment>();
                Dictionary <string, User> users    = null;
                obj["comments"].ToList().ForEach((comment) =>
                {
                    comments.Add(new Comment
                    {
                        Message       = comment["message"].ToString(),
                        Username      = comment["username"].ToString(),
                        CommentID     = comment["id"].ToObject <int>(),
                        CreatedDate   = comment["postDate"].ToObject <long>(),
                        HelpRequestID = comment["help_request"].ToObject <int>()
                    });
                });
                if (getUsers)
                {
                    users = new Dictionary <string, User>();
                    obj["users"].ToList().ForEach((user) =>
                    {
                        users[user.First["username"].ToString()] = new User
                        {
                            Username               = user.First["username"].ToString(),
                            FirstName              = user.First["firstName"].ToString(),
                            LastName               = user.First["lastName"].ToString(),
                            KarmaPoints            = user.First["karmaPoints"].ToObject <int>(),
                            IsLecturer             = Convert.ToBoolean(user.First["lecturer"].ToObject <int>()),
                            ProfilePictureLocation = user.First["profilePicture"].ToString()
                        };
                    });
                }
                GetCommentsResult(GetStatus.Success, comments, users);
            }
            else
            {
                GetStatus status = GetStatus.UnknownError;
                if (!Enum.TryParse <GetStatus>(obj["message"].ToString(), out status))
                {
                    status = GetStatus.UnknownError;
                }
                GetCommentsResult(status, null, null);
            }
        }
Пример #4
0
        private void getLogic(Conversation conversation, long timestamp, bool wait)
        {
            APICaller caller = new APICaller("getMessages.php").AddParam("privateKey", PrivateKey).AddParam("conversation", conversation.Id.ToString()).AddParam("timestamp", timestamp.ToString());

            if (wait)
            {
                caller.AddParam("wait", "");
            }
            var obj = caller.Call();

            //Console.Write(obj);
            if (obj["status"].ToString() == "success")
            {
                List <Message> messages = new List <Message>();

                obj["messages"].ToList().ForEach((message) =>
                {
                    messages.Add(new Message
                    {
                        Id           = message["id"].ToObject <int>(),
                        Username     = message["username"].ToString(),
                        Text         = message["message"].ToString(),
                        Timestamp    = message["timestamp"].ToObject <long>(),
                        Conversation = message["conversation"].ToObject <int>()
                    });
                });
                GetMessageResult(MessageStatus.Success, messages);
            }
            else
            {
                MessageStatus status = MessageStatus.UnknownError;
                if (!Enum.TryParse <MessageStatus>(obj["message"].ToString(), out status))
                {
                    status = MessageStatus.UnknownError;
                }
                GetMessageResult(status, null);
            }
        }
Пример #5
0
        private void getLogic(long timestamp, bool getUsers, bool waitForMessage)
        {
            APICaller caller = new APICaller("getAllMessages.php").AddParam("privateKey", PrivateKey).AddParam("timestamp", timestamp.ToString());

            if (waitForMessage)
            {
                caller.AddParam("wait", "");
            }
            if (getUsers)
            {
                caller.AddParam("user", "");
            }
            var obj = caller.Call();

            //Console.WriteLine(obj);
            if (obj["status"].ToString() == "success")
            {
                List <Conversation> conversations          = new List <Conversation>();
                Dictionary <int, List <Message> > messages = new Dictionary <int, List <Message> >();
                Dictionary <string, User>         users    = null;
                obj["conversations"].ToList().ForEach((conversation) =>
                {
                    var conv = new Conversation
                    {
                        Id           = conversation["id"].ToObject <int>(),
                        Title        = conversation["title"].ToString(),
                        Messages     = conversation["messages"].ToObject <int>(),
                        LastActivity = conversation["lastActivity"].ToObject <long>(),
                        LastMessage  = conversation["lastMessage"].ToString()
                    };
                    conversation["users"].ToList().ForEach((user) =>
                    {
                        conv.Users.Add(user.ToString());
                    });
                    messages[conv.Id] = new List <Message>();
                    conversation["messageArray"].ToList().ForEach((message) =>
                    {
                        messages[conv.Id].Add(new Message
                        {
                            Id           = message["id"].ToObject <int>(),
                            Username     = message["username"].ToString(),
                            Text         = message["message"].ToString(),
                            Timestamp    = message["timestamp"].ToObject <long>(),
                            Conversation = conv.Id
                        });
                    });
                    conversations.Add(conv);
                });
                if (getUsers)
                {
                    users = new Dictionary <string, User>();
                    obj["users"].ToList().ForEach((user) =>
                    {
                        users[user.First["username"].ToString()] = new User
                        {
                            Username               = user.First["username"].ToString(),
                            FirstName              = user.First["firstName"].ToString(),
                            LastName               = user.First["lastName"].ToString(),
                            KarmaPoints            = user.First["karmaPoints"].ToObject <int>(),
                            IsLecturer             = Convert.ToBoolean(user.First["lecturer"].ToObject <int>()),
                            ProfilePictureLocation = user.First["profilePicture"].ToString()
                        };
                    });
                }
                GetMessageResult(MessageStatus.Success, conversations, messages, users);
            }
            else
            {
                MessageStatus status = MessageStatus.UnknownError;
                if (!Enum.TryParse <MessageStatus>(obj["message"].ToString(), out status))
                {
                    status = MessageStatus.UnknownError;
                }
                GetMessageResult(status, null, null, null);
            }
        }
Пример #6
0
        private void getLogic(bool getUsers)
        {
            APICaller caller = new APICaller("getConversations.php").AddParam("privateKey", PrivateKey);

            if (getUsers)
            {
                caller.AddParam("user", "");
            }
            JObject obj = caller.Call();

            //Console.WriteLine(obj);
            if (obj["status"].ToString() == "success")
            {
                List <Conversation> conversations = new List <Conversation>();

                Dictionary <string, User> users = null;
                obj["conversations"].ToList().ForEach((conversation) =>
                {
                    var conv = new Conversation
                    {
                        Id           = conversation["id"].ToObject <int>(),
                        Title        = conversation["title"].ToString(),
                        Messages     = conversation["messages"].ToObject <int>(),
                        LastActivity = conversation["lastActivity"].ToObject <long>(),
                        LastMessage  = conversation["lastMessage"].ToString()
                    };
                    try
                    {
                        conversation["users"].ToList().ForEach((user) =>
                        {
                            conv.Users.Add(user.First.ToString());
                        });
                    }
                    catch (InvalidOperationException e)
                    {
                        conversation["users"].ToList().ForEach((user) =>
                        {
                            conv.Users.Add(user.ToString());
                        });
                    }
                    conversations.Add(conv);
                });


                if (getUsers)
                {
                    users = new Dictionary <string, User>();
                    obj["users"].ToList().ForEach((user) =>
                    {
                        users[user.First["username"].ToString()] = new User
                        {
                            Username               = user.First["username"].ToString(),
                            FirstName              = user.First["firstName"].ToString(),
                            LastName               = user.First["lastName"].ToString(),
                            KarmaPoints            = user.First["karmaPoints"].ToObject <int>(),
                            IsLecturer             = Convert.ToBoolean(user.First["lecturer"].ToObject <int>()),
                            ProfilePictureLocation = user.First["profilePicture"].ToString(),
                        };
                    });
                }
                GetConversationsResult(GetStatus.Success, conversations, users);
            }
            else
            {
                GetStatus status = GetStatus.UnknownError;
                if (!Enum.TryParse <GetStatus>(obj["message"].ToString(), out status))
                {
                    status = GetStatus.UnknownError;
                }
                GetConversationsResult(status, null, null);
            }
        }