public RS.ResourceStructureAttribute CreateResourceStructureAttribute(string name, string description)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(!String.IsNullOrWhiteSpace(description));

            using (DataTypeManager dataTypeManager = new DataTypeManager())
            {
                DataType type = dataTypeManager.Repo.Get(p => p.SystemType.Equals("String")).FirstOrDefault();
                if (type == null)
                {
                    type = dataTypeManager.Create("String", "string", TypeCode.String);
                }

                RS.ResourceStructureAttribute resourceStrucAtt = new RS.ResourceStructureAttribute()
                {
                    Name        = name,
                    Description = description,
                    DataType    = type,
                };


                using (IUnitOfWork uow = this.GetUnitOfWork())
                {
                    IRepository <RS.ResourceStructureAttribute> repo = uow.GetRepository <RS.ResourceStructureAttribute>();
                    repo.Put(resourceStrucAtt);
                    uow.Commit();
                }

                return(resourceStrucAtt);
            }
        }
Ejemplo n.º 2
0
        public StructuredDataStructure CreateADataStructure()
        {
            var unitManager      = new UnitManager();
            var dataTypeManager  = new DataTypeManager();
            var attributeManager = new DataContainerManager();
            var dsManager        = new DataStructureManager();

            try
            {
                var dim  = unitManager.Create("TestDimnesion", "For Unit Testing", "");
                var unit = unitManager.Create("None_UT", "NoneUT", "Use in unit tsting", dim, Dlm.Entities.DataStructure.MeasurementSystem.Metric);

                var intType      = dataTypeManager.Create("Integer", "Integer", TypeCode.Int32);
                var strType      = dataTypeManager.Create("String", "String", TypeCode.String);
                var doubleType   = dataTypeManager.Create("Double", "Double", TypeCode.Double);
                var boolType     = dataTypeManager.Create("Bool", "Bool", TypeCode.Boolean);
                var dateTimeType = dataTypeManager.Create("DateTime", "DateTime", TypeCode.DateTime);

                var dataAttribute1 = attributeManager.CreateDataAttribute(
                    "att1UT", "att1UT", "Attribute for Unit testing",
                    false, false, "", Dlm.Entities.DataStructure.MeasurementScale.Nominal, Dlm.Entities.DataStructure.DataContainerType.ValueType,
                    "", intType, unit,
                    null, null, null, null, null, null
                    );

                var dataAttribute2 = attributeManager.CreateDataAttribute(
                    "att2UT", "att1UT", "Attribute for Unit testing",
                    false, false, "", Dlm.Entities.DataStructure.MeasurementScale.Nominal, Dlm.Entities.DataStructure.DataContainerType.ValueType,
                    "", strType, unit,
                    null, null, null, null, null, null
                    );

                var dataAttribute3 = attributeManager.CreateDataAttribute(
                    "att3UT", "att3UT", "Attribute for Unit testing",
                    false, false, "", Dlm.Entities.DataStructure.MeasurementScale.Nominal, Dlm.Entities.DataStructure.DataContainerType.ValueType,
                    "", doubleType, unit,
                    null, null, null, null, null, null
                    );

                var dataAttribute4 = attributeManager.CreateDataAttribute(
                    "att4UT", "att4UT", "Attribute for Unit testing",
                    false, false, "", Dlm.Entities.DataStructure.MeasurementScale.Nominal, Dlm.Entities.DataStructure.DataContainerType.ValueType,
                    "", boolType, unit,
                    null, null, null, null, null, null
                    );

                var dataAttribute5 = attributeManager.CreateDataAttribute(
                    "att5UT", "att5UT", "Attribute for Unit testing",
                    false, false, "", Dlm.Entities.DataStructure.MeasurementScale.Nominal, Dlm.Entities.DataStructure.DataContainerType.ValueType,
                    "", dateTimeType, unit,
                    null, null, null, null, null, null
                    );

                StructuredDataStructure dataStructure = dsManager.CreateStructuredDataStructure("dsForTesting", "DS for unit testing", "", "", Dlm.Entities.DataStructure.DataStructureCategory.Generic);
                dsManager.AddVariableUsage(dataStructure, dataAttribute1, true, "var1UT", "", "", "Used for unit testing");
                dsManager.AddVariableUsage(dataStructure, dataAttribute2, true, "var2UT", "", "", "Used for unit testing");
                dsManager.AddVariableUsage(dataStructure, dataAttribute3, true, "var3UT", "", "", "Used for unit testing");
                dsManager.AddVariableUsage(dataStructure, dataAttribute4, true, "var4UT", "", "", "Used for unit testing");
                dsManager.AddVariableUsage(dataStructure, dataAttribute5, true, "var5UT", "", "", "Used for unit testing");
                return(dataStructure);
            }
            catch (Exception ex) { return(null); }
            finally
            {
                unitManager.Dispose();
                dataTypeManager.Dispose();
                attributeManager.Dispose();
                dsManager.Dispose();
            }
        }
Ejemplo n.º 3
0
        // create read data types in bpp
        public void CreateDataTypes(ref DataTable mappedDataTypes)
        {
            DataTypeManager dataTypeManager = null;

            try
            {
                dataTypeManager = new DataTypeManager();

                foreach (DataRow mappedDataType in mappedDataTypes.Rows)
                {
                    string dtName        = mappedDataType["Name"].ToString();
                    string dtDescription = mappedDataType["Description"].ToString();
                    DataTypeDisplayPattern dtDisplayPettern = new DataTypeDisplayPattern();
                    TypeCode dtSystemType = new TypeCode();
                    foreach (TypeCode type in Enum.GetValues(typeof(TypeCode)))
                    {
                        if (type.ToString().Equals(mappedDataType["SystemType"].ToString()))
                        {
                            dtSystemType = type;
                        }
                    }

                    if (dtSystemType == TypeCode.DateTime)
                    {
                        if (mappedDataType["DisplayPattern"] != null && mappedDataType["DisplayPattern"].ToString() != "")
                        {
                            dtDisplayPettern = DataTypeDisplayPattern.Pattern.Where(p => p.Systemtype.Equals(DataTypeCode.DateTime) && p.Name.Equals(mappedDataType["DisplayPattern"].ToString())).FirstOrDefault();
                        }
                        else
                        {
                            dtDisplayPettern = DataTypeDisplayPattern.Pattern.Where(p => p.Name.Equals("DateTimeIso")).FirstOrDefault();
                        }
                    }

                    DataType dataType = new DataType();
                    // get existing dataTypes
                    DataType existDT = dataTypeManager.Repo.Get().Where(d =>
                                                                        d.Name.Equals(dtName) &&
                                                                        d.SystemType.ToString().Equals(mappedDataType["SystemType"].ToString())
                                                                        ).FirstOrDefault();
                    // return ID of existing dataType or create dataType
                    if (existDT == null && dtSystemType != null)
                    {
                        dataType = dataTypeManager.Create(dtName, dtDescription, dtSystemType);

                        XmlDocument xmlDoc = new XmlDocument();
                        XmlNode     xmlNode;
                        xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Extra", null);
                        xmlDoc.AppendChild(xmlNode);
                        xmlNode          = xmlDoc.CreateNode(XmlNodeType.Element, "DisplayPattern", null);
                        xmlNode.InnerXml = DataTypeDisplayPattern.Dematerialize(dtDisplayPettern).InnerXml;
                        xmlDoc.DocumentElement.AppendChild(xmlNode);
                        dataType.Extra = xmlDoc;

                        dataTypeManager.Update(dataType);
                    }
                    else
                    {
                        dataType = existDT;
                    }

                    mappedDataType["DataTypesId"] = dataType.Id;
                }
            }
            finally
            {
                dataTypeManager.Dispose();
            }
        }