private bool ValidateValue(MobeelizerFieldAccessor field, double doubleValue, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { bool includeMaxValue = GetIncludeMaxValue(options); bool includeMinValue = GetIncludeMinValue(options); Double minValue = Double.Parse(GetMinValue(options)); Double maxValue = Double.Parse(GetMaxValue(options)); if (includeMaxValue && doubleValue > maxValue) { errors.AddFieldMustBeLessThanOrEqualTo(field.Name, maxValue); return false; } if (!includeMaxValue && doubleValue >= Double.MaxValue) { errors.AddFieldMustBeLessThan(field.Name, maxValue); return false; } if (includeMinValue && doubleValue < minValue) { errors.AddFieldMustBeGreaterThanOrEqual(field.Name, minValue); return false; } if (!includeMinValue && doubleValue <= Double.MinValue) { errors.AddFieldMustBeGreaterThan(field.Name, minValue); return false; } return true; }
internal void SetValueFromMapToDatabase(IDictionary<string, object> values, IDictionary<string, string> map, MobeelizerFieldAccessor field, bool required, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { String value = null; if (map.ContainsKey(GetFieldName(field.Name))) { value = map[GetFieldName(field.Name)]; } else if (map.ContainsKey(field.Name)) { value = map[field.Name]; } if (value == null && required) { errors.AddFieldCanNotBeEmpty(field.Name); return; } if (value == null) { SetNullValueFromMapToDatabase(values, field, options, errors); } else { SetNotNullValueFromMapToDatabase(values, value, field, options, errors); } }
internal static MobeelizerOperationError UpdateFromSyncError(MobeelizerErrorsHolder errors) { return(new MobeelizerOperationError() { Code = "updateFromSync", Message = "Update entities from sync failiture", Arguments = errors.PrepareErrorArguments() }); }
private bool ValidateValue(MobeelizerFieldAccessor field, string value, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { int maxLength = GetMaxLength(options); if (((String)value).Length > maxLength) { errors.AddFieldIsTooLong(field.Name, maxLength); return false; } return true; }
protected override void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { String stringValue = (String)value; if (!errors.IsValid) { return; } if (!((MobeelizerDatabase)Mobeelizer.GetDatabase()).Exists(options["model"], stringValue)) { errors.AddFieldMissingReferenceError(field.Name, stringValue); return; } }
public void Validate(IDictionary<String, object> values, MobeelizerFieldAccessor field, bool required, IDictionary<String, String> options, MobeelizerErrorsHolder errors) { Object value = values[field.Name]; if (value == null && required) { errors.AddFieldCanNotBeEmpty(field.Name); return; } if (value != null) { ValidateValue(value, field, options, errors); } }
internal bool Validate(MobeelizerWp7Model insert, MobeelizerErrorsHolder errors) { Dictionary <String, object> values = new Dictionary <string, object>(); MapEntityToDictionary(insert, values); foreach (MobeelizerField field in this.Fields) { field.Validate(values, errors); } if (!errors.IsValid) { return(false); } return(true); }
private bool ValidateValue(MobeelizerFieldAccessor field, long longValue, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { int maxValue = GetMaxValue(options); int minValue = GetMinValue(options); if (longValue > maxValue) { errors.AddFieldMustBeLessThan(field.Name, (long)maxValue); return false; } if (longValue < minValue) { errors.AddFieldMustBeGreaterThan(field.Name, (long)minValue); return false; } return true; }
protected override void SetNotNullValueFromMapToDatabase(IDictionary<string, object> values, string value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { Int32 intValue = Int32.Parse(value); values.Add(field.Name, intValue); }
protected override void SetNullValueFromMapToDatabase(IDictionary<string, object> values, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { values.Add(field.Name, null); }
protected override void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { String stringValue = (String)value; if (!errors.IsValid) { return; } if (!((MobeelizerDatabase)Mobeelizer.GetDatabase()).Exists(options["model"], stringValue)) { errors.AddFieldMissingReferenceError(field.Name, stringValue); return; } }
private bool ValidateValue(MobeelizerFieldAccessor field, string value, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { int maxLength = GetMaxLength(options); if (((String)value).Length > maxLength) { errors.AddFieldIsTooLong(field.Name, maxLength); return(false); } return(true); }
internal void SetValueFromMapToDatabase(IDictionary <string, object> values, IDictionary <string, string> map, MobeelizerErrorsHolder errors) { FieldType.SetValueFromMapToDatabase(values, map, accesor, this.field.IsRequired, field.Options, errors); }
internal MobeelizerOperationError UpdateFromSync(MobeelizerJsonEntity entity, MobeelizerDatabaseContext db) { var query = from MobeelizerWp7Model e in db.GetTable(this.Type) join MobeelizerModelMetadata m in db.ModelMetadata on e.Guid equals m.Guid where m.Guid == entity.Guid && m.Model == this.Name select new QueryResult() { Entity = e, Metadata = m }; bool exists = true; QueryResult result = null; if (query.Count() == 0) { exists = false; } else { result = query.Single(); } bool modifiedByUser = exists && result.Metadata.ModificationLock == false && result.Entity.Modified; if (modifiedByUser || !exists && entity.IsDeleted) { return(null); } if (entity.ConflictState == MobeelizerJsonEntity.MobeelizerConflictState.NO_IN_CONFLICT && entity.IsDeleted) { if (exists) { var table = db.GetTable(this.Type); table.DeleteAllOnSubmit(from MobeelizerWp7Model record in table where record.Guid == entity.Guid select record); } return(null); } Dictionary <String, object> values = new Dictionary <string, object>(); if (entity.ConflictState == MobeelizerJsonEntity.MobeelizerConflictState.IN_CONFLICT_BECAUSE_OF_YOU || entity.Fields.Count == 0) { PropertyInfo property = this.Type.GetProperty("Conflicted"); PropertyInfo modifiedProperty = this.Type.GetProperty("Modified"); property.SetValue(result.Entity, true, null); modifiedProperty.SetValue(result.Entity, false, null); return(null); } else if (entity.ConflictState == MobeelizerJsonEntity.MobeelizerConflictState.IN_CONFLICT) { values.Add("Conflicted", 1); } else { values.Add("Conflicted", 0); } values.Add("Owner", entity.Owner); values.Add("Modified", 0); try { values.Add("Deleted", entity.IsDeleted ? 1 : 0); } catch (KeyNotFoundException) { values.Add("Deleted", false); } MobeelizerErrorsHolder errors = new MobeelizerErrorsHolder(); foreach (MobeelizerField field in this.Fields) { field.SetValueFromMapToDatabase(values, entity.Fields, errors); } if (!errors.IsValid) { return(MobeelizerOperationError.UpdateFromSyncError(errors)); } if (exists) { UpdateEntity(db, result.Metadata, values, entity.Guid, result.Entity); } else { values.Add("Guid", entity.Guid); InsertEntity(db, values); } return(null); }
protected override void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { ValidateValue(field, (Double)value, options, errors); }
internal bool ValidateEntity(MobeelizerWp7Model insert, MobeelizerErrorsHolder errors) { String model = insert.GetType().Name; return(models[model].Validate(insert, errors)); }
protected virtual void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { }
protected override void SetNotNullValueFromMapToDatabase(IDictionary <string, object> values, string value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { DateTime date = new DateTime(TimeSpan.FromMilliseconds(Int64.Parse(value)).Ticks + new DateTime(1970, 1, 1, 2, 0, 0, DateTimeKind.Utc).Ticks); values.Add(field.Name, date); }
protected virtual void SetNullValueFromMapToDatabase(IDictionary<string, object> values, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { }
protected virtual void SetNullValueFromMapToDatabase(IDictionary <string, object> values, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { }
internal void Validate(Dictionary <string, object> values, MobeelizerErrorsHolder errors) { FieldType.Validate(values, accesor, this.field.IsRequired, field.Options, errors); }
protected override void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { ValidateValue(field, (int)value, options, errors); }
protected override void SetNotNullValueFromMapToDatabase(IDictionary <string, object> values, string value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { Double doubleValue = Double.Parse(value); values.Add(field.Name, doubleValue); }
public void SubmitChanges() { ChangeSet set = dataContext.GetChangeSet(); IList <MobeelizerModelMetadata> metadataToAdd = new List <MobeelizerModelMetadata>(); foreach (var insert in set.Inserts) { if (insert is MobeelizerWp7Model) { MobeelizerWp7Model modelObject = insert as MobeelizerWp7Model; MobeelizerErrorsHolder errors = new MobeelizerErrorsHolder(); if (!db.ValidateEntity(modelObject, errors)) { throw new ArgumentException(errors.GetErrorsSymmary()); } String model = insert.GetType().Name; String guid = Guid.NewGuid().ToString(); String owner = db.User; modelObject.Guid = guid; modelObject.Owner = owner; modelObject.Conflicted = false; modelObject.Deleted = false; modelObject.Modified = true; MobeelizerModelMetadata metadata = new MobeelizerModelMetadata() { Model = model, Guid = guid, ModificationLock = false }; metadataToAdd.Add(metadata); } } foreach (var update in set.Updates) { if (update is MobeelizerWp7Model) { MobeelizerErrorsHolder errors = new MobeelizerErrorsHolder(); if (!db.ValidateEntity(update as MobeelizerWp7Model, errors)) { throw new InvalidOperationException(errors.GetErrorsSymmary()); } String model = update.GetType().Name; String guid = (update as MobeelizerWp7Model).Guid; var query = from meta in dataContext.ModelMetadata where meta.Model == model && meta.Guid == guid select meta; MobeelizerModelMetadata metadata = query.Single(); if (metadata.ModificationLock) { throw new InvalidOperationException("Entity is locked by synchronization process, wait until synchronization finishes."); } (update as MobeelizerWp7Model).Modified = true; } else if (update is MobeelizerModelMetadata) { MobeelizerModelMetadata metadata = update as MobeelizerModelMetadata; if ((update as MobeelizerWp7Model).Deleted && metadata.ModificationLock) { throw new InvalidOperationException("Entity is locked by synchronization process, wait until synchronization finishes."); } } } foreach (MobeelizerModelMetadata metadata in metadataToAdd) { dataContext.ModelMetadata.InsertOnSubmit(metadata); } this.dataContext.SubmitChanges(); }
public void Validate(IDictionary <String, object> values, MobeelizerFieldAccessor field, bool required, IDictionary <String, String> options, MobeelizerErrorsHolder errors) { Object value = values[field.Name]; if (value == null && required) { errors.AddFieldCanNotBeEmpty(field.Name); return; } if (value != null) { ValidateValue(value, field, options, errors); } }
protected override void SetNullValueFromMapToDatabase(IDictionary <string, object> values, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { values.Add(field.Name, null); }
internal void SetValueFromMapToDatabase(IDictionary <string, object> values, IDictionary <string, string> map, MobeelizerFieldAccessor field, bool required, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { String value = null; if (map.ContainsKey(GetFieldName(field.Name))) { value = map[GetFieldName(field.Name)]; } else if (map.ContainsKey(field.Name)) { value = map[field.Name]; } if (value == null && required) { errors.AddFieldCanNotBeEmpty(field.Name); return; } if (value == null) { SetNullValueFromMapToDatabase(values, field, options, errors); } else { SetNotNullValueFromMapToDatabase(values, value, field, options, errors); } }
private bool ValidateValue(MobeelizerFieldAccessor field, double doubleValue, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { bool includeMaxValue = GetIncludeMaxValue(options); bool includeMinValue = GetIncludeMinValue(options); Double minValue = Double.Parse(GetMinValue(options)); Double maxValue = Double.Parse(GetMaxValue(options)); if (includeMaxValue && doubleValue > maxValue) { errors.AddFieldMustBeLessThanOrEqualTo(field.Name, maxValue); return(false); } if (!includeMaxValue && doubleValue >= Double.MaxValue) { errors.AddFieldMustBeLessThan(field.Name, maxValue); return(false); } if (includeMinValue && doubleValue < minValue) { errors.AddFieldMustBeGreaterThanOrEqual(field.Name, minValue); return(false); } if (!includeMinValue && doubleValue <= Double.MinValue) { errors.AddFieldMustBeGreaterThan(field.Name, minValue); return(false); } return(true); }
private bool ValidateValue(MobeelizerFieldAccessor field, long longValue, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { int maxValue = GetMaxValue(options); int minValue = GetMinValue(options); if (longValue > maxValue) { errors.AddFieldMustBeLessThan(field.Name, (long)maxValue); return(false); } if (longValue < minValue) { errors.AddFieldMustBeGreaterThan(field.Name, (long)minValue); return(false); } return(true); }
protected override void SetNotNullValueFromMapToDatabase(IDictionary<string, object> values, string value, MobeelizerFieldAccessor field, IDictionary<string, string> options, MobeelizerErrorsHolder errors) { DateTime date = new DateTime(TimeSpan.FromMilliseconds(Int64.Parse(value)).Ticks + new DateTime(1970,1,1,2,0,0,DateTimeKind.Utc).Ticks); values.Add(field.Name, date); }
protected virtual void ValidateValue(object value, MobeelizerFieldAccessor field, IDictionary <string, string> options, MobeelizerErrorsHolder errors) { }