Exemple #1
0
        private List <DataType> updataAssociatedDataType(Unit unit, long[] newDataTypeIds, UnitManager unitManager)
        {
            if (unit != null)
            {
                DataTypeManager dataTypeManger = null;
                try
                {
                    dataTypeManger = new DataTypeManager();

                    List <DataType> existingDataTypes  = unit.AssociatedDataTypes.ToList();
                    List <DataType> newDataTypes       = newDataTypeIds == null ? new List <DataType>() : dataTypeManger.GetUnitOfWork().GetReadOnlyRepository <DataType>().Query().Where(p => newDataTypeIds.Contains(p.Id)).ToList();
                    List <DataType> tobeAddedDataTypes = newDataTypes.Except(existingDataTypes).ToList();

                    if (tobeAddedDataTypes != null && tobeAddedDataTypes.Count > 0)
                    {
                        unitManager.AddAssociatedDataType(unit, tobeAddedDataTypes);
                    }


                    existingDataTypes = unit.AssociatedDataTypes.ToList();
                    List <DataType> toBeRemoved = existingDataTypes.Except(newDataTypes).ToList();
                    if (toBeRemoved != null && toBeRemoved.Count() > 0)
                    {
                        unitManager.RemoveAssociatedDataType(unit, toBeRemoved);
                    }

                    return(unit.AssociatedDataTypes.ToList());
                }
                finally
                {
                    dataTypeManger.Dispose();
                }
            }
            return(null);
        }
Exemple #2
0
        private void setup()
        {
            bool inUse = false;

            Unit           = new Unit();
            Unit.Dimension = new Dimension();
            DataTypeList   = new List <DataType>();
            DimensionList  = new List <Dimension>();

            UnitManager     unitManager     = null;
            DataTypeManager dataTypeManager = null;

            try
            {
                dataTypeManager = new DataTypeManager();
                unitManager     = new UnitManager();
                DataTypeList    = dataTypeManager.Repo.Get().ToList();
                DimensionList   = unitManager.DimensionRepo.Get().ToList();
            }
            finally
            {
                dataTypeManager.Dispose();
                unitManager.Dispose();
            }
        }
Exemple #3
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 #4
0
        // create read units in bpp
        public void CreateUnits(ref DataTable mappedUnits)
        {
            UnitManager     unitManager    = null;
            DataTypeManager dataTypeManger = null;

            try
            {
                // Javad: The whole loop can be improved!
                var dimentionRepo = unitManager.GetUnitOfWork().GetReadOnlyRepository <Dimension>();
                foreach (DataRow mapUnitsRow in mappedUnits.Rows)
                {
                    unitManager    = new UnitManager();
                    dataTypeManger = new DataTypeManager();
                    Unit unit = new Unit(); // Javad: this can not be out of the loop. in that case, it keeps its link to the session objects and causes the previous unit to be overriden as well as creating a new one!!
                                            // values of the unit
                    unit.Name         = mapUnitsRow["Name"].ToString();
                    unit.Abbreviation = mapUnitsRow["Abbreviation"].ToString();
                    unit.Description  = mapUnitsRow["Description"].ToString();

                    if (unit.Description.Length > 255)
                    {
                        unit.Description = unit.Description.Substring(0, 255);
                    }

                    unit.Dimension = dimentionRepo.Get(Convert.ToInt64(mapUnitsRow["DimensionId"]));

                    // find measurement system
                    foreach (MeasurementSystem msCheck in Enum.GetValues(typeof(MeasurementSystem)))
                    {
                        if (msCheck.ToString().Equals(mapUnitsRow["MeasurementSystem"].ToString()))
                        {
                            unit.MeasurementSystem = msCheck;
                        }
                    }

                    // set data type to created unit or add data type to existing unit
                    List <string> Types = mapUnitsRow["DataTypes"].ToString().Split(' ').Distinct().ToList();

                    // get existing unit or create
                    Unit existU = unitManager.Repo.Get(u => u.Name.ToLower().Equals(unit.Name.ToLower())).FirstOrDefault();
                    if (existU == null)
                    {
                        unit = unitManager.Create(unit.Name, unit.Abbreviation, unit.Description, unit.Dimension, unit.MeasurementSystem);
                        addDataTypes(unit.Id, Types, unitManager, dataTypeManger);
                    }
                    else
                    {
                        addDataTypes(existU.Id, Types, unitManager, dataTypeManger);
                    }
                    // add unit-ID to the mappedUnits Table
                    mapUnitsRow["UnitId"] = unit.Id;
                }
            }
            finally
            {
                unitManager.Dispose();
                dataTypeManger.Dispose();
            }
        }
Exemple #5
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));
                    }
                }
            }
        }
        public ActionResult _getDataTypes(long unitId)
        {
            List <ItemStruct> DataTypes = new List <ItemStruct>();
            UnitManager       um        = null;

            try
            {
                um = new UnitManager();

                Unit unit = um.Repo.Get(unitId);
                if (unit.Name.ToLower() != "none")
                {
                    foreach (DataType dt in unit.AssociatedDataTypes)
                    {
                        DataTypes.Add(new ItemStruct()
                        {
                            Name        = dt.Name,
                            Id          = dt.Id,
                            Description = dt.Description
                        });
                    }
                    return(PartialView("_dropdown", DataTypes.OrderBy(dt => dt.Name).ToList()));
                }
                else
                {
                    DataTypeManager dtm = null;
                    try
                    {
                        dtm = new DataTypeManager();
                        foreach (DataType dt in dtm.Repo.Get())
                        {
                            DataTypes.Add(new ItemStruct()
                            {
                                Name        = dt.Name,
                                Id          = dt.Id,
                                Description = dt.Description
                            });
                        }
                        return(PartialView("_dropdown", DataTypes.OrderBy(dt => dt.Name).ToList()));
                    }
                    finally
                    {
                        dtm.Dispose();
                    }
                }
            }
            finally
            {
                um.Dispose();
            }
        }
Exemple #7
0
        public DataTypeModel(long Id)
        {
            DataTypeManager dtm = null;

            try
            {
                dtm      = new DataTypeManager();
                dataType = dtm.Repo.Get(Id);
                pattern  = DataTypeDisplayPattern.Materialize(dataType.Extra);
            }
            finally
            {
                dtm.Dispose();
            }
        }
Exemple #8
0
        public EditUnitStruct()
        {
            this.Id                = 0;
            this.Name              = "";
            this.Abbreviation      = "";
            this.Description       = "";
            this.DimensionId       = 0;
            this.MeasurementSystem = "";

            this.DataTypeList = new List <ItemStruct>();

            DataTypeManager dataTypeManager = null;
            UnitManager     unitManager     = null;

            try
            {
                dataTypeManager = new DataTypeManager();

                foreach (DataType dt in dataTypeManager.Repo.Get())
                {
                    this.DataTypeList.Add(new ItemStruct()
                    {
                        Name = dt.Name,
                        Id   = dt.Id
                    });
                }

                this.DimensionList = new List <ItemStruct>();

                unitManager = new UnitManager();

                foreach (Dimension dim in unitManager.DimensionRepo.Get())
                {
                    this.DimensionList.Add(new ItemStruct()
                    {
                        Name = dim.Name,
                        Id   = dim.Id
                    });
                }
            }
            finally
            {
                dataTypeManager.Dispose();
                unitManager.Dispose();
            }
        }
Exemple #9
0
        public ActionResult openUnitWindow(long id)
        {
            UnitManager      unitManager     = null;
            DataTypeManager  dataTypeManager = null;
            UnitManagerModel Model;

            try
            {
                unitManager     = new UnitManager();
                dataTypeManager = new DataTypeManager();
                if (id != 0)
                {
                    Model                  = new UnitManagerModel(id);
                    ViewBag.Title          = PresentationModel.GetViewTitleForTenant("Edit Unit: " + Model.editUnitModel.Unit.Name + "(Id: " + Model.editUnitModel.Unit.Id + ")", this.Session.GetTenant());
                    Session["nameMsg"]     = null;
                    Session["abbrMsg"]     = null;
                    Session["dataTypeMsg"] = null;
                    if (Model.editUnitModel.Unit != new Unit())
                    {
                        Unit temp = Model.editUnitModel.Unit;
                        if (temp.Id != Model.editUnitModel.Unit.Id)
                        {
                            Session["checked"] = null;
                        }
                    }
                    Session["Window"]       = true;
                    Session["dimensionMsg"] = null;
                }
                else
                {
                    ViewBag.Title           = PresentationModel.GetViewTitleForTenant("Create Unit", this.Session.GetTenant());
                    Model                   = new UnitManagerModel(0);
                    Session["nameMsg"]      = null;
                    Session["abbrMsg"]      = null;
                    Session["dataTypeMsg"]  = null;
                    Session["Window"]       = true;
                    Session["dimensionMsg"] = null;
                }
            }
            finally
            {
                unitManager.Dispose();
                dataTypeManager.Dispose();
            }
            return(View("UnitManager", Model));
        }
Exemple #10
0
        public DataTypeElement(long dataTypeId)
        {
            DataTypeManager dtm = null;

            try
            {
                dtm = new DataTypeManager();
                Dlm.Entities.DataStructure.DataType dataType = dtm.Repo.Get(dataTypeId);
                Id          = dataType.Id;
                Name        = dataType.Name;
                Description = dataType.Description;
                SystemType  = dataType.SystemType;
            }
            finally
            {
                dtm.Dispose();
            }
        }
Exemple #11
0
        private Unit updataAssociatedDataType(Unit unit, long[] newDataTypeIds)
        {
            if (unit != null)
            {
                DataTypeManager dataTypeManger = null;
                try
                {
                    dataTypeManger = new DataTypeManager();
                    List <DataType> newDataTypes = newDataTypeIds == null ? new List <DataType>() : dataTypeManger.GetUnitOfWork().GetReadOnlyRepository <DataType>().Query().Where(p => newDataTypeIds.Contains(p.Id)).ToList();

                    unit.AssociatedDataTypes = newDataTypes;

                    return(unit);
                }
                finally
                {
                    dataTypeManger.Dispose();
                }
            }
            return(null);
        }
Exemple #12
0
        public void ReloadLists()
        {
            DataTypeList  = new List <DataType>();
            DimensionList = new List <Dimension>();

            UnitManager     unitManager     = null;
            DataTypeManager dataTypeManager = null;

            try
            {
                dataTypeManager = new DataTypeManager();
                unitManager     = new UnitManager();
                DataTypeList    = dataTypeManager.Repo.Get().ToList();
                DimensionList   = unitManager.DimensionRepo.Get().ToList();
            }
            finally
            {
                dataTypeManager.Dispose();
                unitManager.Dispose();
            }
        }
Exemple #13
0
        public JsonResult getDatatypeList(string Id)
        {
            long        tempId      = Convert.ToInt64(Id);
            UnitManager unitManager = null;

            try
            {
                unitManager = new UnitManager();
                Unit            tempUnit     = unitManager.Repo.Get(tempId);
                List <DataType> dataTypeList = new List <DataType>();
                if (tempUnit.Name.ToLower() == "none")
                {
                    DataTypeManager dataTypeManager = null;
                    try
                    {
                        dataTypeManager = new DataTypeManager();
                        dataTypeList    = dataTypeManager.Repo.Get().ToList();
                        dataTypeList    = dataTypeList.OrderBy(p => p.Name).ToList();
                    }
                    finally
                    {
                        dataTypeManager.Dispose();
                    }
                }
                else
                {
                    dataTypeList = unitManager.Repo.Get(tempId).AssociatedDataTypes.ToList();
                    dataTypeList = dataTypeList.OrderBy(p => p.Name).ToList();
                }

                return(Json(new SelectList(dataTypeList.ToArray(), "Id", "Name"), JsonRequestBehavior.AllowGet));
            }
            finally
            {
                unitManager.Dispose();
            }
        }
Exemple #14
0
        // create read attributes in bpp
        public void CreateAttributes(ref DataTable mappedAttributes)
        {
            DataContainerManager attributeManager = null;
            DataTypeManager      dataTypeManager  = null;
            UnitManager          unitManager      = null;

            try
            {
                attributeManager = new DataContainerManager();
                dataTypeManager  = new DataTypeManager();
                unitManager      = new UnitManager();

                foreach (DataRow mapAttributesRow in mappedAttributes.Rows)
                {
                    DataAttribute attribute = new DataAttribute();

                    // values of the attribute
                    attribute.ShortName    = mapAttributesRow["ShortName"].ToString();
                    attribute.Name         = mapAttributesRow["Name"].ToString();
                    attribute.Description  = mapAttributesRow["Description"].ToString();
                    attribute.IsMultiValue = false;
                    attribute.IsBuiltIn    = false;
                    //attribute.Owner = "BMM";
                    attribute.Scope                    = "";
                    attribute.MeasurementScale         = MeasurementScale.Categorial; ////////!!!!!!!!fromMapping??????????????????
                    attribute.ContainerType            = DataContainerType.ReferenceType;
                    attribute.EntitySelectionPredicate = "";
                    attribute.DataType                 = dataTypeManager.Repo.Get(Convert.ToInt64(mapAttributesRow["DataTypeId"]));
                    attribute.Unit               = unitManager.Repo.Get(Convert.ToInt64(mapAttributesRow["UnitId"]));
                    attribute.Methodology        = null;
                    attribute.Classification     = null;
                    attribute.AggregateFunctions = null;
                    attribute.GlobalizationInfos = null;
                    attribute.Constraints        = null;
                    attribute.ExtendedProperties = null;

                    DataAttribute dataAttribute  = new DataAttribute();
                    DataAttribute existAttribute = attributeManager.DataAttributeRepo.Get(a =>
                                                                                          attribute.Name.Equals(a.Name) &&
                                                                                          attribute.ShortName.Equals(a.ShortName) &&
                                                                                          attribute.Unit.Id.Equals(a.Unit.Id) &&
                                                                                          attribute.DataType.Id.Equals(a.DataType.Id)
                                                                                          ).FirstOrDefault();

                    // if attribute not exists (name, shortName) then create
                    if (existAttribute == null)
                    {
                        dataAttribute = attributeManager.CreateDataAttribute(
                            attribute.ShortName,
                            attribute.Name,
                            attribute.Description,
                            attribute.IsMultiValue,
                            attribute.IsBuiltIn,
                            attribute.Scope,
                            attribute.MeasurementScale,
                            attribute.ContainerType,
                            attribute.EntitySelectionPredicate,
                            attribute.DataType,
                            attribute.Unit,
                            attribute.Methodology,
                            attribute.Classification,
                            attribute.AggregateFunctions,
                            attribute.GlobalizationInfos,
                            attribute.Constraints,
                            attribute.ExtendedProperties
                            );
                    }
                    else
                    {
                        dataAttribute = existAttribute;
                    }

                    // add attributeId to the mappedAttributes Table
                    mapAttributesRow["AttributeId"] = dataAttribute.Id;
                }
            }
            finally
            {
                attributeManager.Dispose();
                dataTypeManager.Dispose();
                unitManager.Dispose();
            }
        }
Exemple #15
0
        // read variables from XLSX mapping file for only one dataset
        //public System.Data.DataTable readVariables(string filePath, string dataSetID, System.Data.DataTable mappedAttributes, System.Data.DataTable mappedUnits)
        //{
        //    string mappingFile = filePath + @"\variableMapping.xlsx";
        //    string sheetName = "mapping";
        //    long startRow = 2;
        //    long endRow = startRow;

        //    System.Data.DataTable mappedVariables = new System.Data.DataTable();
        //    mappedVariables.Columns.Add("DatasetId", typeof(string));
        //    mappedVariables.Columns.Add("Name", typeof(string));
        //    mappedVariables.Columns.Add("Description", typeof(string));
        //    mappedVariables.Columns.Add("Block", typeof(int));
        //    mappedVariables.Columns.Add("Attribute", typeof(string));
        //    mappedVariables.Columns.Add("Unit", typeof(string));
        //    mappedVariables.Columns.Add("ConvFactor", typeof(string));
        //    mappedVariables.Columns.Add("AttributeId", typeof(long));
        //    mappedVariables.Columns.Add("UnitId", typeof(long));
        //    mappedVariables.Columns.Add("VarUnitId", typeof(long));

        //    excel_init(mappingFile, sheetName, startRow, ref endRow);

        //    for (long i = startRow; i < endRow; i++)
        //    {
        //        System.Data.DataRow newRow = mappedVariables.NewRow();
        //        if (getValue(i.ToString(), "A") == dataSetID)
        //        {
        //            newRow["DatasetId"] = getValue(i.ToString(), "A");
        //            newRow["Name"] = getValue(i.ToString(), "B");
        //            newRow["Description"] = getValue(i.ToString(), "E");
        //            string AttributeShortName = getValue(i.ToString(), "F");
        //            newRow["Attribute"] = AttributeShortName;
        //            string variableUnit = getValue(i.ToString(), "G");
        //            newRow["Unit"] = variableUnit;
        //            newRow["ConvFactor"] = getValue(i.ToString(), "H");
        //            newRow["Block"] = int.Parse(getValue(i.ToString(), "I"));
        //            if (AttributeShortName.Length > 1) // if not mapped yet
        //            {
        //                // select related attribute as row from mappedAttributes Table
        //                System.Data.DataRow mappedAttributesRow = mappedAttributes.Select("ShortName = '" + AttributeShortName + "'").First<System.Data.DataRow>();
        //                // add related attributeId and unitId to the mappedVariables Table
        //                newRow["AttributeId"] = Convert.ToInt64(mappedAttributesRow["AttributeId"]);
        //                newRow["UnitId"] = Convert.ToInt64(mappedAttributesRow["UnitId"]);
        //            }
        //            if (variableUnit.Length > 0) // if dimensioned
        //            {
        //                // select related unit as row of mappedUnits
        //                System.Data.DataRow mappedUnitsRow = mappedUnits.Select("Abbreviation = '" + variableUnit + "'").First<System.Data.DataRow>();
        //                // add related UnitId of variable Unit to the mappedVariables Table
        //                newRow["VarUnitId"] = Convert.ToInt64(mappedUnitsRow["UnitId"]);
        //            }
        //            mappedVariables.Rows.Add(newRow);
        //        }
        //    }

        //    newWorkbook.Close();

        //    return mappedVariables;
        //}


        // read variables from XLSX mapping file
        //public System.Data.DataTable readVariables(string filePath, System.Data.DataTable mappedAttributes, System.Data.DataTable mappedUnits)
        //{
        //    string mappingFile = filePath + @"\variableMapping.xlsx";
        //    string sheetName = "mapping";
        //    long startRow = 2;
        //    long endRow = startRow;

        //    System.Data.DataTable mappedVariables = new System.Data.DataTable();
        //    mappedVariables.Columns.Add("DatasetId", typeof(string));
        //    mappedVariables.Columns.Add("Name", typeof(string));
        //    mappedVariables.Columns.Add("Description", typeof(string));
        //    mappedVariables.Columns.Add("Block", typeof(int));
        //    mappedVariables.Columns.Add("Attribute", typeof(string));
        //    mappedVariables.Columns.Add("Unit", typeof(string));
        //    mappedVariables.Columns.Add("ConvFactor", typeof(string));
        //    mappedVariables.Columns.Add("AttributeId", typeof(long));
        //    mappedVariables.Columns.Add("UnitId", typeof(long));
        //    mappedVariables.Columns.Add("VarUnitId", typeof(long));

        //    excel_init(mappingFile, sheetName, startRow, ref endRow);
        //    for (long i = startRow; i < endRow; i++)
        //    {
        //        System.Data.DataRow newRow = mappedVariables.NewRow();
        //        newRow["DatasetId"] = getValue(i.ToString(), "A");
        //        newRow["Name"] = getValue(i.ToString(), "B");
        //        newRow["Description"] = getValue(i.ToString(), "E");
        //        string AttributeShortName = getValue(i.ToString(), "F");
        //        newRow["Attribute"] = AttributeShortName;
        //        string variableUnit = getValue(i.ToString(), "G");
        //        newRow["Unit"] = variableUnit;
        //        newRow["ConvFactor"] = getValue(i.ToString(), "H");
        //        newRow["Block"] = int.Parse(getValue(i.ToString(), "I"));
        //        if (AttributeShortName.Length > 1) // if not mapped yet
        //        {
        //            // select related attribute as row from mappedAttributes Table
        //            System.Data.DataRow mappedAttributesRow = mappedAttributes.Select("ShortName = '" + AttributeShortName + "'").First<System.Data.DataRow>();
        //            // add related attributeId and unitId to the mappedVariables Table
        //            newRow["AttributeId"] = Convert.ToInt64(mappedAttributesRow["AttributeId"]);
        //            newRow["UnitId"] = Convert.ToInt64(mappedAttributesRow["UnitId"]);
        //        }
        //        if (variableUnit.Length > 0) // if dimensioned
        //        {
        //            // select related unit as row of mappedUnits
        //            System.Data.DataRow mappedUnitsRow = mappedUnits.Select("Abbreviation = '" + variableUnit + "'").First<System.Data.DataRow>();
        //            // add related UnitId of variable Unit to the mappedVariables Table
        //            newRow["VarUnitId"] = Convert.ToInt64(mappedUnitsRow["UnitId"]);
        //        }
        //        mappedVariables.Rows.Add(newRow);
        //    }

        //    newWorkbook.Close();

        //    return mappedVariables;
        //}


        /// <summary>
        /// read attributes from csv file
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="mappedUnits"></param>
        /// <param name="mappedDataTypes"></param>
        /// <returns></returns>
        public System.Data.DataTable readAttributes(string filePath)
        {
            string mappingFile = filePath + @"\variableMapping.xlsx";

            System.Data.DataTable mappedAttributes = new System.Data.DataTable();
            mappedAttributes.Columns.Add("Name", typeof(string));
            mappedAttributes.Columns.Add("ShortName", typeof(string));
            mappedAttributes.Columns.Add("Description", typeof(string));
            mappedAttributes.Columns.Add("IsMultipleValue", typeof(string));
            mappedAttributes.Columns.Add("IsBuiltIn", typeof(string));
            mappedAttributes.Columns.Add("Owner", typeof(string));
            mappedAttributes.Columns.Add("ContainerType", typeof(string));
            mappedAttributes.Columns.Add("MeasurementScale", typeof(string));
            mappedAttributes.Columns.Add("EntitySelectionPredicate", typeof(string));
            mappedAttributes.Columns.Add("Self", typeof(string));
            mappedAttributes.Columns.Add("DataType", typeof(string));
            mappedAttributes.Columns.Add("Unit", typeof(string));
            mappedAttributes.Columns.Add("Methodology", typeof(string));
            mappedAttributes.Columns.Add("Constraints", typeof(string));
            mappedAttributes.Columns.Add("ExtendedProperties", typeof(string));
            mappedAttributes.Columns.Add("GlobalizationInfos", typeof(string));
            mappedAttributes.Columns.Add("AggregateFunctions", typeof(string));
            mappedAttributes.Columns.Add("DataTypeId", typeof(long));
            mappedAttributes.Columns.Add("UnitId", typeof(long));
            mappedAttributes.Columns.Add("AttributeId", typeof(long));

            if (File.Exists(filePath + "\\attributes.csv") && File.Exists(filePath + "\\datatypes.csv") && File.Exists(filePath + "\\units.csv"))
            {
                StreamReader reader = new StreamReader(filePath + "\\attributes.csv");
                string       line   = "";
                //jump over the first row
                line = reader.ReadLine();

                UnitManager     unitManager     = null;
                DataTypeManager dataTypeManager = null;
                try
                {
                    unitManager     = new UnitManager();
                    dataTypeManager = new DataTypeManager();

                    while ((line = reader.ReadLine()) != null)
                    {
                        // (char)59 = ';'
                        string[] vars = line.Split((char)59);

                        System.Data.DataRow newRow = mappedAttributes.NewRow();
                        newRow["Name"]                     = vars[0];
                        newRow["ShortName"]                = vars[1];
                        newRow["Description"]              = vars[2];
                        newRow["IsMultipleValue"]          = vars[3];
                        newRow["IsBuiltIn"]                = vars[4];
                        newRow["Owner"]                    = vars[5];
                        newRow["ContainerType"]            = vars[6];
                        newRow["MeasurementScale"]         = vars[7];
                        newRow["EntitySelectionPredicate"] = vars[8];
                        newRow["Self"]                     = vars[9];
                        string DataType = vars[10];
                        newRow["DataType"] = DataType;
                        string UnitAbbreviation = vars[11];
                        newRow["Unit"]               = UnitAbbreviation;
                        newRow["Methodology"]        = vars[12];
                        newRow["Constraints"]        = vars[13];
                        newRow["ExtendedProperties"] = vars[14];
                        newRow["GlobalizationInfos"] = vars[15];
                        newRow["AggregateFunctions"] = vars[16];
                        // add DataTypesId and UnitId to the mappedAttributes Table
                        newRow["DataTypeId"] = dataTypeManager.Repo.Get().Where(dt => dt.Name.ToLower().Equals(DataType.ToLower())).FirstOrDefault().Id;
                        Unit unit = unitManager.Repo.Get().Where(u => u.Abbreviation.Equals(UnitAbbreviation)).FirstOrDefault();
                        if (unit != null)
                        {
                            newRow["UnitId"] = unitManager.Repo.Get().Where(u => u.Abbreviation.Equals(UnitAbbreviation)).FirstOrDefault().Id;
                        }
                        else
                        {
                            newRow["UnitId"] = 1;
                        }
                        mappedAttributes.Rows.Add(newRow);
                    }
                }
                finally
                {
                    unitManager.Dispose();
                    dataTypeManager.Dispose();
                }
            }
            return(mappedAttributes);
        }
        /// <summary>
        /// Determin whether the selected datatypes are suitable
        /// </summary>
        private List <Error> ValidateRows(string JsonArray)
        {
            DataTypeManager dtm = new DataTypeManager();

            try
            {
                const int maxErrorsPerColumn = 20;

                TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

                string[][] DeserializedJsonArray = JsonConvert.DeserializeObject <string[][]>(JsonArray);

                List <Error>    ErrorList       = new List <Error>();
                List <RowModel> Rows            = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS];
                RowModel[]      MappedRowsArray = Rows.ToArray();

                List <string> DataArea        = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                List <int[]>  IntDataAreaList = new List <int[]>();
                foreach (string area in DataArea)
                {
                    IntDataAreaList.Add(JsonConvert.DeserializeObject <int[]>(area));
                }

                foreach (int[] IntDataArea in IntDataAreaList)
                {
                    string[,] SelectedDataArea = new string[(IntDataArea[2] - IntDataArea[0]), (IntDataArea[3] - IntDataArea[1])];

                    for (int x = IntDataArea[1]; x <= IntDataArea[3]; x++)
                    {
                        int errorsInColumn = 0;
                        for (int y = IntDataArea[0]; y <= IntDataArea[2]; y++)
                        {
                            int    SelectedY = y - (IntDataArea[0]);
                            int    SelectedX = x - (IntDataArea[1]);
                            string vv        = DeserializedJsonArray[y][x];

                            RowModel mappedHeader = MappedRowsArray.Where(t => t.Index == SelectedX).FirstOrDefault();

                            DataType datatype = null;

                            datatype = dtm.Repo.Get(mappedHeader.SelectedDataType.DataTypeId);

                            string datatypeName = datatype.SystemType;

                            DataTypeCheck dtc;
                            double        DummyValue = 0;
                            if (Double.TryParse(vv, out DummyValue))
                            {
                                if (vv.Contains("."))
                                {
                                    dtc = new DataTypeCheck(mappedHeader.SelectedDataAttribute.Name, datatypeName, DecimalCharacter.point);
                                }
                                else
                                {
                                    dtc = new DataTypeCheck(mappedHeader.SelectedDataAttribute.Name, datatypeName, DecimalCharacter.comma);
                                }
                            }
                            else
                            {
                                dtc = new DataTypeCheck(mappedHeader.SelectedDataAttribute.Name, datatypeName, DecimalCharacter.point);
                            }

                            var ValidationResult = dtc.Execute(vv, y);
                            if (ValidationResult is Error)
                            {
                                ErrorList.Add((Error)ValidationResult);
                                errorsInColumn++;
                            }

                            if (errorsInColumn >= maxErrorsPerColumn)
                            {
                                //Break inner (row) loop to jump to the next column
                                break;
                            }
                        }
                    }
                }

                return(ErrorList);
            }
            finally
            {
                dtm.Dispose();
            }
        }
Exemple #17
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();
            }
        }
Exemple #18
0
        public ActionResult editAttribute(DataAttributeModel Model)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Manage Data Attributes", this.Session.GetTenant());
            DataContainerManager dataAttributeManager = null;

            try
            {
                dataAttributeManager = new DataContainerManager();
                IList <DataAttribute> DataAttributeList = dataAttributeManager.DataAttributeRepo.Get();
                long tempUnitId     = Convert.ToInt64(Model.Unit.Id);
                long tempDataTypeId = Convert.ToInt64(Model.DataType.Id);

                Model.Id          = Model.Id;
                Model.ShortName   = cutSpaces(Model.ShortName);
                Model.Name        = cutSpaces(Model.Name);
                Model.Description = cutSpaces(Model.Description);

                //if (Model.DomainConstraints.Count > 0)
                //{
                //    if (Model.DomainConstraints. != null && Model.DomainItems.Count > 0)
                //    {
                //        Model.DomainConstraints.FirstOrDefault().DomainItems = clearEmptyItems(Model.DomainItems);
                //    }
                //}

                if (Model.Name == "" | Model.Name == null)
                {
                    Session["nameMsg"] = "invalid Name";
                    Session["Window"]  = true;
                    return(View("AttributeManager", new DataAttributeManagerModel(Model)));
                }
                else
                {
                    bool nameNotExist = DataAttributeList.Where(p => p.Name.ToLower().Equals(Model.Name.ToLower())).Count().Equals(0);

                    if (Model.Id == 0)
                    {
                        if (nameNotExist)
                        {
                            UnitManager     um  = null;
                            DataTypeManager dtm = null;
                            try
                            {
                                um  = new UnitManager();
                                dtm = new DataTypeManager();
                                Unit          unit     = new Unit();
                                DataType      dataType = new DataType();
                                DataAttribute temp     = new DataAttribute();

                                if (um.Repo.Get(tempUnitId) != null)
                                {
                                    unit = um.Repo.Get(tempUnitId);
                                }
                                else
                                {
                                    unit = um.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault();
                                }

                                if (dtm.Repo.Get(tempDataTypeId) != null)
                                {
                                    dataType = dtm.Repo.Get(tempDataTypeId);
                                }
                                else
                                {
                                    dataType = dtm.Repo.Get().ToList().FirstOrDefault();
                                }

                                temp = dataAttributeManager.CreateDataAttribute(Model.ShortName, Model.Name, Model.Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null);

                                #region store constraint

                                if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min != null || Model.RangeConstraints.FirstOrDefault().Max != null) &&
                                    (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0))
                                {
                                    temp = storeConstraint(Model.RangeConstraints.First(), temp);
                                }

                                if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase))
                                {
                                    temp = storeConstraint(Model.PatternConstraints.First(), temp);
                                }

                                if (Model.DomainConstraints.Count > 0)
                                {
                                    foreach (DomainConstraintModel d in Model.DomainConstraints)
                                    {
                                        temp = storeConstraint(d, temp);
                                    }
                                }
                                temp = dataAttributeManager.UpdateDataAttribute(temp);
                            }
                            finally
                            {
                                um.Dispose();
                                dtm.Dispose();
                            }

                            #endregion store constraint
                        }
                        else
                        {
                            Session["nameMsg"] = "Name already exist";
                            Session["Window"]  = true;
                            return(View("AttributeManager", new DataAttributeManagerModel(Model)));
                        }
                    }
                    else
                    {
                        if (nameNotExist || DataAttributeList.Where(p => p.Name.ToLower().Equals(Model.Name.ToLower())).ToList().First().Id == Model.Id)
                        {
                            DataAttribute dataAttribute = DataAttributeList.Where(p => p.Id.Equals(Model.Id)).ToList().First();
                            if (!attributeInUse(dataAttribute))
                            {
                                dataAttributeManager      = new DataContainerManager();
                                dataAttribute.Name        = cutSpaces(Model.Name);
                                dataAttribute.ShortName   = Model.ShortName;
                                dataAttribute.Description = Model.Description;

                                UnitManager unitManager = null;
                                try
                                {
                                    unitManager = new UnitManager();

                                    if (unitManager.Repo.Get(tempUnitId) != null)
                                    {
                                        dataAttribute.Unit = unitManager.Repo.Get(tempUnitId);
                                    }
                                    else
                                    {
                                        dataAttribute.Unit = unitManager.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault();
                                    }
                                }
                                finally
                                {
                                    unitManager.Dispose();
                                }
                                DataTypeManager dtm = null;
                                try
                                {
                                    dtm = new DataTypeManager();

                                    if (dtm.Repo.Get(tempDataTypeId) != null)
                                    {
                                        dataAttribute.DataType = dtm.Repo.Get(tempDataTypeId);
                                    }
                                    else
                                    {
                                        dataAttribute.DataType = dtm.Repo.Get().ToList().FirstOrDefault();
                                    }
                                }
                                finally
                                {
                                    dtm.Dispose();
                                }

                                #region store constraint

                                if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min != null || Model.RangeConstraints.FirstOrDefault().Max != null) &&
                                    (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0))
                                {
                                    dataAttribute = storeConstraint(Model.RangeConstraints.First(), dataAttribute);
                                }
                                else
                                {
                                    dataAttribute = deletConstraint(Model.RangeConstraints.First().Id, dataAttribute);
                                }

                                if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase))
                                {
                                    dataAttribute = storeConstraint(Model.PatternConstraints.First(), dataAttribute);
                                }
                                else
                                {
                                    dataAttribute = deletConstraint(Model.PatternConstraints.First().Id, dataAttribute);
                                }

                                if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.DomainConstraints.FirstOrDefault().Terms))
                                {
                                    dataAttribute = storeConstraint(Model.DomainConstraints.First(), dataAttribute);
                                }
                                else
                                {
                                    dataAttribute = deletConstraint(Model.DomainConstraints.First().Id, dataAttribute);
                                }

                                #endregion store constraint

                                dataAttributeManager.UpdateDataAttribute(dataAttribute);
                            }
                        }
                        else
                        {
                            Session["nameMsg"] = "Name already exist";
                            Session["Window"]  = true;
                            return(View("AttributeManager", new DataAttributeManagerModel(Model)));
                        }
                    }
                }
            }
            finally
            {
                dataAttributeManager.Dispose();
            }

            Session["Window"] = false;
            return(RedirectToAction("AttributeManager"));
        }
Exemple #19
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();
            }
        }