Beispiel #1
0
 public AmplaAddDataBinding(List <TModel> models, List <SubmitDataRecord> records, IAmplaViewProperties <TModel> amplaViewProperties, IModelProperties <TModel> modelProperties)
 {
     this.models              = models;
     this.records             = records;
     this.amplaViewProperties = amplaViewProperties;
     this.modelProperties     = modelProperties;
 }
 public AmplaDataSubmissionResultBinding(DataSubmissionResult[] dataSubmissionResults, List <TModel> models, IModelProperties <TModel> modelProperties)
 {
     this.dataSubmissionResults = dataSubmissionResults ?? new DataSubmissionResult[0];
     this.models          = models;
     this.modelProperties = modelProperties;
     idProperty           = ModelIdentifier.GetPropertyName <TModel>();
 }
Beispiel #3
0
 public AmplaRepository(IDataWebServiceClient webServiceClient, ICredentialsProvider credentialsProvider)
 {
     this.webServiceClient    = webServiceClient;
     this.credentialsProvider = credentialsProvider;
     modelProperties          = new ModelProperties <TModel>();
     amplaViewDictionary      = new Dictionary <string, IAmplaViewProperties <TModel> >();
 }
 public AmplaGetDataRecordBinding(GetDataResponse response, List <AmplaRecord> records, IModelProperties <TModel> modelProperties, IAmplaViewProperties <TModel> amplaViewProperties)
 {
     this.response            = response;
     this.records             = records;
     this.modelProperties     = modelProperties;
     this.amplaViewProperties = amplaViewProperties;
 }
 public AmplaGetAuditDataRecordBinding(GetAuditDataResponse response, AmplaRecord record, List <AmplaAuditRecord> records, IModelProperties <TModel> modelProperties)
 {
     this.response        = response;
     this.record          = record;
     this.records         = records;
     this.modelProperties = modelProperties;
 }
 public ModelIdentifierBinding(TModel model, List <int> identifiers, IModelProperties <TModel> modelProperties)
 {
     this.model           = model;
     this.identifiers     = identifiers;
     this.modelProperties = modelProperties;
     idProperty           = ModelIdentifier.GetPropertyName <TModel>();
 }
 public AmplaDeleteDataBinding(List <TModel> models, List <DeleteRecord> records, IModelProperties <TModel> modelProperties)
 {
     this.models          = models;
     this.records         = records;
     this.modelProperties = modelProperties;
     idProperty           = ModelIdentifier.GetPropertyName <TModel>();
 }
 public AmplaUpdateDataBinding(TModel existing, TModel update, List <SubmitDataRecord> records, IAmplaViewProperties <TModel> amplaViewProperties, IModelProperties <TModel> modelProperties)
 {
     this.existing            = existing;
     this.update              = update;
     this.records             = records;
     this.amplaViewProperties = amplaViewProperties;
     this.modelProperties     = modelProperties;
 }
 protected AmplaUpdateRecordStatusBinding(List <TModel> models, List <UpdateRecordStatus> records, IModelProperties <TModel> modelProperties, UpdateRecordStatusAction recordAction)
 {
     this.models          = models;
     this.records         = records;
     this.modelProperties = modelProperties;
     this.recordAction    = recordAction;
     idProperty           = ModelIdentifier.GetPropertyName <TModel>();
 }
 public AmplaGetDataVersionsBinding(AmplaRecord amplaRecord, AmplaAuditRecord auditRecord, TModel currentModel, ModelVersions versions, IModelProperties <TModel> modelProperties, IAmplaViewProperties <TModel> viewProperties)
 {
     this.amplaRecord     = amplaRecord;
     this.auditRecord     = auditRecord;
     this.currentModel    = currentModel;
     this.versions        = versions;
     this.modelProperties = modelProperties;
     this.viewProperties  = viewProperties;
 }
Beispiel #11
0
        public AmplaViewProperties(IModelProperties <TModel> modelProperties)
        {
            this.modelProperties = modelProperties;
            permissions          = new ViewPermissions();
            IViewPermissions modulePermissions =
                ModuleMapping.GetModuleMapping(modelProperties.Module).GetSupportedOperations();

            enforcePermissions = new EnforceViewPermissionsAdapter(modelProperties.Module.ToString(), permissions,
                                                                   modulePermissions);
        }
 public ModelObject(ushort id, ushort tid, ushort parentid)
 {
     Id              = id;
     Tid             = tid;
     Parent          = parentid;
     ModelChildren   = new ModelChildren();
     ModelActions    = new ModelActions();
     ModelRelations  = new ModelRelations();
     ModelProperties = new ModelProperties();
 }
Beispiel #13
0
        /// <summary>
        /// Validates the specified model is not null
        /// </summary>
        /// <param name="modelProperties">The model properties.</param>
        /// <param name="model">The model.</param>
        /// <param name="validationMessages">The validation messages.</param>
        /// <returns></returns>
        public bool Validate(IModelProperties <TModel> modelProperties, TModel model, ValidationMessages validationMessages)
        {
            bool isValid = !Equals(model, null);

            if (!isValid)
            {
                string message = string.Format("Null model specified. Type='{0}'", typeof(TModel));
                validationMessages.Add(message);
            }
            return(isValid);
        }
Beispiel #14
0
        /// <summary>
        /// Try to resolve the value from the model
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <param name="modelProperties">The model properties.</param>
        /// <param name="model">The model.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public override bool TryResolveValue <TModel>(IModelProperties <TModel> modelProperties, TModel model, out string value)
        {
            bool resolved = modelProperties.TryGetPropertyValue(model, Name, out value);

            if (resolved && (value == "0"))
            {
                value = null;
                return(false);
            }
            return(resolved);
        }
Beispiel #15
0
        public override bool CanMapField <TModel>(IModelProperties <TModel> modelProperties, out string message)
        {
            Type propertyType = modelProperties.GetPropertyType(Name);

            if (!typeof(int).IsAssignableFrom(propertyType))
            {
                message = string.Format("{0}.{1} is not a compatible data type ({2}) Ampla field type is {3}.", typeof(TModel), Name, FieldType, typeof(int));
                return(false);
            }
            message = null;
            return(true);
        }
Beispiel #16
0
        /// <summary>
        /// Validates the specified model location is the specified value.
        /// </summary>
        /// <param name="modelProperties">The model properties.</param>
        /// <param name="model">The model.</param>
        /// <param name="validationMessages">The validation messages.</param>
        /// <returns></returns>
        public bool Validate(IModelProperties <TModel> modelProperties, TModel model, ValidationMessages validationMessages)
        {
            string newlocation = modelProperties.GetLocation(model);

            bool isValid = string.Compare(location, newlocation, StringComparison.InvariantCulture) == 0;

            if (!isValid)
            {
                validationMessages.Add("The Location property is not the required value: " + location);
            }
            return(isValid);
        }
        public override bool CanMapField <TModel>(IModelProperties <TModel> modelProperties, out string message)
        {
            Type propertyType = modelProperties.GetPropertyType(Name);

            if (Value.GetType() != propertyType)
            {
                message = string.Format("Unable to map constant value");
                return(false);
            }
            message = null;
            return(true);
        }
Beispiel #18
0
        /// <summary>
        /// Determines whether this instance [can map field] the specified model properties.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="modelProperties">The model properties.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public override bool CanMapField <TModel>(IModelProperties <TModel> modelProperties, out string message)
        {
            bool canRead = modelProperties.CanConvertTo(FieldType, Name);

            if (!canRead)
            {
                Type propertyType = modelProperties.GetPropertyType(Name);
                message = string.Format("{0}.{1} is not able to be read ({2}) Ampla field type is {3}.", typeof(TModel), Name, FieldType, propertyType);

                return(false);
            }
            message = null;
            return(true);
        }
Beispiel #19
0
        public override bool TryResolveValue <TModel>(IModelProperties <TModel> modelProperties, TModel model, out string value)
        {
            string baseValue;

            if (base.TryResolveValue(modelProperties, model, out baseValue))
            {
                if (!modelProperties.IsDefaultValue(model, Name))
                {
                    value = baseValue;
                    return(true);
                }
            }

            value = defaultValue();
            return(true);
        }
        public override bool TryResolveValue <TModel>(IModelProperties <TModel> modelProperties, TModel model, out string value)
        {
            string baseValue;

            if (base.TryResolveValue(modelProperties, model, out baseValue))
            {
                if (validateFunc(baseValue))
                {
                    value = baseValue;
                    return(true);
                }
            }

            value = null;
            return(false);
        }
Beispiel #21
0
        public bool Validate(IModelProperties <TModel> modelProperties, TModel model, ValidationMessages validationMessages)
        {
            string location;

            bool isValid = true;

            if (modelProperties.TryGetPropertyValue(model, "Location", out location))
            {
                isValid = !string.IsNullOrEmpty(location);
                if (!isValid)
                {
                    string message = string.Format("The Location property is not specified. Type='{0}'", typeof(TModel));
                    validationMessages.Add(message);
                }
            }
            return(isValid);
        }
Beispiel #22
0
        /// <summary>
        /// Determines whether this instance [can map field] the specified model properties.
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="modelProperties">The model properties.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public override bool CanMapField <TModel>(IModelProperties <TModel> modelProperties, out string message)
        {
            Type propertyType = modelProperties.GetPropertyType(Name);

            bool canRead  = modelProperties.CanConvertTo(FieldType, Name);
            bool canWrite = CanWrite && modelProperties.CanConvertFrom(FieldType, Name);

            bool canRoundTrip = CanRoundTrip(FieldType, propertyType);

            message = null;
            if (canRead && canWrite && canRoundTrip)
            {
                return(true);
            }

            string verb = !canRead && !canWrite ?"is not" : "may not be";

            message = string.Format("Model property '{0}' ({1}) {2} compatible with the Ampla field ({3})", Name, propertyType, verb, FieldType);
            return(false);
        }
Beispiel #23
0
        private AmplaRecord FindAmplaRecord(GetDataResponse response, IModelProperties <TModel> iModelProperties, IAmplaViewProperties <TModel> amplaViewProperties, out TModel model)
        {
            List <AmplaRecord> records = new List <AmplaRecord>();

            model = null;
            IAmplaBinding amplaBinding = new AmplaGetDataRecordBinding <TModel>(response, records, modelProperties,
                                                                                amplaViewProperties);

            if (amplaBinding.Validate() && amplaBinding.Bind())
            {
                List <TModel> models       = new List <TModel>();
                IAmplaBinding modelBinding = new AmplaGetDataBinding <TModel>(response, models, iModelProperties);
                if (modelBinding.Validate() && modelBinding.Bind())
                {
                    model = models.Count > 0 ? models[0] : null;
                }
                return(records.Count > 0 ? records[0] : null);
            }
            return(null);
        }
 protected override void OnFixtureSetUp()
 {
     base.OnFixtureSetUp();
     modelProperties     = new ModelProperties <ProductionModel>();
     amplaViewProperties = new AmplaViewProperties <ProductionModel>(modelProperties);
 }
Beispiel #25
0
 public AmplaCalendarRepository(IDataWebServiceCalendarClient calendarClient, ICredentialsProvider credentialsProvider)
 {
     this.calendarClient      = calendarClient;
     this.credentialsProvider = credentialsProvider;
     modelProperties          = new ModelProperties <TModel>();
 }
Beispiel #26
0
 public AmplaGetDataBinding(GetDataResponse response, List <TModel> records, IModelProperties <TModel> modelProperties)
 {
     this.modelProperties = modelProperties;
     this.response        = response;
     this.records         = records;
 }
Beispiel #27
0
 public AmplaUnconfirmDataBinding(List <TModel> models, List <UpdateRecordStatus> records, IModelProperties <TModel> modelProperties)
     : base(models, records, modelProperties, UpdateRecordStatusAction.Unconfirm)
 {
 }
Beispiel #28
0
 /// <summary>
 ///     Don't resolve the value from the model
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <param name="modelProperties"></param>
 /// <param name="model"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public override bool TryResolveValue <TModel>(IModelProperties <TModel> modelProperties, TModel model, out string value)
 {
     value = null;
     return(false);
 }
Beispiel #29
0
 /// <summary>
 /// Determines whether this instance [can map field] the specified model properties.
 /// </summary>
 /// <param name="modelProperties">The model properties.</param>
 /// <param name="message">The message.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public abstract bool CanMapField <TModel>(IModelProperties <TModel> modelProperties, out string message) where TModel : new();
Beispiel #30
0
 /// <summary>
 /// Try to resolve the value from the model
 /// </summary>
 /// <typeparam name="TModel">The type of the model.</typeparam>
 /// <param name="modelProperties">The model properties.</param>
 /// <param name="model">The model.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public abstract bool TryResolveValue <TModel>(IModelProperties <TModel> modelProperties, TModel model, out string value) where TModel : new();