public WriteAccessHandlerInfo(WriteAccessHandler h, object p, DataAttribute da) { handler = h; parameter = p; dataAttribute = da; }
public void UpdateTimestampAttributeValue(DataAttribute dataAttr, Timestamp timestamp) { IedServer_updateTimestampAttributeValue(self, dataAttr.self, timestamp.timestampRef); }
public void UpdateQuality(DataAttribute dataAttr, ushort value) { IedServer_updateQuality(self, dataAttr.self, value); }
// 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(); } }
public void UpdateVisibleStringAttributeValue(DataAttribute dataAttr, string value) { IedServer_updateVisibleStringAttributeValue(self, dataAttr.self, value); }
public void UpdateBooleanAttributeValue(DataAttribute dataAttr, bool value) { IedServer_updateBooleanAttributeValue(self, dataAttr.self, value); }
public void UpdateInt64AttributeValue(DataAttribute dataAttr, Int64 value) { IedServer_updateInt64AttributeValue(self, dataAttr.self, value); }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="variables"></param> /// <param name="path"></param> /// <param name="filename"></param> /// <returns></returns> public SpreadsheetDocument CreateTemplate(List <long> variableIds, 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); List <Variable> variables = this.GetUnitOfWork().GetReadOnlyRepository <Variable>() .Query(p => variableIds.Contains(p.Id)) .OrderBy(p => p.OrderNo) .ToList(); foreach (Variable var in variables) { DataContainerManager CM = null; try { 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); } finally { CM.Dispose(); } } 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); }
public DerivedInlineAutoDataAttribute( DataAttribute autoDataAttribute, params object[] values) : base(autoDataAttribute, values) { }
public void UpdateInt32AttributeValue(DataAttribute dataAttr, int val) { IedServer_updateInt32AttributeValue(self, dataAttr.self, val); }
/// <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) { using (var uow = this.GetUnitOfWork()) { DataAttribute dataAttribute = uow.GetReadOnlyRepository <Variable>().Query(p => p.Id == variableValue.VariableId).Select(p => p.DataAttribute).FirstOrDefault(); string message = "row :" + rowIndex + "column:" + columnIndex; Debug.WriteLine(message); string cellRef = getColumnIndex(columnIndex); Cell cell = new Cell(); cell.CellReference = cellRef; cell.StyleIndex = ExcelHelper.GetExcelStyleIndex(dataAttribute.DataType, styleIndex); //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.ToString() != "") { 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.ToString() != "") { DateTime dt; if (dataAttribute.DataType != null && dataAttribute.DataType.Extra != null) { DataTypeDisplayPattern pattern = DataTypeDisplayPattern.Materialize(dataAttribute.DataType.Extra); if (!string.IsNullOrEmpty(pattern.StringPattern)) { IOUtility.ExportDateTimeString(value.ToString(), pattern.StringPattern, out dt); cell.CellValue = new CellValue(dt.ToOADate().ToString()); } else { if (IOUtility.IsDate(value.ToString(), out dt)) { cell.CellValue = new CellValue(dt.ToOADate().ToString()); } } } else { if (IOUtility.IsDate(value.ToString(), out dt)) { 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); } }
public static void Main(string[] args) { bool running = true; /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg"); if (iedModel == null) { Console.WriteLine("No valid data model found!"); return; } DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); IedServer iedServer = new IedServer(iedModel); iedServer.SetControlHandler(spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); if (val) { Console.WriteLine("received binary control command: on"); } else { Console.WriteLine("received binary control command: off"); } return(ControlHandlerResult.OK); }, null); iedServer.Start(102); Console.WriteLine("Server started"); GC.Collect(); DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f"); DataAttribute ggio1AnIn1T = (DataAttribute)ggio1AnIn1.GetChild("t"); float floatVal = 1.0f; while (running) { floatVal += 1f; iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now)); iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal); Thread.Sleep(100); } iedServer.Stop(); Console.WriteLine("Server stopped"); iedServer.Destroy(); }
private MemberAutoMoqDataAttribute(DataAttribute baseAttribute) { _baseAttribute = baseAttribute; }
protected AttributedAbstractMetaDataMember(MemberInfo member, MetaType declaringType, DataAttribute attribute) { memberInfo = member; memberAccessor = LambdaMetaAccessor.Create(member, declaringType.Type); this.declaringType = declaringType; if (attribute.Storage != null) { storageMember = member.DeclaringType.GetSingleMember(attribute.Storage); if (storageMember != null) { storageAccessor = LambdaMetaAccessor.Create(storageMember, declaringType.Type); } } }
/// <summary> /// Initializes a new instance of the <see cref="InlineAutoDataAttribute"/> class. /// </summary> /// <param name="autoDataAttribute">An <see cref="DataAttribute"/>.</param> /// <param name="values">The data values to pass to the theory.</param> /// <remarks> /// <para> /// This constructor overload exists to enable a derived attribute to /// supply a custom <see cref="DataAttribute" /> that again may /// contain custom behavior. /// </para> /// </remarks> /// <example> /// In this example, TheAnswer is a Customization that changes all /// 32-bit integer values to 42. This behavior is encapsulated in /// MyCustomAutoDataAttribute, and transitively in /// MyCustomInlineAutoDataAttribute. A parameterized test demonstrates /// how it can be used. /// <code> /// [Theory] /// [MyCustomInlineAutoData(1337)] /// [MyCustomInlineAutoData(1337, 7)] /// [MyCustomInlineAutoData(1337, 7, 42)] /// public void CustomInlineDataSuppliesExtraValues(int x, int y, int z) /// { /// Assert.Equal(1337, x); /// // y can vary, so we can't express any meaningful assertion for it. /// Assert.Equal(42, z); /// } /// /// private class MyCustomInlineAutoDataAttribute : InlineAutoDataAttribute /// { /// public MyCustomInlineAutoDataAttribute(params object[] values) : /// base(new MyCustomAutoDataAttribute(), values) /// { /// } /// } /// /// private class MyCustomAutoDataAttribute : AutoDataAttribute /// { /// public MyCustomAutoDataAttribute() : /// base(() => new Fixture().Customize(new TheAnswer())) /// { /// } /// /// private class TheAnswer : ICustomization /// { /// public void Customize(IFixture fixture) /// { /// fixture.Inject(42); /// } /// } /// } /// </code> /// </example> protected InlineAutoDataAttribute(DataAttribute autoDataAttribute, params object[] values) : base(new InlineDataAttribute(values), autoDataAttribute) { this.AutoDataAttribute = autoDataAttribute; this.Values = values; }
/// <summary> /// Create ValueValidationManager of a Variable /// </summary> /// <remarks></remarks> /// <param name="varName"></param> /// <param name="dataType"></param> /// <param name="optional"></param> /// <param name="variable"></param> /// <returns></returns> private ValueValidationManager createValueValidationManager(string varName, string dataType, bool optional, DataAttribute variable) { ValueValidationManager vvm = new ValueValidationManager(varName, dataType, optional, Info.Decimal); return(vvm); }
public void UpdateAttributeValue(DataAttribute dataAttr, MmsValue value) { IedServer_updateAttributeValue(self, dataAttr.self, value.valueReference); }
/// <summary> /// Information gain for an attribute on a set of examples /// </summary> private static double Importance(ICollection <Example> examples, DataAttribute attr) { return(Entropy(examples) - Remainder(examples, attr)); }
public void UpdateFloatAttributeValue(DataAttribute dataAttr, float value) { IedServer_updateFloatAttributeValue(self, dataAttr.self, value); }
public static void Main(string[] args) { bool running = true; /* run until Ctrl-C is pressed */ Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("model.cfg"); if (iedModel == null) { Console.WriteLine("No valid data model found!"); return; } DataObject spcso1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.SPCSO1"); TLSConfiguration tlsConfig = new TLSConfiguration(); tlsConfig.SetOwnCertificate(new X509Certificate2("server.cer")); tlsConfig.SetOwnKey("server-key.pem", null); // Add a CA certificate to check the certificate provided by the server - not required when ChainValidation == false tlsConfig.AddCACertificate(new X509Certificate2("root.cer")); // Check if the certificate is signed by a provided CA tlsConfig.ChainValidation = true; // Check that the shown server certificate is in the list of allowed certificates tlsConfig.AllowOnlyKnownCertificates = false; IedServer iedServer = new IedServer(iedModel, tlsConfig); iedServer.SetControlHandler(spcso1, delegate(DataObject controlObject, object parameter, MmsValue ctlVal, bool test) { bool val = ctlVal.GetBoolean(); if (val) { Console.WriteLine("received binary control command: on"); } else { Console.WriteLine("received binary control command: off"); } return(ControlHandlerResult.OK); }, null); iedServer.Start(); Console.WriteLine("Server started"); GC.Collect(); DataObject ggio1AnIn1 = (DataObject)iedModel.GetModelNodeByShortObjectReference("GenericIO/GGIO1.AnIn1"); DataAttribute ggio1AnIn1magF = (DataAttribute)ggio1AnIn1.GetChild("mag.f"); DataAttribute ggio1AnIn1T = (DataAttribute)ggio1AnIn1.GetChild("t"); float floatVal = 1.0f; while (running) { floatVal += 1f; iedServer.UpdateTimestampAttributeValue(ggio1AnIn1T, new Timestamp(DateTime.Now)); iedServer.UpdateFloatAttributeValue(ggio1AnIn1magF, floatVal); Thread.Sleep(100); } iedServer.Stop(); Console.WriteLine("Server stopped"); iedServer.Destroy(); }
private static IEnumerable<object[]> GetData(DataAttribute dataAttribute, [CallerMemberName] string testMethodName = null) { Requires.NotNull(dataAttribute, nameof(dataAttribute)); Requires.NotNullOrEmpty(testMethodName, nameof(testMethodName)); string supposeMethodName = testMethodName.Replace("GetData_", "Suppose_"); var methodInfo = typeof(CombinatorialDataAttributeTests).GetTypeInfo() .DeclaredMethods.First(m => m.Name == supposeMethodName); return dataAttribute.GetData(methodInfo); }
public ActionResult storeVariables(long Id, storeVariableStruct[] variables) { DataStructureManager dataStructureManager = null; DataContainerManager dataContainerManager = null; UnitManager um = null; try { dataStructureManager = new DataStructureManager(); var structureRepo = dataStructureManager.GetUnitOfWork().GetReadOnlyRepository <StructuredDataStructure>(); StructuredDataStructure dataStructure = structureRepo.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 = ""; } try { dataContainerManager = new DataContainerManager(); DataAttribute dataAttribute = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId); if (dataAttribute != null) { try { um = new UnitManager(); variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), um.Repo.Get(svs.UnitId)); svs.Id = variable.Id; } finally { um.Dispose(); } } else { returnObject = new MessageModel() { hasMessage = true, Message = "Not all Variables are stored.", CssId = "0" }; } } finally { // Javad: would be better to conctruct and dispose this object outside of the loop dataContainerManager.Dispose(); } } dataStructure = structureRepo.Get(Id); // Javad: why it is needed? 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(); try { um = new UnitManager(); dataContainerManager = new DataContainerManager(); variable.Unit = um.Repo.Get(svs.UnitId); variable.DataAttribute = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId); variable.IsValueOptional = svs.isOptional; } finally { um.Dispose(); // Javad: would be better to conctruct and dipose these objects outside of the loop dataContainerManager.Dispose(); } } } 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)); } finally { dataStructureManager.Dispose(); dataContainerManager.Dispose(); um.Dispose(); } }