예제 #1
0
        public bool SaveNode(Node node, dynamic rawdata, List <Field> fields = null)
        {
            if (fields != null)
            {
                throw new Exception("SaveNodeData is not consumed in the right way!");
                foreach (var field in fields)
                {
                    try
                    {
                        var value = rawdata[field.Id.ToString()];
                        //raw data has to be processed before saving to database
                        var fieldtype = _fieldrepository.GetFieldType(field);

                        var          type     = System.Type.GetType(fieldtype.ClassPath);
                        FieldContext _context = new FieldContext(field.Id, fieldtype.Id, field.FieldName);
                        _context.RawData  = value;
                        _context.OldValue = null;
                        var fieldobj = Activator.CreateInstance(type, _context);
                        var mi       = type.GetMethod("GetValue");
                        var data     = mi.Invoke(fieldobj, null).ToString();

                        _currentrepository.SaveNodeData(node, field, data);
                    }
                    catch (Exception e) { }
                }
            }
            else
            {
                var list = ((INodeRepository)_currentrepository).GetNodeFieldMapData(node);
                foreach (var nodefield in list)
                {
                    try
                    {
                        var value = rawdata[nodefield.Id.ToString()];
                        //raw data has to be processed before saving to database
                        var          fieldtype = _fieldrepository.GetFieldType(nodefield.Field);
                        var          type      = System.Type.GetType(fieldtype.ClassPath);
                        FieldContext _context  = new FieldContext(nodefield.Field.Id, fieldtype.Id, nodefield.Field.FieldName);
                        _context.RawData  = value;
                        _context.OldValue = nodefield.NodeData;
                        var fieldobj = Activator.CreateInstance(type, _context);
                        //invoke GetValue to get the processed value.
                        var mi   = type.GetMethod("GetValue");
                        var data = mi.Invoke(fieldobj, null).ToString();
                        //call SaveValue to save addition information.
                        mi = type.GetMethod("SaveValue");
                        mi.Invoke(fieldobj, null);

                        nodefield.NodeData = data;
                        _currentrepository.SaveNodeData(nodefield);
                    }
                    catch (Exception e) { }
                }
            }

            return(true);
        }