コード例 #1
0
ファイル: TeeMsHub.cs プロジェクト: JanKuukkanen/TeeMS
        public async Task JoinGroup(string groupname)
        {
            try
            {
                ctx = new TeeMsEntities();

                var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                var rightgroup      = rightperson.group_member.Where(gm => gm.group.name == groupname).SingleOrDefault();

                await Groups.Add(Context.ConnectionId, groupname + rightgroup.group_id.ToString());

                rightconnection.group_id = rightgroup.group_id;
                ctx.SaveChanges();

                Clients.Group(groupname + rightgroup.group_id.ToString()).broadcastMessage("ChatControl", rightperson.username + " Joined group: " + groupname);

                GetChatMembers(rightgroup.group.name);
                GetConversationMessages(rightgroup.group.name);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
ファイル: TeeMsHub.cs プロジェクト: JanKuukkanen/TeeMS
        public void GetConversationMessages(string groupname)
        {
            try
            {
                ctx = new TeeMsEntities();

                var rightperson = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightgroup  = rightperson.group_member.Where(gm => gm.group.name == groupname).SingleOrDefault();

                var ctxmessagelist = ctx.message.Where(msg => msg.group_id == rightgroup.group.group_id).ToList();

                List <string[]> stringarraylist = new List <string[]>();

                foreach (var message in ctxmessagelist)
                {
                    string[] messagearray = { message.person.username, message.creation_date.ToString(), message.message_content };
                    stringarraylist.Add(messagearray);
                }

                string messagejson = JsonConvert.SerializeObject(stringarraylist);

                // Call fillDiscussion method on the clients side
                Clients.Client(Context.ConnectionId).fillDiscussion(messagejson);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public void SaveAssignmentComment(string commentcon)
        {
            try
            {
                ctx = new TeeMsEntities();

                if (commentcon != String.Empty)
                {
                    int    project_id    = int.Parse(this.Context.QueryString["Project"]);
                    int    assignment_id = int.Parse(this.Context.QueryString["Assignment"]);
                    string username      = Context.User.Identity.Name;

                    var rightperson = ctx.person.Where(p => p.username == username).SingleOrDefault();

                    comment newcomment = new comment
                    {
                        comment_content = commentcon,
                        creation_date   = DateTime.Now,
                        person_id       = rightperson.person_id,
                        project_id      = project_id,
                        amt_id          = assignment_id
                    };

                    ctx.comment.Add(newcomment);
                    ctx.SaveChanges();

                    BroadcastUpdateAssignmentComments();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
ファイル: ViewUser.aspx.cs プロジェクト: JanKuukkanen/TeeMS
    protected void Page_Load(object sender, EventArgs e)
    {
        ctx = new TeeMsEntities();

        string user_id = String.Empty;

        try
        {
            user_id = Request.QueryString["Person"];
            int usernro_id = int.Parse(user_id);

            if (user_id != null)
            {
                var rightperson = ctx.person.Where(p => p.person_id == usernro_id).SingleOrDefault();

                if (rightperson.privacy == 1 || rightperson.username == User.Identity.Name)
                {
                    FillControls(usernro_id);
                    FillDivs(usernro_id);
                }
                else if (Request.UrlReferrer.ToString() != String.Empty)
                {
                    Response.Redirect(Request.UrlReferrer.ToString());
                }
                else
                {
                    Response.Redirect(String.Format(Request.ApplicationPath + "Home.aspx"));
                }
            }
        }
        catch (Exception ex)
        {
            lbMessages.Text = ex.Message;
        }
    }
コード例 #5
0
ファイル: TeeMsHub.cs プロジェクト: JanKuukkanen/TeeMS
        protected void SaveAsComment(string message, int personid, int projecttag)
        {
            try
            {
                ctx = new TeeMsEntities();

                var rightperson  = ctx.person.Where(p => p.person_id == personid).SingleOrDefault();
                var rightproject = ctx.project.Where(pr => pr.project_tag == projecttag).SingleOrDefault();

                IHubContext projectContext = GlobalHost.ConnectionManager.GetHubContext <ProjectHub>();

                comment newcomment = new comment()
                {
                    comment_content = message,
                    person          = rightperson,
                    project         = rightproject,
                    creation_date   = DateTime.Now
                };

                ctx.comment.Add(newcomment);
                ctx.SaveChanges();

                // Call updateComments method on the ProjectHub users client side
                projectContext.Clients.Group(rightproject.name + rightproject.project_id.ToString()).updateComments();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
        public void SaveProjectName(string projectname)
        {
            try
            {
                ctx = new TeeMsEntities();

                int    project_id = int.Parse(this.Context.QueryString["Project"]);
                string newname    = projectname;

                var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                var rightproject    = ctx.project.Where(pr => pr.project_id == project_id).SingleOrDefault();

                rightproject.name = newname;
                ctx.SaveChanges();

                // Call updateProjectTitle method on the client side
                // For some reason this call to the client side is made only if the variable passed to the client side is the same as the current project name in the database
                Clients.OthersInGroup(rightproject.name + rightproject.project_id.ToString()).updateProjectName(newname);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #7
0
        // Method to call when a client disconnects from the hub either gracefully or not
        public override async Task OnDisconnected(bool stopCalled)
        {
            try
            {
                ctx = new TeeMsEntities();

                var connectionlist = ctx.connection.ToList();
                var rightperson    = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();

                // We'll set the connection property in the database to false and enter the time of disconnect
                foreach (var connection in connectionlist)
                {
                    if (connection.person_id == rightperson.person_id)
                    {
                        var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();

                        rightconnection.connected       = false;
                        rightconnection.connection_time = DateTime.Now;

                        ctx.SaveChanges();
                    }
                }

                await base.OnDisconnected(stopCalled);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
ファイル: TeeMsHub.cs プロジェクト: JanKuukkanen/TeeMS
        public async Task LeaveGroup(string newgroup)
        {
            try
            {
                ctx = new TeeMsEntities();

                var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                var rightgroup      = rightconnection.group;

                await Groups.Remove(Context.ConnectionId, rightgroup.name + rightgroup.group_id.ToString());

                rightconnection.group_id = null;
                ctx.SaveChanges();

                ChatMemberLeft(rightgroup.name);
                Clients.Group(rightgroup.name + rightgroup.group_id.ToString()).broadcastMessage("ChatControl", rightperson.username + " Left group");

                await JoinGroup(newgroup);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
        // Method to call when a client reconnects to the hub
        public override async Task OnReconnected()
        {
            try
            {
                ctx = new TeeMsEntities();

                var connectionlist = ctx.connection.ToList();
                var rightperson    = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();

                foreach (var connection in connectionlist)
                {
                    if (connection.person_id == rightperson.person_id)
                    {
                        var rightconnection = ctx.connection.Where(con => con.connection_id == connection.connection_id).SingleOrDefault();

                        rightconnection.connected = true;

                        ctx.SaveChanges();
                    }
                }

                await base.OnReconnected();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ctx = new TeeMsEntities();

        HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];

        ticket = FormsAuthentication.Decrypt(authcookie.Value);

        FillLabels();
    }
コード例 #11
0
ファイル: Project.aspx.cs プロジェクト: JanKuukkanen/TeeMS
    protected void Page_Load(object sender, EventArgs e)
    {
        ctx = new TeeMsEntities();

        int  project_id  = 0;
        bool isarchived  = false;
        bool alloweduser = false;

        try
        {
            HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            ticket = FormsAuthentication.Decrypt(authcookie.Value);

            project_id = int.Parse(Request.QueryString["Project"]);

            var rightproject       = ctx.project.Where(g => g.project_id == project_id).SingleOrDefault();
            var rightperson        = ctx.person.Where(p => p.username == User.Identity.Name).SingleOrDefault();
            var rightprojectmember = rightperson.project_person.Where(prope => prope.project_id == rightproject.project_id).SingleOrDefault();

            if (rightprojectmember != null)
            {
                alloweduser = true;
            }

            isarchived = ctx.project.Where(pr => pr.project_id == project_id).SingleOrDefault().finished;
        }
        catch (Exception ex)
        {
            lbMessages.Text = ex.Message;
        }

        if (alloweduser != true)
        {
            Response.Redirect(String.Format(Request.ApplicationPath + "Home.aspx"));
        }

        if (!IsPostBack)
        {
            FillControls(project_id);
        }
        else if (IsPostBack)
        {
            FillComments();
        }

        if (isarchived == true)
        {
            ArchiveProjectPage();
        }
    }
コード例 #12
0
        // Method to call when a client connects to the hub and forms a hubproxy
        public override async Task OnConnected()
        {
            try
            {
                ctx = new TeeMsEntities();

                int group_id = int.Parse(this.Context.QueryString["Group"]);

                var connectionlist = ctx.connection.ToList();
                var rightperson    = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightgroup     = ctx.group.Where(g => g.group_id == group_id).SingleOrDefault();

                foreach (var connection in connectionlist)
                {
                    if (connection.person_id == rightperson.person_id)
                    {
                        var rightconnection = ctx.connection.Where(con => con.connection_id == connection.connection_id).SingleOrDefault();

                        rightconnection.connected = true;

                        ctx.SaveChanges();
                    }
                }

                var groupconnection = rightperson.group_member.Where(gm => gm.group_id == group_id).SingleOrDefault();

                if (groupconnection != null)
                {
                    await JoinGroup(rightgroup.name + rightgroup.group_id.ToString());
                }

                if (rightgroup.name != String.Empty)
                {
                    SendGroupName(rightgroup);
                }

                if (rightgroup.group_picture_url != String.Empty)
                {
                    SendGroupImage(rightgroup);
                }


                await base.OnConnected();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            ticket = FormsAuthentication.Decrypt(authcookie.Value);

            ctx = new TeeMsEntities();
        }
        catch (HttpException ex)
        {
            lbMessages.Text = ex.Message;
        }

        FillDivs();

        FillInvitations();
    }
コード例 #14
0
ファイル: TeeMsHub.cs プロジェクト: JanKuukkanen/TeeMS
        public void Send(string message)
        {
            try
            {
                if (Context.User.Identity.IsAuthenticated)
                {
                    ctx = new TeeMsEntities();

                    var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                    var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                    var rightgroup      = rightconnection.group;

                    message newmessage = new message()
                    {
                        person_id       = rightperson.person_id,
                        group_id        = rightgroup.group_id,
                        message_content = message,
                        creation_date   = DateTime.Now
                    };

                    ctx.message.Add(newmessage);
                    ctx.SaveChanges();

                    Regex regex = new Regex("#PRO(?<tag>[0-9]{1,3})");

                    Match tagmatch = regex.Match(message);

                    if (tagmatch.Success)
                    {
                        string stringtag  = tagmatch.Groups["tag"].Value;
                        int    projecttag = int.Parse(stringtag);
                        SaveAsComment(message, rightperson.person_id, projecttag);
                    }

                    // Call the broadcastMessage method to update clients.
                    Clients.Group(rightgroup.name + rightgroup.group_id.ToString()).broadcastMessage(rightperson.username, message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #15
0
ファイル: Project.aspx.cs プロジェクト: JanKuukkanen/TeeMS
    protected void SaveCommentClick(object sender, CommandEventArgs e)
    {
        // Parse the correct comment id from the linkbutton's id
        var    btn       = sender as LinkButton;
        string parseid   = Regex.Match(btn.ID, @"-?\d+\.?\d*$").Value;
        int    commentid = int.Parse(parseid);

        try
        {
            TeeMsEntities context = new TeeMsEntities();

            string username     = ticket.Name;
            var    rightperson  = ctx.person.Where(p => p.username == username).SingleOrDefault();
            var    rightcomment = ctx.comment.Where(com => com.comment_id == commentid).SingleOrDefault();

            if (rightcomment.person_id == rightperson.person_id)
            {
                var divlist = (List <HtmlGenericControl>)Session["Divs"];

                var rightcommentdiv        = divlist.Where(div => div.ID == String.Format("commentdiv{0}", commentid)).SingleOrDefault();
                var rightcommenttextboxdiv = divlist.Where(div => div.ID == String.Format("commenttextboxdiv{0}", commentid)).SingleOrDefault();

                TextBox divtxt = rightcommenttextboxdiv.Controls[0] as TextBox;

                string newcontent = divtxt.Text;

                rightcomment.comment_content = newcontent;
                rightcomment.edited          = DateTime.Now;

                ctx.SaveChanges();

                rightcommenttextboxdiv.Visible = false;
                rightcommentdiv.Visible        = true;

                FillComments();
            }
        }
        catch (Exception ex)
        {
            lbMessages.Text = ex.Message;
        }
    }
コード例 #16
0
        public void BroadcastUpdateAssignmentComments()
        {
            try
            {
                ctx = new TeeMsEntities();

                int project_id = int.Parse(this.Context.QueryString["Project"]);

                var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                var rightproject    = ctx.project.Where(pr => pr.project_id == project_id).SingleOrDefault();

                // Call updateAssignmentComments method on the clients side
                Clients.Group(rightproject.name + rightproject.project_id.ToString()).updateAssignmentComments();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // set the database context using entity framework
        ctx = new TeeMsEntities();

        try
        {
            HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            ticket = FormsAuthentication.Decrypt(authcookie.Value);
        }
        catch (HttpException ex)
        {
            lbmessages.Text = ex.Message;
        }

        if (!IsPostBack)
        {
            FillControls();
        }
    }
コード例 #18
0
ファイル: TeeMsHub.cs プロジェクト: JanKuukkanen/TeeMS
        public void ChatMemberLeft(string groupname)
        {
            try
            {
                ctx = new TeeMsEntities();

                var rightperson = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightgroup  = rightperson.group_member.Where(gm => gm.group.name == groupname).SingleOrDefault();

                List <string> memberlist = ctx.connection.Where(con => con.connected == true && con.group_id == rightgroup.group_id).Select(con => con.connection_username).ToList();

                string connectionjson = JsonConvert.SerializeObject(memberlist);

                // Call fillMemberList method on the clients side
                Clients.OthersInGroup(groupname + rightgroup.group_id.ToString()).fillMemberList(connectionjson);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #19
0
        public async Task JoinGroup(string groupname)
        {
            try
            {
                ctx = new TeeMsEntities();

                int group_id = int.Parse(this.Context.QueryString["Group"]);

                await Groups.Add(Context.ConnectionId, groupname);

                var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                var rightgroup      = ctx.group.Where(g => g.group_id == group_id).SingleOrDefault();

                rightconnection.group_id = rightgroup.group_id;
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #20
0
ファイル: Group.aspx.cs プロジェクト: JanKuukkanen/TeeMS
    protected void Page_Load(object sender, EventArgs e)
    {
        // set the database context using entity framework
        ctx = new TeeMsEntities();
        string group_textid = String.Empty;
        bool   alloweduser  = false;

        try
        {
            HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            ticket = FormsAuthentication.Decrypt(authcookie.Value);

            group_textid = Request.QueryString["Group"];
            int group_id = int.Parse(group_textid);

            var rightgroup  = ctx.group.Where(g => g.group_id == group_id).SingleOrDefault();
            var rightperson = ctx.person.Where(p => p.username == User.Identity.Name).SingleOrDefault();
            var rightmember = rightperson.group_member.Where(gm => gm.group_id == rightgroup.group_id).SingleOrDefault();

            if (rightmember != null)
            {
                alloweduser = true;
            }
        }
        catch (Exception ex)
        {
            lbMessages.Text = ex.Message;
        }

        if (alloweduser != true)
        {
            Response.Redirect(String.Format(Request.ApplicationPath + "Home.aspx"));
        }

        if (!IsPostBack && group_textid != String.Empty)
        {
            FillControls(int.Parse(group_textid));
        }
    }
コード例 #21
0
ファイル: Encoder.cs プロジェクト: JanKuukkanen/TeeMS
        public Boolean AuthenticateUser(string uname, string password)
        {
            try
            {
                ctx = new TeeMsEntities();

                // Query for the person with a username similar to the users input
                var userperson = ctx.person.Where(p => p.username == uname);
                var logininfo  = ctx.login.Where(p => p.login_name == uname);

                person authenticator = userperson.FirstOrDefault();
                login  loginauth     = logininfo.FirstOrDefault();

                if (authenticator.username == loginauth.login_name)
                {
                    return(BCrypt.Net.BCrypt.Verify(password, loginauth.password));

                    /*string saltedhash = GenerateSaltedHash(password, loginauth.salt);
                     *
                     * if (saltedhash == loginauth.password)
                     * {
                     *  return true;
                     * }
                     * else
                     * {
                     *  return false;
                     * }*/
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #22
0
        public void SaveAssignmentDescription(string assignmentdescription)
        {
            try
            {
                ctx = new TeeMsEntities();

                int project_id = int.Parse(this.Context.QueryString["Project"]);

                var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                var rightproject    = ctx.project.Where(pr => pr.project_id == project_id).SingleOrDefault();

                rightproject.description = assignmentdescription;
                ctx.SaveChanges();

                // Call updateAssignmentDescription method on the clients side
                Clients.OthersInGroup(rightproject.name + rightproject.project_id.ToString()).updateAssignmentDescription(assignmentdescription);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #23
0
        public void SaveGroupImage(string group_imageurl)
        {
            try
            {
                ctx = new TeeMsEntities();

                int group_id = int.Parse(this.Context.QueryString["Group"]);

                var rightperson     = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightconnection = ctx.connection.Where(con => con.person_id == rightperson.person_id).SingleOrDefault();
                var rightgroup      = ctx.group.Where(g => g.group_id == group_id).SingleOrDefault();

                rightgroup.group_picture_url = group_imageurl;
                ctx.SaveChanges();

                // Call updateProjectTitle method on the client side
                Clients.OthersInGroup(rightgroup.name + rightgroup.group_id.ToString()).updateGroupImage(group_imageurl);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #24
0
ファイル: Register.aspx.cs プロジェクト: JanKuukkanen/TeeMS
    protected void CreateNewUser()
    {
        // Create a new person and add them to the database
        string   uname      = txtUserName.Text;
        string   fname      = txtFirstName.Text;
        string   lname      = txtLastName.Text;
        string   password   = txtPassword.Text;
        string   email      = txtEmail.Text;
        DateTime cdate      = DateTime.Now;
        int      privacynro = 1;

        Encoder encoder = new Encoder();

        string salt = encoder.GetSalt();

        string saltedhash = encoder.GenerateSaltedHash(password, salt);

        ctx = new TeeMsEntities();

        if (password == txtConfirmPassword.Text)
        {
            try
            {
                var rightrole     = ctx.role.Where(r => r.@class == 3).SingleOrDefault();
                int role_to_input = rightrole.role_id;

                person p = new person
                {
                    first_name    = fname,
                    last_name     = lname,
                    username      = uname,
                    email         = email,
                    creation_date = cdate,
                    privacy       = privacynro,
                    role_id       = role_to_input
                };

                login l = new login
                {
                    login_name = uname,
                    salt       = salt,
                    password   = saltedhash
                };

                connection newconnection = new connection()
                {
                    connected           = false,
                    connection_username = uname,
                    person_id           = p.person_id
                };

                ctx.person.Add(p);
                ctx.login.Add(l);
                ctx.connection.Add(newconnection);
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                lbMessages.Text = ex.Message;

                if (ex.InnerException != null)
                {
                    lbMessages.Text = ex.InnerException.ToString();
                }
            }

            Response.Redirect("Login.aspx");
        }
    }
コード例 #25
0
    protected int CreateNewGroup()
    {
        ctx = new TeeMsEntities();

        try
        {
            // First add a new group to the database

            UserContentManager contentmanager = new UserContentManager(ticket.Name);
            List <group>       usergroupquery = contentmanager.GetUserGroups();
            int newgroupnamenro = 1;

            if (usergroupquery != null)
            {
                for (int i = 0; i < usergroupquery.Count; i++)
                {
                    if (usergroupquery[i].name == String.Format("New Group {0}", usergroupquery.Count + newgroupnamenro))
                    {
                        newgroupnamenro = newgroupnamenro + 1;
                        i = 0;
                    }
                }
            }

            string newgroupname = String.Format("New Group {0}", usergroupquery.Count + newgroupnamenro);

            var g = new group
            {
                name          = newgroupname,
                creator       = ticket.Name,
                privacy       = 1,
                creation_date = DateTime.Now,
            };

            var grouplist = ctx.group.ToList();

            if (grouplist != null)
            {
                int tagindex = 100;

                foreach (var group in grouplist)
                {
                    tagindex = (int)group.group_tag + 1;
                }

                g.group_tag = tagindex;
            }
            else
            {
                g.group_tag = 100;
            }

            ctx.group.Add(g);
            ctx.SaveChanges();
            return(g.group_id);
        }
        catch (Exception ex)
        {
            lbMessages.Text = ex.Message;
            return(0);
        }
    }
コード例 #26
0
ファイル: TeeMsHub.cs プロジェクト: JanKuukkanen/TeeMS
        // Method to call when a client connects to the hub and forms a hubproxy
        public override async Task OnConnected()
        {
            try
            {
                ctx = new TeeMsEntities();

                var connectionlist = ctx.connection.ToList();
                var rightperson    = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();

                if (connectionlist.Count != 0)
                {
                    bool makenewconnection = true;

                    foreach (var connection in connectionlist)
                    {
                        if (connection.person_id == rightperson.person_id)
                        {
                            var rightconnection = ctx.connection.Where(con => con.connection_id == connection.connection_id).SingleOrDefault();

                            rightconnection.connected = true;

                            ctx.SaveChanges();

                            makenewconnection = false;
                        }
                    }

                    if (makenewconnection == true)
                    {
                        connection newconnection = new connection()
                        {
                            connected           = true,
                            connection_username = rightperson.username,
                            person_id           = rightperson.person_id
                        };

                        ctx.connection.Add(newconnection);
                        ctx.SaveChanges();
                    }
                }
                else
                {
                    connection newconnection = new connection()
                    {
                        connected           = true,
                        connection_username = rightperson.username,
                        person_id           = rightperson.person_id
                    };

                    ctx.connection.Add(newconnection);
                    ctx.SaveChanges();
                }

                List <string> grouplist = GetMemberGroups(rightperson);

                if (grouplist != null)
                {
                    await JoinGroup(grouplist[0]);

                    GetChatMembers(grouplist[0]);
                    Clients.Client(Context.ConnectionId).changeInitialButton();
                }

                await base.OnConnected();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #27
0
 public UserContentManager(string uname)
 {
     username = uname;
     ctx      = new TeeMsEntities();
 }
コード例 #28
0
ファイル: Groups.aspx.cs プロジェクト: JanKuukkanen/TeeMS
    protected int CreateNewGroup()
    {
        ctx = new TeeMsEntities();
        int emptyrow = 0;
        int addedrow = 0;

        // First check for any gaps in the number sequence inside the database
        for (int i = 0; i <= ctx.group.Count(); i++)
        {
            group compareGroup = new group();
            var   checkGroup   = ctx.group.Where(gr => gr.group_tag == i).SingleOrDefault();

            if (checkGroup == compareGroup)
            {
                emptyrow = i;
            }
            else
            {
                compareGroup = checkGroup;
            }
        }

        if (emptyrow == 0)
        {
            addedrow = ctx.group.Count() + 1;
        }
        else
        {
            addedrow = emptyrow;
        }

        // Next add a new group to the database

        try
        {
            UserContentManager contentmanager = new UserContentManager(ticket.Name);
            List <group>       usergroupquery = contentmanager.GetUserGroups();
            int newgroupnamenro = 1;

            if (usergroupquery != null)
            {
                for (int i = 0; i < usergroupquery.Count; i++)
                {
                    if (usergroupquery[i].name == String.Format("New Group {0}", usergroupquery.Count + newgroupnamenro))
                    {
                        newgroupnamenro = newgroupnamenro + 1;
                        i = 0;
                    }
                }
            }

            string newgroupname = String.Format("New Group {0}", usergroupquery.Count + newgroupnamenro);

            var g = new group
            {
                name          = newgroupname,
                group_tag     = addedrow,
                creator       = ticket.Name,
                privacy       = 1,
                creation_date = DateTime.Now,
            };

            ctx.group.Add(g);
            ctx.SaveChanges();
            return(g.group_id);
        }
        catch (Exception ex)
        {
            lbMessages.Text = ex.Message;
            return(0);
        }
    }
コード例 #29
0
        // Method to call when a client connects to the hub and forms a hubproxy
        public override async Task OnConnected()
        {
            try
            {
                ctx = new TeeMsEntities();

                int    project_id        = int.Parse(this.Context.QueryString["Project"]);
                string assignment_textid = String.Empty;

                if (this.Context.QueryString["Assignment"] != null)
                {
                    assignment_textid = this.Context.QueryString["Assignment"];
                }

                var connectionlist = ctx.connection.ToList();
                var rightperson    = ctx.person.Where(p => p.username == Context.User.Identity.Name).SingleOrDefault();
                var rightproject   = ctx.project.Where(pr => pr.project_id == project_id).SingleOrDefault();

                foreach (var connection in connectionlist)
                {
                    if (connection.person_id == rightperson.person_id)
                    {
                        var rightconnection = ctx.connection.Where(con => con.connection_id == connection.connection_id).SingleOrDefault();

                        rightconnection.connected = true;

                        ctx.SaveChanges();
                    }
                }

                var projectconnection = rightperson.project_person.Where(prope => prope.project_id == rightproject.project_id).SingleOrDefault();

                if (projectconnection != null)
                {
                    await JoinGroup(rightproject.name + rightproject.project_id.ToString());
                }

                if (rightproject.name != String.Empty)
                {
                    SendProjectName(rightproject);
                }

                if (rightproject.picture_url != String.Empty)
                {
                    SendProjectImage(rightproject);
                }

                if (assignment_textid != String.Empty)
                {
                    int assignment_id = int.Parse(assignment_textid);

                    var rightassignment = ctx.assignment.Where(amt => amt.amt_id == assignment_id).SingleOrDefault();

                    SendAssignmentDescription(rightproject, rightassignment);

                    Clients.OthersInGroup(rightproject.name + rightproject.project_id.ToString()).updateAssignmentProgress();
                }
                else
                {
                    SendProjectDescription(rightproject);
                }


                await base.OnConnected();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }