/// <summary>
		/// Constructor for ChoiceValues object.
		/// </summary>
		/// <param name="outField">field information used for validation.</param>
		public ChoiceValues(OutField outField)
		{
			OutField = outField;
			Choices = new ObservableCollection<FieldValue>();
			DefaultValue = new FieldValue(null, OutField, true);
			CurrentValue = new FieldValue(null, OutField);
		}
예제 #2
0
 /// <summary>
 /// Constructor for FieldValue object.
 /// </summary>
 /// <param name="value">actual value.</param>
 /// <param name="outField">field information used for validation.</param>
 /// <param name="allowNullOrEmpty">null or empty value allowed.</param>
 /// <param name="validatesUniqueAndNonEmpty">enforces fields to be unique and non-empty.</param>
 /// <param name="activateEditing">activates editing.</param>
 public FieldValue(object value, OutField outField, bool allowNullOrEmpty = false, bool validatesUniqueAndNonEmpty = false, bool activateEditing = false)
 {
     this.validatesUniqueAndNonEmpty = validatesUniqueAndNonEmpty;
     OutField  = outField;
     Value     = value;
     IsEditing = activateEditing;
 }
예제 #3
0
 /// <summary>
 /// Constructor for ChoiceValues object.
 /// </summary>
 /// <param name="outField">field information used for validation.</param>
 public ChoiceValues(OutField outField)
 {
     OutField     = outField;
     Choices      = new ObservableCollection <FieldValue>();
     DefaultValue = new FieldValue(null, OutField, true);
     CurrentValue = new FieldValue(null, OutField);
 }
예제 #4
0
 /// <summary>
 /// Updates serializable properties with values from another ChoiceValues.
 /// </summary>
 /// <param name="source">The source ChoiceValues</param>
 private void CopyAllSettings(ChoiceValues source)
 {
     OutField     = new OutField(source.OutField);
     DefaultValue = new FieldValue(source.DefaultValue);
     SampleValues = source.SampleValues != null ? new List <FieldValue>(from v in source.SampleValues select new FieldValue(v))
                         : new List <FieldValue>();
     Choices = source.Choices != null ? new ObservableCollection <FieldValue>(from c in source.Choices select new FieldValue(c)) :
               new ObservableCollection <FieldValue>();
 }
 /// <summary>
 /// Updates serializable properties with values from another OutField.
 /// </summary>
 /// <param name="source">The source OutField</param>
 private void CopyAllSettings(OutField source)
 {
     if (source == null)
     {
         return;
     }
     Name       = source.Name;
     Alias      = source.Alias;
     Type       = source.Type;
     IsEditable = source.IsEditable;
     Length     = source.Length;
     Domain     = new Dictionary <object, string>();
     if (source.Domain != null)
     {
         foreach (var item in source.Domain)
         {
             Domain[item.Key] = item.Value;
         }
     }
     IsVisible = source.IsVisible;
 }
 /// <summary>
 /// Updates properties of current object with properties of source object.
 /// </summary>
 /// <param name="source"></param>
 public void ApplyChanges(OutField source)
 {
     CopyAllSettings(source);
 }
 /// <summary>
 /// Copy constructor for the OutField object.
 /// </summary>
 /// <param name="source"></param>
 public OutField(OutField source)
 {
     CopyAllSettings(source);
 }
예제 #8
0
        /// <summary>
        /// Converts value to its correct data type while performing type and length validation.
        /// </summary>
        /// <param name="field">field information</param>
        /// <param name="value">value to validate.</param>
        /// <param name="exception">validation exception to be set.</param>
        /// <returns>value converted to its correct data type.</returns>
        private static object ValidateValue(OutField field, object value, out Exception exception)
        {
            object result = value;

            exception = null;
            try
            {
                switch (field.Type)
                {
                case Field.FieldType.Date:
                    // Due to datetime fields format being dependent on the type of backend database
                    // no datetime validation was put in place for this version so as not to be restrictive.
                    // It is assumed that users will know the correct datetime format when working against
                    // their own services. Sample servers often use "date 'yyyy-MM-dd'" or "date 'yyyy-MM-dd hh:mm:ss'".
                    // (see: http://resources.arcgis.com/en/help/main/10.1/index.html#//00s500000033000000)
                    break;

                case Field.FieldType.Double:
                    if (value.GetType() != typeof(double))
                    {
                        result = Convert.ToDouble(value, CultureInfo.InvariantCulture);
                    }
                    break;

                case Field.FieldType.Single:
                    if (value.GetType() != typeof(float))
                    {
                        result = Convert.ToSingle(value, CultureInfo.InvariantCulture);
                    }
                    break;

                case Field.FieldType.OID:
                case Field.FieldType.Integer:
                    if (value.GetType() != typeof(int))
                    {
                        result = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                    }
                    break;

                case Field.FieldType.SmallInteger:
                    if (value.GetType() != typeof(short))
                    {
                        result = Convert.ToInt16(value, CultureInfo.InvariantCulture);
                    }
                    break;

                case Field.FieldType.GUID:
                    if (value.GetType() != typeof(Guid))
                    {
                        Guid output;
                        var  valueStr = Convert.ToString(value, CultureInfo.InvariantCulture);
                        if (!string.IsNullOrEmpty(valueStr))
                        {
                            if (Guid.TryParse(valueStr, out output))
                            {
                                result = output;
                            }
                        }
                    }
                    break;
                }
            }
            catch
            {
                exception = new ArgumentException(string.Format(Resources.Strings.DataTypeMismatch, value, field.Type));
            }

            if (exception == null && field.Type != Field.FieldType.Date && field.Length > 0 && result is string && !((string)result).Contains(Resources.Strings.EnterValue))
            {
                if ((result as string).Length > field.Length)
                {
                    exception = new ArgumentOutOfRangeException(string.Format(Resources.Strings.StringExceededMaxLength, !string.IsNullOrEmpty(field.Alias) ? field.Alias : field.Name, field.Length));
                }
            }
            return(result);
        }
		/// <summary>
		/// Updates serializable properties with values from another ChoiceValues.
		/// </summary>
		/// <param name="source">The source ChoiceValues</param>
		private void CopyAllSettings(ChoiceValues source)
		{
			OutField = new OutField(source.OutField);
			DefaultValue = new FieldValue(source.DefaultValue);
			SampleValues = source.SampleValues != null ? new List<FieldValue>(from v in source.SampleValues select new FieldValue(v)) 
				: new List<FieldValue>();
			Choices = source.Choices != null ? new ObservableCollection<FieldValue>(from c in source.Choices select new FieldValue(c)) : 
				new ObservableCollection<FieldValue>();			
		}
예제 #10
0
		/// <summary>
		/// Updates properties of current object with properties of source object.
		/// </summary>
		/// <param name="source"></param>
		public void ApplyChanges(OutField source)
		{
			CopyAllSettings(source);
		}
예제 #11
0
		/// <summary>
		/// Copy constructor for the OutField object.
		/// </summary>
		/// <param name="source"></param>
		public OutField(OutField source)
		{
			CopyAllSettings(source);
		}
예제 #12
0
		/// <summary>
		/// Updates serializable properties with values from another OutField.
		/// </summary>
		/// <param name="source">The source OutField</param>
		private void CopyAllSettings(OutField source)
		{
			if(source == null)return;
			Name = source.Name;
			Alias = source.Alias;
			Type = source.Type;
			IsEditable = source.IsEditable;
			Length = source.Length;
			Domain = new Dictionary<object, string>();
			if (source.Domain != null)
			{
				foreach (var item in source.Domain)
					Domain[item.Key] = item.Value;
			}
			IsVisible = source.IsVisible;
		}