BExIS.Dlm.Services.DataStructure.DataStructureManager.AddVariableUsage C# (CSharp) Метод

AddVariableUsage() публичный Метод

Creates a link between a StructuredDataStructure and DataAttribute. This link is known as 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.
public AddVariableUsage ( StructuredDataStructure dataStructure, DataAttribute dataAttribute, bool isValueOptional, string label, string defaultValue, string missingValue, string description, Unit variableUnit = null ) : Variable
dataStructure BExIS.Dlm.Entities.DataStructure.StructuredDataStructure The structured data structure to be linked to the data attribute
dataAttribute BExIS.Dlm.Entities.DataStructure.DataAttribute The data attribute to be used in a data structure as a variable
isValueOptional bool Indicates whether the associated to the variable is optional or not. This allows dataset to not provide data values for optional variables.
label string 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.
defaultValue string The default value of the associated variable values. Mainly considered for user interface purposes.
missingValue string A specific sentinel value that when is put into the variable values, means those values are missing and should not be considered data.
description string
variableUnit BExIS.Dlm.Entities.DataStructure.Unit A specific unit for the variable. If not provided the unit of the is used. /// If provided, its dimension must be equal to the dimension of the 's unit.
Результат BExIS.Dlm.Entities.DataStructure.Variable
        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);
        }

Usage Example

Пример #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());
        }
All Usage Examples Of BExIS.Dlm.Services.DataStructure.DataStructureManager::AddVariableUsage