示例#1
0
 public void AddDMSDokument(DMSDocument document)
 {
     if (document == null)
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(document.Filename))
     {
         throw new InvalidFileformatException("Dateiname not set");
     }
     if (this._documents == null)
     {
         this._documents = new List <DocumentType>();
     }
     else
     {
         if (document.Filename.Equals(MetadataFile.MetaDataFileName))
         {
             throw new InvalidFileformatException($"Adding a document with the name {document.Filename} is not allowed");
         }
         // Check if there is already an entry with the same name
         if (this._documents.Any(d =>
                                 string.Compare(d.Filename, document.Filename, StringComparison.OrdinalIgnoreCase) == 0))
         {
             // entry already exists
             throw new InvalidFileformatException($"An entry with filename {document.Filename} already exists");
         }
     }
     this._documents.Add(document);
 }
示例#2
0
        internal DocumentsCollection(XElement documentsElement, XNamespace ns) : base(ns)
        {
            var versionElement = documentsElement.Element(ns + ElementNameVersion);

            if (versionElement == null)
            {
                throw new InvalidFileformatException("Version-Element not found");
            }
            if (!int.TryParse(versionElement.Value, out int version) || version != (int)FileVersion.One)
            {
                throw new InvalidFileformatException("Version not supported");
            }
            this.Version = (FileVersion)version;
            var programsystemElement = documentsElement.Element(ns + ProgramSystemInfo.ElementName);

            if (programsystemElement != null)
            {
                this.Programsystem = new ProgramSystemInfo(programsystemElement, ns);
            }

            var documentElements   = documentsElement.Elements(ns + DocumentType.ElementName);
            var documentEnumerator = documentElements?.GetEnumerator();

            if (documentEnumerator == null || documentEnumerator.MoveNext() == false)
            {
                documentEnumerator?.Dispose();
                throw new InvalidFileformatException("Dokument element not found");
            }

            bool goOn = true; // MoveNext was called previously, so we have at least one document

            while (goOn)
            {
                var current = documentEnumerator.Current;
                var target  = this.GetValueFromElement(current, DocumentType.ElementNameZiel);
                if (target != DocumentTarget.Dms)
                {
                    throw new InvalidFileformatException($"Invalid Ziel {target}");
                }
                var dmsDocument = new DMSDocument(current, ns);
                this.AddDMSDokument(dmsDocument);
                goOn = documentEnumerator.MoveNext();
            }
        }