Ejemplo n.º 1
0
        private bool TryCreatePatchRequest2Legacy(
            IReadOnlyDictionary <string, object> json,
            out Schematized schematized)
        {
            schematized = null;
            try
            {
                ISchematizedJsonDeserializingFactory <PatchRequest2> deserializer =
                    this.PatchRequest2DeserializationBehavior ?? new PatchRequest2JsonDeserializingFactory();
                schematized = deserializer.Create(json);
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (ThreadInterruptedException)
            {
                throw;
            }
            catch (StackOverflowException)
            {
                throw;
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool TryCreateExtensionObjectFrom(
            IReadOnlyDictionary <string, object> json,
            IReadOnlyCollection <string> schemaIdentifiers,
            out Schematized schematized)
        {
            schematized = null;

            if (null == json)
            {
                throw new ArgumentNullException(nameof(json));
            }

            if (null == schemaIdentifiers)
            {
                throw new ArgumentNullException(nameof(schemaIdentifiers));
            }

            if (null == this.Extensions)
            {
                return(false);
            }

            if (this.Extensions.TryMatch(schemaIdentifiers, out IExtension matchingExtension))
            {
                schematized = matchingExtension.JsonDeserializingFactory(json);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private bool TryCreateProtocolObjectFrom(
            IReadOnlyDictionary <string, object> json,
            IReadOnlyCollection <string> schemaIdentifiers,
            out Schematized schematized)
        {
            schematized = null;

            if (null == json)
            {
                throw new ArgumentNullException(nameof(json));
            }

            if (null == schemaIdentifiers)
            {
                throw new ArgumentNullException(nameof(schemaIdentifiers));
            }

            if (schemaIdentifiers.Count != 1)
            {
                return(false);
            }

            if
            (
                schemaIdentifiers
                .SingleOrDefault(
                    (string item) =>
                    item.Equals(
                        ProtocolSchemaIdentifiers.Version2PatchOperation,
                        StringComparison.OrdinalIgnoreCase)) != null
            )
            {
                schematized = this.CreatePatchRequest(json);
                return(true);
            }

            if
            (
                schemaIdentifiers
                .SingleOrDefault(
                    (string item) =>
                    item.Equals(
                        ProtocolSchemaIdentifiers.Version2Error,
                        StringComparison.OrdinalIgnoreCase)) != null
            )
            {
                schematized = new ErrorResponseJsonDeserializingFactory().Create(json);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        private bool TryCreateResourceFrom(
            IReadOnlyDictionary <string, object> json,
            IReadOnlyCollection <string> schemaIdentifiers,
            out Schematized schematized)
        {
            schematized = null;

            if (null == json)
            {
                throw new ArgumentNullException(nameof(json));
            }

            if (null == schemaIdentifiers)
            {
                throw new ArgumentNullException(nameof(schemaIdentifiers));
            }

            if
            (
                schemaIdentifiers
                .SingleOrDefault(
                    (string item) =>
                    item.Equals(
                        SchemaIdentifiers.Core2User,
                        StringComparison.OrdinalIgnoreCase)) != null
            )
            {
                schematized = this.CreateUser(schemaIdentifiers, json);
                return(true);
            }

            if
            (
                schemaIdentifiers
                .SingleOrDefault(
                    (string item) =>
                    item.Equals(
                        SchemaIdentifiers.Core2Group,
                        StringComparison.OrdinalIgnoreCase)) != null
            )
            {
                schematized = this.CreateGroup(schemaIdentifiers, json);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        private static bool TryCreatePatchRequest2Compliant(
            IReadOnlyDictionary <string, object> json,
            out Schematized schematized)
        {
            schematized = null;
            try
            {
                ISchematizedJsonDeserializingFactory <PatchRequest2> deserializer =
                    new PatchRequest2JsonDeserializingFactory();
                schematized = deserializer.Create(json);
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (ThreadInterruptedException)
            {
                throw;
            }
            catch (StackOverflowException)
            {
                throw;
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
            {
                return(false);
            }
#pragma warning restore CA1031 // Do not catch general exception types

            return(true);
        }
Ejemplo n.º 6
0
        private async Task WriteToStream(
            Type type,
            object value,
            Stream writeStream,
            Func <byte[], Task> writeFunction)
        {
            if (null == type)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (null == value)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (null == writeStream)
            {
                throw new ArgumentNullException(nameof(writeStream));
            }

            string characters;

            if (typeof(string) == type)
            {
                characters = (string)value;
            }
            else
            {
                IDictionary <string, object> json;
                if (typeof(IDictionary <string, object>).IsAssignableFrom(type))
                {
                    json       = (IDictionary <string, object>)value;
                    characters = JsonFactory.Instance.Create(json, this.DeserializingFactory.AcceptLargeObjects);
                }
                else if (typeof(Schematized).IsAssignableFrom(type))
                {
                    Schematized schematized = (Schematized)value;
                    json       = schematized.ToJson();
                    characters = JsonFactory.Instance.Create(json, this.DeserializingFactory.AcceptLargeObjects);
                }
                else
                {
                    throw new NotSupportedException(type.FullName);
                }
            }
            string information =
                string.Concat(
                    SystemForCrossDomainIdentityManagementServiceResources.InformationWrote,
                    characters);
            IInformationNotification notification =
                InformationNotificationFactory.Instance.CreateNotification(
                    information,
                    null,
                    ServiceNotificationIdentifiers.SchematizedMediaTypeFormatterWroteToStream);

            this.Monitor.Inform(notification);
            byte[] bytes = SchematizedMediaTypeFormatter.Encoding.GetBytes(characters);
            await writeFunction(bytes).ConfigureAwait(false);

            writeStream.Flush();
        }
Ejemplo n.º 7
0
        private async Task <object> ReadFromStream(Type type, Stream readStream, HttpContent content)
        {
            if (null == type)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (null == readStream)
            {
                throw new ArgumentNullException(nameof(readStream));
            }

            if
            (
                !typeof(IDictionary <string, object>).IsAssignableFrom(type) &&
                !typeof(Schematized).IsAssignableFrom(type) &&
                typeof(string) != type
            )
            {
                throw new NotSupportedException(type.FullName);
            }

            string characters = await SchematizedMediaTypeFormatter.ReadFromStream(readStream).ConfigureAwait(false);

            string information = string.Concat(SystemForCrossDomainIdentityManagementServiceResources.InformationRead, characters);
            IInformationNotification notification =
                InformationNotificationFactory.Instance.CreateNotification(
                    information,
                    null,
                    ServiceNotificationIdentifiers.SchematizedMediaTypeFormatterReadFromStream);

            this.Monitor.Inform(notification);

            if
            (
                string.Equals(
                    content?.Headers?.ContentType?.MediaType,
                    MediaTypes.JavaWebToken,
                    StringComparison.Ordinal)
            )
            {
                return(characters);
            }

            Dictionary <string, object> json =
                JsonFactory.Instance.Create(
                    characters,
                    this.DeserializingFactory.AcceptLargeObjects);

            if (typeof(IDictionary <string, object>).IsAssignableFrom(type))
            {
                return(json);
            }

            try
            {
                Schematized result = this.DeserializingFactory.Create(json);
                return(result);
            }
            catch (ArgumentException)
            {
                return(new HttpResponseException(HttpStatusCode.BadRequest));
            }
            catch (NotSupportedException)
            {
                return(new HttpResponseException(HttpStatusCode.BadRequest));
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
            {
                return(new HttpResponseException(HttpStatusCode.BadRequest));
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }