Esempio n. 1
0
        private void btn_SyncAcc_Click(object sender, EventArgs e)
        {
            SynapseModule             mod = SynapseModule.LoadByID((long)comboBox1.SelectedValue);
            IList <ACCSynapseProfile> Ap  = ACCSynapseProfile.Load("WHERE FK_MODULEID = " + mod.ID);
            IList <SynapseProfile>    Pp  = SynapseProfile.Load("WHERE FK_MODULEID = " + mod.ID);

            if (Ap.Count != Pp.Count)
            {
                MessageBox.Show("ERROR : Sync before");
                return;
            }
            IList <ACCTOPRD> links = ACCTOPRD.Load("WHERE OBJECTTYPE = 'ACCSynapseProfile'");

            foreach (ACCSynapseProfile aprof in Ap)
            {
                if (links.Where(l => l.ACCID == aprof.ID).Count() == 0)
                {
                    ACCTOPRD atop = new ACCTOPRD();
                    atop.ACCID      = aprof.ID;
                    atop.PRDID      = Pp.Where(p => p.TECHNICALNAME == aprof.TECHNICALNAME).FirstOrDefault().ID;
                    atop.OBJECTTYPE = typeof(ACCSynapseProfile).Name;
                    if (atop.ACCID != 0 && atop.PRDID != 0)
                    {
                        atop.save();
                    }
                }
            }
            links = ACCTOPRD.Load("WHERE OBJECTTYPE = 'ACCSynapseProfile'");
            foreach (ACCSynapseUser u in olv_ACCUSERS.CheckedObjects)
            {
                SynapseUser pu = SynapseUser.LoadByUserID(u.UserID);
                IList <ACCSynapseUser_Profile> AccRoles = ACCSynapseUser_Profile.Load("WHERE [FK_SECURITY_USER] = " + u.ID + " AND [FK_SECURITY_PROFILE] in (" + string.Join(",", Ap.Select(a => a.ID.ToString()).ToArray()) + ")");
                IList <SynapseUser_Profile>    PrdRoles = SynapseUser_Profile.Load("WHERE [FK_SECURITY_USER] = " + pu.ID + " AND [FK_SECURITY_PROFILE] in (" + string.Join(",", Pp.Select(a => a.ID.ToString()).ToArray()) + ")");
                foreach (ACCSynapseUser_Profile Aup in AccRoles)
                {
                    if (PrdRoles.Where(pr => pr.FK_SECURITY_PROFILE == Ap.Where(a => a.ID == Aup.FK_SECURITY_PROFILE).FirstOrDefault().PrdID(links)).Count() == 0)
                    {
                        SynapseUser_Profile pup = new SynapseUser_Profile();
                        pup.FK_SECURITY_USER    = pu.ID;
                        pup.FK_SECURITY_PROFILE = Ap.Where(a => a.ID == Aup.FK_SECURITY_PROFILE).FirstOrDefault().PrdID(links);
                        if (MessageBox.Show("Add Group " + Ap.Where(a => a.ID == Aup.FK_SECURITY_PROFILE).FirstOrDefault().TECHNICALNAME + " to user " + pu.LASTNAME + " " + pu.FIRSTNAME, "Modify ?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                        {
                            pup.save();
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 private void btn_SyncUserDB_Click(object sender, EventArgs e)
 {
     foreach (ACCSynapseUser auser in Acc_Users)
     {
         SynapseUser puser = SynapseUser.LoadByUserID(auser.UserID);
         if (puser.UserID != auser.UserID)
         {
             puser           = new SynapseUser();
             puser.CULTURE   = auser.CULTURE;
             puser.FIRSTNAME = auser.FIRSTNAME;
             puser.LASTNAME  = auser.LASTNAME;
             puser.UserID    = auser.UserID;
             puser.save();
         }
     }
     foreach (SynapseUser puser in Prd_Users)
     {
         ACCSynapseUser auser = ACCSynapseUser.LoadByUserID(puser.UserID);
         if (puser.UserID != auser.UserID)
         {
             auser           = new ACCSynapseUser();
             auser.CULTURE   = puser.CULTURE;
             auser.FIRSTNAME = puser.FIRSTNAME;
             auser.LASTNAME  = puser.LASTNAME;
             auser.UserID    = puser.UserID;
             auser.save();
         }
     }
     AccToPrdID = ACCTOPRD.Load("WHERE PRDID<>0");
     foreach (ACCSynapseUser auser in Acc_Users)
     {
         SynapseUser puser = SynapseUser.LoadByUserID(auser.UserID);
         if (puser == null)
         {
             ACCTOPRD lnk = AccToPrdID.Where(a => a.ACCID == auser.ID && a.PRDID == puser.ID && a.OBJECTTYPE == typeof(ACCSynapseUser).Name).FirstOrDefault();
             if (lnk == null)
             {
                 lnk            = new ACCTOPRD();
                 lnk.OBJECTTYPE = typeof(ACCSynapseUser).Name;
                 lnk.ACCID      = auser.ID;
                 lnk.PRDID      = puser.ID;
             }
         }
     }
 }
Esempio n. 3
0
        private void btn_Sync_Click(object sender, EventArgs e)
        {
            AccToPrdID = ACCTOPRD.Load("WHERE PRDID<>0");
            Int64 UsersCount           = 0;
            Int64 ControlsCount        = 0;
            Int64 ProfilesCount        = 0;
            Int64 ProfileControlsCount = 0;
            Int64 UserAssignmentCount  = 0;

            richTextBox1.Clear();
            if (chk_SyncUser.Checked)
            {
                // ======= Create user in prod ========
                foreach (ACCSynapseUser A_user in from au in Acc_Users where au.PrdID(AccToPrdID) == 0 select au)
                {
                    if (chk_verbose.Checked)
                    {
                        richTextBox1.AppendText(A_user.GetType().Name + ": " + A_user.UserID + "\n");
                    }
                    SynapseUser user = new SynapseUser();
                    CopyProperties(user, A_user);
                    user.ID = 0;
                    if (chk_save.Checked)
                    {
                        user.save();
                    }
                    UsersCount++;
                    CreateLinkEntry(A_user, A_user.ID, user.ID);
                }
            }
            // ======= Create controls in prod ========
            foreach (ACCSynapseControl A_ctrl in from ac in Acc_Controls where ac.PrdID(AccToPrdID) == 0 select ac)
            {
                if (chk_verbose.Checked)
                {
                    richTextBox1.AppendText(A_ctrl.GetType().Name + ": " + A_ctrl.CTRL_NAME + "\n");
                }
                SynapseControl ctrl = new SynapseControl();
                CopyProperties(ctrl, A_ctrl);
                ctrl.ID = 0;
                if (chk_save.Checked)
                {
                    ctrl.save();
                }
                ControlsCount++;
                CreateLinkEntry(A_ctrl, A_ctrl.ID, ctrl.ID);
            }
            // ======= Create profiles in prod ========
            foreach (ACCSynapseProfile A_prof in from ap in Acc_Profiles where ap.PrdID(AccToPrdID) == 0 select ap)
            {
                if (chk_verbose.Checked)
                {
                    richTextBox1.AppendText(A_prof.GetType().Name + ": " + A_prof.TECHNICALNAME + "\n");
                }
                SynapseProfile prof = new SynapseProfile();
                CopyProperties(prof, A_prof);
                prof.ID = 0;
                if (chk_save.Checked)
                {
                    prof.save();
                }
                ProfilesCount++;
                CreateLinkEntry(A_prof, A_prof.ID, prof.ID);
            }
            // ======= Create link control-profile in prod ========
            foreach (ACCSynapseProfile_Control A_profControl in from apc in Acc_ProfileControls where apc.PrdID(AccToPrdID) == 0 select apc)
            {
                if (chk_verbose.Checked)
                {
                    richTextBox1.AppendText(A_profControl.GetType().Name + ": " + A_profControl.FK_PROFILEID + "=>" + A_profControl.FK_CONTROLID + "\n");
                }
                SynapseProfile_Control ProfControl = new SynapseProfile_Control();
                ProfControl.IS_ACTIVE  = A_profControl.IS_ACTIVE;
                ProfControl.IS_VISIBLE = A_profControl.IS_VISIBLE;
                try
                {
                    ProfControl.FK_CONTROLID = AccToPrdID.ConvertID(typeof(ACCSynapseControl), A_profControl.FK_CONTROLID);
                    ProfControl.FK_PROFILEID = AccToPrdID.ConvertID(typeof(ACCSynapseProfile), A_profControl.FK_PROFILEID);
                    if (chk_save.Checked)
                    {
                        ProfControl.save();
                    }
                    ProfileControlsCount++;
                    CreateLinkEntry(A_profControl, A_profControl.ID, ProfControl.ID);
                }
                catch (MissingFieldException ex)
                {
                    richTextBox1.AppendText("ERROR(" + ex.Message + "): " + A_profControl.GetType().Name + ": " + A_profControl.FK_PROFILEID + "=>" + A_profControl.FK_CONTROLID + "\n", Color.Red);
                    richTextBox1.ScrollToCaret();
                }
                catch (KeyNotFoundException ex)
                {
                    richTextBox1.AppendText("WARNING(" + ex.Message + "): " + A_profControl.GetType().Name + ": " + A_profControl.FK_PROFILEID + "=>" + A_profControl.FK_CONTROLID + "\n", Color.Orange);
                    richTextBox1.ScrollToCaret();
                }
            }
            if (chk_UserAssignment.Checked)
            {
                // ======= Create link user-profile in prod ========
                foreach (ACCSynapseUser_Profile A_userP in from aup in Acc_UserProfiles where aup.PrdID(AccToPrdID) == 0 select aup)
                {
                    if (chk_verbose.Checked)
                    {
                        richTextBox1.AppendText(A_userP.GetType().Name + ": " + A_userP.FK_SECURITY_PROFILE + "=>" + A_userP.FK_SECURITY_USER + "\n");
                    }
                    SynapseUser_Profile UserProf = new SynapseUser_Profile();
                    try
                    {
                        UserProf.FK_SECURITY_PROFILE = AccToPrdID.ConvertID(typeof(ACCSynapseProfile), A_userP.FK_SECURITY_PROFILE);
                        UserProf.FK_SECURITY_USER    = AccToPrdID.ConvertID(typeof(ACCSynapseUser), A_userP.FK_SECURITY_USER);
                        if (chk_save.Checked)
                        {
                            UserProf.save();
                        }
                        UserAssignmentCount++;
                        CreateLinkEntry(A_userP, A_userP.ID, UserProf.ID);
                    }
                    catch (MissingFieldException ex)
                    {
                        richTextBox1.AppendText("ERROR(" + ex.Message + "): " + A_userP.GetType().Name + ": " + A_userP.FK_SECURITY_PROFILE + "=>" + A_userP.FK_SECURITY_USER + "\n", Color.Red);
                        richTextBox1.ScrollToCaret();
                    }
                    catch (KeyNotFoundException ex)
                    {
                        richTextBox1.AppendText("WARNING(" + ex.Message + "): " + A_userP.GetType().Name + ": " + A_userP.FK_SECURITY_PROFILE + "=>" + A_userP.FK_SECURITY_USER + "\n", Color.Orange);
                        richTextBox1.ScrollToCaret();
                    }
                }
            }
            if (chk_save.Checked)
            {
                foreach (ACCTOPRD atp in from l in AccToPrdID where l.ID == 0 select l)
                {
                    atp.save();
                }
            }
            Int64 lnk = 0;

            richTextBox1.AppendText(UsersCount + " Users will be added", Color.Blue);
            lnk = AccToPrdID.Where(l => l.ID == 0 && l.OBJECTTYPE == typeof(ACCSynapseUser).Name).Count();
            richTextBox1.AppendText(" with " + lnk + " new links\n", UsersCount == lnk ? Color.Blue : Color.Red);

            richTextBox1.AppendText(ControlsCount + " Controls will be added", Color.Blue);
            lnk = AccToPrdID.Where(l => l.ID == 0 && l.OBJECTTYPE == typeof(ACCSynapseControl).Name).Count();
            richTextBox1.AppendText(" with " + lnk + " new links\n", ControlsCount == lnk ? Color.Blue : Color.Red);

            richTextBox1.AppendText(ProfilesCount + " Profiles will be added", Color.Blue);
            lnk = AccToPrdID.Where(l => l.ID == 0 && l.OBJECTTYPE == typeof(ACCSynapseProfile).Name).Count();
            richTextBox1.AppendText(" with " + lnk + " new links\n", ProfilesCount == lnk ? Color.Blue : Color.Red);

            richTextBox1.AppendText(ProfileControlsCount + " Profile-Control link will be added", Color.Blue);
            lnk = AccToPrdID.Where(l => l.ID == 0 && l.OBJECTTYPE == typeof(ACCSynapseProfile_Control).Name).Count();
            richTextBox1.AppendText(" with " + lnk + " new links\n", ProfileControlsCount == lnk ? Color.Blue : Color.Red);

            richTextBox1.AppendText(UserAssignmentCount + " Users assignments will be added", Color.Blue);
            lnk = AccToPrdID.Where(l => l.ID == 0 && l.OBJECTTYPE == typeof(ACCSynapseUser_Profile).Name).Count();
            richTextBox1.AppendText(" with " + lnk + " new links\n", UserAssignmentCount == lnk ? Color.Blue : Color.Red);

            richTextBox1.ScrollToCaret();
        }