Exemple #1
0
        public DataAttributeModel(bool showConstraints)
        {
            Id              = 0;
            Name            = "";
            ShortName       = "";
            Description     = "";
            InUse           = false;
            ShowConstraints = showConstraints;

            DataType = new DataTypeItemModel();
            Unit     = new UnitItemModel();

            try
            {
                dataTypeManager = new DataTypeManager();
                unitManager     = new UnitManager();
                dataTypeManager.Repo.Get().OrderBy(dt => dt.Name).ToList().ForEach(dt => DataTypes.Add(new DataTypeItemModel(dt)));
                unitManager.Repo.Get().OrderBy(u => u.Name).ToList().ForEach(u => Units.Add(new UnitItemModel(u)));
            }
            finally
            {
                dataTypeManager.Dispose();
                unitManager.Dispose();
            }

            RangeConstraints   = new List <RangeConstraintModel>();
            DomainConstraints  = new List <DomainConstraintModel>();
            PatternConstraints = new List <PatternConstraintModel>();
        }
Exemple #2
0
        public DataAttributeModel(DataAttribute dataAttribute, bool showConstraints = false)
        {
            Id              = dataAttribute.Id;
            Name            = dataAttribute.Name;
            ShortName       = dataAttribute.ShortName;
            Description     = dataAttribute.Description;
            ShowConstraints = showConstraints;

            DataType = new DataTypeItemModel(dataAttribute.DataType);
            Unit     = new UnitItemModel(dataAttribute.Unit);

            try
            {
                dataTypeManager = new DataTypeManager();
                unitManager     = new UnitManager();
                dataTypeManager.Repo.Get().OrderBy(dt => dt.Name).ToList().ForEach(dt => DataTypes.Add(new DataTypeItemModel(dt)));
                unitManager.Repo.Get().OrderBy(u => u.Name).ToList().ForEach(u => Units.Add(new UnitItemModel(u)));
            }
            finally
            {
                dataTypeManager.Dispose();
                unitManager.Dispose();
            }

            RangeConstraints   = new List <RangeConstraintModel>();
            DomainConstraints  = new List <DomainConstraintModel>();
            PatternConstraints = new List <PatternConstraintModel>();

            dataAttribute.Constraints.ToList().Where(c => c.GetType().Equals(typeof(RangeConstraint))).ToList().ForEach(rc => RangeConstraints.Add(RangeConstraintModel.Convert((RangeConstraint)rc, Id)));
            dataAttribute.Constraints.ToList().Where(c => c.GetType().Equals(typeof(PatternConstraint))).ToList().ForEach(pc => PatternConstraints.Add(PatternConstraintModel.Convert((PatternConstraint)pc, Id)));
            dataAttribute.Constraints.ToList().Where(c => c.GetType().Equals(typeof(DomainConstraint))).ToList().ForEach(dc => DomainConstraints.Add(DomainConstraintModel.Convert((DomainConstraint)dc, Id)));

            if (dataAttribute.UsagesAsVariable != null && dataAttribute.UsagesAsVariable.Count > 0)
            {
                InUse = true;
            }

            if (dataAttribute.Constraints.Count > 0)
            {
                foreach (Constraint c in dataAttribute.Constraints)
                {
                    if (c is RangeConstraint)
                    {
                        RangeConstraints.Add(RangeConstraintModel.Convert((RangeConstraint)c, Id));
                    }
                    if (c is PatternConstraint)
                    {
                        PatternConstraints.Add(PatternConstraintModel.Convert((PatternConstraint)c, Id));
                    }

                    if (c is DomainConstraint)
                    {
                        DomainConstraints.Add(DomainConstraintModel.Convert((DomainConstraint)c, Id));
                    }
                }
            }
        }