コード例 #1
0
        //CreateDocument - Gets document from BLOB storage and sends it to P360
        public static async Task <CreateDocumentResponse> CreateDocument(CreateDocumentRequest createDocumentRequest, string transactionId)
        {
            ArcheoLogger ArchLogger = new ArcheoLogger(null, new ArcheoConfiguration()
            {
                ApiKey = _ArchKey
            });

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

                //Get the document for given case. Document from BLOB-URL
                string filepath = createDocumentRequest.parameter.URL;
                var    response = await newClient.GetAsync(createDocumentRequest.parameter.URL);

                System.IO.MemoryStream stream = (System.IO.MemoryStream) await response.Content.ReadAsStreamAsync();


                //Converts the file to ByteArray
                byte[] bytes = stream.ToArray();

                //If List is empty, create a new one and add the following parameters
                if (createDocumentRequest.parameter.Files == null)
                {
                    createDocumentRequest.parameter.Files = new List <File>();
                }
                createDocumentRequest.parameter.Files.Add(new File()
                {
                    Data   = bytes,
                    Format = "pdf",
                    Title  = createDocumentRequest.parameter.Title,
                    URL    = createDocumentRequest.parameter.URL,
                    Status = createDocumentRequest.parameter.StatusFile
                });

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

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

                    //Logs the response
                    ArchLogger.Log(
                        Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(responseData)),
                        "Response from CreateDocument",
                        "CreateDocumentResponse.json",
                        transactionId: transactionId,
                        transactionType: "DocumentToP360",
                        status: "Success",
                        processed: DateTime.UtcNow);
                    return(responseData);
                }
                else
                {
                    //logs exception
                    ArchLogger.LogHttpFailure(
                        response: result,
                        transactionId: transactionId,
                        transactionType: "DocumentToP360",
                        status: "Error",
                        description: "Return code to https://360.vtfk.no was NOT 200",
                        processed: DateTime.UtcNow);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                //logs exception
                ArchLogger.LogException(ex, "Error during UpdateCase execution", transactionId: transactionId,
                                        transactionType: "DocumentToP360",
                                        status: "Error",
                                        logTimestamp: DateTime.UtcNow);
                return(null);
            }
            finally
            {
                //Sends log to Archeo
                await ArchLogger.SendLogs();
            }
        }
コード例 #2
0
        //GetPrivatePersons - Checks if a person exist with given PersonalIdNumber from input
        public static async Task <PrivatePersonLookupResponse> GetPrivatePerson(PrivatePersonLookupRequest privatePersonLookupRequest, string transactionId)
        {
            ArcheoLogger ArchLogger = new ArcheoLogger(null, new ArcheoConfiguration()
            {
                ApiKey = _ArchKey
            });

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

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

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

                    //Logs response from P360
                    ArchLogger.Log(
                        Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(responseData)),
                        "Response from GetPrivatePersons",
                        "PrivatePersonLookupResponse.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://360.vtfk.no was NOT 200",
                        processed: DateTime.UtcNow);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                //logs Exception
                ArchLogger.LogException(ex, "Error during GetPrivatePersons execution", transactionId: transactionId,
                                        transactionType: "DocumentToP360",
                                        status: "Error",
                                        logTimestamp: DateTime.UtcNow);
                return(null);
            }
            finally
            {
                //Sends all logs to Archeo
                await ArchLogger.SendLogs();
            }
        }