Esempio n. 1
0
        /// <inheritdoc />
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var nodeType = value as NodeType;

            if (nodeType == null)
            {
                throw new ODataException(SNSR.GetString(SNSR.Exceptions.OData.CannotConvertToJSON_2, typeof(NodeType).FullName, value.GetType().FullName), ODataExceptionCode.CannotConvertToJSON);
            }
            writer.WriteValue(nodeType.Name);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var versionData = value as VersionNumber;

            if (versionData == null)
            {
                throw new ODataException(SNSR.GetString(SNSR.Exceptions.OData.CannotConvertToJSON_2, typeof(VersionNumber).FullName, value.GetType().FullName), ODataExceptionCode.CannotConvertToJSON);
            }
            writer.WriteValue(versionData.ToString());
        }
Esempio n. 3
0
 internal static IEnumerable <ODataActionItem> GetActionItems(Content content, ODataRequest request, HttpContext httpContext)
 {
     return(GetActionsWithScenario(content, request, httpContext).Select(a => new ODataActionItem
     {
         Name = a.Action.Name,
         DisplayName = SNSR.GetString(a.Action.Text),
         Icon = a.Action.Icon,
         Index = a.Action.Index,
         Url = a.Action.Uri,
         Forbidden = a.Action.Forbidden,
         IsODataAction = a.Action.IsODataOperation,
         ActionParameters = a.Action.ActionParameters.Select(p => p.Name).ToArray(),
         Scenario = a.Scenario
     }));
 }
Esempio n. 4
0
        /// <inheritdoc />
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var imgData = value as ImageField.ImageFieldData;

            if (imgData == null)
            {
                throw new ODataException(SNSR.GetString(SNSR.Exceptions.OData.CannotConvertToJSON_2, typeof(ImageField.ImageFieldData).FullName, value.GetType().FullName), ODataExceptionCode.CannotConvertToJSON);
            }
            writer.WriteStartObject();
            var url = imgData.Field == null ? "#" : ((ImageField)imgData.Field).ImageUrl;

            writer.WritePropertyName("Url");
            writer.WriteValue(url);
            writer.WriteEnd();
        }
Esempio n. 5
0
 private ODataOperation CreateOdataOperation(ActionBase a, string selfUrl)
 {
     return(new ODataOperation
     {
         Title = SNSR.GetString(a.Text),
         Name = a.Name,
         Target = string.Concat(selfUrl, "/", a.Name),
         Forbidden = a.Forbidden,
         Parameters = a.ActionParameters.Select(p => new ODataOperationParameter
         {
             Name = p.Name,
             Type = ResolveODataParameterType(p.Type),
             Required = p.Required
         }).ToArray()
     });
 }
Esempio n. 6
0
        /// <inheritdoc />
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var urls = value as Dictionary <string, string>;

            if (urls == null)
            {
                throw new ODataException(SNSR.GetString(SNSR.Exceptions.OData.CannotConvertToJSON_2, "Dictionary<string, string>", value.GetType().FullName), ODataExceptionCode.CannotConvertToJSON);
            }

            writer.WriteStartArray();
            foreach (var item in urls)
            {
                writer.WriteStartObject();
                writer.WritePropertyName(item.Key);
                writer.WriteValue(item.Value);
                writer.WriteEndObject();
            }
            writer.WriteEndArray();
        }
 internal static void ResourceNotFound()
 {
     throw new ODataException(SNSR.GetString(SNSR.Exceptions.OData.ResourceNotFound), ODataExceptionCode.ResourceNotFound);
 }
 internal static void ResourceNotFound(Content content, string propertyName)
 {
     throw new ODataException(SNSR.GetString(SNSR.Exceptions.OData.ResourceNotFound_2, content.Path, propertyName), ODataExceptionCode.ResourceNotFound);
 }
 internal static void ContentAlreadyExists(string path)
 {
     throw new ODataException(SNSR.GetString(SNSR.Exceptions.OData.ContentAlreadyExists_1, path), ODataExceptionCode.ContentAlreadyExists);
 }