public ContentField GetModel(ProtoContent content, ContentFieldDefinition fieldDefinition)
        {
            var fcfg     = fieldDefinition.Config.DirectCastTo <FilePickerFieldConfiguration>();
            var mdl      = new FilePickerField();
            var fnPrefix = $"{fieldDefinition.FieldName}.{nameof(FilePickerField.Val)}.";

            if (!fcfg.IsMultiSelect)
            {
                var cf = content.ContentFields.FirstOrDefault(x => x.FieldName.StartsWith(fnPrefix));
                if (cf?.StringValue != null)
                {
                    mdl.Val = new[] {
                        cf.StringValue
                    };
                }
            }
            else
            {
                var cfs = content.ContentFields.Where(
                    x => x.FieldName.StartsWith(fnPrefix)).ToArray();
                var vals = new List <Tuple <int, string> >();
                foreach (var cf in cfs)
                {
                    var idxStr = cf.FieldName.Replace(fnPrefix, "");
                    if (!int.TryParse(idxStr, out var idx))
                    {
                        continue;
                    }
                    if (cf.StringValue != null)
                    {
                        vals.Add(Tuple.Create(idx, cf.StringValue));
                    }
                }
                mdl.Val = vals.OrderBy(x => x.Item1).Select(x => x.Item2).ToArray();
            }
            mdl.UpdateRelatedPaths(_fileMgr.GetHandler());
            return(mdl);
        }
示例#2
0
 public IHttpActionResult PathInfo()
 {
     try {
         if (!Request.Headers.Contains(PATH_INPUT_HEADER))
         {
             throw new HttpException(400,
                                     $"ProtoCMS: file explorer path-info requires path param in request header '{PATH_INPUT_HEADER}'.");
         }
         var path    = Request.Headers.GetValues(PATH_INPUT_HEADER).FirstOrDefault();
         var handler = _fileMgr.GetHandler();
         var result  = handler.PathInfo(path);
         return(JsonProto(result));
     } catch (HttpException hexc) {
         throw RestfulApiError(hexc);
     }
 }