Exemplo n.º 1
0
        public static Header Read(StandardBusinessDocumentHeader sbdh) // throws SbdhException
        {
            Header header = Header.NewInstance();

            // Sender
            PartnerIdentification senderIdentifier = sbdh.Sender[0].Identifier;

            header = header.SetSender(
                ParticipantIdentifier.Of(senderIdentifier.Value, Scheme.Of(senderIdentifier.Authority)));

            // Receiver
            PartnerIdentification receiverIdentifier = sbdh.Receiver[0].Identifier;

            header = header.SetReceiver(
                ParticipantIdentifier.Of(receiverIdentifier.Value, Scheme.Of(receiverIdentifier.Authority)));

            // Identifier
            header = header.SetIdentifier(InstanceIdentifier.Of(sbdh.DocumentIdentification.InstanceIdentifier));

            // InstanceType
            header = header.SetInstanceType(
                InstanceType.Of(
                    sbdh.DocumentIdentification.Standard,
                    sbdh.DocumentIdentification.Type,
                    sbdh.DocumentIdentification.TypeVersion));

            // CreationTimestamp
            if (sbdh.DocumentIdentification.CreationDateAndTime == null)
            {
                throw new SbdhException("Element 'CreationDateAndTime' is not set or contains invalid value.");
            }

            header = header.SetCreationTimestamp(sbdh.DocumentIdentification.CreationDateAndTime);

            // Scope
            foreach (Scope scope in sbdh.BusinessScope)
            {
                if (scope.Type.Equals("DOCUMENTID"))
                {
                    Scheme scheme = scope.Identifier != null
                                        ? Scheme.Of(scope.Identifier)
                                        : DocumentTypeIdentifier.DefaultScheme;

                    header = header.SetDocumentType(DocumentTypeIdentifier.Of(scope.InstanceIdentifier, scheme));
                }
                else if (scope.Type.Equals("PROCESSID"))
                {
                    Scheme scheme = scope.Identifier != null
                                        ? Scheme.Of(scope.Identifier)
                                        : ProcessIdentifier.DefaultScheme;

                    header = header.SetProcess(ProcessIdentifier.Of(scope.InstanceIdentifier, scheme));
                }
            }

            return(header);
        }
Exemplo n.º 2
0
        public static void Write(XmlTextWriter streamWriter, Header header)
        {
            try
            {
                StandardBusinessDocumentHeader sbdh = new StandardBusinessDocumentHeader();
                sbdh.HeaderVersion = "1.0";

                // Sender
                sbdh.Sender = new[] { SbdhHelper.CreatePartner(header.Sender) };

                // Receiver
                sbdh.Receiver = new[] { SbdhHelper.CreatePartner(header.Receiver) };

                sbdh.DocumentIdentification = new DocumentIdentification();
                // Standard
                sbdh.DocumentIdentification.Standard = header.InstanceType.Standard;
                // TypeVersion
                sbdh.DocumentIdentification.TypeVersion = header.InstanceType.Version;
                // Identifier
                sbdh.DocumentIdentification.InstanceIdentifier = header.Identifier.Identifier;
                // Type
                sbdh.DocumentIdentification.Type = header.InstanceType.Type;
                // CreationDateAndTime
                var creationTime = header.CreationTimestamp;
                if (creationTime == null)
                {
                    throw new InvalidOperationException("CreationTimestamp cannot be null");
                }
                sbdh.DocumentIdentification.CreationDateAndTime = creationTime.Value;

                sbdh.BusinessScope = new[]
                {
                    // DocumentID
                    SbdhHelper.CreateScope(header.DocumentType),
                    // ProcessID
                    SbdhHelper.CreateScope(header.Process)
                };

                XmlTools.WriteXmlFragment(streamWriter, sbdh);
            }
            catch (Exception e)
            {
                throw new SbdhException("Unable to write SBDH.", e);
            }
        }
Exemplo n.º 3
0
        private async Task <StandardBusinessDocument> ConstructStandardBusinessDocument(string instanceGuid, Instance instance)
        {
            DateTime completedTime = DateTime.Now;

            Sender digdirSender = new Sender
            {
                Identifier = new Identifier
                {
                    // 0192 prefix for all Norwegian organisations.
                    Value     = $"0192:{_appSettings.EFormidlingSender}",
                    Authority = "iso6523-actorid-upis"
                }
            };

            List <Receiver> receivers = await GetEFormidlingReceivers(instance);

            Scope scope =
                new Scope
            {
                Identifier         = _appMetadata.EFormidling.Process,
                InstanceIdentifier = Guid.NewGuid().ToString(),
                Type             = "ConversationId",
                ScopeInformation = new List <ScopeInformation>
                {
                    new ScopeInformation
                    {
                        ExpectedResponseDateTime = completedTime.AddHours(2)
                    }
                },
            };

            BusinessScope businessScope = new BusinessScope
            {
                Scope = new List <Scope> {
                    scope
                }
            };

            DocumentIdentification documentIdentification = new DocumentIdentification
            {
                InstanceIdentifier  = instanceGuid,
                Standard            = _appMetadata.EFormidling.Standard,
                TypeVersion         = _appMetadata.EFormidling.TypeVersion,
                CreationDateAndTime = completedTime,
                Type = _appMetadata.EFormidling.Type
            };

            StandardBusinessDocumentHeader sbdHeader = new StandardBusinessDocumentHeader
            {
                HeaderVersion          = "1.0",
                BusinessScope          = businessScope,
                DocumentIdentification = documentIdentification,
                Receiver = receivers,
                Sender   = new List <Sender> {
                    digdirSender
                }
            };

            StandardBusinessDocument sbd = new StandardBusinessDocument
            {
                StandardBusinessDocumentHeader = sbdHeader,
                Arkivmelding = new Arkivmelding {
                    Sikkerhetsnivaa = _appMetadata.EFormidling.SecurityLevel
                },
            };

            return(sbd);
        }