├── README.md ├── inbound └── README.md ├── outbound ├── README.md ├── Batch │ ├── AltinnSimulator │ │ ├── Run.bat │ │ ├── Service References │ │ │ └── OnlineBatchReceiver │ │ │ │ ├── AltinnSimulator.OnlineBatchReceiver.HelloWorldResponse.datasource │ │ │ │ ├── OnlineBatchReceiverSoap.disco │ │ │ │ ├── AltinnSimulator.OnlineBatchReceiver.ReceiveOnlineBatchExternalAttachmentResponse.datasource │ │ │ │ ├── configuration.svcinfo │ │ │ │ ├── Reference.svcmap │ │ │ │ └── OnlineBatchReceiverSoap.wsdl │ │ ├── App.config │ │ ├── AltinnSimulator.sln │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── Arguments.cs │ │ ├── TestData │ │ │ └── Inn1.xml │ │ ├── AltinnSimulator.csproj │ │ └── Program.cs │ ├── AltinnReceiverWithXmlSerialization │ │ ├── OnlineBatchReceiver │ │ │ ├── Global.asax │ │ │ ├── packages.config │ │ │ ├── OnlineBatchReceiverSoap.asmx │ │ │ ├── xsd │ │ │ │ ├── output.config │ │ │ │ ├── OnlineBatchReceipt.xsd │ │ │ │ ├── FormTaskSkjema.xsd │ │ │ │ ├── OnlineBatchReciever.wsdl │ │ │ │ ├── genericbatch.2013.06.xsd │ │ │ │ └── OnlineBatchReceiver.cs │ │ │ ├── Global.asax.cs │ │ │ ├── Web.Debug.config │ │ │ ├── Web.Release.config │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── Web.config │ │ │ ├── Model │ │ │ │ ├── FormTaskSkjema.cs │ │ │ │ └── OnlineBatchReceipt.cs │ │ │ ├── Utils │ │ │ │ ├── XmlUtils.cs │ │ │ │ └── FileUtil.cs │ │ │ ├── OnlineBatchReceiverSoap.asmx.cs │ │ │ └── OnlineBatchReceiver.csproj │ │ ├── OnlineBatchRecieverTest │ │ │ ├── packages.config │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── OnlineBatchRecieverTest.csproj │ │ │ └── OnlineBatchReceiverSoapTest.cs │ │ ├── README.md │ │ └── AltinnReceiver.sln │ ├── AltinnBatchReceiverService │ │ ├── AltinnBatchReceiverService │ │ │ ├── OnlineBatchReceiverSoap.asmx │ │ │ ├── packages.config │ │ │ ├── Resources │ │ │ │ ├── Response.cs │ │ │ │ └── Payload.cs │ │ │ ├── Web.Debug.config │ │ │ ├── Web.Release.config │ │ │ ├── Properties │ │ │ │ └── AssemblyInfo.cs │ │ │ ├── Web.config │ │ │ ├── OnlineBatchReceiverInterfaces.cs │ │ │ ├── Utils │ │ │ │ ├── SchemaValidator.cs │ │ │ │ └── Logger.cs │ │ │ ├── Schema │ │ │ │ ├── OnlineBatchReceipt.xsd │ │ │ │ └── genericbatch.2013.06.xsd │ │ │ ├── AltinnBatchReceiverService.csproj │ │ │ └── OnlineBatchReceiverSoap.asmx.cs │ │ └── AltinnBatchReceiverService.sln │ └── README.md └── DownloadQueue │ ├── README.md │ ├── DownloadQueueExampleClient │ ├── Service References │ │ ├── DownloadQueueService │ │ │ ├── DownloadQueueExampleClient.DownloadQueueService.TestResponse.datasource │ │ │ ├── DownloadQueueExampleClient.DownloadQueueService.ArchivedFormTaskDQBE.datasource │ │ │ ├── DownloadQueueExampleClient.DownloadQueueService.DownloadQueueItemBEList.datasource │ │ │ ├── DownloadQueueExampleClient.DownloadQueueService.GetFormSetPdfBasicResponse.datasource │ │ │ ├── configuration.svcinfo │ │ │ └── Reference.svcmap │ │ └── ServiceOwnerArchiveExternalStreamed │ │ │ ├── DownloadQueueExampleClient.ServiceOwnerArchiveExternalStreamed.TestResponse.datasource │ │ │ ├── Reference.svcmap │ │ │ └── configuration.svcinfo │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── App.config │ ├── Utils │ │ ├── FileSaver.cs │ │ └── Logger.cs │ ├── DownloadQueueExampleClient.csproj │ └── DownloadQueueHandler.cs │ └── DownloadQueueExampleClient.sln └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | # agencysystem-dotnet 2 | -------------------------------------------------------------------------------- /inbound/README.md: -------------------------------------------------------------------------------- 1 | # Agency System .Net Inbound 2 | 3 | ... 4 | -------------------------------------------------------------------------------- /outbound/README.md: -------------------------------------------------------------------------------- 1 | # Agency System .Net Outbound 2 | 3 | ... 4 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Run.bat: -------------------------------------------------------------------------------- 1 | bin\debug\AltinnSimulator help 2 | bin\debug\AltinnSimulator folder TestData\ 3 | pause -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="OnlineBatchReceiver.Global" Language="C#" %> 2 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchRecieverTest/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/OnlineBatchReceiverSoap.asmx: -------------------------------------------------------------------------------- 1 | <%@ WebService Language="C#" CodeBehind="OnlineBatchReceiverSoap.asmx.cs" Class="OnlineBatchReceiver.OnlineBatchReceiverSoap" %> 2 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/OnlineBatchReceiverSoap.asmx: -------------------------------------------------------------------------------- 1 | <%@ WebService Language="C#" CodeBehind="OnlineBatchReceiverSoap.asmx.cs" Class="AltinnBatchReceiverService.OnlineBatchReceiverSoap" %> 2 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/README.md: -------------------------------------------------------------------------------- 1 | # Download Queue Sample 2 | 3 | This is a console application as a sample / reference application for fetching download queue items. 4 | This saves the PDF with attachments to files. 5 | The configuration defines authentication, servie and the inbox (path) where downloaded items should be saved. 6 | The application generates a directory for each downoloaded schema and saves the pdf and attachments to that folder. 7 | The name of the folder and the pdf file is the same as the Archive reference. 8 | 9 | See source files for more detailed documentation. 10 | 11 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/README.md: -------------------------------------------------------------------------------- 1 | # A sample implementation of OnlineBatchReceiver 2 | ## ReceiveOnlineBatchExternalAttachment 3 | 4 | ### AltinnReceiverWithXmlSerialization 5 | A service which receives form requests from Altinn. 6 | 7 | Contains a SoapUI test project with example xml requests. 8 | 9 | Uses log4net, and creates a .log file in the OnlineBatchReceiver folder. 10 | 11 | Unit tests for xml validation and authentication are avalable. Implemented with NUnit. 12 | 13 | 14 | * Make sure you have .NET 4.5.2 installed 15 | * Open the solution in Visual Studio 2015 or later. 16 | * Run 17 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Service References/OnlineBatchReceiver/AltinnSimulator.OnlineBatchReceiver.HelloWorldResponse.datasource: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | AltinnSimulator.OnlineBatchReceiver.HelloWorldResponse, Service References.OnlineBatchReceiver.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/DownloadQueueService/DownloadQueueExampleClient.DownloadQueueService.TestResponse.datasource: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | DownloadQueueExampleClient.DownloadQueueService.TestResponse, Service References.DownloadQueueService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Service References/OnlineBatchReceiver/OnlineBatchReceiverSoap.disco: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/DownloadQueueService/DownloadQueueExampleClient.DownloadQueueService.ArchivedFormTaskDQBE.datasource: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | DownloadQueueExampleClient.DownloadQueueService.ArchivedFormTaskDQBE, Service References.DownloadQueueService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/DownloadQueueService/DownloadQueueExampleClient.DownloadQueueService.DownloadQueueItemBEList.datasource: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | DownloadQueueExampleClient.DownloadQueueService.DownloadQueueItemBEList, Service References.DownloadQueueService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/DownloadQueueService/DownloadQueueExampleClient.DownloadQueueService.GetFormSetPdfBasicResponse.datasource: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | DownloadQueueExampleClient.DownloadQueueService.GetFormSetPdfBasicResponse, Service References.DownloadQueueService.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Service References/OnlineBatchReceiver/AltinnSimulator.OnlineBatchReceiver.ReceiveOnlineBatchExternalAttachmentResponse.datasource: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | AltinnSimulator.OnlineBatchReceiver.ReceiveOnlineBatchExternalAttachmentResponse, Service References.OnlineBatchReceiver.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/ServiceOwnerArchiveExternalStreamed/DownloadQueueExampleClient.ServiceOwnerArchiveExternalStreamed.TestResponse.datasource: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | DownloadQueueExampleClient.ServiceOwnerArchiveExternalStreamed.TestResponse, Service References.ServiceOwnerArchiveExternalStreamed.Reference.cs.dll, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 10 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Resources/Response.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Xml; 3 | using System.Xml.Serialization; 4 | 5 | namespace AltinnBatchReceiverService.Resources 6 | { 7 | /// 8 | /// The response object 9 | /// 10 | [XmlRoot(ElementName = "OnlineBatchReceipt")] 11 | public class Response 12 | { 13 | [XmlElement(ElementName = "Result")] 14 | public Result Result { get; set; } 15 | 16 | public static string SerializeAsXml(Response response) 17 | { 18 | var stringWriter = new StringWriter(); 19 | XmlSerializer ser = new XmlSerializer(typeof(Response)); 20 | ser.Serialize(stringWriter, response); 21 | return stringWriter.ToString(); 22 | } 23 | } 24 | 25 | 26 | public class Result 27 | { 28 | [XmlAttribute(AttributeName = "resultCode")] 29 | public string Code { get; set; } 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/AltinnSimulator.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AltinnSimulator", "AltinnSimulator.csproj", "{05E8ADA9-D8F9-473A-BD36-F91E5E235E18}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {05E8ADA9-D8F9-473A-BD36-F91E5E235E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {05E8ADA9-D8F9-473A-BD36-F91E5E235E18}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {05E8ADA9-D8F9-473A-BD36-F91E5E235E18}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {05E8ADA9-D8F9-473A-BD36-F91E5E235E18}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DownloadQueueExampleClient", "DownloadQueueExampleClient\DownloadQueueExampleClient.csproj", "{D89A955E-2007-4F7B-9B5F-4D1E5BC9625B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {D89A955E-2007-4F7B-9B5F-4D1E5BC9625B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D89A955E-2007-4F7B-9B5F-4D1E5BC9625B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D89A955E-2007-4F7B-9B5F-4D1E5BC9625B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D89A955E-2007-4F7B-9B5F-4D1E5BC9625B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AltinnBatchReceiverService", "AltinnBatchReceiverService\AltinnBatchReceiverService.csproj", "{0D0955CF-1559-43AB-98C4-20B63800D0D3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0D0955CF-1559-43AB-98C4-20B63800D0D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0D0955CF-1559-43AB-98C4-20B63800D0D3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0D0955CF-1559-43AB-98C4-20B63800D0D3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0D0955CF-1559-43AB-98C4-20B63800D0D3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/xsd/output.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using log4net; 5 | 6 | namespace OnlineBatchReceiver 7 | { 8 | public class Global : System.Web.HttpApplication 9 | { 10 | 11 | protected void Application_Start(object sender, EventArgs e) 12 | { 13 | var uri = new UriBuilder(Assembly.GetExecutingAssembly().Location).Path; 14 | GlobalContext.Properties["LogFileName"] = Path.GetDirectoryName(Uri.UnescapeDataString(uri)) + "\\Debug.log"; //log file path 15 | log4net.Config.XmlConfigurator.Configure(); 16 | } 17 | 18 | protected void Session_Start(object sender, EventArgs e) 19 | { 20 | 21 | } 22 | 23 | protected void Application_BeginRequest(object sender, EventArgs e) 24 | { 25 | 26 | } 27 | 28 | protected void Application_AuthenticateRequest(object sender, EventArgs e) 29 | { 30 | 31 | } 32 | 33 | protected void Application_Error(object sender, EventArgs e) 34 | { 35 | 36 | } 37 | 38 | protected void Session_End(object sender, EventArgs e) 39 | { 40 | 41 | } 42 | 43 | protected void Application_End(object sender, EventArgs e) 44 | { 45 | 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using DownloadQueueExampleClient.DownloadQueueService; 3 | using System; 4 | using System.IO; 5 | using System.Configuration; 6 | using System.Reflection; 7 | 8 | namespace DownloadQueueExampleClient 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | string username = ConfigurationManager.AppSettings["username"]; 15 | string password = ConfigurationManager.AppSettings["password"]; 16 | string servicecode = ConfigurationManager.AppSettings["servicecode"]; 17 | string maxdownloadstr = ConfigurationManager.AppSettings["maxdownload"]; 18 | string langidstr = ConfigurationManager.AppSettings["languageid"]; 19 | 20 | int maxdownload; 21 | if (!int.TryParse(maxdownloadstr, out maxdownload)) 22 | maxdownload = 10; 23 | 24 | int langid; 25 | if (!int.TryParse(langidstr, out langid)) 26 | maxdownload = 10; 27 | 28 | Console.WriteLine($"{DateTime.Now} - DownloadQueueClient started..."); 29 | 30 | var downloadQueueProcessor = new DownloadQueueHandler(username, password, servicecode); 31 | downloadQueueProcessor.Execute(maxdownload, langid); 32 | 33 | Console.WriteLine($"{DateTime.Now} - DownloadQueueClient completed!"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Mottak")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Capgemini")] 12 | [assembly: AssemblyProduct("Mottak")] 13 | [assembly: AssemblyCopyright("Copyright © Capgemini 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0d0955cf-1559-43ab-98c4-20b63800d0d3")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("DownloadQueueExampleClient")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("DownloadQueueExampleClient")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("d89a955e-2007-4f7b-9b5f-4d1e5bc9625b")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("client")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Capgemini")] 12 | [assembly: AssemblyProduct("client")] 13 | [assembly: AssemblyCopyright("Copyright © Capgemini 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("05e8ada9-d8f9-473a-bd36-f91e5e235e18")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Mottak")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Mottak")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c5f20aed-8f58-46b7-a316-24723f262da3")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Service References/OnlineBatchReceiver/configuration.svcinfo: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchRecieverTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("OnlineBatchRecieverTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("OnlineBatchRecieverTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("372255fc-e447-4f78-832f-89f5f0ce31e4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/AltinnReceiver.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnlineBatchReceiver", "OnlineBatchReceiver\OnlineBatchReceiver.csproj", "{FA4DEDE9-BB7F-40E4-8122-2F7FB9613A2B}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnlineBatchRecieverTest", "OnlineBatchRecieverTest\OnlineBatchRecieverTest.csproj", "{372255FC-E447-4F78-832F-89F5F0CE31E4}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {FA4DEDE9-BB7F-40E4-8122-2F7FB9613A2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {FA4DEDE9-BB7F-40E4-8122-2F7FB9613A2B}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {FA4DEDE9-BB7F-40E4-8122-2F7FB9613A2B}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {FA4DEDE9-BB7F-40E4-8122-2F7FB9613A2B}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {372255FC-E447-4F78-832F-89F5F0CE31E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {372255FC-E447-4F78-832F-89F5F0CE31E4}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {372255FC-E447-4F78-832F-89F5F0CE31E4}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {372255FC-E447-4F78-832F-89F5F0CE31E4}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /outbound/Batch/README.md: -------------------------------------------------------------------------------- 1 | # Altinn Batch Receiver Samples 2 | 3 | There are three solutions in this sample: 4 | * AltinnBatchReceiverService 5 | * AltinnReceiverWithXmlSerialization 6 | * AltinnSimulator 7 | 8 | ## AltinnBatchReceiverService 9 | This is the server which receives messages from Altinn. To test the server: 10 | 11 | * Make sure you have .NET 4.5.2 installed 12 | * Open the solution in Visual Studio 2015 or later. 13 | * Run 14 | 15 | Two folders will be created when running the test clinet - AltinnSimulator: 16 | * Log 17 | Contains log.txt 18 | * Inbox 19 | Contains the received messages 20 | 21 | The Service will also log to Windows Application Log. 22 | 23 | There is more documentation within the source files. 24 | 25 | ## AltinnReceiverWithXmlSerialization 26 | Another service which receives form requests from Altinn. 27 | 28 | Contains a SoapUI test project with example xml requests. 29 | 30 | Uses log4net, and creates a .log file in the OnlineBatchReceiver folder. 31 | 32 | Unit tests for xml validation and authentication are avalable. Implemented with NUnit. 33 | 34 | 35 | * Make sure you have .NET 4.5.2 installed 36 | * Open the solution in Visual Studio 2015 or later. 37 | * Run 38 | 39 | ## AltinnSimulator 40 | This console application simulates Altinn by fetching testdata and sending it to the AltinnBatchReceiverService. 41 | It fetches data from the Testdata folder. 42 | In order to run: 43 | 44 | * Make sure you have .NET 4.5.2 installed 45 | * Open the solution in Visual Studio 2015 or later. 46 | * Run the AltinnBatchReceiverService 47 | * Select Properties -> Debug, edit the Command Line: folder ..\\..\\Tesdata 48 | * Run the console application 49 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/OnlineBatchReceiverInterfaces.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.ComponentModel; 13 | using System.Diagnostics; 14 | using System.Web.Services; 15 | using System.Web.Services.Protocols; 16 | using System.Xml.Serialization; 17 | 18 | // 19 | // This source code was auto-generated by wsdl, Version=4.6.1055.0. 20 | // 21 | 22 | 23 | /// 24 | [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.1055.0")] 25 | [System.Web.Services.WebServiceBindingAttribute(Name="OnlineBatchReceiverSoap", Namespace="http://AltInn.no/webservices/")] 26 | public interface IOnlineBatchReceiverSoap { 27 | 28 | /// 29 | [System.Web.Services.WebMethodAttribute()] 30 | [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://AltInn.no/webservices/ReceiveOnlineBatchExternalAttachment", 31 | RequestNamespace="http://AltInn.no/webservices/", 32 | ResponseNamespace="http://AltInn.no/webservices/", 33 | Use=System.Web.Services.Description.SoapBindingUse.Literal, 34 | ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 35 | string ReceiveOnlineBatchExternalAttachment(string username, string passwd, string receiversReference, long sequenceNumber, string batch, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] byte[] attachments); 36 | } 37 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/DownloadQueueService/configuration.svcinfo: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/DownloadQueueService/Reference.svcmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | true 7 | 8 | false 9 | false 10 | false 11 | 12 | 13 | true 14 | Auto 15 | true 16 | true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Utils/SchemaValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml.Linq; 3 | using System.Xml.Schema; 4 | 5 | namespace AltinnBatchReceiverService.Utils 6 | { 7 | public static class SchemaValidator 8 | { 9 | /// 10 | /// This is a generic Schema verification method, which will verify any XML vs. the Schema. 11 | /// /// 12 | /// The XML to be verified 13 | /// File path to the XSD schema 14 | /// True if successful verification 15 | /// 16 | /// This could be optimized to build a SchemaSet once and reuse it. 17 | /// 18 | public static bool VerifyVsSchema(string xml, string xsdFilePath) 19 | { 20 | XDocument xdoc; 21 | 22 | try 23 | { 24 | xdoc = XDocument.Parse(xml); 25 | } 26 | catch (Exception ex) 27 | { 28 | Logger.Log(string.Format("Failed to parse Data XML: {0} : {1}", ex.Message, xml), true); 29 | return false; 30 | } 31 | var schema = new XmlSchemaSet(); 32 | 33 | try 34 | { 35 | schema.Add("", xsdFilePath); 36 | } 37 | catch (Exception ex) 38 | { 39 | Logger.Log(string.Format("Failed to load XSD Schema: {0} : {1}", ex.Message, xsdFilePath), true); 40 | return false; 41 | } 42 | 43 | Boolean result = true; 44 | xdoc.Validate(schema, (sender, e) => 45 | { 46 | result = false; 47 | Logger.Log(string.Format("Invalid Schema detected: {0} : {1}", e.Message, xml), true); 48 | }); 49 | 50 | return result; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/ServiceOwnerArchiveExternalStreamed/Reference.svcmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | true 7 | 8 | false 9 | false 10 | false 11 | 12 | 13 | true 14 | Auto 15 | true 16 | true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Resources/Payload.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Web; 7 | using System.Xml; 8 | using System.Xml.Serialization; 9 | 10 | namespace AltinnBatchReceiverService.Resources 11 | { 12 | 13 | /// 14 | /// We created a simple object to hold the received data. 15 | /// 16 | [XmlRoot] 17 | [Serializable] 18 | public class Payload 19 | { 20 | [XmlElement] 21 | public string Username { get; set; } 22 | [XmlElement] 23 | public string Password { get; set; } 24 | [XmlElement] 25 | public string ReceiverReference { get; set; } 26 | [XmlElement] 27 | public long SequenceNumber { get; set; } 28 | [XmlElement] 29 | public string Batch { get; set; } 30 | [XmlElement] 31 | public byte[] Attachments { get; set; } 32 | 33 | public override int GetHashCode() 34 | { 35 | string str = string.Format("{0}{1}{2}{3}", Username, ReceiverReference, SequenceNumber, Batch); 36 | return str.GetHashCode(); 37 | } 38 | 39 | public override bool Equals(object obj) 40 | { 41 | return GetHashCode() == ((Payload)obj).GetHashCode(); 42 | } 43 | 44 | /// 45 | /// Generates an XML string of the Payload object and saves it to the specifid path 46 | /// 47 | /// The object to serialize 48 | /// The path to store the XML 49 | public static void SerializeAsXml(Payload payload, string path) 50 | { 51 | XmlSerializer ser = new XmlSerializer(typeof(Payload)); 52 | TextWriter writer = new StreamWriter(path); 53 | ser.Serialize(writer, payload); 54 | writer.Close(); 55 | } 56 | 57 | } 58 | } -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Service References/OnlineBatchReceiver/Reference.svcmap: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | true 7 | 8 | false 9 | false 10 | false 11 | 12 | 13 | true 14 | Auto 15 | true 16 | true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Service References/ServiceOwnerArchiveExternalStreamed/configuration.svcinfo: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Schema/OnlineBatchReceipt.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Denne XSDen beskriver kvitteringen som skal returneres fra et mottakssystem etter å ha 8 | mottatt en online forsendelse fra Altinn. Kvitteringen begrenser seg til å kun 9 | beskrive selve mottaket av batchen, og det er ikke lagt opp til at kvitteringen skal 10 | inneholde informasjon vedrørende prosessering av selve batchen. 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Dette elementet har ett attributt resultCode som beskriver status på mottatt 19 | batch. Innholdet i Result-elementet er en valgfri streng. Denne blir ikke 20 | brukt programmatisk, men vil bli lest av driftspersonell i tilfelle feil. 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | De forskjellige resultatkodene som kan returneres fra mottaket. 38 | OK - Batch er mottatt OK. 39 | FAILED - Batch er ikke mottatt, eller det oppstod en feil i mottaket. Altinn 40 | kan forsøke forsendelse på ny. 41 | FAILED_DO_NOT_RETRY - Samme som FAILED, men Altinn skal ikke forsøke å sende batch på ny. 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/xsd/OnlineBatchReceipt.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Denne XSDen beskriver kvitteringen som skal returneres fra et mottakssystem etter å ha 8 | mottatt en online forsendelse fra Altinn. Kvitteringen begrenser seg til å kun 9 | beskrive selve mottaket av batchen, og det er ikke lagt opp til at kvitteringen skal 10 | inneholde informasjon vedrørende prosessering av selve batchen. 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Dette elementet har ett attributt resultCode som beskriver status på mottatt 19 | batch. Innholdet i Result-elementet er en valgfri streng. Denne blir ikke 20 | brukt programmatisk, men vil bli lest av driftspersonell i tilfelle feil. 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | De forskjellige resultatkodene som kan returneres fra mottaket. 38 | OK - Batch er mottatt OK. 39 | FAILED - Batch er ikke mottatt, eller det oppstod en feil i mottaket. Altinn 40 | kan forsøke forsendelse på ny. 41 | FAILED_DO_NOT_RETRY - Samme som FAILED, men Altinn skal ikke forsøke å sende batch på ny. 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/xsd/FormTaskSkjema.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 40 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Arguments.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AltinnSimulator 4 | { 5 | /// 6 | /// Class to decompose and hold the arguments. 7 | /// Arguments must be on format: command -name value -name value source, 8 | /// the first word must be a command, then a number of name value pair, where name starts with -, 9 | /// The value is optional. The names are always converted to lowercase. 10 | /// The source is any main parameter which applies to the command such as a folder name or file name. 11 | /// 12 | public class Arguments 13 | { 14 | private Dictionary _arguments = new Dictionary(); 15 | 16 | /// 17 | /// The command is the first argument, always fetched as lowercase 18 | /// 19 | public string Command { get; private set; } 20 | 21 | /// 22 | /// The main parameter (not initiated with -nm), always fetched as lowercase 23 | /// 24 | public string Source { get; private set; } 25 | 26 | /// 27 | /// Constructor 28 | /// 29 | /// The arguments to analyze 30 | public Arguments(string[] args) 31 | { 32 | Decompose(args); 33 | } 34 | 35 | /// 36 | /// Fetches one argument given the name 37 | /// 38 | /// 39 | /// The found argument or null if not found 40 | public string this[string name] 41 | { 42 | get 43 | { 44 | string val = null; 45 | try 46 | { 47 | val = _arguments[name]; 48 | } 49 | catch 50 | { } 51 | return val; 52 | } 53 | } 54 | 55 | 56 | private void Decompose(string[] args) 57 | { 58 | if (args.Length > 0) 59 | { 60 | Command = args[0].ToLower(); 61 | int inx = 1; 62 | while (inx < args.Length) 63 | { 64 | if (args[inx].StartsWith("-")) 65 | { 66 | string nm = args[inx].Substring(1).ToLower(); ; 67 | inx++; 68 | if (inx < args.Length && !args[inx].StartsWith("-")) 69 | { 70 | _arguments.Add(nm, args[inx++]); 71 | } 72 | else 73 | { 74 | _arguments.Add(nm, ""); 75 | } 76 | } 77 | else 78 | { 79 | Source = args[inx].ToLower(); 80 | inx++; 81 | } 82 | } 83 | } 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Utils/FileSaver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace DownloadQueueExampleClient.Utils 11 | { 12 | 13 | /// 14 | /// A generic file saver using the app config inbox and storing files (string or byte[]) relative to the inbox. 15 | /// 16 | public static class FileSaver 17 | { 18 | 19 | /// 20 | /// This property is fetched from Web Config (key = inbox), see Web.Config file. 21 | /// This is where the messages will be saved. 22 | /// 23 | private static string inboxDirPath = null; 24 | 25 | 26 | /// 27 | /// Saves content (text or byte[]) to a file relative to the inbox app configuration. 28 | /// 29 | /// The file content to be saved. This must be either a string or byte[] 30 | /// The folder where file will be saved as a subfolder to inbox. If null, the file is saved on inbox folder 31 | /// The name of the file with or without extension 32 | /// An optional extension 33 | public static void SaveFile(object file, string folder, string filename, string extension = null) 34 | { 35 | GetConfiguration(); 36 | string folderPath; 37 | 38 | if (!string.IsNullOrEmpty(folder)) 39 | { 40 | folderPath = Path.Combine(inboxDirPath, folder); 41 | if (!Directory.Exists(folderPath)) 42 | Directory.CreateDirectory(folderPath); 43 | } 44 | else 45 | folderPath = inboxDirPath; 46 | 47 | string filePath = Path.Combine(folderPath, filename); 48 | 49 | if (!string.IsNullOrEmpty(extension)) 50 | { 51 | if (!extension.StartsWith(".")) 52 | filePath += "."; 53 | filePath += extension; 54 | } 55 | 56 | if (file is byte[]) 57 | File.WriteAllBytes(filePath, (byte[])file); 58 | else if (file is string) 59 | File.WriteAllText(filePath, (string)file); 60 | } 61 | 62 | 63 | private static void GetConfiguration() 64 | { 65 | if (inboxDirPath != null) 66 | return; 67 | try 68 | { 69 | inboxDirPath = ConfigurationManager.AppSettings["inbox"]; 70 | } 71 | catch 72 | { 73 | inboxDirPath = "/inbox"; 74 | } 75 | 76 | if (!inboxDirPath.Contains(":")) 77 | { 78 | string curpath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)); 79 | inboxDirPath = Path.Combine(curpath, inboxDirPath); 80 | } 81 | 82 | if (!Directory.Exists(inboxDirPath)) 83 | Directory.CreateDirectory(inboxDirPath); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchRecieverTest/OnlineBatchRecieverTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {372255FC-E447-4F78-832F-89F5F0CE31E4} 8 | Library 9 | Properties 10 | OnlineBatchRecieverTest 11 | OnlineBatchRecieverTest 12 | v4.5.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll 35 | True 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | {c5f20aed-8f58-46b7-a316-24723f262da3} 57 | OnlineBatchReceiver 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Model/FormTaskSkjema.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System.Xml.Serialization; 12 | 13 | // 14 | // This source code was auto-generated by xsd, Version=4.6.1055.0. 15 | // 16 | 17 | 18 | /// 19 | [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")] 20 | [System.SerializableAttribute()] 21 | [System.Diagnostics.DebuggerStepThroughAttribute()] 22 | [System.ComponentModel.DesignerCategoryAttribute("code")] 23 | [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://seres.no/xsd/Kursdomene/LånesøknadJME_M/2011")] 24 | [System.Xml.Serialization.XmlRootAttribute("melding", Namespace="http://seres.no/xsd/Kursdomene/LånesøknadJME_M/2011", IsNullable=false)] 25 | public partial class LånesøknadJME_M { 26 | 27 | private Innsender innsenderField; 28 | 29 | private System.Xml.XmlAttribute[] anyAttrField; 30 | 31 | /// 32 | public Innsender Innsender { 33 | get { 34 | return this.innsenderField; 35 | } 36 | set { 37 | this.innsenderField = value; 38 | } 39 | } 40 | 41 | /// 42 | [System.Xml.Serialization.XmlAnyAttributeAttribute()] 43 | public System.Xml.XmlAttribute[] AnyAttr { 44 | get { 45 | return this.anyAttrField; 46 | } 47 | set { 48 | this.anyAttrField = value; 49 | } 50 | } 51 | } 52 | 53 | /// 54 | [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")] 55 | [System.SerializableAttribute()] 56 | [System.Diagnostics.DebuggerStepThroughAttribute()] 57 | [System.ComponentModel.DesignerCategoryAttribute("code")] 58 | [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://seres.no/xsd/Kursdomene/LånesøknadJME_M/2011")] 59 | public partial class Innsender { 60 | 61 | private Søker søkerField; 62 | 63 | /// 64 | public Søker søker { 65 | get { 66 | return this.søkerField; 67 | } 68 | set { 69 | this.søkerField = value; 70 | } 71 | } 72 | } 73 | 74 | /// 75 | [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")] 76 | [System.SerializableAttribute()] 77 | [System.Diagnostics.DebuggerStepThroughAttribute()] 78 | [System.ComponentModel.DesignerCategoryAttribute("code")] 79 | [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://seres.no/xsd/Kursdomene/LånesøknadJME_M/2011")] 80 | public partial class Søker { 81 | 82 | private string fødselsnummerField; 83 | 84 | private string navnField; 85 | 86 | /// 87 | public string fødselsnummer { 88 | get { 89 | return this.fødselsnummerField; 90 | } 91 | set { 92 | this.fødselsnummerField = value; 93 | } 94 | } 95 | 96 | /// 97 | [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] 98 | public string navn { 99 | get { 100 | return this.navnField; 101 | } 102 | set { 103 | this.navnField = value; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Model/OnlineBatchReceipt.cs: -------------------------------------------------------------------------------- 1 | // 2 | // This source code was auto-generated by xsd, Version=4.6.81.0. 3 | // 4 | 5 | using System; 6 | 7 | namespace OnlineBatchReceiver 8 | { 9 | //------------------------------------------------------------------------------ 10 | // 11 | // This code was generated by a tool. 12 | // Runtime Version:4.0.30319.42000 13 | // 14 | // Changes to this file may cause incorrect behavior and will be lost if 15 | // the code is regenerated. 16 | // 17 | //------------------------------------------------------------------------------ 18 | 19 | // 20 | // This source code was auto-generated by xsd, Version=4.6.81.0. 21 | // 22 | 23 | 24 | /// 25 | [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")] 26 | [System.SerializableAttribute()] 27 | [System.Diagnostics.DebuggerStepThroughAttribute()] 28 | [System.ComponentModel.DesignerCategoryAttribute("code")] 29 | [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 30 | [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)] 31 | public partial class OnlineBatchReceipt 32 | { 33 | 34 | private OnlineBatchReceiptResult resultField; 35 | 36 | /// 37 | public OnlineBatchReceiptResult Result 38 | { 39 | get 40 | { 41 | return this.resultField; 42 | } 43 | set 44 | { 45 | this.resultField = value; 46 | } 47 | } 48 | } 49 | 50 | /// 51 | [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")] 52 | [System.SerializableAttribute()] 53 | [System.Diagnostics.DebuggerStepThroughAttribute()] 54 | [System.ComponentModel.DesignerCategoryAttribute("code")] 55 | [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 56 | public partial class OnlineBatchReceiptResult 57 | { 58 | 59 | private resultCodeType resultCodeField; 60 | 61 | private bool resultCodeFieldSpecified; 62 | 63 | private string valueField; 64 | 65 | /// 66 | [System.Xml.Serialization.XmlAttribute()] 67 | public resultCodeType resultCode 68 | { 69 | get 70 | { 71 | return this.resultCodeField; 72 | } 73 | set 74 | { 75 | this.resultCodeField = value; 76 | } 77 | } 78 | 79 | /// 80 | [System.Xml.Serialization.XmlIgnoreAttribute()] 81 | public bool resultCodeSpecified 82 | { 83 | get 84 | { 85 | return this.resultCodeFieldSpecified; 86 | } 87 | set 88 | { 89 | this.resultCodeFieldSpecified = value; 90 | } 91 | } 92 | 93 | /// 94 | [System.Xml.Serialization.XmlTextAttribute()] 95 | public string Value 96 | { 97 | get 98 | { 99 | return this.valueField; 100 | } 101 | set 102 | { 103 | this.valueField = value; 104 | } 105 | } 106 | } 107 | 108 | /// 109 | [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.81.0")] 110 | [System.SerializableAttribute()] 111 | public enum resultCodeType 112 | { 113 | 114 | /// 115 | OK, 116 | 117 | /// 118 | FAILED, 119 | 120 | /// 121 | FAILED_DO_NOT_RETRY, 122 | } 123 | 124 | } -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/TestData/Inn1.xml: -------------------------------------------------------------------------------- 1 | 2 | Altinn 3 | 1234567 4 | f5c7892e-e4ff-4820-98eb-38641fb983b3 5 | 0 6 | <DataBatch schemaVersion="1.0" batchReference="0" previousReference="0" receiverReference="f5c7892e-e4ff-4820-98eb-38641fb983b3" timeStamp="2015-09-15T13:30:51" formTasksInBatch="1"><DataUnits><DataUnit reportee="03033140044" archiveReference="AR98330" archiveTimeStamp="2015-09-15T13:30:48.91"><Approvers><Approver approverId="03033140044" approvedTimeStamp="2015-09-15T13:30:48.833" securityLevel="lessSensitive" /></Approvers><FormTask><ServiceCode>3903</ServiceCode><ServiceEditionCode>150512</ServiceEditionCode><Form><DataFormatId>1243</DataFormatId><DataFormatVersion>10656</DataFormatVersion><Reference>39815</Reference><ParentReference>0</ParentReference><FormData><![CDATA[<Skjema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:brreg="http://www.brreg.no/or" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://www.altinn.no/services/ServiceEngine/ServiceMetaData/2009/10" xmlns:q1="http://schemas.altinn.no/services/ServiceEngine/ServiceMetaData/2009/10" xmlns:ns1="http://www.altinn.no/services/Register/ER/2009/10" xmlns:ns2="http://schemas.altinn.no/services/Register/2009/10" xmlns:ns3="http://www.altinn.no/services/2009/10" xmlns:q3="http://www.altinn.no/services/common/fault/2009/10" xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-11T08:42:27" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" skjemanummer="1243" spesifikasjonsnummer="10656" blankettnummer="RF-1117" tittel="Klage på likningen" gruppeid="5800" etatid="NoAgency"><Skattyterinfor-grp-5801 gruppeid="5801"><info-grp-5802 gruppeid="5802"></info-grp-5802><Kontakt-grp-5803 gruppeid="5803"><KontaktpersonEPost-datadef-27688 orid="27688">xxx@yyy.no</KontaktpersonEPost-datadef-27688><Samtykke_Skatt-datadef-30001>2</Samtykke_Skatt-datadef-30001><Samtykke_Folkeregister-datadef-30002>2</Samtykke_Folkeregister-datadef-30002></Kontakt-grp-5803><klagefrist-grp-5804 gruppeid="5804"><KlageGjeldendeInntektsar-datadef-25455 orid="25455">2014</KlageGjeldendeInntektsar-datadef-25455><KlagemeldingSendtInnenKlagefrist-datadef-25454 orid="25454">Ja</KlagemeldingSendtInnenKlagefrist-datadef-25454></klagefrist-grp-5804></Skattyterinfor-grp-5801><klage-grp-5805 gruppeid="5805"><spesifisering-grp-5836 gruppeid="5836"><KlageSpesifisering-datadef-25457 orid="25457">3t5q5</KlageSpesifisering-datadef-25457></spesifisering-grp-5836></klage-grp-5805></Skjema>]]></FormData></Form></FormTask></DataUnit></DataUnits></DataBatch> 7 | 8 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Utils/XmlUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Xml; 5 | using System.Xml.Schema; 6 | using System.Xml.Serialization; 7 | 8 | namespace OnlineBatchReceiver.Utils 9 | { 10 | /// 11 | /// Utils for handling XML 12 | /// 13 | public static class XmlUtils 14 | { 15 | /// 16 | /// Creating XmlSerializer object 17 | /// 18 | /// T 19 | /// an object of type T 20 | public static XmlSerializer GetXmlSerializerOfType() 21 | { 22 | var serializer = new XmlSerializer(typeof(T)); 23 | 24 | return serializer; 25 | } 26 | 27 | /// 28 | /// Deserializing an XMLstring 29 | /// 30 | /// T 31 | /// The XmlSerializer object 32 | /// batch as string 33 | /// T 34 | public static T DeserializeXmlString(XmlSerializer serializer, string batch) 35 | { 36 | T result; 37 | 38 | using (TextReader reader = new StringReader(batch)) 39 | { 40 | result = (T)serializer.Deserialize(reader); 41 | } 42 | 43 | return result; 44 | } 45 | 46 | /// 47 | /// XML valitation 48 | /// 49 | /// batch as string 50 | /// the location of the file 51 | /// a list of schemas 52 | /// true or false 53 | public static bool ValidateBatchXml(string batchXml, string filepath, List xmlSchemas) 54 | { 55 | try 56 | { 57 | var doc = new XmlDocument(); 58 | 59 | foreach (var xmlSchema in xmlSchemas) 60 | { 61 | doc.Schemas.Add("", filepath + xmlSchema); 62 | } 63 | 64 | doc.LoadXml(batchXml); 65 | doc.Validate(xmlValidationEventHandler); 66 | } 67 | catch (Exception) 68 | { 69 | return false; 70 | } 71 | 72 | return true; 73 | } 74 | 75 | /// 76 | /// XML Validation EventHandler 77 | /// 78 | /// the sender 79 | /// validation event argument 80 | private static void xmlValidationEventHandler(object sender, ValidationEventArgs e) 81 | { 82 | switch (e.Severity) 83 | { 84 | case XmlSeverityType.Warning: 85 | throw new XmlSchemaValidationException(); 86 | case XmlSeverityType.Error: 87 | throw new XmlSchemaValidationException(); 88 | default: 89 | throw new ArgumentOutOfRangeException(); 90 | } 91 | } 92 | 93 | /// 94 | /// Serializing an XML object to string 95 | /// 96 | /// T 97 | /// the OnlineBatchReceiptResult 98 | /// XML as string 99 | public static string SerializeXmlObjectToString(T receiptResult) 100 | { 101 | var stringWriter = new StringWriter(); 102 | var serializer = new XmlSerializer(typeof(T)); 103 | serializer.Serialize(stringWriter, receiptResult); 104 | return stringWriter.ToString(); 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/Utils/FileUtil.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Xml.Serialization; 3 | 4 | namespace OnlineBatchReceiver.Utils 5 | { 6 | /// 7 | /// Utils for handling File 8 | /// 9 | public static class FileUtil 10 | { 11 | /// 12 | /// Save XMLfile to Disk 13 | /// 14 | /// T 15 | /// the file path 16 | /// the folder name 17 | /// the file name 18 | /// the XMLSerializer 19 | /// 20 | public static void SaveXmlFileToDisk(string filepath, string folderName, string filename, XmlSerializer serializer, T result) 21 | { 22 | var pathAndFile = GetPathWithFilename(filepath, folderName, filename, ".xml"); 23 | var file = File.Create(pathAndFile); 24 | 25 | serializer.Serialize(file, result); 26 | file.Close(); 27 | } 28 | 29 | /// 30 | /// Use file path and folder name to get path 31 | /// 32 | /// the file path 33 | /// the folder name 34 | /// the file name 35 | /// the file extention 36 | /// path as string 37 | private static string GetPathWithFilename(string filepath, string folderName, string filename, string fileextention) 38 | { 39 | var path = Path.Combine(filepath + "\\" + folderName + "\\"); 40 | Directory.CreateDirectory(path); 41 | 42 | var pathAndFile = Path.Combine(path, SafeFileName(filename + fileextention)); 43 | return pathAndFile; 44 | } 45 | 46 | /// 47 | /// Make path safe by removing unwanted characters 48 | /// 49 | /// the path 50 | /// "trimmed" path as string 51 | private static string SafeFileName(string path) 52 | { 53 | return path.Replace("\\", "").Replace("/", "").Replace("\"", "").Replace("*", "").Replace(":", "").Replace("?", "").Replace("<", "").Replace(">", "").Replace("|", ""); 54 | } 55 | 56 | /// 57 | /// Check if files already exists 58 | /// 59 | /// the file path 60 | /// the folder name 61 | /// the username 62 | /// receivers reference 63 | /// the sequence number 64 | /// true or false 65 | public static bool AlreadyExists(string filepath, string folderName, string username, 66 | string receiversReference, long sequenceNumber) 67 | { 68 | var path = Path.Combine(filepath + "\\" + folderName + "\\"); 69 | var dir = new DirectoryInfo(path); 70 | var filesInDir = dir.GetFiles("*" + receiversReference + "*.*"); 71 | 72 | return filesInDir.Length > 0; 73 | } 74 | 75 | /// 76 | /// Save attatcments as zip 77 | /// 78 | /// the file path 79 | /// the folder name 80 | /// the file name 81 | /// attacments as byte array 82 | public static void SaveAttatchmentsAsZip(string filepath, string folderName, string filename, byte[] attachments) 83 | { 84 | if (attachments == null || attachments.Length == 0) return; 85 | 86 | File.WriteAllBytes(GetPathWithFilename(filepath, folderName, filename, ".zip"), attachments); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/xsd/OnlineBatchReciever.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/AltinnSimulator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {05E8ADA9-D8F9-473A-BD36-F91E5E235E18} 8 | Exe 9 | Properties 10 | AltinnSimulator 11 | AltinnSimulator 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | True 53 | True 54 | Reference.svcmap 55 | 56 | 57 | 58 | 59 | 60 | Reference.svcmap 61 | 62 | 63 | Reference.svcmap 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | WCF Proxy Generator 85 | Reference.cs 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 103 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Utils/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Diagnostics; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Web; 9 | 10 | namespace AltinnBatchReceiverService.Utils 11 | { 12 | public static class Logger 13 | { 14 | 15 | /// 16 | /// The semaphore is used to logging. 17 | /// 18 | private static object semaphore = new object(); 19 | 20 | /// 21 | /// This property is fetched from Web Config (key = appname). 22 | /// It is the name of the application as it will appear in the Event Log. 23 | /// 24 | private static string appName; 25 | 26 | /// 27 | /// Applog object for logging to Event Log 28 | /// 29 | private static System.Diagnostics.EventLog appLog = null; 30 | 31 | /// 32 | /// This property is fetched from Web Config (key = logdir), see Web.Config file. 33 | /// This is the file path where log files are saved. 34 | /// 35 | private static string logFilePath; 36 | 37 | /// 38 | /// This property is fetched from Web Config (key = log_thresholdMB). 39 | /// When the log file reaches the size defined (in MB), it will give the log file a new name with a time stamp and start filling up a new empty log file. 40 | /// 41 | private static long logFileThresholdMB; 42 | 43 | static Logger() 44 | { 45 | string curpath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)); 46 | 47 | // Event Logger 48 | appName = ConfigurationManager.AppSettings["appname"]; 49 | if (appName == null) 50 | appName = "Unnamed"; 51 | 52 | appLog = new System.Diagnostics.EventLog(); 53 | appLog.Source = appName; 54 | 55 | // File logger 56 | string logDirPath = ConfigurationManager.AppSettings["logdir"]; 57 | if (logDirPath != null) 58 | { 59 | if (!logDirPath.Contains(":")) 60 | logDirPath = Path.Combine(curpath, logDirPath); 61 | } 62 | else 63 | logDirPath = Path.Combine(curpath, "Log"); 64 | 65 | if (!Directory.Exists(logDirPath)) 66 | Directory.CreateDirectory(logDirPath); 67 | 68 | logFilePath = Path.Combine(logDirPath, "log.txt"); 69 | 70 | // Threshold 71 | string str = ConfigurationManager.AppSettings["log_thresholdMB"]; 72 | long lstr; 73 | if (long.TryParse(str, out lstr)) 74 | logFileThresholdMB = lstr; 75 | else 76 | logFileThresholdMB = 5; 77 | } 78 | 79 | 80 | /// 81 | /// Logs the data to file and optionally to Application event log. 82 | /// 83 | /// The message to log 84 | /// True if also log to event log, default false 85 | /// The entry type of event log, default Error 86 | /// 87 | /// We have chosen here a simple log to file, but other logging strategies could be implemented, such as using NLog or logging to Application Event Log only. 88 | /// 89 | public static void Log(string msg, bool logToEvent = false, EventLogEntryType logEntryType = EventLogEntryType.Error) 90 | { 91 | lock (semaphore) 92 | { 93 | if (File.Exists(logFilePath)) 94 | { 95 | FileInfo fi = new FileInfo(logFilePath); 96 | if (fi.Length > logFileThresholdMB * 1024 * 1000) 97 | { 98 | DateTime dt = DateTime.Now; 99 | File.Move(logFilePath, logFilePath.Replace("log.txt", string.Format("log - {0}-{1:00}-{2:00} {3:00}.{4:00}.{5:00}.{6:000}.txt", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond))); 100 | } 101 | } 102 | try 103 | { 104 | using (System.IO.StreamWriter file = new System.IO.StreamWriter(logFilePath, true)) 105 | { 106 | file.WriteLine($"{DateTime.Now}:{msg}"); 107 | file.WriteLine(); 108 | } 109 | if (logToEvent) 110 | appLog.WriteEntry(msg, logEntryType); 111 | } 112 | catch 113 | { } 114 | } 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/OnlineBatchReceiverSoap.asmx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.IO; 5 | using System.Reflection; 6 | using System.Web.Services; 7 | using System.Xml.Serialization; 8 | using log4net; 9 | using OnlineBatchReceiver.Utils; 10 | 11 | namespace OnlineBatchReceiver 12 | { 13 | /// 14 | /// Summary description for OnlineBatchReceiverSoap 15 | /// 16 | // [WebService(Namespace = "http://tempuri.org/")] 17 | // [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 18 | // [System.ComponentModel.ToolboxItem(false)] 19 | // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 20 | // [System.Web.Script.Services.ScriptService] 21 | [WebServiceBinding(Name = "OnlineBatchReceiverSoap", Namespace = "http://AltInn.no/webservices/")] 22 | public class OnlineBatchReceiverSoap : WebService 23 | { 24 | private readonly ILog _logger; 25 | // Finds the directory where the app is deployed 26 | private readonly string _filepath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)); 27 | private readonly string _foldername = ConfigurationManager.AppSettings["RecievedXmlFolder"]; 28 | 29 | public OnlineBatchReceiverSoap() 30 | { 31 | _logger = LogManager.GetLogger(GetType()); 32 | } 33 | 34 | [WebMethod] 35 | [System.Web.Services.Protocols.SoapDocumentMethod("http://AltInn.no/webservices/ReceiveOnlineBatchExternalAttachment", 36 | RequestNamespace = "http://AltInn.no/webservices/", 37 | ResponseNamespace = "http://AltInn.no/webservices/", 38 | Use = System.Web.Services.Description.SoapBindingUse.Literal, 39 | ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 40 | public string ReceiveOnlineBatchExternalAttachment(string username, string passwd, string receiversReference, long sequenceNumber, string batch, [XmlElement(DataType = "base64Binary")] byte[] attachments) 41 | { 42 | _logger.Info("ReceiveOnlineBatchExternalAttachment Recieved from: " + username); 43 | _logger.Debug("ReceiveOnlineBatchExternalAttachment Recieved from: " + username + " Batch: " + batch); 44 | 45 | // Authenticate username + passw 46 | if (!Authenticate(username, passwd)) 47 | { 48 | _logger.Debug("ReceiveOnlineBatchExternalAttachment Invalid request"); 49 | return Response(resultCodeType.FAILED_DO_NOT_RETRY); 50 | } 51 | _logger.Debug("ReceiveOnlineBatchExternalAttachment, User Aithenticated"); 52 | // Verify batch vs. XSD (Schema verification) 53 | if (!XmlUtils.ValidateBatchXml(batch, _filepath, new List { "/xsd/genericbatch.2013.06.xsd" })) 54 | { 55 | _logger.Debug("ReceiveOnlineBatchExternalAttachment Validation Failed"); 56 | return Response(resultCodeType.FAILED_DO_NOT_RETRY); 57 | } 58 | 59 | try 60 | { 61 | var serializer = XmlUtils.GetXmlSerializerOfType(); 62 | // result is a DataBack object, which can be sent async to a recipient in the reciever application portfolio 63 | var result = XmlUtils.DeserializeXmlString(serializer, batch); 64 | 65 | if (FileUtil.AlreadyExists(_filepath, _foldername, username, receiversReference, sequenceNumber)) 66 | { 67 | _logger.Debug("ReceiveOnlineBatchExternalAttachment Duplicate Request"); 68 | return Response(resultCodeType.FAILED_DO_NOT_RETRY); 69 | } 70 | // Saving payload to disk 71 | var filename = Guid.NewGuid() + "_" + username + "_" + receiversReference + "_" + sequenceNumber; 72 | FileUtil.SaveXmlFileToDisk(_filepath, _foldername, filename, serializer, result); 73 | FileUtil.SaveAttatchmentsAsZip(_filepath, _foldername, filename, attachments); 74 | } 75 | catch (Exception ex) 76 | { 77 | _logger.Error(ex); 78 | return ex.Message; 79 | } 80 | 81 | _logger.Debug("ReceiveOnlineBatchExternalAttachment Validated OK "); 82 | return Response(resultCodeType.OK); 83 | } 84 | 85 | /// 86 | /// Authenticate user, in this example the user is always Altinn, and password cannot be empty 87 | /// 88 | /// the username 89 | /// the password 90 | /// true or false 91 | private static bool Authenticate(string username, string password) 92 | { 93 | return username == "Altinn" && !string.IsNullOrEmpty(password); 94 | } 95 | 96 | /// 97 | /// return OnlineBatchReceiptResult object as a string 98 | /// 99 | /// the resultCodeType 100 | /// object as string 101 | private string Response(resultCodeType code) 102 | { 103 | var receiptResult = new OnlineBatchReceiptResult 104 | { 105 | resultCode = code, 106 | resultCodeSpecified = true, 107 | Value = "" 108 | }; 109 | 110 | return XmlUtils.SerializeXmlObjectToString(receiptResult); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Service References/OnlineBatchReceiver/OnlineBatchReceiverSoap.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/DownloadQueueExampleClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D89A955E-2007-4F7B-9B5F-4D1E5BC9625B} 8 | Exe 9 | Properties 10 | DownloadQueueExampleClient 11 | DownloadQueueExampleClient 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | True 54 | True 55 | Reference.svcmap 56 | 57 | 58 | True 59 | True 60 | Reference.svcmap 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Reference.svcmap 69 | 70 | 71 | Reference.svcmap 72 | 73 | 74 | Reference.svcmap 75 | 76 | 77 | Reference.svcmap 78 | 79 | 80 | 81 | Reference.svcmap 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | WCF Proxy Generator 101 | Reference.cs 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | WCF Proxy Generator 113 | Reference.cs 114 | 115 | 116 | 117 | 124 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/OnlineBatchReceiver.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 9 | 2.0 10 | {FA4DEDE9-BB7F-40E4-8122-2F7FB9613A2B} 11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 12 | Library 13 | Properties 14 | OnlineBatchReceiver 15 | OnlineBatchReceiver 16 | v4.5.2 17 | True 18 | true 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | true 28 | full 29 | false 30 | bin\ 31 | DEBUG;TRACE 32 | prompt 33 | 4 34 | 35 | 36 | pdbonly 37 | true 38 | bin\ 39 | TRACE 40 | prompt 41 | 4 42 | 43 | 44 | 45 | ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll 46 | True 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | Global.asax 78 | 79 | 80 | 81 | OnlineBatchReceiverSoap.asmx 82 | Component 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | Web.config 94 | 95 | 96 | Web.config 97 | 98 | 99 | Designer 100 | Always 101 | 102 | 103 | Designer 104 | Always 105 | 106 | 107 | Designer 108 | Always 109 | 110 | 111 | 112 | 10.0 113 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | False 123 | True 124 | 56453 125 | / 126 | http://localhost:56453/ 127 | False 128 | False 129 | 130 | 131 | False 132 | 133 | 134 | 135 | 136 | 143 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/Utils/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Reflection; 6 | 7 | namespace DownloadQueueExampleClient.Utils 8 | { 9 | public static class Logger 10 | { 11 | 12 | /// 13 | /// The semaphore is used to logging. 14 | /// 15 | private static object semaphore = new object(); 16 | 17 | /// 18 | /// This property is fetched from Web Config (key = appname). 19 | /// It is the name of the application as it will appear in the Event Log. 20 | /// 21 | private static string appName; 22 | 23 | /// 24 | /// Applog object for logging to Event Log 25 | /// 26 | private static System.Diagnostics.EventLog appLog = null; 27 | 28 | /// 29 | /// This property is fetched from Web Config (key = logdir), see Web.Config file. 30 | /// This is the file path where log files are saved. 31 | /// 32 | private static string logFilePath; 33 | 34 | /// 35 | /// This property is fetched from Web Config (key = log_thresholdMB). 36 | /// When the log file reaches the size defined (in MB), it will give the log file a new name with a time stamp and start filling up a new empty log file. 37 | /// 38 | private static long logFileThresholdMB; 39 | 40 | static Logger() 41 | { 42 | string curpath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)); 43 | 44 | // Event Logger 45 | appName = ConfigurationManager.AppSettings["appname"]; 46 | if (appName == null) 47 | appName = "Unnamed"; 48 | 49 | appLog = new System.Diagnostics.EventLog(); 50 | appLog.Source = appName; 51 | 52 | // File logger 53 | string logDirPath = ConfigurationManager.AppSettings["logdir"]; 54 | if (logDirPath != null) 55 | { 56 | if (!logDirPath.Contains(":")) 57 | logDirPath = Path.Combine(curpath, logDirPath); 58 | } 59 | else 60 | logDirPath = Path.Combine(curpath, "Log"); 61 | 62 | if (!Directory.Exists(logDirPath)) 63 | Directory.CreateDirectory(logDirPath); 64 | 65 | logFilePath = Path.Combine(logDirPath, "log.txt"); 66 | 67 | // Threshold 68 | string str = ConfigurationManager.AppSettings["log_thresholdMB"]; 69 | long lstr; 70 | if (long.TryParse(str, out lstr)) 71 | logFileThresholdMB = lstr; 72 | else 73 | logFileThresholdMB = 5; 74 | } 75 | 76 | 77 | /// 78 | /// Logs the data to file and optionally to Application event log. 79 | /// 80 | /// The message to log 81 | /// True if also log to event log, default false 82 | /// The entry type of event log, default Error 83 | /// 84 | /// We have chosen here a simple log to file, but other logging strategies could be implemented, such as using NLog or logging to Application Event Log only. 85 | /// 86 | public static void Log(string msg, bool logToEvent = false, EventLogEntryType logEntryType = EventLogEntryType.Error) 87 | { 88 | lock (semaphore) 89 | { 90 | if (File.Exists(logFilePath)) 91 | { 92 | FileInfo fi = new FileInfo(logFilePath); 93 | if (fi.Length > logFileThresholdMB * 1024 * 1000) 94 | { 95 | DateTime dt = DateTime.Now; 96 | File.Move(logFilePath, logFilePath.Replace("log.txt", string.Format("log - {0}-{1:00}-{2:00} {3:00}.{4:00}.{5:00}.{6:000}.txt", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond))); 97 | } 98 | } 99 | try 100 | { 101 | using (System.IO.StreamWriter file = new System.IO.StreamWriter(logFilePath, true)) 102 | { 103 | file.WriteLine($"{DateTime.Now}:{msg}"); 104 | file.WriteLine(); 105 | } 106 | if (logToEvent) 107 | appLog.WriteEntry(msg, logEntryType); 108 | 109 | Console.WriteLine($"{DateTime.Now}:{msg}"); 110 | } 111 | catch 112 | { } 113 | } 114 | } 115 | } 116 | //public class Logger 117 | //{ 118 | // private static string logdir; 119 | 120 | // private static object semaphore = new object(); 121 | // private static System.Diagnostics.EventLog appLog = null; 122 | // private static string logFilePath; 123 | // private static long logFileThresholdMB = 5; 124 | 125 | // static Logger() 126 | // { 127 | 128 | // //TODO:: get params from config 129 | // appLog = new System.Diagnostics.EventLog(); 130 | // appLog.Source = "DownloadQueueExampleClient"; 131 | 132 | // //string logDirPath = ConfigurationManager.AppSettings["logdir"]; 133 | // //if (logDirPath == null) 134 | // // logDirPath = HttpContent.Current.Server.MapPath("~"); 135 | // logFilePath = Path.Combine("C:\\Temp\\", "log.txt"); 136 | 137 | // //string str = ConfigurationManager.AppSettings["log_thresholdMB"]; 138 | // //long lstr; 139 | // //if (long.TryParse(str, out lstr)) 140 | // // logFileThresholdMB = lstr; 141 | // //else 142 | // // logFileThresholdMB = 5; 143 | // } 144 | // public static void Log(string msg, bool logToEvent = false, EventLogEntryType logEntryType = EventLogEntryType.Error) 145 | // { 146 | // lock (semaphore) 147 | // { 148 | // if (File.Exists(logFilePath)) 149 | // { 150 | // FileInfo fi = new FileInfo(logFilePath); 151 | // if (fi.Length > logFileThresholdMB * 1024 * 1000) 152 | // { 153 | // DateTime dt = DateTime.Now; 154 | // File.Move(logFilePath, logFilePath.Replace("log.txt", string.Format("log - {0}-{1:00}-{2:00} {3:00}.{4:00}.{5:00}.{6:000}.txt", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond))); 155 | // } 156 | // } 157 | // try 158 | // { 159 | // using (System.IO.StreamWriter file = new System.IO.StreamWriter(logFilePath, true)) 160 | // { 161 | // file.WriteLine($"{DateTime.Now}:{msg}"); 162 | // file.WriteLine(); 163 | // } 164 | // if (logToEvent) 165 | // appLog.WriteEntry(msg, logEntryType); 166 | 167 | // Console.WriteLine($"{DateTime.Now}:{msg}"); 168 | // } 169 | // catch (Exception ex) 170 | // { } 171 | // } 172 | 173 | // } 174 | //} 175 | } 176 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/Schema/genericbatch.2013.06.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/xsd/genericbatch.2013.06.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnSimulator/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Xml; 4 | 5 | namespace AltinnSimulator 6 | { 7 | 8 | /// 9 | /// This Console Application simulates Altinn sending messages to the Online Batch Receiver Soap service. 10 | /// It reads messages from a file and sends them to the service. The service Endpoint is configured in the App.Config file. 11 | /// 12 | class Program 13 | { 14 | // Holding the command line arguments 15 | private static Arguments _arguments; 16 | 17 | // Counters for different status return 18 | 19 | private static int _ok_count; 20 | private static int _failed_count; 21 | private static int _failed_do_not_retry_count; 22 | 23 | private static string helptext = 24 | @" 25 | folder [-max count] [-maxerr count] folderPath 26 | Loads all or a max number of messages from the specified folderPath 27 | and sends them to the URL defined in the configuration. 28 | "; 29 | 30 | /// 31 | /// 32 | /// 33 | /// 34 | /// -1: fatal error, 1 there are errors, 0 OK 35 | static int Main(string[] args) 36 | { 37 | _arguments = new Arguments(args); 38 | 39 | 40 | // HELP 41 | if (_arguments.Command == null || _arguments.Command.Equals("help") || _arguments.Command.Equals("?")) 42 | { 43 | Console.WriteLine(helptext); 44 | } 45 | 46 | // FOLDER 47 | // folder [-max count] [-maxerr count] folderPath 48 | else if (_arguments.Command.Equals("folder")) 49 | { 50 | // Loads data from a folder - the arguments Source is the name of the folder 51 | if (string.IsNullOrEmpty(_arguments.Source)) 52 | { 53 | return Error("Missing the Folder-Path"); 54 | } 55 | 56 | if (!Directory.Exists(_arguments.Source)) 57 | { 58 | return Error("The Folder-Path does not exists"); 59 | } 60 | 61 | int max = int.MaxValue; 62 | string maxarg = _arguments["max"]; 63 | if (!string.IsNullOrEmpty(maxarg)) 64 | { 65 | int m; 66 | if (int.TryParse(maxarg, out m)) 67 | max = m; 68 | else 69 | return Error("-max value is not a valid number value"); 70 | } 71 | 72 | int maxerr = int.MaxValue; 73 | string maxerrarg = _arguments["maxerr"]; 74 | if (!string.IsNullOrEmpty(maxerrarg)) 75 | { 76 | int m; 77 | if (int.TryParse(maxerrarg, out m)) 78 | maxerr = m; 79 | else 80 | return Error("-maxerr value is not a valid number value"); 81 | } 82 | 83 | // Process all the files in the given folder 84 | string[] files = Directory.GetFiles(_arguments.Source, "*.xml"); 85 | int successCount = 0; 86 | int errorCount = 0; 87 | foreach (string file in files) 88 | { 89 | if (successCount == max) 90 | break; 91 | try 92 | { 93 | SendXml(file); 94 | successCount++; 95 | } 96 | catch (Exception ex) 97 | { 98 | Console.WriteLine(ErrorMessage(ex)); 99 | errorCount++; 100 | } 101 | if (errorCount >= maxerr) 102 | break; 103 | } 104 | Console.WriteLine("Transmission summary:"); 105 | Console.WriteLine("\tSuccess: {0}", successCount); 106 | Console.WriteLine("\tErrors: {0}", errorCount); 107 | WriteRetResult(); 108 | Console.ReadLine(); 109 | return errorCount > 0 ? 1 : 0; 110 | } 111 | 112 | else 113 | { 114 | Console.WriteLine("Missing Command"); 115 | } 116 | 117 | Console.ReadLine(); 118 | 119 | return 0; 120 | } 121 | 122 | 123 | static private int Error(string msg) 124 | { 125 | Console.WriteLine(msg); 126 | Console.ReadLine(); 127 | return -1; 128 | } 129 | 130 | 131 | private static string ErrorMessage(Exception ex) 132 | { 133 | return string.Format("EXCEPTION: {0}, Source: {1}", ex.Message, ex.Source); 134 | } 135 | 136 | 137 | private static void WriteRetResult() 138 | { 139 | Console.WriteLine("Return result summary:"); 140 | Console.WriteLine("\tOK: {0}", _ok_count); 141 | Console.WriteLine("\tFAILED: {0}", _failed_count); 142 | Console.WriteLine("\tFAILED_DO_NOT_RETRY: {0}", _failed_do_not_retry_count); 143 | } 144 | 145 | static void SendXml(string filename) 146 | { 147 | string username = null; 148 | string password = null; 149 | string recref = null; 150 | long seqno = 0; 151 | string batch = null; 152 | byte[] attachments = null; 153 | 154 | XmlDocument xmldoc = new XmlDocument(); 155 | xmldoc.LoadXml(File.ReadAllText(filename)); 156 | 157 | var enumerator = xmldoc.GetEnumerator(); 158 | while (enumerator.MoveNext()) 159 | { 160 | XmlNode node = (XmlNode)enumerator.Current; 161 | if (node.LocalName == "ReceiveOnlineBatchExternalAttachment") 162 | { 163 | var enumerator2 = node.GetEnumerator(); 164 | while (enumerator2.MoveNext()) 165 | { 166 | XmlNode node2 = (XmlNode)enumerator2.Current; 167 | if (node2.LocalName == "username") 168 | username = node2.InnerText; 169 | else if (node2.LocalName == "passwd") 170 | password = node2.InnerText; 171 | else if (node2.LocalName == "receiversReference") 172 | recref = node2.InnerText; 173 | else if (node2.LocalName == "sequenceNumber") 174 | { 175 | string seqnostr = node2.InnerText; 176 | long sno; 177 | long.TryParse(seqnostr, out sno); 178 | seqno = sno; 179 | } 180 | else if (node2.LocalName == "batch") 181 | batch = node2.InnerText; 182 | else if (node2.LocalName == "attachments") 183 | { 184 | attachments = System.Convert.FromBase64String(node2.InnerText); 185 | } 186 | 187 | } 188 | 189 | } 190 | 191 | } 192 | 193 | using (var cli = new OnlineBatchReceiver.OnlineBatchReceiverSoapSoapClient()) 194 | { 195 | string resp = cli.ReceiveOnlineBatchExternalAttachment(username, password, recref, seqno, batch, attachments); 196 | cli.Close(); 197 | if (resp.Contains("FAILED_DO_NOT_RETRY")) 198 | _failed_do_not_retry_count++; 199 | else if (resp.Contains("FAILED")) 200 | _failed_count++; 201 | else 202 | _ok_count++; 203 | } 204 | 205 | } 206 | 207 | } 208 | 209 | } 210 | -------------------------------------------------------------------------------- /outbound/DownloadQueue/DownloadQueueExampleClient/DownloadQueueHandler.cs: -------------------------------------------------------------------------------- 1 | using DownloadQueueExampleClient.DownloadQueueService; 2 | using DownloadQueueExampleClient.Utils; 3 | using System; 4 | using System.Configuration; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Reflection; 8 | 9 | namespace DownloadQueueExampleClient 10 | { 11 | 12 | /// 13 | /// Handler for donwloading schema files with attachments from an altinn download queue for a specific service owner and for a specific service. 14 | /// 15 | public class DownloadQueueHandler 16 | { 17 | private string systemUserName; 18 | private string systemPassword; 19 | private string serviceCode; 20 | private int languageId; 21 | 22 | /// 23 | /// Constructor 24 | /// 25 | /// Service Owner 26 | /// Password in clear text 27 | /// Specifies the specific service 28 | public DownloadQueueHandler(string systemUserName, string systemPassword, string serviceCode) 29 | { 30 | this.systemUserName = systemUserName; 31 | this.systemPassword = systemPassword; 32 | this.serviceCode = serviceCode; 33 | } 34 | 35 | 36 | /// 37 | /// Runs the download, maximum given items, and saves to the configured inbox (one folder with attachments for each schema) 38 | /// 39 | /// Downloads a maximum given or if not given, all schemas. 40 | /// 41 | /// Performs the following steps for each item: 42 | /// 1. Fetces the item from queue 43 | /// 2. Saves the schema and attachments 44 | /// 3. Purges the item (remove from queue) 45 | /// 46 | public void Execute(int maxItemsToProcess = int.MaxValue, int languageId = 1044) 47 | { 48 | int it = 0; 49 | this.languageId = languageId; 50 | DownloadQueueItemBE item; 51 | do 52 | { 53 | //1. Get item 54 | try 55 | { 56 | item = GetDownloadQueueItem(); 57 | if (item == null) 58 | { 59 | Logger.Log("Download queue empty!"); 60 | return; 61 | } 62 | } 63 | catch (Exception e) 64 | { 65 | Logger.Log($"Failed to get download queue item. {e.Message}"); 66 | return; 67 | } 68 | 69 | //2. Persist/process item - download formset data as pdf & save attachments 70 | try 71 | { 72 | PersistItem(item); 73 | } 74 | catch (Exception exceptionWhileProcessingItem) 75 | { 76 | Logger.Log($"Error while processing queue item: {exceptionWhileProcessingItem.Message}", true); 77 | continue; 78 | } 79 | 80 | //3. Purge item 81 | try 82 | { 83 | PurgeItem(item.ArchiveReference); 84 | Logger.Log($"Successfully processed queue item and removed from download queue: {item.ArchiveReference}"); 85 | } 86 | catch (Exception exceptionOnPurgeItem) 87 | { 88 | Logger.Log($"Error while removing item from download queue: {exceptionOnPurgeItem.Message}", true); 89 | } 90 | 91 | it++; 92 | } 93 | while (item != null && it < maxItemsToProcess); 94 | } 95 | 96 | private DownloadQueueItemBE GetDownloadQueueItem() 97 | { 98 | using (var client = new DownloadQueueExternalBasicClient()) 99 | { 100 | var queueItems = client.GetDownloadQueueItems(systemUserName, systemPassword, serviceCode); 101 | if (queueItems != null) 102 | Logger.Log($"Download queue contains {queueItems.Count} elements."); 103 | return queueItems.FirstOrDefault(); 104 | } 105 | } 106 | 107 | private void PurgeItem(string archiveReference) 108 | { 109 | using (var client = new DownloadQueueExternalBasicClient()) 110 | { 111 | client.PurgeItem(systemUserName, systemPassword, archiveReference); 112 | } 113 | } 114 | 115 | private void PersistItem(DownloadQueueItemBE item) 116 | { 117 | //save formset 118 | DownloadFormSet(item.ArchiveReference); 119 | 120 | //save attachments 121 | DownloadAttachments(item.ArchiveReference); 122 | } 123 | 124 | private void DownloadFormSet(string archiveReference) 125 | { 126 | byte[] formData; 127 | try 128 | { 129 | using (var client = new DownloadQueueExternalBasicClient()) 130 | { 131 | formData = client.GetFormSetPdfBasic(systemUserName, systemPassword, archiveReference, languageId); 132 | } 133 | } 134 | catch(Exception e) 135 | { 136 | Logger.Log($"Failed to download form set for item {archiveReference}. {e.Message}"); 137 | throw; 138 | } 139 | 140 | Logger.Log($"Successfully downloaded form set for item {archiveReference}."); 141 | 142 | SaveFile(formData, archiveReference, archiveReference, ".pdf"); 143 | } 144 | 145 | private void DownloadAttachments(string archiveReference) 146 | { 147 | using (var client = new DownloadQueueExternalBasicClient()) 148 | { 149 | var formTask = client.GetArchivedFormTaskBasicDQ(systemUserName, systemPassword, archiveReference, languageId); 150 | var attachments = formTask.Attachments; 151 | 152 | foreach(var attachment in attachments) 153 | { 154 | //attachment > 30MB, use streaming service 155 | if (attachment.AttachmentData == null) 156 | { 157 | SaveStreamedAttachment(attachment.AttachmentId, attachment.FileName, archiveReference); 158 | } 159 | else //save attachment data to file 160 | { 161 | SaveFile(attachment.AttachmentData, archiveReference, attachment.FileName); 162 | } 163 | } 164 | } 165 | } 166 | 167 | private void SaveStreamedAttachment(int attachmentId, string fileName, string archiveReference) 168 | { 169 | byte[] data; 170 | try 171 | { 172 | using (var client = new ServiceOwnerArchiveExternalStreamed.ServiceOwnerArchiveExternalStreamedBasicClient()) 173 | { 174 | data = client.GetAttachmentDataStreamedBasic(systemUserName, systemPassword, attachmentId); 175 | } 176 | } 177 | catch (Exception e) 178 | { 179 | Logger.Log($"Failed download streamed attachment for attachmentId: {attachmentId}. {e.Message}"); 180 | throw; 181 | } 182 | 183 | Logger.Log($"Successfully downloaded streamed attachment with id {attachmentId}."); 184 | 185 | SaveFile(data, archiveReference, fileName); 186 | } 187 | 188 | 189 | private static void SaveFile(object file, string folder, string filename, string extension = null) 190 | { 191 | try 192 | { 193 | FileSaver.SaveFile(file, folder, filename, extension); 194 | } 195 | catch (Exception e) 196 | { 197 | Logger.Log($"Error while saving file {filename}. {e.Message}"); 198 | throw; 199 | } 200 | } 201 | 202 | 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/AltinnBatchReceiverService.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | 10 | 11 | 2.0 12 | {0D0955CF-1559-43AB-98C4-20B63800D0D3} 13 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 14 | Library 15 | Properties 16 | AltinnBatchReceiverService 17 | AltinnBatchReceiverService 18 | v4.5.2 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | true 30 | full 31 | false 32 | bin\ 33 | DEBUG;TRACE 34 | prompt 35 | 4 36 | 37 | 38 | pdbonly 39 | true 40 | bin\ 41 | TRACE 42 | prompt 43 | 4 44 | 45 | 46 | 47 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 48 | True 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | Designer 73 | Always 74 | 75 | 76 | Designer 77 | Always 78 | 79 | 80 | Web.config 81 | 82 | 83 | Web.config 84 | 85 | 86 | 87 | 88 | 89 | Designer 90 | 91 | 92 | 93 | 94 | 95 | OnlineBatchReceiverSoap.asmx 96 | Component 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 10.0 107 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | True 117 | True 118 | 5133 119 | / 120 | http://localhost:5133/ 121 | False 122 | False 123 | 124 | 125 | False 126 | 127 | 128 | 129 | 130 | 131 | 132 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 133 | 134 | 135 | 136 | 137 | 144 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchRecieverTest/OnlineBatchReceiverSoapTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Reflection; 6 | using NUnit.Framework; 7 | using OnlineBatchReceiver; 8 | 9 | namespace OnlineBatchRecieverTest 10 | { 11 | [TestFixture] 12 | public class OnlineBatchReceiverSoapTest 13 | { 14 | [OneTimeTearDown] 15 | public void OneTimeTearDown() 16 | { 17 | // Delete files generated in the test 18 | var path = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)); 19 | var files = GetFiles(path, ".xml", ".zip"); 20 | foreach (var file in files) 21 | { 22 | try 23 | { 24 | file.Attributes = FileAttributes.Normal; 25 | File.Delete(file.FullName); 26 | } 27 | catch 28 | { 29 | // ignored 30 | } 31 | } 32 | } 33 | 34 | private static IEnumerable GetFiles(string path, params string[] extensions) 35 | { 36 | var list = new List(); 37 | foreach (var ext in extensions) 38 | list.AddRange(new DirectoryInfo(path).GetFiles("*" + ext).Where(p => 39 | p.Extension.Equals(ext, StringComparison.CurrentCultureIgnoreCase)) 40 | .ToArray()); 41 | return list; 42 | } 43 | 44 | [Test] 45 | public void ReceiveOnlineBatchExternalAttachment_Returns_FAILED_DO_NOT_RETRY_when_InvalidUser_and_InvalidPassword_and_InvalidXml() 46 | { 47 | var target = new OnlineBatchReceiverSoap(); 48 | 49 | var result = target.ReceiveOnlineBatchExternalAttachment("BogusUser", "", "", 0, "test", null); 50 | Assert.IsTrue(result.Contains(resultCodeType.FAILED_DO_NOT_RETRY.ToString())); 51 | } 52 | 53 | [Test] 54 | public void ReceiveOnlineBathExternalAttachment_Returns_FAILED_DO_NOT_RETRY_when_InvalidUser_and_InvalidPassword_and_ValidXml() 55 | { 56 | var target = new OnlineBatchReceiverSoap(); 57 | 58 | var result = target.ReceiveOnlineBatchExternalAttachment("BogusUser", "", "", 0, 59 | "3903150512
124310656398150xxx@yyy.no222014Ja3t5q5]]>
", null); 60 | Assert.IsTrue(result.Contains(resultCodeType.FAILED_DO_NOT_RETRY.ToString())); 61 | } 62 | 63 | [Test] 64 | public void ReceiveOnlineBatchExternalAttachment_Returns_FAILED_DO_NOT_RETRY_When_ValidUser_and_ValidPassword_and_InvalidXml() 65 | { 66 | var target = new OnlineBatchReceiverSoap(); 67 | 68 | var result = target.ReceiveOnlineBatchExternalAttachment("Altinn", "GotPassword", "", 0, "test", null); 69 | Assert.IsTrue(result.Contains(resultCodeType.FAILED_DO_NOT_RETRY.ToString())); 70 | } 71 | 72 | [Test] 73 | public void ReceiveOnlineBatchExternalAttachment_Returns_OK_When_ValidUser_and_ValidPassword_and_ValidXml() 74 | { 75 | var target = new OnlineBatchReceiverSoap(); 76 | 77 | var result = target.ReceiveOnlineBatchExternalAttachment("Altinn", "GotPassword", Guid.NewGuid().ToString(), 0, 78 | "3903150512
124310656398150xxx@yyy.no222014Ja3t5q5]]>
", null); 79 | Assert.IsTrue(result.Contains(resultCodeType.OK.ToString())); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnReceiverWithXmlSerialization/OnlineBatchReceiver/xsd/OnlineBatchReceiver.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | 12 | 13 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 14 | [System.ServiceModel.ServiceContractAttribute(Namespace="http://AltInn.no/webservices/", ConfigurationName="OnlineBatchReceiverSoap")] 15 | public interface OnlineBatchReceiverSoap 16 | { 17 | 18 | // CODEGEN: Generating message contract since element name username from namespace http://AltInn.no/webservices/ is not marked nillable 19 | [System.ServiceModel.OperationContractAttribute(Action="http://AltInn.no/webservices/ReceiveOnlineBatchExternalAttachment", ReplyAction="*")] 20 | ReceiveOnlineBatchExternalAttachmentResponse ReceiveOnlineBatchExternalAttachment(ReceiveOnlineBatchExternalAttachmentRequest request); 21 | 22 | [System.ServiceModel.OperationContractAttribute(Action="http://AltInn.no/webservices/ReceiveOnlineBatchExternalAttachment", ReplyAction="*")] 23 | System.Threading.Tasks.Task ReceiveOnlineBatchExternalAttachmentAsync(ReceiveOnlineBatchExternalAttachmentRequest request); 24 | } 25 | 26 | [System.Diagnostics.DebuggerStepThroughAttribute()] 27 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 28 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 29 | [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] 30 | public partial class ReceiveOnlineBatchExternalAttachmentRequest 31 | { 32 | 33 | [System.ServiceModel.MessageBodyMemberAttribute(Name="ReceiveOnlineBatchExternalAttachment", Namespace="http://AltInn.no/webservices/", Order=0)] 34 | public ReceiveOnlineBatchExternalAttachmentRequestBody Body; 35 | 36 | public ReceiveOnlineBatchExternalAttachmentRequest() 37 | { 38 | } 39 | 40 | public ReceiveOnlineBatchExternalAttachmentRequest(ReceiveOnlineBatchExternalAttachmentRequestBody Body) 41 | { 42 | this.Body = Body; 43 | } 44 | } 45 | 46 | [System.Diagnostics.DebuggerStepThroughAttribute()] 47 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 48 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 49 | [System.Runtime.Serialization.DataContractAttribute(Namespace="http://AltInn.no/webservices/")] 50 | public partial class ReceiveOnlineBatchExternalAttachmentRequestBody 51 | { 52 | 53 | [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=0)] 54 | public string username; 55 | 56 | [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=1)] 57 | public string passwd; 58 | 59 | [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=2)] 60 | public string receiversReference; 61 | 62 | [System.Runtime.Serialization.DataMemberAttribute(Order=3)] 63 | public long sequenceNumber; 64 | 65 | [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=4)] 66 | public string batch; 67 | 68 | [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=5)] 69 | public byte[] attachments; 70 | 71 | public ReceiveOnlineBatchExternalAttachmentRequestBody() 72 | { 73 | } 74 | 75 | public ReceiveOnlineBatchExternalAttachmentRequestBody(string username, string passwd, string receiversReference, long sequenceNumber, string batch, byte[] attachments) 76 | { 77 | this.username = username; 78 | this.passwd = passwd; 79 | this.receiversReference = receiversReference; 80 | this.sequenceNumber = sequenceNumber; 81 | this.batch = batch; 82 | this.attachments = attachments; 83 | } 84 | } 85 | 86 | [System.Diagnostics.DebuggerStepThroughAttribute()] 87 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 88 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 89 | [System.ServiceModel.MessageContractAttribute(IsWrapped=false)] 90 | public partial class ReceiveOnlineBatchExternalAttachmentResponse 91 | { 92 | 93 | [System.ServiceModel.MessageBodyMemberAttribute(Name="ReceiveOnlineBatchExternalAttachmentResponse", Namespace="http://AltInn.no/webservices/", Order=0)] 94 | public ReceiveOnlineBatchExternalAttachmentResponseBody Body; 95 | 96 | public ReceiveOnlineBatchExternalAttachmentResponse() 97 | { 98 | } 99 | 100 | public ReceiveOnlineBatchExternalAttachmentResponse(ReceiveOnlineBatchExternalAttachmentResponseBody Body) 101 | { 102 | this.Body = Body; 103 | } 104 | } 105 | 106 | [System.Diagnostics.DebuggerStepThroughAttribute()] 107 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 108 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 109 | [System.Runtime.Serialization.DataContractAttribute(Namespace="http://AltInn.no/webservices/")] 110 | public partial class ReceiveOnlineBatchExternalAttachmentResponseBody 111 | { 112 | 113 | [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=0)] 114 | public string ReceiveOnlineBatchExternalAttachmentResult; 115 | 116 | public ReceiveOnlineBatchExternalAttachmentResponseBody() 117 | { 118 | } 119 | 120 | public ReceiveOnlineBatchExternalAttachmentResponseBody(string ReceiveOnlineBatchExternalAttachmentResult) 121 | { 122 | this.ReceiveOnlineBatchExternalAttachmentResult = ReceiveOnlineBatchExternalAttachmentResult; 123 | } 124 | } 125 | 126 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 127 | public interface OnlineBatchReceiverSoapChannel : OnlineBatchReceiverSoap, System.ServiceModel.IClientChannel 128 | { 129 | } 130 | 131 | [System.Diagnostics.DebuggerStepThroughAttribute()] 132 | [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 133 | public partial class OnlineBatchReceiverSoapClient : System.ServiceModel.ClientBase, OnlineBatchReceiverSoap 134 | { 135 | 136 | public OnlineBatchReceiverSoapClient() 137 | { 138 | } 139 | 140 | public OnlineBatchReceiverSoapClient(string endpointConfigurationName) : 141 | base(endpointConfigurationName) 142 | { 143 | } 144 | 145 | public OnlineBatchReceiverSoapClient(string endpointConfigurationName, string remoteAddress) : 146 | base(endpointConfigurationName, remoteAddress) 147 | { 148 | } 149 | 150 | public OnlineBatchReceiverSoapClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 151 | base(endpointConfigurationName, remoteAddress) 152 | { 153 | } 154 | 155 | public OnlineBatchReceiverSoapClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 156 | base(binding, remoteAddress) 157 | { 158 | } 159 | 160 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 161 | ReceiveOnlineBatchExternalAttachmentResponse OnlineBatchReceiverSoap.ReceiveOnlineBatchExternalAttachment(ReceiveOnlineBatchExternalAttachmentRequest request) 162 | { 163 | return base.Channel.ReceiveOnlineBatchExternalAttachment(request); 164 | } 165 | 166 | public string ReceiveOnlineBatchExternalAttachment(string username, string passwd, string receiversReference, long sequenceNumber, string batch, byte[] attachments) 167 | { 168 | ReceiveOnlineBatchExternalAttachmentRequest inValue = new ReceiveOnlineBatchExternalAttachmentRequest(); 169 | inValue.Body = new ReceiveOnlineBatchExternalAttachmentRequestBody(); 170 | inValue.Body.username = username; 171 | inValue.Body.passwd = passwd; 172 | inValue.Body.receiversReference = receiversReference; 173 | inValue.Body.sequenceNumber = sequenceNumber; 174 | inValue.Body.batch = batch; 175 | inValue.Body.attachments = attachments; 176 | ReceiveOnlineBatchExternalAttachmentResponse retVal = ((OnlineBatchReceiverSoap)(this)).ReceiveOnlineBatchExternalAttachment(inValue); 177 | return retVal.Body.ReceiveOnlineBatchExternalAttachmentResult; 178 | } 179 | 180 | [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] 181 | System.Threading.Tasks.Task OnlineBatchReceiverSoap.ReceiveOnlineBatchExternalAttachmentAsync(ReceiveOnlineBatchExternalAttachmentRequest request) 182 | { 183 | return base.Channel.ReceiveOnlineBatchExternalAttachmentAsync(request); 184 | } 185 | 186 | public System.Threading.Tasks.Task ReceiveOnlineBatchExternalAttachmentAsync(string username, string passwd, string receiversReference, long sequenceNumber, string batch, byte[] attachments) 187 | { 188 | ReceiveOnlineBatchExternalAttachmentRequest inValue = new ReceiveOnlineBatchExternalAttachmentRequest(); 189 | inValue.Body = new ReceiveOnlineBatchExternalAttachmentRequestBody(); 190 | inValue.Body.username = username; 191 | inValue.Body.passwd = passwd; 192 | inValue.Body.receiversReference = receiversReference; 193 | inValue.Body.sequenceNumber = sequenceNumber; 194 | inValue.Body.batch = batch; 195 | inValue.Body.attachments = attachments; 196 | return ((OnlineBatchReceiverSoap)(this)).ReceiveOnlineBatchExternalAttachmentAsync(inValue); 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /outbound/Batch/AltinnBatchReceiverService/AltinnBatchReceiverService/OnlineBatchReceiverSoap.asmx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Configuration; 4 | using System.Diagnostics; 5 | using AltinnBatchReceiverService.Utils; 6 | using AltinnBatchReceiverService.Resources; 7 | using System.Reflection; 8 | 9 | namespace AltinnBatchReceiverService 10 | { 11 | 12 | /// 13 | /// Summary description for OnlineBatchReceiverSoap. 14 | /// 15 | /// 16 | /// This is a sample implementation of Altinn Service Receive. It receives messages and perform these steps: 17 | /// 1) Authenticate with username and password (just a placeholder in this sample code) 18 | /// 2) Verifies the Xml Batch Data vs. the Batch schema XSD file 19 | /// 3) Receives the message, in this example code it is saved to file, but in real solution it may pushed to MSMQ, saved to DB, sent to web service (async) or otherwise processed. 20 | /// 21 | /// This strategy is chosen on return: 22 | /// 23 | /// FAILED: When the message was not persisted. The same principle could apply for messages not saed to DB, not sent to MSMQ, failure on sending to an internal REST endpoint etc. 24 | /// The message will be resent by Altinn after a configured (default 30 seconds) time. 25 | /// This means that the message may have been received, but we could persist it or pass it on internally. 26 | /// We also set FAILED when the data load (batch) do not verify vs. schema. After 3 retries, Altinn will stop sending messages and the issue with the Schema must be corrected. 27 | /// 28 | /// FAILED_DO_NOT_RETRY: When the message was a duplicate. This is detected when saved to file. When other implementations are chosed such as MSMQ there should be some mechanism to detect 29 | /// that a message has been received. 30 | /// 31 | /// Regarding point 3: 32 | /// It is important to handle the reception of the message in such a way that we quickly return the result to Altinn. 33 | /// This means that further processing should be asynchronous with the message reception. 34 | /// Further processing may be done by either pulling files from the Inbox directory (using directory monitoring), pulling from MSMQ, receive an Synch stream on a REST service, pussing data from DB etc. 35 | /// 36 | /// Regarding Schema validation strategy: 37 | /// We have chosen to validate the Batch schema only as this is within Altinn's responsibility. 38 | /// The question is: should the Request Schema also be verified (the actual data from end user). 39 | /// This should not be done here as part of receiving the data as it is not within Altinn's responsibility. 40 | /// However, we suggest that this is first step of the further (asynchronous) processing of the message. 41 | /// 42 | /// We also validate the response schema. We suggest this is done only during development and testing, and be removed before production setting. 43 | /// 44 | /// Regarding Logging: 45 | /// We have chosen a very simple logging to file in this sample code, using a Semaphore to control concurrency. The configuration contain log file limit. When log file limit is reached, it is copied and 46 | /// a new empty log file is created. It also logs to the Application Event Log. The real service implementation may perfectly well use this approach, but may also choose other approaches such as: 47 | /// * Only logging to Event Log 48 | /// * Using NLog 49 | /// 50 | /// Regarding Security: 51 | /// This sample service implementation does not contain any transportation or policy security, this must be implemented by the service owner. 52 | /// 53 | /// Regarding the actual Schema Data: 54 | /// It would be an idea to validate the incoming data vs. the schema. This Schema is known by the Service Owner. 55 | /// 56 | /// 57 | public class OnlineBatchReceiverSoap : System.Web.Services.WebService, IOnlineBatchReceiverSoap 58 | { 59 | private const string FAILED_DO_NOT_RETRY = "FAILED_DO_NOT_RETRY"; 60 | private const string FAILED = "FAILED"; 61 | private const string OK = "OK"; 62 | 63 | /// 64 | /// This property is fetched from Web Config (key = inbox), see Web.Config file. 65 | /// This is where the messages will be saved. 66 | /// 67 | private static string inboxDirPath; 68 | 69 | /// 70 | /// This property is fetched from Web Config (key = batch_schema_path). 71 | /// This is the batch schema XSD 72 | /// 73 | private static string schFilePath; 74 | 75 | /// 76 | /// This property is fetched from Web Config (key = response_schema_path). 77 | /// This is the response schema XSD. Used to verify the response data vs. Schema. 78 | /// 79 | private static string rschFilePath; 80 | 81 | /// 82 | /// This static constructor is called only once, first time a message is received. 83 | /// 84 | /// 85 | /// Fetches configuration information and initiates the static properties. 86 | /// 87 | static OnlineBatchReceiverSoap() 88 | { 89 | GetConfig(); 90 | Logger.Log("Application Started"); 91 | } 92 | 93 | 94 | /// 95 | /// The receive endpoint fo the service 96 | /// 97 | /// The response XML (OnlineBatchReceipt.xsd) 98 | public string ReceiveOnlineBatchExternalAttachment(string username, string passwd, string receiversReference, long sequenceNumber, string batch, byte[] attachments) 99 | { 100 | 101 | //1. Authenticate username + passw: if not authenticated: log, ignore message and return failed do not retry 102 | // The Authenticate method must be implemented by Service owner. 103 | if (!Authenticate(username, passwd)) 104 | { 105 | Logger.Log($"User not authenticated: {username}", true); 106 | return BuildResponse(FAILED_DO_NOT_RETRY); 107 | } 108 | 109 | 110 | //2. Verify batch vs. XSD (Schema verification) - if fails: log the error and return failed do not retry 111 | if (!VerifyBatchSchema(batch)) 112 | { 113 | return BuildResponse(FAILED_DO_NOT_RETRY); 114 | } 115 | 116 | // We have chosen to capture all data within an object in order to serialize it, get hash code etc. 117 | // The service owner may for example choose just to keep the Batch and Attachments and pass them on for further asynchronous processing 118 | Payload payload = new Payload() 119 | { 120 | Username = username, 121 | Password = passwd, 122 | ReceiverReference = receiversReference, 123 | SequenceNumber = sequenceNumber, 124 | Batch = batch, 125 | Attachments = attachments 126 | }; 127 | 128 | 129 | //3. Save or add to queue - if fail, tell to resend or if duplicate - tell to ignore 130 | int ret = ReceiveMessage(payload); 131 | if (ret == 1) 132 | return BuildResponse(FAILED); 133 | else if (ret == 2) 134 | return BuildResponse(FAILED_DO_NOT_RETRY); 135 | 136 | return BuildResponse(OK); 137 | 138 | } 139 | 140 | 141 | /// 142 | /// This builds a response object which will be serialized as XML, and verified 143 | /// 144 | /// The response message 145 | /// The serialized XML 146 | /// 147 | /// respMessage must be one of: 148 | /// OK 149 | /// FAILED 150 | /// FAILED_DO_NOT_RETRY 151 | /// 152 | private string BuildResponse(string respMessage) 153 | { 154 | var response = new Response 155 | { 156 | Result = new Result 157 | { 158 | Code = respMessage 159 | } 160 | }; 161 | 162 | var xmlResponse = Response.SerializeAsXml(response); 163 | SchemaValidator.VerifyVsSchema(xmlResponse, rschFilePath); 164 | return Response.SerializeAsXml(response); 165 | } 166 | 167 | 168 | /// 169 | /// A place holder where the service owner authenticates the message and return TRUE if authenticated. 170 | /// 171 | /// The username as received from Altinn 172 | /// The password as received from Altinn 173 | /// True if authenticated 174 | private bool Authenticate(string username, string password) 175 | { 176 | // TODO: Add authentication, log if authentication fails 177 | return true; 178 | } 179 | 180 | /// 181 | /// This will verify the Batch data vs. the batch schema. 182 | /// 183 | /// Batch data (as XML) 184 | /// True if verified 185 | /// 186 | /// It will not be verified if the configuration does not contain any reference to the Schema. 187 | /// 188 | private bool VerifyBatchSchema(string batchXml) 189 | { 190 | return schFilePath == null || SchemaValidator.VerifyVsSchema(batchXml, schFilePath); 191 | } 192 | 193 | /// 194 | /// This is where the logic goes for processing the received message. 195 | /// 196 | /// The received data is placed in the Payload object 197 | /// 198 | /// 0 for OK 199 | /// 1 to Retry (Failed) 200 | /// 2 to Ignore (Failed do not retry) 201 | /// 202 | /// 203 | /// This is where the service owner can choose how to process the incoming message. 204 | /// We have chosed here to save to file, but other strategies could be implemented, 205 | /// as long as it is asynchronous with the further processing of user data. 206 | /// Example of other strategies: 207 | /// - Send to MSMQ. Receiving the message is asynchronous from sending. 208 | /// - Send to REST uri as a POST without return (fire and forget). 209 | /// - Save to DB. Another program will poll data and process it. 210 | /// - Save to File as done here, but in addition pass on to for example an internal Queue which is asynchronously picked up by another thread for further processing. 211 | /// 212 | private int ReceiveMessage(Payload payload) 213 | { 214 | string recref = payload.ReceiverReference ?? ""; 215 | string filepath = Path.Combine(inboxDirPath, "pl_" + payload.GetHashCode() + "_" + recref + ".xml"); 216 | 217 | // Here we perform a duplicate check of the file. 218 | // If we receive the message before, we inform Altinn of this by returning Failed do not retry. 219 | // Note that, for this work 100%, a receiverReference (GUID) should be used 220 | if (File.Exists(filepath)) 221 | { 222 | Logger.Log($"Duplicate message received {filepath}", true, EventLogEntryType.Warning); 223 | return 2; 224 | } 225 | 226 | try 227 | { 228 | if (payload.Attachments != null && payload.Attachments.Length > 0) 229 | { 230 | string attfilepath = filepath.Replace(".xml", ".zip"); 231 | File.WriteAllBytes(attfilepath, payload.Attachments); 232 | payload.Attachments = null; 233 | } 234 | 235 | Payload.SerializeAsXml(payload, filepath); 236 | } 237 | catch (Exception ex) 238 | { 239 | Logger.Log(ex.Message, true); 240 | return 1; 241 | } 242 | 243 | return 0; 244 | } 245 | 246 | /// 247 | /// Fetches all the configuraiton settings. 248 | /// See the Web.config file for how the configuration data is represented. 249 | /// 250 | private static void GetConfig() 251 | { 252 | string curpath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)); 253 | 254 | schFilePath = ConfigurationManager.AppSettings["batch_schema_path"]; 255 | rschFilePath = ConfigurationManager.AppSettings["response_schema_path"]; 256 | inboxDirPath = ConfigurationManager.AppSettings["inbox"]; 257 | 258 | if (!schFilePath.Contains(":")) 259 | schFilePath = Path.Combine(curpath, schFilePath); 260 | 261 | if (!rschFilePath.Contains(":")) 262 | rschFilePath = Path.Combine(curpath, rschFilePath); 263 | 264 | if (!inboxDirPath.Contains(":")) 265 | inboxDirPath = Path.Combine(curpath, inboxDirPath); 266 | 267 | if (!Directory.Exists(inboxDirPath)) 268 | Directory.CreateDirectory(inboxDirPath); 269 | } 270 | } 271 | } 272 | --------------------------------------------------------------------------------