فهرست منبع

finish Connector.PS

Dalibor Votruba 4 سال پیش
والد
کامیت
91a1f44482

+ 0 - 8
AppServer/Connector.PS/Class1.cs

@@ -1,8 +0,0 @@
-using System;
-
-namespace Connector.PS
-{
-    public class Class1
-    {
-    }
-}

+ 74 - 0
AppServer/Connector.PS/Connection.cs

@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading.Tasks;
+using BO.AppServer.Metadata.Dto;
+using BO.AppServer.Metadata.Enums;
+using BO.Connector;
+using Quadarax.Foundation.Core.Data.Interface.Entity.Dto;
+using Quadarax.Foundation.Core.Logging;
+
+namespace Connector.PS
+{
+    public class Connection : AbstractConnection
+    {
+        #region *** Private fields ***
+        protected override string ApiName => "PS";
+        private string _psIdentifier;
+        #endregion
+
+
+        #region *** Constructor ***
+        public Connection(Uri uriApiBase, TimeSpan timeout,string psIdentifier, ILogHandler log = null, bool isDumpContentEnabled = false) : base(uriApiBase, timeout, log, isDumpContentEnabled)
+        {
+            if (string.IsNullOrEmpty(psIdentifier))
+                throw new ArgumentNullException(nameof(psIdentifier));
+            _psIdentifier = psIdentifier;
+        }
+        #endregion
+
+        #region *** Public operations ***
+
+        public async Task<IEnumerable<DocumentRDto>> GetDocumentsAsync(DocumentsScopeEnums scope)
+        {
+            if (!(scope == DocumentsScopeEnums.Pending || scope == DocumentsScopeEnums.Working))
+                throw new ArgumentOutOfRangeException(
+                    $"Document list scope value must be '{DocumentsScopeEnums.Working}' or '{DocumentsScopeEnums.Pending}' int this context.");
+            var result = await CallRequestAsync<ResultsValueDto<DocumentRDto>>($"{Ticket}/{_psIdentifier}/documents/{scope}", RestCallTypeEnum.Get);
+            return result.Values;
+        }
+
+        public async Task<DocumentStatusEnum> GetDocumentStateAsync(long documentId)
+        {
+            var result = await CallRequestAsync<ResultValueDto<PingDto>>($"{Ticket}/{_psIdentifier}/document/{documentId}", RestCallTypeEnum.Get);
+            return Enum.Parse<DocumentStatusEnum>(result.Value.Status);
+
+        }
+
+        public async Task<DocumentStatusEnum> SetDocumentStateAsync(long documentId, DocumentStatusEnum status)
+        {
+            var result = await CallRequestAsync<ResultValueDto<PingDto>>($"{Ticket}/{_psIdentifier}/document/{documentId}", RestCallTypeEnum.Put,new PingDto(){Status = status.ToString()});
+            return Enum.Parse<DocumentStatusEnum>(result.Value.Status);
+
+        }
+
+        public async Task<Stream> GetDocumentContentAsync(long artifactId)
+        {
+            var result = await CallGetStreamAsync($"{Ticket}/{_psIdentifier}/artifact/{artifactId}");
+            return result;
+        }
+        #endregion
+
+
+        #region *** Private operations and overrides ***
+        protected override void OnOpening()
+        {
+            base.OnOpening();
+            var result = Task.Run(() =>  CallRequestAsync<ResultPlain>($"{Ticket}/register", RestCallTypeEnum.Post, new PingDto(){Status = _psIdentifier}));
+            if (!result.Result.IsSuccess)
+                throw result.Result.ToAggregateException();
+            Log(LogSeverityEnum.Info,$"Process server '{_psIdentifier}' is registered.");
+        }
+        #endregion
+    }
+}

+ 4 - 0
AppServer/Connector.PS/Connector.PS.csproj

@@ -8,4 +8,8 @@
     <DelaySign>false</DelaySign>
   </PropertyGroup>
 
+  <ItemGroup>
+    <ProjectReference Include="..\Connector\Connector.csproj" />
+  </ItemGroup>
+
 </Project>

+ 23 - 3
AppServer/Connector/AbstractConnection.cs

@@ -1,9 +1,9 @@
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.IO.Abstractions;
 using System.Net.Http;
 using System.Net.Http.Headers;
-using System.Text.Json;
 using System.Threading.Tasks;
 using BO.AppServer.Metadata.Dto;
 using Quadarax.Foundation.Core.Data.Interface;
@@ -54,9 +54,11 @@ namespace BO.Connector
             _client = CreateClient();
             InitTicket(magicKey);
             Login(userName, userPassword);
+            OnOpening();
             Log(LogSeverityEnum.Debug, $"Connector '{ApiName}' open for user '{userName}' with timeout setting {_timeout}.");
         }
 
+
         public void Close()
         {
             _client?.CancelPendingRequests();
@@ -138,7 +140,23 @@ namespace BO.Connector
             return result;
         }
 
-        protected async Task<TResult> CallRequestAsync<TResult>(string relativeUrlApiCall,RestCallTypeEnum method, IDto data = null,IDictionary<string,string> headerAttributes = null, bool silent = false) where TResult : ResultDto
+        protected async Task<Stream> CallGetStreamAsync(string relativeUrlApiCall,
+            IDictionary<string, string> headerAttributes = null, bool silent = false)
+        {
+            Log(LogSeverityEnum.Trace, $"Calling REST API GET STREAM {_uriApiBase.AbsoluteUri + relativeUrlApiCall}");
+            if (headerAttributes != null)
+            {
+                foreach (var key in headerAttributes.Keys)
+                {
+                    _client.DefaultRequestHeaders.Remove(key);
+                    _client.DefaultRequestHeaders.Add(key,headerAttributes[key]);
+                }
+            }
+            return await _client.GetStreamAsync(relativeUrlApiCall);
+        }
+
+        protected async Task<TResult> CallRequestAsync<TResult>(string relativeUrlApiCall,RestCallTypeEnum method, IDto data = null,IDictionary<string,string> headerAttributes = null, bool silent = false) 
+            where TResult : ResultDto
         {
             if (data == null)
                 if(method != RestCallTypeEnum.Get && method != RestCallTypeEnum.GetStream && method != RestCallTypeEnum.Delete)
@@ -219,7 +237,9 @@ namespace BO.Connector
 
             throw new AggregateException(excps);
         }
-
+        protected virtual void OnOpening()
+        {
+        }
 
         private HttpClient CreateClient()
         {

+ 15 - 0
versions.txt

@@ -0,0 +1,15 @@
+Versions scope list
+-------------------
+Last updated: 14.08.2021
+
+
+Version		Status		Scope
+0.0.1		InProgress	AppServer,Console,ProcessServer,Houdini pipeline integrated
+						Basic pipeline feature
+						Without Invoicing, Without Web App
+0.0.2		Pending		Web App
+						Houdini simple billing plan
+						Without invoicing
+0.0.3		Pending		Invoicing
+						Houdini alternative billing plans
+0.0.4		Planning