Beispiel #1
0
 public static XElement Encode(Metadata dublinCore, string granularity)
 {
     return new XElement(MlNamespaces.oaiDc + "dc",
             new XAttribute(XNamespace.Xmlns + "oai_dc", MlNamespaces.oaiDc),
             new XAttribute(XNamespace.Xmlns + "dc", MlNamespaces.dcNs),
             new XAttribute(XNamespace.Xmlns + "xsi", MlNamespaces.dcXsi),
             new XAttribute(MlNamespaces.dcXsi + "schemaLocation", MlNamespaces.dcSchemaLocation),
             /* content */
             MlEncode.Element(MlNamespaces.dcNs + "title", dublinCore.Title),
             MlEncode.Element(MlNamespaces.dcNs + "creator", dublinCore.Creator),
             MlEncode.Element(MlNamespaces.dcNs + "subject", dublinCore.Subject),
             MlEncode.Element(MlNamespaces.dcNs + "description", dublinCore.Description),
             MlEncode.Element(MlNamespaces.dcNs + "publisher", dublinCore.Publisher),
             MlEncode.Element(MlNamespaces.dcNs + "contributor", dublinCore.Contributor),
             !dublinCore.Date.HasValue ? null
                    : new XElement(MlNamespaces.dcNs + "date",
                        dublinCore.Date.Value.ToUniversalTime().ToString(granularity)),
             MlEncode.Element(MlNamespaces.dcNs + "type", dublinCore.Type),
             MlEncode.Element(MlNamespaces.dcNs + "format", dublinCore.Format),
             MlEncode.Element(MlNamespaces.dcNs + "identifier", dublinCore.Identifier),
             MlEncode.Element(MlNamespaces.dcNs + "source", dublinCore.Source),
             MlEncode.Element(MlNamespaces.dcNs + "language", dublinCore.Language),
             MlEncode.Element(MlNamespaces.dcNs + "relation", dublinCore.Relation),
             MlEncode.Element(MlNamespaces.dcNs + "coverage", dublinCore.Coverage),
             MlEncode.Element(MlNamespaces.dcNs + "rights", dublinCore.Rights)
            );
 }
Beispiel #2
0
        public static void AddRecMetadataToDatabase(OaiPmhContext context, int recId, Metadata metadata)
        {
            if (context == null || recId == 0 || metadata == null)
            {
                return;
            }

            AddToDatabase(context, recId, Enums.ObjectType.OAIRecord, Enums.MetadataType.Metadata, metadata);
        }
Beispiel #3
0
 public static void AddMetadataToDatabase(OaiPmhContext context, int objId, byte objType, byte metaType, Metadata metadata)
 {
     context.Metadata.Add(metadata);
     context.SaveChanges();
     context.ObjectMetadata.Add(new ObjectMetadata()
     {
         ObjectId = objId,
         ObjectType = objType,
         MetadataType = metaType,
         MetadataId = metadata.MetadataId
     });
 }
Beispiel #4
0
        public static void AddToDatabase(OaiPmhContext context, int objId, byte objType, byte metaType, Metadata metadata)
        {
            switch (FormatList.Int2Format(metadata.MdFormat))
            {
                case Enums.MetadataFormats.DublinCore:
                    DublinCore.AddToDatabase(context, objId, objType, metaType, metadata);
                    break;
                case Enums.MetadataFormats.Provenance:
                    Provenance.AddToDatabase(context, objId, objType, metaType, metadata);
                    break;

                // TODO: Add format here

                case Enums.MetadataFormats.None:
                default:
                    break;
            }
        }
Beispiel #5
0
        public static XElement Metadata(string containerName, Metadata metadata, string granularity)
        {
            if (string.IsNullOrEmpty(containerName) || metadata == null || string.IsNullOrEmpty(granularity))
            {
                return null;
            }

            switch (FormatList.Int2Format(metadata.MdFormat))
            {
                case Enums.MetadataFormats.DublinCore:
                    return new XElement(containerName, DublinCore.Encode(metadata, granularity));
                case Enums.MetadataFormats.Provenance:
                    return new XElement(containerName, Provenance.Encode(metadata, granularity));

                // TODO: Add format here

                case Enums.MetadataFormats.None:
                default:
                    return null;
            }
        }
Beispiel #6
0
 public static void AddToDatabase(OaiPmhContext context, int objId, byte objType, byte metaType, Metadata dublinCore)
 {
     DbQueries.AddMetadataToDatabase(context, objId, objType, metaType, dublinCore);
 }
 public RecordQueryResult(Header header, Metadata metadata, IEnumerable<Metadata> about)
 {
     this.Header = header;
     this.Metadata = metadata;
     this.About = about == null ? null : about.ToList();
 }
 public RecordQueryResult(Header header, Metadata metadata)
 {
     this.Header = header;
     this.Metadata = metadata;
 }
Beispiel #9
0
        public static XElement Encode(Metadata provenance, string granularity)
        {
            XElement mainElement = EncodeOne(provenance, granularity);

            if (provenance.NestedElements != null && provenance.NestedElements.Count > 0)
            {
                /* nest origin descriptions */
                XElement tempElement = mainElement;
                foreach (var item in provenance.NestedElements)
                {
                    tempElement.Add(EncodeOne(item, granularity));
                    tempElement = tempElement.Element("originDescription");
                }
            }

            return new XElement(MlNamespaces.provNs + "provenance",
                        new XAttribute(XNamespace.Xmlns + "xsi", MlNamespaces.provXsi),
                        new XAttribute(MlNamespaces.provXsi + "schemaLocation", MlNamespaces.provSchemaLocation),
                        mainElement
                       );
        }
Beispiel #10
0
        public static void AddToDatabase(OaiPmhContext context, int objId, byte objType, byte metaType, Metadata provenance)
        {
            context.Metadata.Add(provenance);
            context.SaveChanges();
            context.ObjectMetadata.Add(new ObjectMetadata()
            {
                ObjectId = objId,
                ObjectType = objType,
                MetadataType = metaType,
                MetadataId = provenance.MetadataId
            });

            if (provenance.NestedElements != null)
            {
                int prevId = provenance.MetadataId;
                foreach (var item in provenance.NestedElements)
                {
                    item.AdditionalInt1 = prevId;

                    context.Metadata.Add(item);
                    context.SaveChanges();
                    context.ObjectMetadata.Add(new ObjectMetadata()
                    {
                        ObjectId = objId,
                        ObjectType = objType,
                        MetadataType = metaType,
                        MetadataId = item.MetadataId
                    });

                    prevId = item.MetadataId;
                }
            }
        }
Beispiel #11
0
 private static XElement EncodeOne(Metadata provenance, string granularity)
 {
     return new XElement("originDescription",
                 new XAttribute("harvestDate",
                     DateInGranularity(provenance.AdditionalDateTime1, provenance.AdditionalBool2, granularity)),
                 new XAttribute("altered",
                     !provenance.AdditionalBool1.HasValue ? bool.FalseString.ToLower() :
                         provenance.AdditionalBool1.Value.ToString().ToLower()),
                 MlEncode.Element("baseUrl", provenance.Source),
                 MlEncode.Element("identifier", provenance.Identifier),
                 new XAttribute("datestamp",
                     DateInGranularity(provenance.Date, provenance.AdditionalBool3, granularity)),
                 MlEncode.Element("metadataNamespace", provenance.Format)
                );
 }
Beispiel #12
0
 private static void DeleteMetadataAndLink(OaiPmhContext context, ObjectMetadata objectMetadata, Metadata metadata)
 {
     if (metadata != null)
     {
         context.Metadata.Remove(metadata);
     }
     if (objectMetadata != null)
     {
         context.ObjectMetadata.Remove(objectMetadata);
     }
 }
Beispiel #13
0
 public static async Task<XElement> MetadataAsync(string containerName, Metadata metadata, string granularity)
 {
     return await Task.Run<XElement>(() => Metadata(containerName, metadata, granularity)).ConfigureAwait(false);
 }
Beispiel #14
0
 public static XElement Metadata(Metadata metadata, string granularity)
 {
     return Metadata("metadata", metadata, granularity);
 }