コード例 #1
0
        /// <summary>
        /// Download the file.
        /// </summary>
        /// <param name="Parameters">Query string parameters.</param>
        /// <returns>The resource as a file.</returns>
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.Communication.REST.File> DownloadFileAsync(System.String Parameters)
        {
            SoftmakeAll.SDK.Communication.REST REST = new SoftmakeAll.SDK.Communication.REST();
            REST.Method = "GET";
            REST.URL    = $"{SoftmakeAll.SDK.Fluent.SDKContext.APIBaseAddress}/{base.Route}/{Parameters}";
            SoftmakeAll.SDK.Communication.REST.File File = await REST.DownloadFileAsync();

            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.ExitCode = 0;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.Count    = 1;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.Message  = "";
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.ID       = null;

            if (REST.HasRequestErrors)
            {
                SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.ExitCode = (int)REST.StatusCode;
                SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.Count    = 0;
            }

            return(File);
        }
コード例 #2
0
        /// <summary>
        /// Creates a OperationResult object based on HTTP Request.
        /// </summary>
        /// <param name="REST">REST object that contains the HTTP Request information.</param>
        /// <param name="RESTResult">The output of Send method.</param>
        /// <returns>A OperationResult with JSON property Data.</returns>
        private static SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> ProcessRESTRequestResult(SoftmakeAll.SDK.Communication.REST REST, System.Text.Json.JsonElement RESTResult)
        {
            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> Result = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();
            if (REST.HasRequestErrors)
            {
                Result.ExitCode = (int)REST.StatusCode;
            }
            else
            {
                Result.ExitCode = RESTResult.GetInt32("ExitCode");
            }

            if (RESTResult.IsValid())
            {
                Result.Message = RESTResult.GetString("Message");
                Result.ID      = RESTResult.GetString("ID");
                Result.Count   = RESTResult.GetInt32("Count");
                Result.Data    = RESTResult.GetJsonElement("Data").ToObject <System.Text.Json.JsonElement>();
            }

            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.ExitCode = Result.ExitCode;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.Message  = Result.Message;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.Count    = Result.Count;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.ID       = Result.ID;

            return(Result);
        }
コード例 #3
0
        /// <summary>
        /// Perform the HTTP Request based on REST object information.
        /// </summary>
        /// <param name="REST">REST object that contains the HTTP Request information.</param>
        /// <param name="SkipAuthorizationHeader">Removes the Authentication Header before sending. The default value is false.</param>
        /// <returns>A OperationResult with JSON property Data.</returns>
        public static async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> > PerformRESTRequestAsync(SoftmakeAll.SDK.Communication.REST REST, System.Boolean SkipAuthorizationHeader = false)
        {
            if (REST == null)
            {
                return(null);
            }

            System.Boolean RemoveAuthorization = false;
            if ((!(SkipAuthorizationHeader)) && (REST.Headers != null) && (!(REST.Headers.ContainsKey("Authorization"))))
            {
                try
                {
                    await SoftmakeAll.SDK.Fluent.SDKContext.AuthenticateAsync();

                    REST.Headers.Add("Authorization", SoftmakeAll.SDK.Fluent.SDKContext.InMemoryCredentials.Authorization);
                    RemoveAuthorization = true;
                }
                catch { }
            }
            else if ((SkipAuthorizationHeader) && (REST.Headers != null) && (REST.Headers.ContainsKey("Authorization")))
            {
                REST.Headers.Remove("Authorization");
            }

            REST.URL = $"{SoftmakeAll.SDK.Fluent.SDKContext.APIBaseAddress}/API/{REST.URL}";
            System.Text.Json.JsonElement RESTResult = await REST.SendAsync();

            if (RemoveAuthorization)
            {
                REST.Headers.Remove("Authorization");
            }

            return(SoftmakeAll.SDK.Fluent.SDKContext.ProcessRESTRequestResult(REST, RESTResult));
        }