protected override IEnumerable <ValidationResult> CollectIfNotNull(IEnumerable <object> models) { return(Enumerable.Range(0, models.Count()) .Zip(models, (index, model) => new { Path = this.Current.Path.TakeIndex(index), Model = model }) .SelectMany(nested => nested.Model == null ? MissingValue.For(nested.Path).Once() : this.Current.Validation.CreateFor(nested.Path).Validate(nested.Model))); }
public void BeginEdit() { if (inEdit) { return; } inEdit = true; bakMissingValue = missingValue.Clone() as MissingValue; }
public void EndEdit() { if (!inEdit) { return; } inEdit = false; bakMissingValue = null; Memorize(); }
/// <summary> /// Tells if the value is the special missing value. (Unlike 'Equals', this works even if the special missing value is null.) /// </summary> /// <param name="value">The value to test</param> /// <returns>true if the value is the special missing value</returns> virtual public bool IsMissing(TValue value) { if (null == MissingValue) { return(null == value); } else { return(MissingValue.Equals(value)); } }
/// <summary> /// Generate data info text /// </summary> /// <returns>info text</returns> public override string GenerateInfoText() { string dataInfo; dataInfo = "File Name: " + FileName; dataInfo += Environment.NewLine + "Data Type: ASCII Grid"; dataInfo += Environment.NewLine + "XNum = " + XNum.ToString() + " YNum = " + YNum.ToString(); dataInfo += Environment.NewLine + "XMin = " + XMin.ToString() + " YMin = " + YMin.ToString(); dataInfo += Environment.NewLine + "XSize = " + XDelt.ToString() + " YSize = " + YDelt.ToString(); dataInfo += Environment.NewLine + "MissingValue = " + MissingValue.ToString(); return(dataInfo); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { MissingValue missingValue = null; MissingTypeEnum missingType = MissingTypeEnum.First; missingType = MissingTypeEnum.Find(reader.Value.ToString()); if (missingType != null) { missingValue = new MissingValue(missingType); } else { missingValue = new MissingValue(reader.Value.ToString()); } return missingValue; }
public MissingValue Create(string displayName, string description, Variable variable, string placeholder = null) { Contract.Requires(!string.IsNullOrWhiteSpace(displayName)); Contract.Requires(variable != null); Contract.Ensures(Contract.Result <MissingValue>() != null && Contract.Result <MissingValue>().Id >= 0); TypeCode typecode = new TypeCode(); foreach (DataTypeCode tc in Enum.GetValues(typeof(DataTypeCode))) { if (tc.ToString() == variable.DataAttribute.DataType.SystemType) { typecode = (TypeCode)tc; break; } } if (String.IsNullOrEmpty(placeholder)) { placeholder = getPlaceholder(typecode, variable.Id); } if (!String.IsNullOrEmpty(placeholder) && ValidatePlaceholder(typecode, placeholder, variable.Id)) { using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <MissingValue> repo = uow.GetRepository <MissingValue>(); MissingValue missingValue = new MissingValue() { DisplayName = displayName, Placeholder = placeholder, Description = description, Variable = variable, }; repo.Put(missingValue); uow.Commit(); return(missingValue); } } return(null); }
public bool Delete(MissingValue entity) { Contract.Requires(entity != null); Contract.Requires(entity.Id >= 0); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <MissingValue> repo = uow.GetRepository <MissingValue>(); entity = repo.Reload(entity); //delete the unit repo.Delete(entity); // commit changes uow.Commit(); } // if any problem was detected during the commit, an exception will be thrown! return(true); }
public MissingValue Update(MissingValue entity) { Contract.Requires(entity != null, "provided entity can not be null"); Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID"); Contract.Ensures(Contract.Result <MissingValue>() != null && Contract.Result <MissingValue>().Id >= 0, "No entity is persisted!"); using (IUnitOfWork uow = this.GetUnitOfWork()) { TypeCode typecode = new TypeCode(); foreach (DataTypeCode tc in Enum.GetValues(typeof(DataTypeCode))) { if (tc.ToString() == entity.Variable.DataAttribute.DataType.SystemType) { typecode = (TypeCode)tc; break; } } if (String.IsNullOrEmpty(entity.Placeholder)) { entity.Placeholder = getPlaceholder(typecode, entity.Variable.Id); } if (!String.IsNullOrEmpty(entity.Placeholder) && ValidatePlaceholder(typecode, entity.Placeholder, entity.Variable.Id, entity.Id)) { IRepository <MissingValue> repo = uow.GetRepository <MissingValue>(); repo.Merge(entity); var merged = repo.Get(entity.Id); repo.Put(merged); uow.Commit(); return(entity); } else { return(null); } } }
private static IRValueNode CreateConstant(ParseContext context) { var tokens = context.Tokens; var currentToken = tokens.CurrentToken; IRValueNode term = null; switch (currentToken.TokenType) { case RTokenType.NaN: case RTokenType.Infinity: case RTokenType.Number: term = new NumericalValue(); break; case RTokenType.Complex: term = new ComplexValue(); break; case RTokenType.Logical: term = new LogicalValue(); break; case RTokenType.String: term = new StringValue(); break; case RTokenType.Null: term = new NullValue(); break; case RTokenType.Missing: term = new MissingValue(); break; } Debug.Assert(term != null); term.Parse(context, null); return(term); }
public ActionResult _getMissingValueElement(long missinValueId = 0) { MissingValueStruct missingValueStruct = new MissingValueStruct(); if (missinValueId > 0) { MissingValueManager missingValueManager = null; try { missingValueManager = new MissingValueManager(); MissingValue missingValue = missingValueManager.Repo.Get(missinValueId); if (missingValue == null) { return(null); } else { missingValueStruct = new MissingValueStruct() { Id = missingValue.Id, DisplayName = missingValue.DisplayName, Description = missingValue.Description, Placeholder = missingValue.Placeholder }; } } catch { return(null); } finally { missingValueManager.Dispose(); } } return(PartialView("_missingValueElement", missingValueStruct)); }
public ActionResult storeVariables(long Id, storeVariableStruct[] variables) { DataStructureManager dataStructureManager = null; DataContainerManager dataContainerManager = null; MissingValueManager missingValueManager = null; UnitManager um = null; try { dataStructureManager = new DataStructureManager(); missingValueManager = new MissingValueManager(); dataContainerManager = new DataContainerManager(); um = new UnitManager(); 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.Any()) { 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)) { List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(v.Id)).ToList(); foreach (MissingValue mv in missingValues) { missingValueManager.Delete(mv); } 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 = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId); if (dataAttribute != null) { variable = dataStructureManager.AddVariableUsage(dataStructure, dataAttribute, svs.isOptional, svs.Lable.Trim(), null, null, svs.Description.Trim(), um.Repo.Get(svs.UnitId)); svs.Id = variable.Id; foreach (MissingValueStruct mvs in svs.MissingValues) { if (mvs.Id == 0) { if (String.IsNullOrEmpty(mvs.Placeholder)) { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable); } else { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable, mvs.Placeholder); } } } } else { returnObject = new MessageModel() { hasMessage = true, Message = "Not all Variables are stored.", CssId = "0" }; } } //dataStructure = structureRepo.Get(Id); // Javad: why it is needed? variables = variables.Where(v => v.Id != 0).ToArray(); MissingValue missingValue = new MissingValue(); 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 = um.Repo.Get(svs.UnitId); variable.DataAttribute = dataContainerManager.DataAttributeRepo.Get(svs.AttributeId); variable.IsValueOptional = svs.isOptional; List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(svs.Id)).ToList(); foreach (MissingValue mv in missingValues) { if (!svs.MissingValues.Select(mvs => mvs.Id).Contains(mv.Id)) { missingValueManager.Delete(mv); } } foreach (MissingValueStruct mvs in svs.MissingValues) { if (mvs.Id == 0) { if (String.IsNullOrEmpty(mvs.Placeholder)) { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable); } else { missingValueManager.Create(mvs.DisplayName, mvs.Description, variable, mvs.Placeholder); } } else if (mvs.Id > 0) { missingValue = missingValues.Where(mv => mv.Id.Equals(mvs.Id)).FirstOrDefault(); if (missingValue != null) { missingValue.DisplayName = mvs.DisplayName; missingValue.Description = mvs.Description; missingValue.Placeholder = mvs.Placeholder; missingValueManager.Update(missingValue); } } } } } dataStructure = dataStructureManager.UpdateStructuredDataStructure(dataStructure); DataStructureIO.setVariableOrder(dataStructure, variables.Select(svs => svs.Id).ToList()); } else { foreach (Variable v in dataStructure.Variables) { List <MissingValue> missingValues = missingValueManager.Repo.Query(mv => mv.Variable.Id.Equals(v.Id)).ToList(); foreach (MissingValue mv in missingValues) { missingValueManager.Delete(mv); } dataStructureManager.RemoveVariableUsage(v); } } LoggerFactory.LogCustom("Variables for Data Structure " + Id + " stored."); return(Json(returnObject, JsonRequestBehavior.AllowGet)); } finally { dataStructureManager.Dispose(); dataContainerManager.Dispose(); um.Dispose(); missingValueManager.Dispose(); } }
private static IRValueNode CreateConstant(ParseContext context) { TokenStream<RToken> tokens = context.Tokens; RToken currentToken = tokens.CurrentToken; IRValueNode term = null; switch (currentToken.TokenType) { case RTokenType.NaN: case RTokenType.Infinity: case RTokenType.Number: term = new NumericalValue(); break; case RTokenType.Complex: term = new ComplexValue(); break; case RTokenType.Logical: term = new LogicalValue(); break; case RTokenType.String: term = new StringValue(); break; case RTokenType.Null: term = new NullValue(); break; case RTokenType.Missing: term = new MissingValue(); break; } Debug.Assert(term != null); term.Parse(context, null); return term; }
public MissingValueVM(MissingValue missingValue) { this.missingValue = missingValue; }