public AddVariableUsage ( |
||
dataStructure | The structured data structure to be linked to the data attribute | |
dataAttribute | The data attribute to be used in a data structure as a variable | |
isValueOptional | bool | Indicates whether the |
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 | A specific unit for the variable. If not provided the unit of the |
|
리턴 |
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()); }
public DataStructure CreateDataStructure(string dataSetID, DataTable mapVariables, List<string> variableNames) { DataStructureManager dataStructureManager = new DataStructureManager(); DataContainerManager attributeManager = new DataContainerManager(); StructuredDataStructure dataStructure = new StructuredDataStructure(); UnitManager unitManager = new UnitManager(); // values of DataStructure ExcelTemplateProvider provider = new ExcelTemplateProvider(); string name = "oldBExIS" + dataSetID; string description = "old BExIS datastructure, created for " + dataSetID + ", possibly used by other"; //metadata.Title; string xsdFileName = "";//"xsdFileName"; string xslFileName = "";//"xslFileName"; DataStructureCategory indexerType = DataStructureCategory.Generic; // if dataStructure not exists StructuredDataStructure existDS = existingDataStructures(mapVariables, dataSetID); if (existDS.Name == null) { // create dataStructure dataStructure = dataStructureManager.CreateStructuredDataStructure(name, description, xsdFileName, xslFileName, indexerType, null); foreach (string varName in variableNames) { // values of variables string attName = ""; string convFactor = ""; string varDescription = ""; int Block = -999; long AttributeId = -999, UnitId = -999, VarUnitId = -999; foreach (DataRow mapRow in mapVariables.Select("DatasetId = '" + dataSetID + "'")) { if (mapRow["Name"].ToString() == varName) { attName = mapRow["Attribute"].ToString(); convFactor = mapRow["ConvFactor"].ToString(); varDescription = mapRow["Description"].ToString(); Block = int.Parse(mapRow["Block"].ToString()); if (attName.Length > 1) // if not mapped yet { AttributeId = Convert.ToInt64(mapRow["AttributeId"].ToString()); UnitId = Convert.ToInt64(mapRow["UnitId"].ToString()); if (mapRow["Unit"].ToString().Length > 0) VarUnitId = Convert.ToInt64(mapRow["VarUnitId"].ToString()); } } } if (AttributeId > 0 && Block == 0) // if not mapped yet AND variable is in block 0 { // find existing attribute for each variable DataAttribute attribute = attributeManager.DataAttributeRepo.Get(AttributeId); Unit varUnit = null; if (VarUnitId > 0) { varUnit = unitManager.Repo.Get(VarUnitId); } // add variables to dataStructure Variable variable = dataStructureManager.AddVariableUsage(dataStructure, attribute, true, varName, null, null, varDescription, varUnit); dataStructure.Variables.Add(variable); } } provider.CreateTemplate(dataStructure); return dataStructure; } else { return existDS; } }
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); }