コード例 #1
0
ファイル: ActionController.cs プロジェクト: mparsin/Elements
        public ProcessInfo Get(string name, int id)
        {
            MQ1Principal.Login("admin", "aimhi"); //TODO: use http headers instead 
            var dynamicTypeManager = new DynamicTypeManager();
            var editableRootType = dynamicTypeManager.GetEditableRootType(name);

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

            var methodName = string.Format(CultureInfo.InvariantCulture, "Get{0}", name);
            //if (!string.IsNullOrWhiteSpace(filter))
            //{
            //    var filterDescriptor = FilterDescriptor.GetFilterList(filter);                
            //}

            var editableRoot = (IEditableRoot)MethodCaller.CallFactoryMethod(editableRootType, methodName, id);


            if (editableRoot == null)
                throw new VeyronException(string.Format(CultureInfo.InvariantCulture, "Cannot get List for process: {0}", name));

            var visibleFields = new HashSet<string>(editableRoot.Sections.SelectMany(s => s.Fields).Where(f => !f.IsHidden).Select(f => f.SystemName));

            var fields = GetFields(editableRoot, visibleFields);

            var result = new ProcessInfo();
            foreach (var section in editableRoot.Sections)
            {
                var sectionInfo = new SectionInfo {Name = section.Name};
                foreach (var field in section.Fields)
                {
                    var fieldInfo = fields.FirstOrDefault(f => f.SystemName == field.SystemName);
                    if (fieldInfo != null)
                    {
                        var value = fieldInfo.Model.GetType().GetProperty(field.SystemName).GetValue(fieldInfo.Model, null);
                        fieldInfo.Value = value == null ? string.Empty : value.ToString();
                        sectionInfo.Fields.Add(fieldInfo);
                    }
                }
                result.Sections.Add(sectionInfo);

            }

            result.Name = editableRoot.ProcessName;
            return result;
        }
コード例 #2
0
ファイル: ActionController.cs プロジェクト: mparsin/Elements
        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();
            
        }