Inheritance: BaseUsage
コード例 #1
0
        public ActionResult copyDataStructure(long Id, bool isStructured, string Name = "" , string Description = "", string cssId = "")
        {
            Name = Server.UrlDecode(Name);
            Description = Server.UrlDecode(Description);
            DataStructureManager dataStructureManager = new DataStructureManager();

            if (!isStructured)
            {
                UnStructuredDataStructure dataStructure = dataStructureManager.UnStructuredDataStructureRepo.Get(Id);
                if (dataStructure != null)
                {
                    if (Name == "")
                    {
                        Name = dataStructure.Name + " - Copy";
                    }

                    if (Description == "" && dataStructure.Description != null)
                    {
                        Description = dataStructure.Description;
                    }
                    LoggerFactory.LogCustom("Copy Data Structure" + Id);
                    return createDataStructure(0, Name.Trim(), isStructured, Description.Trim(), cssId);
                }
            }
            else
            {
                StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);
                if (dataStructure != null)
                {
                    if (Name == "")
                    {
                        Name = dataStructure.Name + " - Copy";
                    }

                    if (Description == "" && dataStructure.Description != null)
                    {
                        Description = dataStructure.Description;
                    }

                    MessageModel messageModel = storeDataStructure(0, Name.Trim(), isStructured, Description.Trim(), cssId);
                    List<long> order = new List<long>();
                    Variable variable = new Variable();

                    if (!messageModel.hasMessage)
                    {
                        StructuredDataStructure dataStructureCopy = dataStructureManager.StructuredDataStructureRepo.Get(Convert.ToInt64(messageModel.Message));
                        foreach (Variable v in DataStructureIO.getOrderedVariables(dataStructure))
                        {
                            variable = dataStructureManager.AddVariableUsage(dataStructureCopy, v.DataAttribute, v.IsValueOptional, v.Label.Trim(), v.DefaultValue, v.MissingValue, v.Description.Trim(), v.Unit);
                            order.Add(variable.Id);
                        }
                        DataStructureIO.setVariableOrder(dataStructureCopy, order);
                    }
                    LoggerFactory.LogCustom("Copy Data Structure" + Id);
                    return PartialView("_message", messageModel);
                }
            }
            return PartialView("_message", new MessageModel());
        }
コード例 #2
0
ファイル: DataStructureEditModel.cs プロジェクト: BEXIS2/Core
        public VariablePreviewStruct fill(Variable variable, bool getConstraints)
        {
            variable.Unit = variable.Unit ?? new Unit();
            variable.Unit.Dimension = variable.Unit.Dimension ?? new Dimension();
            variable.DataAttribute = variable.DataAttribute ?? new DataAttribute();
            variable.DataAttribute.DataType = variable.DataAttribute.DataType ?? new DataType();

            this.Id = variable.Id;
            this.Name = variable.Label;
            this.Description = variable.Description;
            this.isOptional = variable.IsValueOptional;
            this.Unit.Id = variable.Unit.Id;
            this.Unit.Name = variable.Unit.Name;
            this.convertibleUnits = getUnitListByDimenstionAndDataType(variable.Unit.Dimension.Id, variable.DataAttribute.DataType.Id);
            this.DataType = variable.DataAttribute.DataType.Name;

            if (getConstraints)
            {
                if (variable.DataAttribute.Constraints != null)
                {
                    foreach (Constraint c in variable.DataAttribute.Constraints)
                    {
                        c.Materialize();
                        this.Constraints.Add(c.Id, c.FormalDescription);
                    }
                }
            }

            this.Attribute = Attribute.fill(variable.DataAttribute, false);

            return this;
        }
コード例 #3
0
ファイル: DataStructureEditModel.cs プロジェクト: BEXIS2/Core
 public VariablePreviewStruct fill(Variable variable)
 {
     return this.fill(variable, true);
 }
コード例 #4
0
ファイル: DataStructureEditModel.cs プロジェクト: BEXIS2/Core
        public VariablePreviewStruct fill(long attributeId, bool getConstraints)
        {
            DataContainerManager dataAttributeManager = new DataContainerManager();
            DataAttribute dataAttribute = dataAttributeManager.DataAttributeRepo.Get(attributeId);
            Variable variable = new Variable()
            {
                Label = dataAttribute.Name,
                Description = dataAttribute.Description,
                Unit = dataAttribute.Unit,
                DataAttribute = dataAttribute
            };

            return this.fill(variable, getConstraints);
        }
コード例 #5
0
ファイル: DataStructureManager.cs プロジェクト: BEXIS2/Core
        /// <summary>
        /// Creates a structured data structure <seealso cref="StructuredDataStructure"/> and persists the entity in the database.
        /// </summary>
        /// <param name="name">The name of the data structure</param>
        /// <param name="description">A free text describing the purpose, usage, and/or the domain of the data structure usage.</param>
        /// <param name="xsdFileName">Not in use.</param>
        /// <param name="xslFileName">Not in use.</param>
        /// <param name="indexerType">If the data structure is used as a matrix, The indexer type show what kind of column would be represented by the indexer variable. <see cref="DataStructureCategory"/></param>
        /// <param name="indexer">The variable indicating the first indexing column of the matrix, if the data structure is representing a matrix.</param>
        /// <returns>The persisted structured data structure instance.</returns>
        public StructuredDataStructure CreateStructuredDataStructure(string name, string description, string xsdFileName, string xslFileName, DataStructureCategory indexerType, Variable indexer = null)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(indexerType != DataStructureCategory.Generic ? (indexer != null) : true);
            Contract.Ensures(Contract.Result<StructuredDataStructure>() != null && Contract.Result<StructuredDataStructure>().Id >= 0);

            StructuredDataStructure e = new StructuredDataStructure()
            {
                Name = name,
                Description = description,
                XsdFileName = xsdFileName,
                XslFileName = xslFileName,
                IndexerType = indexerType,
                // Indexer = indexer, // how its possible to have the indexer before assigning variable to the structure
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<StructuredDataStructure> repo = uow.GetRepository<StructuredDataStructure>();
                repo.Put(e);
                uow.Commit();
            }
            return (e);
        }
コード例 #6
0
ファイル: DataStructureManager.cs プロジェクト: BEXIS2/Core
        /// <summary>
        /// Detaches the data attribute and the data structure that were linked by the variable and then deletes the variable from the database.
        /// </summary>
        /// <param name="usage">The variable object to be deleted.</param>
        /// <remarks>If the variable is referenced by any <see cref="DataValue"/> the method fails to delete the variable. Also, all the parameters associated to the variable will be deleted.</remarks>
        public void RemoveVariableUsage(Variable usage)
        {
            Contract.Requires(usage != null && usage.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Variable> repo = uow.GetRepository<Variable>();
                IRepository<Parameter> paramRepo = uow.GetRepository<Parameter>();
                repo.Delete(usage);
                paramRepo.Delete(usage.Parameters.ToList());
                uow.Commit();
            }
        }
コード例 #7
0
ファイル: DataStructureManager.cs プロジェクト: BEXIS2/Core
        /// <summary>
        /// Creates a link between a <see cref="StructuredDataStructure"/> and <see cref="DataAttribute"/>. This link is known as <see cref="Variable"/>.
        /// In addition to what a variable inherits from the associated data attribute, it can have its own label, default and missing values, and optionality of its value.
        /// </summary>
        /// <param name="dataStructure">The structured data structure to be linked to the data attribute</param>
        /// <param name="dataAttribute">The data attribute to be used in a data structure as a variable</param>
        /// <param name="isValueOptional">Indicates whether the <see cref="VariableValue"/> associated to the variable is optional or not. This allows dataset to not provide data values for optional variables.</param>
        /// <param name="label">The display name of the variable. It may differ from the associated data attribute name. The variable label usually indicates the role of the data attribute in the structure. 
        /// Its possible for a data structure to use a data attribute more than once by creating more than one variables, hence having different labels.</param>
        /// <param name="defaultValue">The default value of the associated variable values. Mainly considered for user interface purposes.</param>
        /// <param name="missingValue">A specific sentinel value that when is put into the variable values, means those values are missing and should not be considered data.</param>
        /// <param name="variableUnit">A specific unit for the variable. If not provided the unit of the <paramref name="dataAttibute"/> is used.
        /// If provided, its dimension must be equal to the dimension of the <paramref name="dataAttribute"/>'s unit.</param>
        /// <returns>A created and persisted variable object.</returns>
        public Variable AddVariableUsage(StructuredDataStructure dataStructure, DataAttribute dataAttribute, bool isValueOptional, string label, string defaultValue, string missingValue, string description, Unit variableUnit = null)
        {
            Contract.Requires(dataStructure != null && dataStructure.Id >= 0);
            Contract.Requires(dataAttribute != null && dataAttribute.Id >= 0);
            Contract.Requires((variableUnit == null && dataAttribute.Unit == null) || (variableUnit == null) || (variableUnit.Dimension == dataAttribute.Unit.Dimension));
            Contract.Ensures(Contract.Result<Variable>() != null && Contract.Result<Variable>().Id >= 0);

            //StructuredDataStructureRepo.Reload(dataStructure);
            StructuredDataStructureRepo.LoadIfNot(dataStructure.Variables);
            int count = (from v in dataStructure.Variables
                         where v.DataAttribute.Id.Equals(dataAttribute.Id)
                         select v
                        )
                        .Count();

            //if (count > 0)
            //    throw new Exception(string.Format("Data attribute {0} is already used as a variable in data structure {0}", dataAttribute.Id, dataStructure.Id));

            Variable usage = new Variable()
            {
                DataStructure = dataStructure,
                DataAttribute = dataAttribute,
                MinCardinality = isValueOptional ? 0 : 1,
                // if there is no label provided, use the data attribute name and a sequence number calculated by the number of occurrences of that data attribute in the current structure
                Label = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? dataAttribute.Name : string.Format("{0} ({1})", dataAttribute.Name, count)),
                DefaultValue = defaultValue,
                MissingValue = missingValue,
                Description = description,
                Unit = (variableUnit != null ? variableUnit : dataAttribute.Unit),
            };
            dataAttribute.UsagesAsVariable.Add(usage);
            dataStructure.Variables.Add(usage);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Variable> repo = uow.GetRepository<Variable>();
                repo.Put(usage);
                uow.Commit();
            }
            return (usage);
        }
コード例 #8
0
ファイル: DataStructureManager.cs プロジェクト: BEXIS2/Core
        /// <summary>
        /// The method functions in a similar way to the <see cref="AddVariableUsage"/> method, but operates on a <see cref="Parameter"/>
        /// </summary>
        /// <param name="variableUsage"></param>
        /// <param name="dataAttribute"></param>
        /// <param name="isValueOptional"></param>
        /// <param name="label"></param>
        /// <param name="defaultValue"></param>
        /// <param name="missingValue"></param>
        /// <returns></returns>
        public Parameter AddParameterUsage(Variable variableUsage, DataAttribute dataAttribute, bool isValueOptional, string label, string defaultValue, string missingValue, string description)
        {
            Contract.Requires(variableUsage != null && variableUsage.DataAttribute.Id >= 0);
            Contract.Requires(dataAttribute != null && dataAttribute.Id >= 0);
            Contract.Ensures(Contract.Result<Parameter>() != null && Contract.Result<Parameter>().Id >= 0);

            VariableRepo.Reload(variableUsage);
            VariableRepo.LoadIfNot(variableUsage.Parameters);
            int count = (from pu in variableUsage.Parameters
                         where pu.DataAttribute.Id.Equals(dataAttribute.Id)
                         select pu
                        )
                        .Count();

            // support multiple use of a data attribute as a parameter in a variable context
            //if (count > 0)
            //    throw new Exception(string.Format("Data attribute {0} is already used as a parameter in conjunction with variable {1} in data structure {2}", dataAttribute.Id, variableUsage.DataAttribute.Id, variableUsage.DataStructure.Id));

            Parameter usage = new Parameter()
            {
                DataAttribute = dataAttribute,
                Variable = variableUsage,
                MinCardinality = isValueOptional ? 0 : 1,
                // if there is no label provided, use the data attribute name and a sequence number calculated by the number of occurrences of that data attribute in the current usage
                Label = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? dataAttribute.Name : string.Format("{0} ({1})", dataAttribute.Name, count)),
                DefaultValue = defaultValue,
                MissingValue = missingValue,
                Description = description
            };
            dataAttribute.UsagesAsParameter.Add(usage);
            variableUsage.Parameters.Add(usage);
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Parameter> repo = uow.GetRepository<Parameter>();
                repo.Put(usage);
                uow.Commit();
            }
            return (usage);
        }
コード例 #9
0
ファイル: DataReader.cs プロジェクト: BEXIS2/Core
        /// <summary>
        /// Get VariableUsage based on VariableIdentifer
        /// </summary>
        /// <remarks></remarks>
        /// <param name="hv"></param>
        /// <returns></returns>
        private Variable getVariableUsage(VariableIdentifier hv)
        {
            Variable sdvu = new Variable();

            if (hv.id != 0)
            {
                var dsVar = (from v in this.StructuredDataStructure.Variables
                             where v.Id == hv.id && v.Label == hv.name
                             select v).FirstOrDefault();
                if (dsVar != null) sdvu = dsVar;

            }
            else
            {
                var dsVar = (from v in this.StructuredDataStructure.Variables
                             where v.Label == hv.name
                             select v).FirstOrDefault();
                if (dsVar != null) sdvu = dsVar;
            }

            return sdvu;
        }
コード例 #10
0
 private string getDescription(Variable v)
 {
     if (v.Description != null && v.Description != "")
     return v.Description;
     else
     return v.DataAttribute.Description;
 }
コード例 #11
0
        public ActionResult storeVariables(long Id, storeVariableStruct[] variables)
        {
            DataStructureManager dataStructureManager = new DataStructureManager();
            StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);
            MessageModel returnObject = new MessageModel();
            MessageModel messageModel = MessageModel.validateDataStructureInUse(dataStructure.Id, dataStructure);
            if (messageModel.hasMessage)
            {
                foreach (Variable v in dataStructure.Variables)
                {
                    if (variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                    {
                        v.Description = variables.Where(svs => svs.Id == v.Id).FirstOrDefault().Description;
                        dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                    }
                }
                return PartialView("_messageWindow", messageModel);
            }

            if (variables != null && variables.Count() > 0)
            {
                Variable variable = new Variable();
                List<long> order = new List<long>();

                foreach (Variable v in dataStructure.Variables)
                {
                    if (!variables.Select(svs => svs.Id).ToList().Contains(v.Id))
                        dataStructureManager.RemoveVariableUsage(v);
                }

                foreach (storeVariableStruct svs in variables.Where(svs => svs.Id == 0).ToList())
                {
                    if (svs.Lable == null)
                        svs.Lable = "";
                    if (svs.Description == null)
                        svs.Description = "";

                    DataAttribute dataAttribute = new DataContainerManager().DataAttributeRepo.Get(svs.AttributeId);
                    if (dataAttribute != null)
                    {
                        variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), new UnitManager().Repo.Get(svs.UnitId));
                        svs.Id = variable.Id;
                    }
                    else
                    {
                        returnObject = new MessageModel()
                        {
                            hasMessage = true,
                            Message = "Not all Variables are stored.",
                            CssId = "0"
                        };
                    }
                }
                dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(Id);

                variables = variables.Where(v => v.Id != 0).ToArray();

                foreach (storeVariableStruct svs in variables.Where(svs => svs.Id != 0).ToList())
                {
                    if (svs.Lable == null)
                        svs.Lable = "";
                    if (svs.Description == null)
                        svs.Description = "";

                    variable = dataStructure.Variables.Where(v => v.Id == svs.Id).FirstOrDefault();
                    if (variable != null)
                    {
                        variable.Label = svs.Lable.Trim();
                        variable.Description = svs.Description.Trim();
                        variable.Unit = new UnitManager().Repo.Get(svs.UnitId);
                        variable.DataAttribute = new DataContainerManager().DataAttributeRepo.Get(svs.AttributeId);
                        variable.IsValueOptional = svs.isOptional;
                    }
                }

                dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure);
                DataStructureIO.setVariableOrder(dataStructure, variables.Select(svs => svs.Id).ToList());
            }
            else
            {
                foreach (Variable v in dataStructure.Variables)
                {
                    dataStructureManager.RemoveVariableUsage(v);
                }
            }
            LoggerFactory.LogCustom("Variables for Data Structure " + Id + " stored.");
            return Json(returnObject, JsonRequestBehavior.AllowGet);
        }