Esempio n. 1
0
        public async Task <FileResponse> CreateFileAsync(string container, string filepath, string content, bool checkExists = true)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            IHttpAddress address = baseAddress.WithResource(container, filepath).WithParameter("check_exist", checkExists);
            IHttpRequest request = new HttpRequest(HttpMethod.Post, address.Build(), baseHeaders.Exclude(HttpHeaders.ContentTypeHeader), content);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var data = new { file = new List <FileResponse>() };

            return(contentSerializer.Deserialize(response.Body, data).file.First());
        }
Esempio n. 2
0
        public async Task <ConfigResponse> GetConfigAsync()
        {
            IHttpAddress address = baseAddress.WithResource("config");
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            return(contentSerializer.Deserialize <ConfigResponse>(response.Body));
        }
Esempio n. 3
0
        public async Task <IEnumerable <TableInfo> > GetAccessComponentsAsync()
        {
            IHttpRequest request = new HttpRequest(HttpMethod.Get, baseAddress.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var resource = new { resource = new List <TableInfo>() };

            return(contentSerializer.Deserialize(response.Body, resource).resource);
        }
Esempio n. 4
0
        public async Task <IEnumerable <string> > GetCustomSettingsAsync()
        {
            var          address = baseAddress.WithResource(CustomResource);
            IHttpRequest request = new HttpRequest(HttpMethod.Get, address.Build(), baseHeaders);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            Dictionary <string, object> settings = new Dictionary <string, object>();

            return(contentSerializer.Deserialize(response.Body, settings).Keys);
        }
            private async Task <IWorkflowBlueprint> GetWorkflowBlueprintAsync(WorkflowDefinition workflowDefinition)
            {
                var json = _serializer.Serialize(workflowDefinition);
                var deserializedWorkflowDefinition = _serializer.Deserialize <WorkflowDefinition>(json);

                return(await _materializer.CreateWorkflowBlueprintAsync(deserializedWorkflowDefinition));
            }
Esempio n. 6
0
        public async Task <IActionResult> Handle(string workflowDefinitionId, [FromForm] IFormFile?file, CancellationToken cancellationToken)
        {
            if (file == null)
            {
                return(BadRequest());
            }

            var json = await file.OpenReadStream().ReadStringToEndAsync(cancellationToken);

            var workflowDefinition = await _workflowPublisher.GetDraftAsync(workflowDefinitionId, cancellationToken) ?? _workflowPublisher.New();

            var postedModel = _contentSerializer.Deserialize <WorkflowDefinition>(json);

            workflowDefinition.Activities               = postedModel.Activities;
            workflowDefinition.Connections              = postedModel.Connections;
            workflowDefinition.Description              = postedModel.Description;
            workflowDefinition.Name                     = postedModel.Name;
            workflowDefinition.Tag                      = postedModel.Tag;
            workflowDefinition.Variables                = postedModel.Variables;
            workflowDefinition.ContextOptions           = postedModel.ContextOptions;
            workflowDefinition.CustomAttributes         = postedModel.CustomAttributes;
            workflowDefinition.DisplayName              = postedModel.DisplayName;
            workflowDefinition.IsSingleton              = postedModel.IsSingleton;
            workflowDefinition.DeleteCompletedInstances = postedModel.DeleteCompletedInstances;

            await _workflowPublisher.SaveDraftAsync(workflowDefinition, cancellationToken);

            return(Ok(workflowDefinition));
        }
Esempio n. 7
0
        private async Task <TResult> DeserializeResponseMessageAsync <TResult>(HttpResponseMessage responseMessage)
            where TResult : class
        {
            if (typeof(TResult) == typeof(Empty))
            {
                return((TResult)(object)Empty.New);
            }

            var httpContent = responseMessage.EnsureSuccessStatusCode().Content;
            var content     = await httpContent.ReadAsStringAsync();

            if (content == null)
            {
                throw new ContentNullException();
            }

            var result = _contentSerializer.Deserialize <TResult>(content);

            if (result == null)
            {
                throw new ContentNullException();
            }

            return(result);
        }
Esempio n. 8
0
        public static object ReadBody(this MessageModel message, Type type, IContentSerializer serializer)
        {
            if (type == typeof(string))
            {
                return(Encoding.UTF8.GetString(message.Body));
            }

            var bytes = message.Body;
            var json  = Encoding.UTF8.GetString(bytes);

            return(serializer.Deserialize(json, type) !);
        }
Esempio n. 9
0
        private Variables ParseVariables(string?json)
        {
            if (string.IsNullOrWhiteSpace(json))
            {
                return(new Variables());
            }

            var dictionary = _contentSerializer.Deserialize <Dictionary <string, object?> >(json);
            var variables  = new Variables(dictionary);

            return(variables);
        }
 internal static object RoundTrip(
     this IXmlAttributedTestEvent @event,
     IContentSerializer serializer)
 {
     using (var ms = new MemoryStream())
     using (var w = XmlWriter.Create(ms))
     {
         serializer.Serialize(w, @event);
         w.Flush();
         ms.Position = 0;
         using (var r = XmlReader.Create(ms))
             return serializer.Deserialize(r).Item;
     }
 }
Esempio n. 11
0
        public override async IAsyncEnumerable <IWorkflowBlueprint> GetWorkflowsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
        {
            var blobs = await _storage.ListFilesAsync(new ListOptions(), cancellationToken);

            foreach (var blob in blobs)
            {
                var json = await _storage.ReadTextAsync(blob.FullPath, Encoding.UTF8, cancellationToken);

                var model     = _contentSerializer.Deserialize <WorkflowDefinition>(json);
                var blueprint = await _workflowBlueprintMaterializer.CreateWorkflowBlueprintAsync(model, cancellationToken);

                yield return(blueprint);
            }
        }
Esempio n. 12
0
 internal static object RoundTrip(
     this IDataContractTestEvent @event,
     IContentSerializer serializer)
 {
     using (var ms = new MemoryStream())
         using (var w = XmlWriter.Create(ms))
         {
             serializer.Serialize(w, @event);
             w.Flush();
             ms.Position = 0;
             using (var r = XmlReader.Create(ms))
                 return(serializer.Deserialize(r).Item);
         }
 }
Esempio n. 13
0
        public async Task <bool> RegisterAsync(Register register, bool login = false)
        {
            if (register == null)
            {
                throw new ArgumentNullException("register");
            }

            var address = baseAddress.WithResource("register");

            if (login)
            {
                address = address.WithParameter("login", true);
            }

            string       content = contentSerializer.Serialize(register);
            IHttpRequest request = new HttpRequest(HttpMethod.Post,
                                                   address.Build(),
                                                   baseHeaders,
                                                   content);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var success = new { success = false };

            success = contentSerializer.Deserialize(response.Body, success);

            if (success.success && login)
            {
                Session session = await GetSessionAsync();

                baseHeaders.AddOrUpdate(HttpHeaders.DreamFactorySessionTokenHeader, session.session_id);
            }

            return(success.success);
        }
        private async IAsyncEnumerable <IWorkflowBlueprint> ListInternalAsync([EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            var blobs = await _storage.ListFilesAsync(new ListOptions(), cancellationToken);

            foreach (var blob in blobs)
            {
                var json = await _storage.ReadTextAsync(blob.FullPath, Encoding.UTF8, cancellationToken);

                var model     = _contentSerializer.Deserialize <WorkflowDefinition>(json);
                var blueprint = await TryMaterializeBlueprintAsync(model, cancellationToken);

                if (blueprint != null)
                {
                    yield return(blueprint);
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Creates an <see cref="XmlAtomContent" /> instance from XML.
        /// </summary>
        /// <param name="xmlReader">
        /// The <see cref="XmlReader" /> containing the XML representation of
        /// the Atom Content element.
        /// </param>
        /// <param name="serializer">
        /// The <see cref="IContentSerializer" /> used to deserialize the XML
        /// into an instance of the correct object type.
        /// </param>
        /// <returns>
        /// A new instance <see cref="XmlAtomContent" /> containing the data
        /// from the XML representation of the Atom Content element contained
        /// in <paramref name="xmlReader" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="xmlReader" />
        /// or
        /// <paramref name="serializer" /> is <see langword="null" />.
        /// </exception>
        public static XmlAtomContent ReadFrom(
            XmlReader xmlReader,
            IContentSerializer serializer)
        {
            if (xmlReader == null)
            {
                throw new ArgumentNullException("xmlReader");
            }
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }
            GuardContentElement(xmlReader);

            xmlReader.Read();

            return(serializer.Deserialize(xmlReader));
        }
Esempio n. 16
0
        public async Task <int> SendEmailAsync(EmailRequest emailRequest)
        {
            if (emailRequest == null)
            {
                throw new ArgumentNullException("emailRequest");
            }

            string       content = contentSerializer.Serialize(emailRequest);
            IHttpRequest request = new HttpRequest(HttpMethod.Post, baseAddress.Build(), baseHeaders, content);

            IHttpResponse response = await httpFacade.RequestAsync(request);

            HttpUtils.ThrowOnBadStatus(response, contentSerializer);

            var emailsSent = new { count = 0 };

            return(contentSerializer.Deserialize(response.Body, emailsSent).count);
        }
Esempio n. 17
0
        private static string TryGetErrorMessage(IHttpResponse response, IContentSerializer serializer, string @default)
        {
            try
            {
                string message = @default;
                var    body    = new { error = new Error() };
                body = serializer.Deserialize(response.Body, body);
                if (body != null && body.error != null)
                {
                    message = body.error.Message;
                }

                return(string.Format("{0} - {1}", response.Code, message));
            }
            catch (Exception)
            {
                return(@default);
            }
        }
Esempio n. 18
0
        private static string TryGetErrorMessage(IHttpResponse response, IContentSerializer serializer, string @default)
        {
            try
            {
                string message = @default;
                var    error   = new { error = new List <Error>() };
                error = serializer.Deserialize(response.Body, error);
                if (error != null && error.error != null)
                {
                    message = error.error.First().message;
                }

                return(string.Format("{0} - {1}", response.Code, message));
            }
            catch (Exception)
            {
                return(@default);
            }
        }
Esempio n. 19
0
        private bool TryParseVariables(string?json, out Variables variables)
        {
            variables = new Variables();

            if (string.IsNullOrWhiteSpace(json))
            {
                return(true);
            }

            try
            {
                var dictionary = _contentSerializer.Deserialize <Dictionary <string, object?> >(json);
                variables = new Variables(dictionary);

                return(true);
            }
            catch (JsonReaderException e)
            {
                return(false);
            }
        }
Esempio n. 20
0
        private async Task <TContent> GetResponseContentAsync <TContent>(HttpResponseMessage response)
        {
            var contentString = await response.Content.ReadAsStringAsync();

            return(_contentSerializer.Deserialize <TContent>(contentString));
        }
Esempio n. 21
0
        private static string TryGetErrorMessage(IHttpResponse response, IContentSerializer serializer, string @default)
        {
            try
            {
                string message = @default;
                var body = new { error = new Error() };
                body = serializer.Deserialize(response.Body, body);
                if (body != null && body.error != null)
                {
                    message = body.error.Message;
                }

                return string.Format("{0} - {1}", response.Code, message);
            }
            catch (Exception)
            {
                return @default;
            }
        }
Esempio n. 22
0
        private static string TryGetErrorMessage(IHttpResponse response, IContentSerializer serializer, string @default)
        {
            try
            {
                string message = @default;
                var error = new { error = new List<Error>() };
                error = serializer.Deserialize(response.Body, error);
                if (error != null && error.error != null)
                {
                    message = error.error.First().message;
                }

                return string.Format("{0} - {1}", response.Code, message);
            }
            catch (Exception)
            {
                return @default;
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Creates an <see cref="XmlAtomContent" /> instance from XML.
        /// </summary>
        /// <param name="xmlReader">
        /// The <see cref="XmlReader" /> containing the XML representation of
        /// the Atom Content element.
        /// </param>
        /// <param name="serializer">
        /// The <see cref="IContentSerializer" /> used to deserialize the XML
        /// into an instance of the correct object type.
        /// </param>
        /// <returns>
        /// A new instance <see cref="XmlAtomContent" /> containing the data
        /// from the XML representation of the Atom Content element contained
        /// in <paramref name="xmlReader" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="xmlReader" />
        /// or
        /// <paramref name="serializer" /> is <see langword="null" />.
        /// </exception>
        public static XmlAtomContent ReadFrom(
            XmlReader xmlReader,
            IContentSerializer serializer)
        {
            if (xmlReader == null)
                throw new ArgumentNullException("xmlReader");
            if (serializer == null)
                throw new ArgumentNullException("serializer");
            GuardContentElement(xmlReader);

            xmlReader.Read();

            return serializer.Deserialize(xmlReader);
        }