Ejemplo n.º 1
0
        public UserHandler(ForumSystem sys)
        {
            _usr = null;
            _sys = sys;
            username = null;

        }
Ejemplo n.º 2
0
        public TpcServer(int port, ForumSystem sys)
        {
            _listener = null;
            _port     = port;

            _sys = sys;
        }
Ejemplo n.º 3
0
        public UserHandler(ForumSystem sys)
        {
            _usr = null;
            _sys = sys;

            int max = (int)Enum.GetValues(typeof(FuncMsgClient.FuncType)).Cast <FuncMsgClient.FuncType>().Max();

            _actions = Enumerable.Repeat(default(ActionHandler), max + 1).ToList();


            _actions[(int)FuncMsgClient.FuncType.entry]                  = entry;
            _actions[(int)FuncMsgClient.FuncType.SetPolicy]              = SetPolicy;
            _actions[(int)FuncMsgClient.FuncType.Registration]           = Registration;
            _actions[(int)FuncMsgClient.FuncType.login]                  = login;
            _actions[(int)FuncMsgClient.FuncType.loggout]                = loggout;
            _actions[(int)FuncMsgClient.FuncType.AddNewSubForum]         = AddNewSubForum;
            _actions[(int)FuncMsgClient.FuncType.WatchAllSubForum]       = WatchAllSubForum;
            _actions[(int)FuncMsgClient.FuncType.WatchAllThreads]        = WatchAllThreads;
            _actions[(int)FuncMsgClient.FuncType.WatchAllComments]       = WatchAllComments;
            _actions[(int)FuncMsgClient.FuncType.PublishNewThread]       = PublishNewThread;
            _actions[(int)FuncMsgClient.FuncType.PublishCommentPost]     = PublishCommentPost;
            _actions[(int)FuncMsgClient.FuncType.checkHowMuchMemberType] = checkHowMuchMemberType;
            _actions[(int)FuncMsgClient.FuncType.addNewType]             = addNewType;
            _actions[(int)FuncMsgClient.FuncType.promoteMemberToAdmin]   = promoteMemberToAdmin;
            _actions[(int)FuncMsgClient.FuncType.EmailConfirm]           = EmailConfirm;
            _actions[(int)FuncMsgClient.FuncType.deleteType]             = deleteType;
            _actions[(int)FuncMsgClient.FuncType.deletePost]             = deletePost;
            _actions[(int)FuncMsgClient.FuncType.SPlogin]                = SPlogin;
            _actions[(int)FuncMsgClient.FuncType.WatchAllForums]         = WatchAllForums;
            _actions[(int)FuncMsgClient.FuncType.BuildForum]             = BuildForum;
            _actions[(int)FuncMsgClient.FuncType.CancelForum]            = CancelForum;
            _actions[(int)FuncMsgClient.FuncType.GetForumByName]         = GetForumByName;
        }
Ejemplo n.º 4
0
        public static void Run(ForumSystem sys)
        {
            IPAddress   aa        = LocalIPAddress();
            TcpListener _listener = new TcpListener(IPAddress.Any, 12345);

            _listener.Start();


            //ForumSystemImpl testSystem = new ForumSystemImpl("amir", "1234", "*****@*****.**", "amir m", "db");
            while (true)
            {
                TcpClient Client = null;
                try
                {
                    Console.WriteLine("listening...");

                    Client = _listener.AcceptTcpClient();

                    Console.WriteLine("got client");
                }
                catch
                {
                    Console.WriteLine("Error");
                    return;
                }

                ConnectionHandler con       = new ConnectionHandler(Client, sys);
                Thread            conThread = new Thread(con.run);
                conThread.Start();
            }
        }
Ejemplo n.º 5
0
        public string addSubForum(string subForumName)
        {
            SubForum subForum = getSubForum(subForumName);

            if (subForum != null)
            {
                return("Sub forum " + subForumName + " already exist.");
            }
            subForum = SubForum.create(_name, subForumName);
            if (subForum == null)
            {
                return("Invalid sub forum name.");
            }
            if (!ForumSystem._testFlag)
            {
                if (!ForumSystem._db.addSubForum(_name, subForumName))
                {
                    return(Constants.DB_ERROR);
                }
            }
            _subForums.Add(subForum);
            if (!_subForums.Contains(subForum))
            {
                return(Constants.FUNCTION_ERRROR); // cannot cover this case
            }
            ForumSystem.notify("A new sub forum has been added to the forum you are currently in.", _interactiveNotifications, _name);
            return(Constants.SUCCESS);
        }
Ejemplo n.º 6
0
        public string editPost(int postNo, string requestingUser, permission p, string content)
        {
            Post post = searchPost(_threads, postNo);

            if (post == null)
            {
                return(Constants.INVALID_INPUT);
            }
            if (!ForumSystem._testFlag)
            {
                if (!ForumSystem._db.changeForumPost(post.getTitle(), content, _forumName, _name, postNo))
                {
                    return(Constants.DB_ERROR);
                }
            }
            if (p < permission.MODERATOR && !post.getWriter().Equals(requestingUser))
            {
                return(Constants.UNAUTHORIZED);
            }
            post.setContent(content);
            if (content.Equals(post.getContent()))
            {
                ForumSystem.notify("A post you are following has been changed.", post.getAllFollowers(), _forumName);
                ForumSystem.notify("A post in a thread you are currently watching has been changed.", getAncestor(post).getInteractiveFollowers(), _forumName);
                return(Constants.SUCCESS);
            }
            return("Could not edit post."); // cannot cover this case
        }
Ejemplo n.º 7
0
 public MainWindow()
 {
     InitializeComponent();
     WindowStartupLocation = WindowStartupLocation.CenterScreen;
     //controller = ForumSystem.deserialize();
     controller = ForumSystem.getInstance();
 }
Ejemplo n.º 8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            IController controller = ForumSystem.getInstance();
            MainWindow  view       = new MainWindow();

            controller.setView(view);
            view.Show();
        }
Ejemplo n.º 9
0
        public UserHandler(ForumSystem sys,string id ,string forum)
        {
            _usr = null;
            _sys = sys;
            _id = id;
            _forum = forum;
            username = null;

        }
Ejemplo n.º 10
0
        // writePost incomplete - need to synchronize a part inside
        public string writePost(int parentPostNo, User user, string title, string content)
        {
            Post repliedTo = searchPost(_threads, parentPostNo);
            Post post      = Post.create(title, content, user, repliedTo);

            if (post == null)
            {
                return(Constants.INVALID_INPUT);
            }
            if (!ForumSystem._testFlag)
            {
                if (!ForumSystem._db.addSubForumPost(title, content, _forumName, _name, user.getUsername(), post.getCreationDate(), post.getSN(), parentPostNo))
                {
                    return(Constants.DB_ERROR);
                }
            }
            string deletedParent = "The post you are trying to reply to has been deleted.";

            if (repliedTo == null)
            {
                if (parentPostNo > 0)
                {
                    return(deletedParent);
                }
                _threads.Add(post);
                if (!_threads.Contains(post))
                {
                    return("Could not write post."); // cannot cover this case
                }
                _numOfPosts++;
                ForumSystem.notify("A new thread has been opened in the sub forum you are currently in.", _interativeNotifications, _forumName);
                return(SUCCESS);
            }
            // start synchronization
            if (isLiveThread(repliedTo))
            {
                if (!repliedTo.addReply(post, _forumName))
                {
                    return("Could not reply."); // cannot cover this case
                }
                _numOfPosts++;
                string msg = "Hello " + repliedTo.getWriter() + ",\n" + user.getUsername() + " has replied to your post in forum " + _forumName + "," +
                             " sub forum " + _name + ", on the topic " + getThreadName(post);
                Constants.sendMail(repliedTo.getWriterEMail(), "Your post have been replied to", msg);
                return(SUCCESS);
            }
            return(deletedParent); // cannot cover this case
        }
Ejemplo n.º 11
0
 public bool addReply(Post reply, string forumName)
 {
     // verify entire tree of reply does not contain this post
     _replies.Add(reply);
     if (_replies.Contains(reply))
     {
         observe("follow", reply.getWriter());
         if (!ForumSystem._testFlag)
         {
             if (ForumSystem._db.addPostFollower(_sn, reply.getWriter()))
             {
                 ForumSystem.notify("A new reply has been added to the thread you are currently in.", _interactiveNotifications, forumName);
                 return(true);
             }
             return(false);
         }
         ForumSystem.notify("A new reply has been added to the thread you are currently in.", _interactiveNotifications, forumName);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 12
0
 public ConnectionHandler(TcpClient con, ForumSystem system)
 {
     _con     = con;
     _usrHand = new UserHandler(system);
 }
Ejemplo n.º 13
0
        // deletePost need to be synchronized
        public string deletePost(int postNo, postDeletionPermission pdp, permission p, string requestingUser)
        {
            Post post = searchPost(_threads, postNo);

            if (post == null)
            {
                return("Post doesn't exist");
            }
            switch (pdp)
            {
            case postDeletionPermission.WRITER:
                if (p < permission.MODERATOR && !post.getWriter().Equals(requestingUser))
                {
                    return(Constants.noPermissionToDeletePost(requestingUser));
                }
                break;

            case postDeletionPermission.MODERATOR:
                if (p < permission.MODERATOR)
                {
                    return(Constants.noPermissionToDeletePost(requestingUser));
                }
                break;

            case postDeletionPermission.ADMIN:
                if (p < permission.ADMIN)
                {
                    return(Constants.noPermissionToDeletePost(requestingUser));
                }
                break;

            case postDeletionPermission.SUPER_ADMIN:
                if (p < permission.SUPER_ADMIN)
                {
                    return(Constants.noPermissionToDeletePost(requestingUser));
                }
                break;

            default:
                if (p != permission.SUPER_ADMIN)
                {
                    return(Constants.noPermissionToDeletePost(requestingUser));
                }
                break;
            }
            if (!ForumSystem._testFlag)
            {
                if (!ForumSystem._db.removeSubForumPost(post.getSN()))
                {
                    return(Constants.DB_ERROR);
                }
            }
            if (_threads.Contains(post))
            {
                _threads.Remove(post);
                if (_threads.Contains(post))
                {
                    throw new ShouldNotHappenException(); // cannot cover this case
                }
                List <Tuple <string, string, DateTime, int, int, string, DateTime> > list = new List <Tuple <string, string, DateTime, int, int, string, DateTime> >();
                post.getAllTree(list);
                _numOfPosts -= list.Count;
                ForumSystem.notify("A thread you are following has been deleted.", post.getAllFollowers(), _forumName);
                ForumSystem.notify("A thread you are currently watching has been deleted.", post.getInteractiveFollowers(), _forumName);
                return(Constants.SUCCESS);
            }
            Tuple <bool, List <string> > deletion = post.delete();

            if (deletion.Item1)
            {
                List <Tuple <string, string, DateTime, int, int, string, DateTime> > list = new List <Tuple <string, string, DateTime, int, int, string, DateTime> >();
                post.getAllTree(list);
                _numOfPosts -= list.Count;
                ForumSystem.notify("A post you are following has been deleted.", post.getAllFollowers(), _forumName);
                ForumSystem.notify("A post in a thread you are currently watching has been deleted.", getAncestor(post).getInteractiveFollowers(), _forumName);
                return(Constants.SUCCESS);
            }
            return("Could not delete post"); // cannot cover this case
        }