예제 #1
0
 /// <summary>
 /// Gets the property.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="editableRootType">Type of the editable root.</param>
 /// <returns>PropertyInfo.</returns>
 /// <exception cref="System.ArgumentException">Cannot find a field with the name {0}.</exception>
 private static PropertyInfo GetProperty(FieldData field, Type editableRootType)
 {
     PropertyInfo propertyInfo = editableRootType.GetProperty(field.FieldName);
     if (propertyInfo == null)
     {
         var basePropertyInfo = editableRootType.GetProperty(Constants.BaseEditPropertyName);
         if (basePropertyInfo == null) 
             throw new ArgumentException("Cannot find a field with the name {0}.", field.FieldName);
         //var baseEdit = editableRootType.GetProperty(Constants.BaseEditPropertyName) as IEditableRoot;
         return GetProperty(field, basePropertyInfo.PropertyType);
     }
     return propertyInfo;
 }
예제 #2
0
        public void Put(FieldData field)//, int recordId, string fieldName, string value)
        {
            if (field == null) throw new ArgumentNullException("field");

            MQ1Principal.Login("admin", "aimhi"); //TODO: use http headers instead 

            var dynamicTypeManager = new DynamicTypeManager();
            var editableRootType = dynamicTypeManager.GetEditableRootType(field.ProcessName);

            if (editableRootType == null)
                throw new VeyronException(string.Format(CultureInfo.InvariantCulture, "Cannot get Process Type {0}", field.ProcessName));

            var methodName = string.Format(CultureInfo.InvariantCulture, "Get{0}", field.ProcessName);
            var editableRoot = (IEditableRoot)MethodCaller.CallFactoryMethod(editableRootType, methodName, field.RecordId);
            
            var propertyInfo = GetProperty(field, editableRootType);

            if (propertyInfo.DeclaringType == editableRootType)
            {
                propertyInfo.SetValue(editableRoot,
                                      Convert.ChangeType(field.Value, propertyInfo.PropertyType,
                                                         CultureInfo.InvariantCulture), null);
            }
            else
            {
                var basePropertyInfo = editableRootType.GetProperty(Constants.BaseEditPropertyName);
                if (propertyInfo.DeclaringType == basePropertyInfo.PropertyType)
                {
                    var baseEditableRoot = basePropertyInfo.GetValue(editableRoot);
                    propertyInfo.SetValue(baseEditableRoot, Convert.ChangeType(field.Value, propertyInfo.PropertyType,
                                                         CultureInfo.InvariantCulture), null);
                }
            }

            ((ISavable) editableRoot).Save();
            
        }