示例#1
0
        //TODO: Bad name: GetJsonObject is a method for odata serializing
        internal static object GetJsonObject(Field field, string selfUrl)
        {
            object data;

            if (field is ReferenceField)
            {
                return(ODataReference.Create(String.Concat(selfUrl, "/", field.Name)));
            }
            else if (field is BinaryField)
            {
                var binaryField = (BinaryField)field;
                var binaryData  = (BinaryData)binaryField.GetData();

                return(ODataBinary.Create(BinaryField.GetBinaryUrl(field.Content.Id, field.Name, binaryData.Timestamp), null, binaryData.ContentType, null));
            }
            else if (ODataHandler.DeferredFieldNames.Contains(field.Name))
            {
                return(ODataReference.Create(String.Concat(selfUrl, "/", field.Name)));
            }
            data = field.GetData();
            var nodeType = data as NodeType;

            if (nodeType != null)
            {
                return(nodeType.Name);
            }
            return(data);
        }
示例#2
0
        //TODO: Bad name: GetJsonObject is a method for odata serializing
        internal static object GetJsonObject(Field field, string selfUrl)
        {
            object data;

            if (field is ReferenceField)
            {
                return(ODataReference.Create(String.Concat(selfUrl, "/", field.Name)));
            }
            else if (field is BinaryField)
            {
                var binaryField = (BinaryField)field;
                var binaryData  = (BinaryData)binaryField.GetData();

                return(ODataBinary.Create(BinaryField.GetBinaryUrl(field.Content.Id, field.Name, binaryData.Timestamp), null, binaryData.ContentType, null));
            }
            else if (ODataHandler.DeferredFieldNames.Contains(field.Name))
            {
                return(ODataReference.Create(String.Concat(selfUrl, "/", field.Name)));
            }
            try
            {
                data = field.GetData();
            }
            catch (SenseNetSecurityException)
            {
                // The user does not have access to this field (e.g. cannot load
                // a referenced content). In this case we serve a null value.
                data = null;

                SnTrace.Repository.Write("PERMISSION warning: user {0} does not have access to field '{1}' of {2}.", User.LoggedInUser.Username, field.Name, field.Content.Path);
            }

            var nodeType = data as NodeType;

            if (nodeType != null)
            {
                return(nodeType.Name);
            }
            return(data);
        }