public ActionResult deletAttribute(long id, string name) { if (id != 0) { DataContainerManager DAM = new DataContainerManager(); DataAttribute dataAttribute = DAM.DataAttributeRepo.Get(id); if (dataAttribute != null) { if (!attributeInUse(dataAttribute)) { DAM.DeleteDataAttribute(dataAttribute); } } } return RedirectToAction("AttributeManager"); }
public ActionResult deleteDataAttribute(long Id, string cssId = "") { MessageModel DataAttributeDeleteValidation = MessageModel.validateAttributeDelete(Id); if (DataAttributeDeleteValidation.hasMessage) { return PartialView("_messageWindow", DataAttributeDeleteValidation); } else { DataContainerManager dataAttributeManager = new DataContainerManager(); DataAttribute dataAttribute = dataAttributeManager.DataAttributeRepo.Get(Id); dataAttributeManager.DeleteDataAttribute(dataAttribute); return PartialView("_message", new MessageModel() { Message = "DataStructure" + Id + "deleted", hasMessage = false, CssId = "deleted" }); } }
public DataAttribute deletConstraint(long constraintId, DataAttribute attribute) { DataContainerManager dam = new DataContainerManager(); if (constraintId != 0 && attribute.Id != 0) { foreach (Constraint c in attribute.Constraints.ToList()) { if (c.Id == constraintId) { attribute.Constraints.Remove(c); if (c is RangeConstraint) dam.RemoveConstraint((RangeConstraint)c); if (c is PatternConstraint) dam.RemoveConstraint((PatternConstraint)c); if (c is DomainConstraint) dam.RemoveConstraint((DomainConstraint)c); break; } } } return (attribute); }
// private void createADataStructure() // { // DataStructureGenerator sdGen = new DataStructureGenerator(); // StructuredDataStructure sds = sdGen.GenerateStructuredDataStructure(); // DataContainerManager dcm = new DataContainerManager(); // List<Parameter> pps = (from vari in sds.VariableUsages // from pari in vari.DataAttribute.ParameterUsages // select pari.Parameter).ToList(); // if(sds.Indexer != null) // pps.Add(sds.Indexer); // pps = pps.Distinct().ToList(); // foreach (var item in pps) //{ // dcm.CreateParameter(item.Name, //} // DataStructureManager dsm = new DataStructureManager(); // dsm.CreateStructuredDataStructure( // } private void testExtendedProperty() { DatasetManager dm = new DatasetManager(); DataContainerManager dcManager = new DataContainerManager(); Dataset ds = dm.GetDataset(24L); StructuredDataStructure sds = (ds.DataStructure.Self as StructuredDataStructure); ExtendedProperty exp = null; try { exp = dcManager.ExtendedPropertyRepo.Get(1); } catch { } //if(exp == null) // exp = dcManager.CreateExtendedProperty("Source", "the data provider", sds.VariableUsages.First().DataAttribute, null); // issue with session management //ds.ExtendedPropertyValues = new List<ExtendedPropertyValue>() //{ // new ExtendedPropertyValue() {Dataset = ds, ExtendedPropertyId = exp.Id, Value="Jena Experiment"}, // new ExtendedPropertyValue() {Dataset = ds, ExtendedPropertyId = exp.Id, Value="MPI"}, //}; ds.Dematerialize(); //dm.UpdateDataset(ds); }
private void addConstraintsTo() { DataContainerManager dcManager = new DataContainerManager(); var attr = dcManager.DataAttributeRepo.Get(1); var c1 = new RangeConstraint(ConstraintProviderSource.Internal, "", "en-US", "should be between 1 and 12 meter", true, null, null, null, 1.00, true, 12.00, true); dcManager.AddConstraint(c1, attr); var v1 = c1.IsSatisfied(14); var c2 = new PatternConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple email validation constraint", false, null, null, null, @"^\S+@\S+$", false); dcManager.AddConstraint(c2, attr); var v2 = c2.IsSatisfied("*****@*****.**"); List<DomainItem> items = new List<DomainItem>() { new DomainItem () {Key = "A", Value = "This is A" }, new DomainItem () {Key = "B", Value = "This is B" }, new DomainItem () {Key = "C", Value = "This is C" }, new DomainItem () {Key = "D", Value = "This is D" }, }; var c3 = new DomainConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple domain validation constraint", false, null, null, null, items); dcManager.AddConstraint(c3, attr); var v3 = c3.IsSatisfied("A"); v3 = c3.IsSatisfied("E"); c3.Negated = true; v3 = c3.IsSatisfied("A"); var c4 = new ComparisonConstraint(ConstraintProviderSource.Internal, "", "en-US", "a comparison validation constraint", false, null, null, null , ComparisonOperator.GreaterThanOrEqual, ComparisonTargetType.Value, "", ComparisonOffsetType.Ratio, 1.25); dcManager.AddConstraint(c4, attr); var v4 = c4.IsSatisfied(14, 10); }
// create read attributes in bpp public void CreateAttributes(ref DataTable mappedAttributes) { foreach (DataRow mapAttributesRow in mappedAttributes.Rows) { DataContainerManager attributeManager = new DataContainerManager(); DataTypeManager dataTypeManager = new DataTypeManager(); UnitManager unitManager = new UnitManager(); 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; } }
public ActionResult deletConstraint(long Id, long attributeId) { if (Id != 0 && attributeId != 0) { DataContainerManager dam = new DataContainerManager(); DataAttribute dataattribute = dam.DataAttributeRepo.Get(attributeId); Constraint constraint = dam.DataAttributeRepo.Get(attributeId).Constraints.Where(c => c.Id == Id).FirstOrDefault(); foreach (Constraint c in dataattribute.Constraints.ToList()) { if (c.Id == constraint.Id) { dataattribute.Constraints.Remove(c); break; } } dataattribute = dam.UpdateDataAttribute(dataattribute); //if (constraint is RangeConstraint) // dam.RemoveConstraint((RangeConstraint)constraint); } return RedirectToAction("openAttributeWindow", new { Id = attributeId, showConstraints = true }); }
public ActionResult editAttribute(DataAttributeModel Model) { ViewBag.Title = PresentationModel.GetViewTitleForTenant( "Manage Data Attributes", this.Session.GetTenant()); DataContainerManager 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 = new UnitManager(); Unit unit = new Unit(); DataTypeManager DTM = new DataTypeManager(); DataType dataType = new DataType(); DataContainerManager DAM = new DataContainerManager(); 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 = DAM.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); } } #endregion temp = DAM.UpdateDataAttribute(temp); } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } else { if (nameNotExist || DataAttributeList.Where(p => p.Name.Equals(Model.Name)).ToList().First().Id == Model.Id) { DataAttribute dataAttribute = DataAttributeList.Where(p => p.Id.Equals(Model.Id)).ToList().First(); if (!attributeInUse(dataAttribute)) { DataContainerManager DAM = new DataContainerManager(); dataAttribute.Name = cutSpaces(Model.Name); dataAttribute.ShortName = Model.ShortName; dataAttribute.Description = Model.Description; UnitManager UM = new UnitManager(); if (UM.Repo.Get(tempUnitId) != null) dataAttribute.Unit = UM.Repo.Get(tempUnitId); else dataAttribute.Unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault(); DataTypeManager DTM = new DataTypeManager(); if (DTM.Repo.Get(tempDataTypeId) != null) dataAttribute.DataType = DTM.Repo.Get(tempDataTypeId); else dataAttribute.DataType = DTM.Repo.Get().ToList().FirstOrDefault(); #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 DAM.UpdateDataAttribute(dataAttribute); } } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } } Session["Window"] = false; return RedirectToAction("AttributeManager"); }
public AttributePreviewStruct fill(long attributeId, bool getConstraints) { DataContainerManager dataAttributeManager = new DataContainerManager(); DataAttribute DataAttribute = dataAttributeManager.DataAttributeRepo.Get(attributeId); return this.fill(DataAttribute, getConstraints); }
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); }
public DataAttribute storeRangeConstraint(RangeConstraintModel constraintModel) { DataContainerManager dcManager = new DataContainerManager(); DataAttribute dataAttribute = dcManager.DataAttributeRepo.Get(constraintModel.AttributeId); if (constraintModel.Max != 0 || constraintModel.Min != 0) { if (constraintModel.Id == 0) { RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, constraintModel.Description, constraintModel.Negated, null, null, null, constraintModel.Min, constraintModel.MinInclude, constraintModel.Max, constraintModel.MaxInclude); dcManager.AddConstraint(constraint, dataAttribute); } else { for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == constraintModel.Id) { ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description = constraintModel.Description; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = constraintModel.Negated; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound = constraintModel.Min; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = constraintModel.MinInclude; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound = constraintModel.Max; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = constraintModel.MaxInclude; break; } } } } return dataAttribute; }
public DataAttribute storePatternConstraint(PatternConstraintModel constraintModel) { DataContainerManager dcManager = new DataContainerManager(); DataAttribute dataAttribute = dcManager.DataAttributeRepo.Get(constraintModel.AttributeId); if (constraintModel.MatchingPhrase != null && constraintModel.MatchingPhrase != "") { if (constraintModel.Id == 0) { PatternConstraint constraint = new PatternConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, constraintModel.Description, constraintModel.Negated, null, null, null, constraintModel.MatchingPhrase, false); dcManager.AddConstraint(constraint, dataAttribute); } else { for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == constraintModel.Id) { ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Description = constraintModel.Description; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = constraintModel.Negated; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).MatchingPhrase = constraintModel.MatchingPhrase; break; } } } } return dataAttribute; }
public DataAttribute storeDomainConstraint(DomainConstraintModel constraintModel) { DataContainerManager dcManager = new DataContainerManager(); DataAttribute dataAttribute = dcManager.DataAttributeRepo.Get(constraintModel.AttributeId); List<DomainItem> items = new List<DomainItem>(); if (constraintModel.Terms != null && constraintModel.Terms.Trim() != "") items = createDomainItems(constraintModel.Terms.Trim()); if (items.Count > 0) { if (constraintModel.Id == 0) { DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, constraintModel.Description, constraintModel.Negated, null, null, null, items); dcManager.AddConstraint(constraint, dataAttribute); } else { DomainConstraint temp = new DomainConstraint(); for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == constraintModel.Id) { temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i); temp.Materialize(); temp.Description = constraintModel.Description; temp.Negated = constraintModel.Negated; temp.Items = items; dcManager.AddConstraint(temp, dataAttribute); break; } } } } return dataAttribute; }
public MessageModel storeAtttribute(long Id, string Name, long unitId, long dataTypeId, string Description = "", string cssId = "", bool inUse = false) { Name = Server.UrlDecode(Name); Description = Server.UrlDecode(Description); MessageModel DataStructureValidation = MessageModel.validateAttributeInUse(Id); if (DataStructureValidation.hasMessage && inUse == false) { return DataStructureValidation; } else { DataStructureValidation = MessageModel.validateAttributeName(Id, Name, cssId); if (DataStructureValidation.hasMessage) { return DataStructureValidation; } else { DataContainerManager dataAttributeManager = new DataContainerManager(); DataAttribute dataAttribute; if (Id == 0) { Unit unit = new UnitManager().Repo.Get(unitId); DataType dataType = new DataTypeManager().Repo.Get(dataTypeId); dataAttribute = dataAttributeManager.CreateDataAttribute(Name, Name, Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null); return new MessageModel() { Message = dataAttribute.Id.ToString(), hasMessage = false, CssId = "refresh" }; } else { dataAttribute = dataAttributeManager.DataAttributeRepo.Get(Id); dataAttribute.Name = Name; dataAttribute.Description = Description; dataAttribute = dataAttributeManager.UpdateDataAttribute(dataAttribute); return new MessageModel() { Message = Id.ToString(), hasMessage = false, CssId = "refresh" }; } } } }
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 AttributePreviewModel fill(bool getConstraints) { this.AttributePreviews = new List<AttributePreviewStruct>(); DataContainerManager dataAttributeManager = new DataContainerManager(); foreach (DataAttribute da in dataAttributeManager.DataAttributeRepo.Get().ToList()) { this.AttributePreviews.Add(new AttributePreviewStruct().fill(da, getConstraints)); } return this; }
public static MessageModel validateAttributeInUse(long Id) { DataContainerManager dataAttributeManager = new DataContainerManager(); DataAttribute dataAttribute = dataAttributeManager.DataAttributeRepo.Get(Id); return validateAttributeInUse(Id, dataAttribute); }
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); }
public static MessageModel validateAttributeName(long Id, string Name, string cssId = "") { if (Name.Trim() == "" || string.IsNullOrEmpty(Name)) { return new MessageModel() { hasMessage = true, Message = "The Name field is required.", CssId = cssId }; } else { List<DataAttribute> dataAttributes = new DataContainerManager().DataAttributeRepo.Get().ToList(); foreach (DataAttribute da in dataAttributes) { if (Id != da.Id) { if (da.Name.Trim().ToLower() == Name.Trim().ToLower()) { return new MessageModel() { hasMessage = true, Message = "A Variable Template with same Name already exists.", CssId = cssId }; } } } } return new MessageModel() { CssId = cssId }; }
private DataAttribute storeConstraint(ConstraintModel constraintModel, DataAttribute dataAttribute) { DataContainerManager dcManager = new DataContainerManager(); if (constraintModel is RangeConstraintModel) { RangeConstraintModel rcm = (RangeConstraintModel)constraintModel; if (rcm.Id == 0) { RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, rcm.Description, rcm.Negated, null, null, null, rcm.Min, rcm.MinInclude, rcm.Max, rcm.MaxInclude); dcManager.AddConstraint(constraint, dataAttribute); } else { for(int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == rcm.Id) { ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description = rcm.Description; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = rcm.Negated; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound = rcm.Min; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = rcm.MinInclude; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound = rcm.Max; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = rcm.MaxInclude; break; } } } } if (constraintModel is PatternConstraintModel) { PatternConstraintModel pcm = (PatternConstraintModel)constraintModel; if (pcm.Id == 0) { PatternConstraint constraint = new PatternConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, pcm.Description, pcm.Negated, null, null, null, pcm.MatchingPhrase, false); dcManager.AddConstraint(constraint, dataAttribute); } else { for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == pcm.Id) { ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Description = pcm.Description; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = pcm.Negated; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).MatchingPhrase = pcm.MatchingPhrase; break; } } } } if (constraintModel is DomainConstraintModel) { DomainConstraintModel dcm = (DomainConstraintModel)constraintModel; List<DomainItem> items = createDomainItems(dcm.Terms); dcm.Terms = cutSpaces(dcm.Terms); if (items.Count > 0) { if (dcm.Id == 0) { DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, dcm.Description, dcm.Negated, null, null, null, items); dcManager.AddConstraint(constraint, dataAttribute); } else { DomainConstraint temp = new DomainConstraint(); for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == dcm.Id) { temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i); temp.Materialize(); temp.Description = dcm.Description; temp.Negated = dcm.Negated; temp.Items = items; dcManager.AddConstraint(temp, dataAttribute); break; } } } } } return dataAttribute; }
public static MessageModel validateAttributeDelete(long Id) { DataAttribute dataAttribute = new DataContainerManager().DataAttributeRepo.Get(Id); return validateAttributeDelete(Id, dataAttribute); }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> public void GetDataAttributeList() { DataContainerManager DataAttributeManager = new DataContainerManager(); this.dataAttributeList = DataAttributeManager.DataAttributeRepo.Get().ToList(); }
public List<VariableStruct> getOrderedVariableStructs(StructuredDataStructure structuredDataStructure) { List<VariableStruct> variableStructs = new List<VariableStruct>(); List<Variable> variables = getOrderedVariables(structuredDataStructure); DataContainerManager dataAttributeManager = new DataContainerManager(); VariableStruct temp = new VariableStruct(); List<BExIS.Dlm.Entities.DataStructure.Constraint> tempconstraints; UnitDimenstionModel unitDimenstionModel = new UnitDimenstionModel(); foreach (Variable v in variables) { unitDimenstionModel = new UnitDimenstionModel(); temp.variable = v; temp.unitStructs = unitDimenstionModel.getUnitListByDimenstionAndDataType(v.DataAttribute.Unit.Dimension.Id, v.DataAttribute.DataType.Id); tempconstraints = dataAttributeManager.DataAttributeRepo.Get(v.DataAttribute.Id).Constraints.ToList(); temp.rangeConstraints = new List<RangeConstraint>(); temp.domainConstraints = new List<DomainConstraint>(); temp.patternConstraints = new List<PatternConstraint>(); foreach(BExIS.Dlm.Entities.DataStructure.Constraint c in tempconstraints) { if (c is DomainConstraint) { DomainConstraint tempDomainConstraint = (DomainConstraint)c; tempDomainConstraint.Materialize(); temp.domainConstraints.Add(tempDomainConstraint); } if (c is PatternConstraint) temp.patternConstraints.Add((PatternConstraint)c); if (c is RangeConstraint) temp.rangeConstraints.Add((RangeConstraint)c); } variableStructs.Add(temp); } return variableStructs; }
/// <summary> /// Convert a VariableValue to Cell /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="variableValue"></param> /// <param name="rowIndex"></param> /// <param name="columnIndex"></param> /// <returns></returns> protected Cell VariableValueToCell(VariableValue variableValue, int rowIndex, int columnIndex) { string message = "row :" + rowIndex + "column:" + columnIndex; Debug.WriteLine(message); DataContainerManager CM = new DataContainerManager(); DataAttribute dataAttribute = CM.DataAttributeRepo.Get(variableValue.DataAttribute.Id); string cellRef = getColumnIndex(columnIndex); Cell cell = new Cell(); cell.CellReference = cellRef; cell.StyleIndex = getExcelStyleIndex(dataAttribute.DataType.SystemType, styleIndexArray); //cell.DataType = new EnumValue<CellValues>(getExcelType(dataAttribute.DataType.SystemType)); //cell.CellValue = new CellValue(variableValue.Value.ToString()); CellValues cellValueType = getExcelType(dataAttribute.DataType.SystemType); object value = variableValue.Value; if (value != null && !(value is DBNull) && cellValueType == CellValues.Number) { cell.DataType = new EnumValue<CellValues>(CellValues.Number); try { if (value != "") { double d = Convert.ToDouble(value, System.Globalization.CultureInfo.InvariantCulture); cell.CellValue = new CellValue(d.ToString(System.Globalization.CultureInfo.InvariantCulture)); } } catch (Exception ex) { throw new Exception(ex.Message + "\n|"+message); } return cell; } else { if (value != null && !(value is DBNull) && cellValueType == CellValues.Date) { cell.DataType = new EnumValue<CellValues>(CellValues.Number); //CultureInfo provider = CultureInfo.InvariantCulture; try { if (value != "") { DateTime dt = Convert.ToDateTime(value.ToString()); cell.CellValue = new CellValue(dt.ToOADate().ToString()); } } catch(Exception ex) { throw new Exception(ex.Message + "|" + message); } } else { cell.DataType = new EnumValue<CellValues>(CellValues.String); if(value==null) cell.CellValue = new CellValue(""); else cell.CellValue = new CellValue(value.ToString()); } } return cell; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="variables"></param> /// <param name="path"></param> /// <param name="filename"></param> /// <returns></returns> public SpreadsheetDocument CreateTemplate(List<Variable> variables, string path, string filename) { if (!Directory.Exists(Path.Combine(AppConfiguration.DataPath, path))) { Directory.CreateDirectory(Path.Combine(AppConfiguration.DataPath, path)); } SpreadsheetDocument template = SpreadsheetDocument.Open(Path.Combine(AppConfiguration.GetModuleWorkspacePath("RPM"),"Template",_fileName),true); SpreadsheetDocument dataStructureFile = SpreadsheetDocument.Create(Path.Combine(AppConfiguration.DataPath, path, filename), template.DocumentType); //dataStructureFile = SpreadsheetDocument.Open(Path.Combine(AppConfiguration.GetModuleWorkspacePath("RPM"), "Template", filename), true); foreach (OpenXmlPart part in template.GetPartsOfType<OpenXmlPart>()) { OpenXmlPart newPart = dataStructureFile.AddPart<OpenXmlPart>(part); } template.Close(); // get worksheet List<StyleIndexStruct> styleIndex = new List<StyleIndexStruct>(); CellFormats cellFormats = dataStructureFile.WorkbookPart.WorkbookStylesPart.Stylesheet.Elements<CellFormats>().First(); //number 0,00 CellFormat cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)2U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)1U, ApplyNumberFormat = true}; cellFormat.Protection = new Protection(); cellFormat.Protection.Locked = false; cellFormats.Append(cellFormat); styleIndex.Add(new StyleIndexStruct() { Name = "Decimal", Index = (uint)cellFormats.Count++, DisplayPattern = null }); //number 0 cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)1U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)1U, ApplyNumberFormat = true}; cellFormat.Protection = new Protection(); cellFormat.Protection.Locked = false; cellFormats.Append(cellFormat); styleIndex.Add(new StyleIndexStruct() { Name = "Number", Index = (uint)cellFormats.Count++, DisplayPattern = null }); //text cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)49U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)1U, ApplyNumberFormat = true}; cellFormat.Protection = new Protection(); cellFormat.Protection.Locked = false; cellFormats.Append(cellFormat); styleIndex.Add(new StyleIndexStruct() { Name = "Text", Index = (uint)cellFormats.Count++, DisplayPattern = null }); //DateTime cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)22U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)1U, ApplyNumberFormat = true}; cellFormat.Protection = new Protection(); cellFormat.Protection.Locked = false; cellFormats.Append(cellFormat); styleIndex.Add(new StyleIndexStruct() { Name = "DateTime", Index = (uint)cellFormats.Count++, DisplayPattern = DataTypeDisplayPattern.Pattern.Where(p => p.Systemtype.Equals(DataTypeCode.DateTime) && p.Name.Equals("DateTime")).FirstOrDefault() }); //Date cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)14U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)1U, ApplyNumberFormat = true }; cellFormat.Protection = new Protection(); cellFormat.Protection.Locked = false; cellFormats.Append(cellFormat); styleIndex.Add(new StyleIndexStruct() { Name = "Date", Index = (uint)cellFormats.Count++, DisplayPattern = DataTypeDisplayPattern.Pattern.Where(p => p.Systemtype.Equals(DataTypeCode.DateTime) && p.Name.Equals("Date")).FirstOrDefault() }); //Time cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)21U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)1U, ApplyNumberFormat = true }; cellFormat.Protection = new Protection(); cellFormat.Protection.Locked = false; cellFormats.Append(cellFormat); styleIndex.Add(new StyleIndexStruct() { Name = "Time", Index = (uint)cellFormats.Count++, DisplayPattern = DataTypeDisplayPattern.Pattern.Where(p => p.Systemtype.Equals(DataTypeCode.DateTime) && p.Name.Equals("Time")).FirstOrDefault() }); Worksheet worksheet = dataStructureFile.WorkbookPart.WorksheetParts.First().Worksheet; List<Row> rows = GetRows(worksheet,1,11); foreach (Variable var in variables) { DataContainerManager CM = new DataContainerManager(); DataAttribute dataAttribute = CM.DataAttributeRepo.Get(var.DataAttribute.Id); int indexVar = variables.ToList().IndexOf(var) + 1; string columnIndex = GetClomunIndex(indexVar); string cellRef = columnIndex + 1; Cell cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(var.Label) }; rows.ElementAt(0).AppendChild(cell); cellRef = columnIndex + 2; cell = new Cell() { CellReference = cellRef, DataType = CellValues.String, StyleIndex = getExcelStyleIndex(dataAttribute.DataType, styleIndex), CellValue = new CellValue("") }; rows.ElementAt(1).AppendChild(cell); cellRef = columnIndex + 3; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(var.Id.ToString()) }; rows.ElementAt(2).AppendChild(cell); cellRef = columnIndex + 4; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(dataAttribute.ShortName) }; rows.ElementAt(3).AppendChild(cell); // description from variable // if not then from attribute string description = ""; description = String.IsNullOrEmpty(var.Description) ? dataAttribute.Description : var.Description; cellRef = columnIndex + 5; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(description) }; rows.ElementAt(4).AppendChild(cell); string classification = ""; if (dataAttribute.Classification != null) { classification = dataAttribute.Classification.Name; } cellRef = columnIndex + 6; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(classification) }; rows.ElementAt(5).AppendChild(cell); string unit = ""; if (var.Unit != null) { unit = var.Unit.Name; } cellRef = columnIndex + 7; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(unit) }; rows.ElementAt(6).AppendChild(cell); string dataType = ""; if (dataAttribute.DataType != null) { dataType = dataAttribute.DataType.Name; } cellRef = columnIndex + 8; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(dataType) }; rows.ElementAt(7).AppendChild(cell); cellRef = columnIndex + 9; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(var.IsValueOptional.ToString()) }; rows.ElementAt(8).AppendChild(cell); cellRef = columnIndex + 10; cell = new Cell() { CellReference = cellRef, StyleIndex = (UInt32Value)4U, DataType = CellValues.String, CellValue = new CellValue(dataAttribute.IsMultiValue.ToString()) }; rows.ElementAt(9).AppendChild(cell); } foreach (DefinedName name in dataStructureFile.WorkbookPart.Workbook.GetFirstChild<DefinedNames>()) { if (name.Name == "Data" || name.Name == "VariableIdentifiers") { string[] tempArr = name.InnerText.Split('$'); string temp = ""; tempArr[tempArr.Count() - 2] = GetClomunIndex(variables.Count()); foreach(string t in tempArr) { if (t == tempArr.First()) { temp = temp + t; } else { temp = temp + "$" + t; } } name.Text = temp; } } //WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart; //WorksheetPart worksheetPart = workbookPart.WorksheetParts.First(); dataStructureFile.WorkbookPart.Workbook.Save(); dataStructureFile.Close(); return dataStructureFile; }