/// <summary> /// Initializes a new instance of the <see cref="UploadPresetParams"/> class. /// </summary> /// <param name="preset">The preset returned from API.</param> public UploadPresetParams(GetUploadPresetResult preset) { Name = preset.Name; Unsigned = preset.Unsigned; if (preset.Settings == null) { return; } DisallowPublicId = preset.Settings.DisallowPublicId; Backup = preset.Settings.Backup; Type = preset.Settings.Type; if (preset.Settings.Tags != null) { if (preset.Settings.Tags.Type == JTokenType.String) { Tags = preset.Settings.Tags.ToString(); } else if (preset.Settings.Tags.Type == JTokenType.Array) { Tags = String.Join(",", preset.Settings.Tags.Values <string>().ToArray()); } } Invalidate = preset.Settings.Invalidate; UseFilename = preset.Settings.UseFilename; UniqueFilename = preset.Settings.UniqueFilename; DiscardOriginalFilename = preset.Settings.DiscardOriginalFilename; NotificationUrl = preset.Settings.NotificationUrl; Proxy = preset.Settings.Proxy; Folder = preset.Settings.Folder; Overwrite = preset.Settings.Overwrite; RawConvert = preset.Settings.RawConvert; if (preset.Settings.Context != null) { Context = new StringDictionary(); foreach (JProperty prop in preset.Settings.Context) { Context.Add(prop.Name, prop.Value.ToString()); } } if (preset.Settings.AllowedFormats != null) { if (preset.Settings.AllowedFormats.Type == JTokenType.String) { AllowedFormats = preset.Settings.AllowedFormats.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } else if (preset.Settings.AllowedFormats.Type == JTokenType.Array) { AllowedFormats = preset.Settings.AllowedFormats.Select(t => t.ToString()).ToArray(); } } Moderation = preset.Settings.Moderation; Format = preset.Settings.Format; if (preset.Settings.Transformation != null) { if (preset.Settings.Transformation.Type == JTokenType.String) { Transformation = preset.Settings.Transformation.ToString(); } else if (preset.Settings.Transformation.Type == JTokenType.Array) { var dict = new Dictionary <string, object>(); foreach (JObject obj in preset.Settings.Transformation) { foreach (var prop in obj) { dict.Add(prop.Key, prop.Value.ToString()); } } Transformation = new Transformation(dict); } } if (preset.Settings.EagerTransforms != null) { EagerTransforms = new List <object>(); foreach (JToken token in preset.Settings.EagerTransforms) { if (token.Type == JTokenType.String) { EagerTransforms.Add(token.ToString()); } else if (token.Type == JTokenType.Array) { var dict = new Dictionary <string, object>(); foreach (JObject obj in token) { foreach (var prop in obj) { dict.Add(prop.Key, prop.Value.ToString()); } } EagerTransforms.Add(new Transformation(dict)); } } } Exif = preset.Settings.Exif; Colors = preset.Settings.Colors; Faces = preset.Settings.Faces; if (preset.Settings.FaceCoordinates != null) { if (preset.Settings.FaceCoordinates.Type == JTokenType.String) { FaceCoordinates = preset.Settings.FaceCoordinates.ToString(); } else if (preset.Settings.FaceCoordinates.Type == JTokenType.Array) { var fc = new List <Rectangle>(); foreach (JToken token in preset.Settings.FaceCoordinates) { fc.Add(new System.Drawing.Rectangle(token[0].Value <int>(), token[1].Value <int>(), token[2].Value <int>(), token[3].Value <int>())); } } } Metadata = preset.Settings.Metadata; EagerAsync = preset.Settings.EagerAsync; EagerNotificationUrl = preset.Settings.EagerNotificationUrl; Categorization = preset.Settings.Categorization; AutoTagging = preset.Settings.AutoTagging; Detection = preset.Settings.Detection; SimilaritySearch = preset.Settings.SimilaritySearch; Ocr = preset.Settings.Ocr; }
/// <summary> /// Initializes a new instance of the <see cref="UploadPresetParams"/> class. /// </summary> /// <param name="preset">The preset returned from API.</param> public UploadPresetParams(GetUploadPresetResult preset) { Name = preset.Name; Unsigned = preset.Unsigned; if (preset.Settings == null) return; DisallowPublicId = preset.Settings.DisallowPublicId; Backup = preset.Settings.Backup; Type = preset.Settings.Type; if (preset.Settings.Tags != null) { if (preset.Settings.Tags.Type == JTokenType.String) Tags = preset.Settings.Tags.ToString(); else if (preset.Settings.Tags.Type == JTokenType.Array) Tags = String.Join(",", preset.Settings.Tags.Values<string>().ToArray()); } Invalidate = preset.Settings.Invalidate; UseFilename = preset.Settings.UseFilename; UniqueFilename = preset.Settings.UniqueFilename; DiscardOriginalFilename = preset.Settings.DiscardOriginalFilename; NotificationUrl = preset.Settings.NotificationUrl; Proxy = preset.Settings.Proxy; Folder = preset.Settings.Folder; Overwrite = preset.Settings.Overwrite; RawConvert = preset.Settings.RawConvert; if (preset.Settings.Context != null) { Context = new StringDictionary(); foreach (JProperty prop in preset.Settings.Context) { Context.Add(prop.Name, prop.Value.ToString()); } } if (preset.Settings.AllowedFormats != null) { if (preset.Settings.AllowedFormats.Type == JTokenType.String) AllowedFormats = preset.Settings.AllowedFormats.ToString().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); else if (preset.Settings.AllowedFormats.Type == JTokenType.Array) AllowedFormats = preset.Settings.AllowedFormats.Select(t => t.ToString()).ToArray(); } Moderation = preset.Settings.Moderation; Format = preset.Settings.Format; if (preset.Settings.Transformation != null) { if (preset.Settings.Transformation.Type == JTokenType.String) { Transformation = preset.Settings.Transformation.ToString(); } else if (preset.Settings.Transformation.Type == JTokenType.Array) { var dict = new Dictionary<string, object>(); foreach (JObject obj in preset.Settings.Transformation) { foreach (var prop in obj) { dict.Add(prop.Key, prop.Value.ToString()); } } Transformation = new Transformation(dict); } } if (preset.Settings.EagerTransforms != null) { EagerTransforms = new List<object>(); foreach (JToken token in preset.Settings.EagerTransforms) { if (token.Type == JTokenType.String) { EagerTransforms.Add(token.ToString()); } else if (token.Type == JTokenType.Array) { var dict = new Dictionary<string, object>(); foreach (JObject obj in token) { foreach (var prop in obj) { dict.Add(prop.Key, prop.Value.ToString()); } } EagerTransforms.Add(new Transformation(dict)); } } } Exif = preset.Settings.Exif; Colors = preset.Settings.Colors; Faces = preset.Settings.Faces; if (preset.Settings.FaceCoordinates != null) { if (preset.Settings.FaceCoordinates.Type == JTokenType.String) { FaceCoordinates = preset.Settings.FaceCoordinates.ToString(); } else if (preset.Settings.FaceCoordinates.Type == JTokenType.Array) { var fc = new List<Rectangle>(); foreach (JToken token in preset.Settings.FaceCoordinates) { fc.Add(new System.Drawing.Rectangle(token[0].Value<int>(), token[1].Value<int>(), token[2].Value<int>(), token[3].Value<int>())); } } } Metadata = preset.Settings.Metadata; EagerAsync = preset.Settings.EagerAsync; EagerNotificationUrl = preset.Settings.EagerNotificationUrl; Categorization = preset.Settings.Categorization; AutoTagging = preset.Settings.AutoTagging; Detection = preset.Settings.Detection; SimilaritySearch = preset.Settings.SimilaritySearch; Ocr = preset.Settings.Ocr; }