Example #1
0
        public void ApplyToObjet(object objet)
        {
            CRestrictionUtilisateurSurType rest = GetRestriction(objet.GetType()).Clone() as CRestrictionUtilisateurSurType;

            rest.ApplyToObjet(objet);
            SetRestriction(rest);
        }
Example #2
0
        /// /////////////////////////////////////////////////////////
        private void AddRestrictionsHorsPriorites(Type tp, CRestrictionUtilisateurSurType rest)
        {
            CRestrictionUtilisateurSurType restO = GetRestriction(tp);

            restO.AddRestrictionsHorsPriorite(rest);
            m_tableRestrictions[tp] = restO;
        }
Example #3
0
        /// /////////////////////////////////////////////////////////
        public CRestrictionUtilisateurSurType GetRestriction(Type tp)
        {
            if (m_bIsAdministrateur)
            {
                return(new CRestrictionUtilisateurSurType(tp));
            }
            CRestrictionUtilisateurSurType rest = (CRestrictionUtilisateurSurType)m_tableRestrictions[tp];

            if (rest == null)
            {
                rest = new CRestrictionUtilisateurSurType(tp);
            }
            object[] attribs = tp.GetCustomAttributes(typeof(RestrictionHeriteeAttribute), true);
            CRestrictionUtilisateurSurType restClone = (CRestrictionUtilisateurSurType)rest.Clone();

            if (attribs != null && attribs.Length > 0)
            {
                Type newTp = tp.BaseType;
                if (tp != null)
                {
                    restClone.Combine(GetRestriction(newTp));
                }
            }
            if (SeuilAnnulationPriorites != null)
            {
                restClone.SurchageComplete = true;
                restClone.Priorite         = (int)SeuilAnnulationPriorites;
            }
            return(restClone);
        }
        /// <summary>
        /// Retourne une indication sur se qu'il faut faire pour la combinaison
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static int EstCeQuiYaUnPlusFortEtSiOuiCestQui(CRestrictionUtilisateurSurType x, CRestrictionUtilisateurSurType y)
        {
            if (x == null && y == null)
            {
                return(0);
            }
            else if (x == null)
            {
                return(-1);
            }
            else if (y == null)
            {
                return(1);
            }
            if (x.TypeAssocie != y.TypeAssocie)
            {
                return(0);
            }

            if (x.Priorite == y.Priorite)
            {
                if (!x.SurchageComplete && y.SurchageComplete)
                {
                    return(-1);
                }
                else if (x.SurchageComplete && !y.SurchageComplete)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else if (x.Priorite > y.Priorite)
            {
                if (x.SurchageComplete)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                if (y.SurchageComplete)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            }
        }
 /// ///////////////////////////////////////////
 public void AddRestrictionsHorsPriorite(CRestrictionUtilisateurSurType restriction)
 {
     m_restrictionHorsPriorité |= restriction.RestrictionGlobale;
     foreach (DictionaryEntry entry in restriction.m_tableRestrictions)
     {
         SetRestrictionHorsPriorite((string)entry.Key,
                                    GetRestrictionHorsPriorite((string)entry.Key) |
                                    restriction.GetRestriction((string)entry.Key));
     }
 }
        /// ///////////////////////////////////////////
        public object Clone()
        {
            CRestrictionUtilisateurSurType restriction = new CRestrictionUtilisateurSurType(m_type);

            foreach (string strKey in m_tableRestrictions.Keys)
            {
                restriction.m_tableRestrictions[strKey] = (ERestriction)m_tableRestrictions[strKey];
            }
            foreach (string strKey in m_tableRestrictionsHorsPriorites.Keys)
            {
                restriction.m_tableRestrictionsHorsPriorites[strKey] = m_tableRestrictionsHorsPriorites[strKey];
            }
            restriction.RestrictionUtilisateur    = RestrictionUtilisateur;
            restriction.RestrictionSysteme        = RestrictionSysteme;
            restriction.m_restrictionHorsPriorité = m_restrictionHorsPriorité;
            restriction.m_nPriorite         = Priorite;
            restriction.m_bSurchageComplete = SurchageComplete;
            restriction.ContextesException  = ContextesException;

            return(restriction);
        }
Example #7
0
        /// /////////////////////////////////////////////////////////
        public void AddRestriction(CRestrictionUtilisateurSurType restriction)
        {
            if (restriction == null)
            {
                return;
            }
            Type tp = restriction.TypeAssocie;
            CRestrictionUtilisateurSurType resEx = GetRestriction(tp);

            if (SeuilAnnulationPriorites == null || resEx.Priorite >= (int)SeuilAnnulationPriorites)
            {
                if (resEx != null && resEx.HasRestrictions)
                {
                    m_tableRestrictions[tp] = CRestrictionUtilisateurSurType.Combine(resEx, restriction);
                }
                else
                {
                    m_tableRestrictions[tp] = (CRestrictionUtilisateurSurType)restriction.Clone();
                }
            }
        }
        /// ///////////////////////////////////////////
        public static CRestrictionUtilisateurSurType Combine(CRestrictionUtilisateurSurType restriction1, CRestrictionUtilisateurSurType restriction2)
        {
            CRestrictionUtilisateurSurType rest = null;

            if (restriction1 == null && restriction2 == null ||
                restriction1.TypeAssocie != restriction2.TypeAssocie)
            {
                return(null);
            }

            if (restriction1 == null)
            {
                return((CRestrictionUtilisateurSurType)restriction2.Clone());
            }
            if (restriction2 == null)
            {
                return((CRestrictionUtilisateurSurType)restriction1.Clone());
            }

            rest = (CRestrictionUtilisateurSurType)restriction1.Clone();
            rest.Combine(restriction2);
            return(rest);
        }
        /// ///////////////////////////////////////////
        public void Combine(CRestrictionUtilisateurSurType rest)
        {
            if (rest == null || rest.TypeAssocie != TypeAssocie)
            {
                return;
            }

            //Les restrictions d'affichage se combinent toujours
            m_restrictionHorsPriorité |= rest.m_restrictionHorsPriorité;
            foreach (DictionaryEntry entry in rest.m_tableRestrictionsHorsPriorites)
            {
                SetRestrictionHorsPriorite((string)entry.Key,
                                           GetRestrictionHorsPriorite((string)entry.Key) | rest.GetRestrictionHorsPriorite((string)entry.Key));
            }

            //Dans le cas d'une restriction système les 2 restrictions doivent
            //se "fusionner" quelque soit leur priorité ex:
            //Une restriction système est créé au lancement d'une application mais
            //l'utilisateur à ajouté d'autres restriction

            int nCompare = EstCeQuiYaUnPlusFortEtSiOuiCestQui(this, rest);

            if (nCompare == 1)            //c'est moi le plus fort
            {
                RestrictionSysteme |= rest.RestrictionSysteme;
                return;
            }
            else if (nCompare == -1)            //C'est l'autre le plus fort
            {
                m_tableRestrictions.Clear();
                foreach (string strKey in rest.m_tableRestrictions.Keys)
                {
                    SetRestrictionLocale(strKey, rest.GetRestrictionLocale(strKey));
                }
                Priorite               = rest.Priorite;
                SurchageComplete       = true;
                RestrictionUtilisateur = rest.RestrictionUtilisateur;
                RestrictionSysteme    |= rest.RestrictionSysteme;
                ContextesException     = rest.ContextesException;
                return;
            }
            else            //Il n'y a pas de plus fort
            {
                //Les lignes suivantes fusionnent les restrictions :
                SurchageComplete = (SurchageComplete && Priorite >= rest.Priorite) ||
                                   (rest.SurchageComplete && rest.Priorite >= Priorite);
                Priorite = Math.Max(Priorite, rest.Priorite);
                RestrictionUtilisateur = rest.RestrictionUtilisateur | RestrictionUtilisateur;
                RestrictionSysteme    |= rest.RestrictionSysteme;

                foreach (string strKey in rest.m_tableRestrictions.Keys)
                {
                    ERestriction rest1 = GetRestrictionLocale(strKey);
                    ERestriction rest2 = rest.GetRestrictionLocale(strKey);
                    SetRestrictionLocale(strKey, rest1 | rest2);
                }

                // On passe par une liste tampon car la tables parcourue peut être modifiée
                ArrayList listeKeysDeLaTablesDesRestrictions = new ArrayList(m_tableRestrictions.Keys);
                foreach (string strKey in listeKeysDeLaTablesDesRestrictions)
                {
                    ERestriction rest1 = GetRestrictionLocale(strKey);
                    ERestriction rest2 = rest.GetRestrictionLocale(strKey);
                    SetRestrictionLocale(strKey, rest1 | rest2);
                }
                Dictionary <string, bool> dicContextes = new Dictionary <string, bool>();
                foreach (string strContexte in ContextesException)
                {
                    dicContextes[strContexte] = true;
                }
                foreach (string strContexte in rest.ContextesException)
                {
                    dicContextes[strContexte] = true;
                }
                string[] strContextes = new string[dicContextes.Count];
                int      nContexte    = 0;
                foreach (string strcontexte in dicContextes.Keys)
                {
                    strContextes[nContexte] = strcontexte;
                }
                ContextesException = strContextes;
            }
        }
Example #10
0
 ///--------------------------------------------------------------------
 /// <summary>
 /// remplace la restriction en cours
 /// </summary>
 /// <param name="restriction"></param>
 public void SetRestriction(CRestrictionUtilisateurSurType restriction)
 {
     m_tableRestrictions[restriction.TypeAssocie] = restriction;
 }