Beispiel #1
0
        public static async Task Run([OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log)
        {
            _globalLogger = log;

            //Input from VTFK
            var docToP360Request = context.GetInput <(DocToP360Request DocToP360Request, string archeoTransGuid)>();

            PrivatePersonLookupRequest privatePersonLookupRequest = (PrivatePersonLookupRequest)docToP360Request.DocToP360Request;

            //Check if the personalIdNumber exsits in P360
            if (!await context.CallActivityAsync <bool>("DoesPersonExsist", (privatePersonLookupRequest, docToP360Request.archeoTransGuid)))
            {
                //if not, create a user with given input
                PrivatePersonSyncRequest privatePersonSyncRequest = (PrivatePersonSyncRequest)docToP360Request.DocToP360Request;

                await context.CallActivityAsync("CreatePrivatePerson", (privatePersonSyncRequest, docToP360Request.archeoTransGuid));
            }

            //Checks if d exists with given Initials
            EnterpriseDepartmentLookupRequest enterpriseDepartmentLookupRequest = (EnterpriseDepartmentLookupRequest)docToP360Request.DocToP360Request.parameter;

            //Gets the Recno from GetEnterprise
            var recNO = await context.CallActivityAsync <int>("GetEnterPriseRecno", (enterpriseDepartmentLookupRequest, docToP360Request.archeoTransGuid));

            //Sends GetEnterprise recno to CreateCase
            CreateCaseRequest createCaseRequest = (CreateCaseRequest)(docToP360Request.DocToP360Request, recNO);

            createCaseRequest.parameter.ResponsibleEnterpriseRecno = recNO;

            //Stores CaseNumber from CreateCase
            var caseNumber = await context.CallActivityAsync <string>("CreateCase", (createCaseRequest, docToP360Request.archeoTransGuid));

            //Creates document with given parameters, CaseNumber from CreateCase and Recno from GetEnterprise
            CreateDocumentRequest createDocumentRequest = (CreateDocumentRequest)(docToP360Request.DocToP360Request, caseNumber, recNO);

            CreateDocumentResponse createDocumentResponse = await context.CallActivityAsync <CreateDocumentResponse>("CreateDocument", (createDocumentRequest, docToP360Request.archeoTransGuid));

            //Updates the case with created CaseNumber
            UpdateCaseRequest updateCaseRequest = (UpdateCaseRequest)(docToP360Request.DocToP360Request, caseNumber);

            UpdateCaseResponse UpdateCaseResponse = await context.CallActivityAsync <UpdateCaseResponse>("UpdateCase", (updateCaseRequest, docToP360Request.archeoTransGuid));
        }
        //GetEnterprise - Gets Recno for a department with given Initials parameter from input
        public static async Task <EnterpriseDepartmentLookupResponse> GetEnterpriseRecno(EnterpriseDepartmentLookupRequest enterpriseDepartmentLookupRequest, string transactionId)
        {
            ArcheoLogger ArchLogger = new ArcheoLogger(null, new ArcheoConfiguration()
            {
                ApiKey = _ArchKey
            });

            try
            {
                //Logs the request
                ArchLogger.Log(
                    Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(enterpriseDepartmentLookupRequest)),
                    "Request to GetEnterprise",
                    "EnterpriseDepartmentLookupRequest.Json",
                    transactionId: transactionId,
                    transactionType: "DocumentToP360",
                    status: "Success",
                    processed: DateTime.UtcNow);

                //Json serializer
                var stringContent          = new StringContent(JsonConvert.SerializeObject(enterpriseDepartmentLookupRequest), Encoding.UTF8, "application/json");
                HttpResponseMessage result = await newClient.PostAsync(_BaseUrl + "/ContactService/GetEnterprises?authKey=" + _ApiAuthKey, stringContent);

                if (result.IsSuccessStatusCode)
                {
                    //Read Server Response
                    var responseData = await result.Content.ReadAsAsync <EnterpriseDepartmentLookupResponse>();

                    //Logs the response
                    ArchLogger.Log(
                        Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(responseData)),
                        "Response from GetEnterprise",
                        "EnterpriseDepartmentLookupResponse.json",
                        transactionId: transactionId,
                        transactionType: "DocumentToP360",
                        status: "Success",
                        processed: DateTime.UtcNow);
                    return(responseData);
                }
                else
                {
                    //If server response isn't 200
                    ArchLogger.LogHttpFailure(
                        response: result,
                        transactionId: transactionId,
                        transactionType: "DocumentToP360",
                        status: "Error",
                        description: "Return code to https://360test.vtfk.no was NOT 200",
                        processed: DateTime.UtcNow);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                //logs Exception
                ArchLogger.LogException(ex, "Error during GetEnterprise execution", transactionId: transactionId,
                                        transactionType: "DocumentToP360",
                                        status: "Error",
                                        logTimestamp: DateTime.UtcNow);
                return(null);
            }
            finally
            {
                //Sends log to Archeo
                await ArchLogger.SendLogs();
            }
        }