Beispiel #1
0
        //---------------------------------------------------------------
        public CValeursProprietes GetValeurParente(CDefinitionProprieteDynamique def)
        {
            AssureValeurs();
            CValeursProprietes val = null;

            if (m_dicValeursParentes.TryGetValue(def, out val))
            {
                return(val);
            }
            return(null);
        }
Beispiel #2
0
        //---------------------------------------------------------------
        public CResultAErreur Serialize(C2iSerializer serializer)
        {
            int            nVersion = GetNumVersion();
            CResultAErreur result   = serializer.TraiteVersion(ref nVersion);

            if (!result)
            {
                return(result);
            }
            bool bIsCalcule = m_dicValeursSimples != null;

            serializer.TraiteBool(ref bIsCalcule);
            if (bIsCalcule)
            {
                int nNb = m_dicValeursSimples.Count;
                serializer.TraiteInt(ref nNb);
                switch (serializer.Mode)
                {
                case ModeSerialisation.Lecture:
                    m_dicValeursSimples = new Dictionary <CDefinitionProprieteDynamique, object>();
                    for (int n = 0; n < nNb; n++)
                    {
                        CDefinitionProprieteDynamique def = null;
                        result = serializer.TraiteObject <CDefinitionProprieteDynamique>(ref def);
                        if (!result)
                        {
                            return(result);
                        }
                        object val = null;
                        result = serializer.TraiteObjetSimple(ref val);
                        if (!result)
                        {
                            return(result);
                        }
                        m_dicValeursSimples[def] = val;
                    }
                    break;

                case ModeSerialisation.Ecriture:
                    foreach (KeyValuePair <CDefinitionProprieteDynamique, object> kv in m_dicValeursSimples)
                    {
                        CDefinitionProprieteDynamique def = kv.Key;
                        result = serializer.TraiteObject <CDefinitionProprieteDynamique>(ref def);
                        if (!result)
                        {
                            return(result);
                        }
                        object val = kv.Value;
                        result = serializer.TraiteObjetSimple(ref val);
                        if (!result)
                        {
                            return(result);
                        }
                    }
                    break;
                }

                nNb = m_dicValeursParentes.Count;
                serializer.TraiteInt(ref nNb);
                switch (serializer.Mode)
                {
                case ModeSerialisation.Lecture:
                    m_dicValeursParentes = new Dictionary <CDefinitionProprieteDynamique, CValeursProprietes>();
                    for (int n = 0; n < nNb; n++)
                    {
                        CDefinitionProprieteDynamique def = null;
                        result = serializer.TraiteObject <CDefinitionProprieteDynamique>(ref def);
                        if (!result)
                        {
                            return(result);
                        }
                        CValeursProprietes val = null;
                        result = serializer.TraiteObject <CValeursProprietes>(ref val);
                        if (!result)
                        {
                            return(result);
                        }
                        m_dicValeursParentes[def] = val;
                    }
                    break;

                case ModeSerialisation.Ecriture:
                    foreach (KeyValuePair <CDefinitionProprieteDynamique, CValeursProprietes> kv in m_dicValeursParentes)
                    {
                        CDefinitionProprieteDynamique def = kv.Key;
                        result = serializer.TraiteObject <CDefinitionProprieteDynamique>(ref def);
                        if (!result)
                        {
                            return(result);
                        }
                        CValeursProprietes val = kv.Value;
                        result = serializer.TraiteObject <CValeursProprietes>(ref val);
                        if (!result)
                        {
                            return(result);
                        }
                    }
                    break;
                }

                nNb = m_dicValeursFilles.Count;
                serializer.TraiteInt(ref nNb);
                switch (serializer.Mode)
                {
                case ModeSerialisation.Lecture:
                    m_dicValeursFilles = new Dictionary <CDefinitionProprieteDynamique, List <CValeursProprietes> >();
                    for (int n = 0; n < nNb; n++)
                    {
                        CDefinitionProprieteDynamique def = null;
                        result = serializer.TraiteObject <CDefinitionProprieteDynamique>(ref def);
                        if (!result)
                        {
                            return(result);
                        }

                        List <CValeursProprietes> lst = new List <CValeursProprietes>();
                        result = serializer.TraiteListe <CValeursProprietes>(lst);
                        if (!result)
                        {
                            return(result);
                        }
                        m_dicValeursFilles[def] = lst;
                    }
                    break;

                case ModeSerialisation.Ecriture:
                    foreach (KeyValuePair <CDefinitionProprieteDynamique, List <CValeursProprietes> > kv in m_dicValeursFilles)
                    {
                        CDefinitionProprieteDynamique def = kv.Key;
                        result = serializer.TraiteObject <CDefinitionProprieteDynamique>(ref def);
                        if (!result)
                        {
                            return(result);
                        }
                        List <CValeursProprietes> lst = kv.Value;
                        result = serializer.TraiteListe <CValeursProprietes>(lst);
                        if (!result)
                        {
                            return(result);
                        }
                    }
                    break;
                }
            }
            return(result);
        }
Beispiel #3
0
        //---------------------------------------------------------------
        private void CalculeValeurs(IEnumerable <CDefinitionProprieteDynamique> lstChamps)
        {
            m_dicValeursSimples  = new Dictionary <CDefinitionProprieteDynamique, object>();
            m_dicValeursParentes = new Dictionary <CDefinitionProprieteDynamique, CValeursProprietes>();
            m_dicValeursFilles   = new Dictionary <CDefinitionProprieteDynamique, List <CValeursProprietes> >();
            if (m_objetAssocie == null)
            {
                return;
            }

            DataRowVersion oldVers = m_objetAssocie.VersionToReturn;

            m_objetAssocie.VersionToReturn = m_versionObjetStocke;

            m_strLibelleObjet = m_objetAssocie.DescriptionElement;


            HashSet <CDbKey> dicChampsAffectes = new HashSet <CDbKey>();
            //Optimisation des champs custom
            IElementAChamps eltAChamps = m_objetAssocie as IElementAChamps;

            if (eltAChamps != null)
            {
                foreach (CRelationElementAChamp_ChampCustom rel in eltAChamps.RelationsChampsCustom)
                {
                    dicChampsAffectes.Add(rel.ChampCustom.DbKey);
                }
            }


            CResultAErreur res = CResultAErreur.True;

            foreach (CDefinitionProprieteDynamique def in lstChamps)
            {
                if (IsChampCompatibleImport(m_objetAssocie.GetType(), def))
                {
                    try
                    {
                        bool bInterprete = true;
                        CDefinitionProprieteDynamiqueChampCustom defCust = def as CDefinitionProprieteDynamiqueChampCustom;
                        if (defCust != null)
                        {
                            bInterprete = dicChampsAffectes.Contains(defCust.DbKeyChamp);
                        }
                        if (bInterprete)
                        {
                            DateTime dt = DateTime.Now;
                            res = CInterpreteurProprieteDynamique.GetValue(m_objetAssocie, def);
                            TimeSpan sp = DateTime.Now - dt;
                            if (sp.TotalMilliseconds > 400)
                            {
                                dt = DateTime.Now;
                            }
                            if (res)
                            {
                                object obj = res.Data;
                                if (obj is CObjetDonnee)
                                {
                                    CValeursProprietes val = new CValeursProprietes((CObjetDonnee)obj, m_bAvecValeursOriginales);
                                    m_dicValeursParentes[def] = val;
                                }
                                else if (obj is IEnumerable && !(obj is string))
                                {
                                    List <CValeursProprietes> lst = new List <CValeursProprietes>();
                                    foreach (object valDeListe in (IEnumerable)obj)
                                    {
                                        if (valDeListe is CObjetDonnee)
                                        {
                                            lst.Add(new CValeursProprietes((CObjetDonnee)valDeListe, m_bAvecValeursOriginales));
                                        }
                                    }
                                    if (lst.Count > 0)
                                    {
                                        m_dicValeursFilles[def] = lst;
                                    }
                                }
                                else if (obj != null && C2iSerializer.IsObjetSimple(obj))
                                {
                                    m_dicValeursSimples[def] = obj;
                                }
                            }
                        }
                    }

                    catch { }
                }
            }
            if (m_bAvecValeursOriginales && m_objetAssocie.Row.RowState == DataRowState.Modified)
            {
                m_objetAssocie.VersionToReturn = DataRowVersion.Original;
                m_valeursOriginales            = new CValeursProprietes(m_objetAssocie, false);
            }
            m_objetAssocie.VersionToReturn = oldVers;
        }