예제 #1
0
        private static MetadataIndexViewModel ParseSearchResults(int offset, int limit, SearchResultsType results)
        {
            var model = new MetadataIndexViewModel();
            var metadata = new Dictionary<string, MetadataItemViewModel>();

            if (results.Items != null)
            {
                foreach (var item in results.Items)
                {
                    RecordType record = (RecordType)item;

                    string title = null;
                    string uuid = null;
                    string publisher = null;
                    string creator = null;
                    string organization = null;
                    string type = null;
                    string relation = null;

                    string uri = null;
                    string uriProtocol = null;
                    string uriName = null;

                    for (int i = 0; i < record.ItemsElementName.Length; i++)
                    {
                        var name = record.ItemsElementName[i];
                        var value = record.Items[i].Text != null ? record.Items[i].Text[0] : null;

                        if (name == ItemsChoiceType24.title)
                            title = value;
                        else if (name == ItemsChoiceType24.identifier)
                            uuid = value;
                        else if (name == ItemsChoiceType24.creator)
                            creator = value;
                        else if (name == ItemsChoiceType24.publisher)
                            publisher = value;
                        else if (name == ItemsChoiceType24.type)
                            type = value;
                        else if (name == ItemsChoiceType24.relation)
                            relation = value;
                        else if (name == ItemsChoiceType24.URI)
                        {
                            uri = value;
                            var uriAttributes = (SimpleUriLiteral)record.Items[i];
                            if (uriAttributes != null)
                            {
                                if (!string.IsNullOrEmpty(uriAttributes.protocol))
                                    uriProtocol = uriAttributes.protocol;
                                if (!string.IsNullOrEmpty(uriAttributes.name))
                                    uriName = uriAttributes.name;
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(creator))
                    {
                        organization = creator;
                    }
                    else
                    {
                        organization = publisher;
                    }

                    var metadataItem = new MetadataItemViewModel
                    {
                        Title = title,
                        Uuid = uuid,
                        Organization = organization,
                        Type = type,
                        Relation = relation,
                        GeoNetworkViewUrl = GeoNetworkUtil.GetViewUrl(uuid),
                        GeoNetworkXmlDownloadUrl = GeoNetworkUtil.GetXmlDownloadUrl(uuid),
                        Uri = uri,
                        UriProtocol = uriProtocol,
                        UriName = uriName
                    };

                    if (uuid != null)
                        metadata.Add(uuid, metadataItem);

                }

                model.MetadataItems = metadata.Values.ToList();
                model.Limit = limit;
                model.Offset = offset;
                model.NumberOfRecordsReturned = int.Parse(results.numberOfRecordsReturned);
                model.TotalNumberOfRecords = int.Parse(results.numberOfRecordsMatched);
            }
            return model;
        }
        private static MetadataIndexViewModel ParseSearchResults(int offset, int limit, SearchResultsType results)
        {
            var model    = new MetadataIndexViewModel();
            var metadata = new Dictionary <string, MetadataItemViewModel>();

            if (results.Items != null)
            {
                foreach (var item in results.Items)
                {
                    RecordType record = (RecordType)item;

                    string title        = null;
                    string uuid         = null;
                    string publisher    = null;
                    string creator      = null;
                    string organization = null;
                    string type         = null;
                    string relation     = null;

                    for (int i = 0; i < record.ItemsElementName.Length; i++)
                    {
                        var name  = record.ItemsElementName[i];
                        var value = record.Items[i].Text != null ? record.Items[i].Text[0] : null;

                        if (name == ItemsChoiceType24.title)
                        {
                            title = value;
                        }
                        else if (name == ItemsChoiceType24.identifier)
                        {
                            uuid = value;
                        }
                        else if (name == ItemsChoiceType24.creator)
                        {
                            creator = value;
                        }
                        else if (name == ItemsChoiceType24.publisher)
                        {
                            publisher = value;
                        }
                        else if (name == ItemsChoiceType24.type)
                        {
                            type = value;
                        }
                        else if (name == ItemsChoiceType24.relation)
                        {
                            relation = value;
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(publisher))
                    {
                        organization = publisher;
                    }
                    else
                    {
                        organization = creator;
                    }

                    var metadataItem = new MetadataItemViewModel
                    {
                        Title                    = title,
                        Uuid                     = uuid,
                        Organization             = organization,
                        Type                     = type,
                        Relation                 = relation,
                        GeoNetworkViewUrl        = GeoNetworkUtil.GetViewUrl(uuid),
                        GeoNetworkXmlDownloadUrl = GeoNetworkUtil.GetXmlDownloadUrl(uuid)
                    };

                    if (uuid != null)
                    {
                        metadata.Add(uuid, metadataItem);
                    }
                }

                model.MetadataItems           = metadata.Values.ToList();
                model.Limit                   = limit;
                model.Offset                  = offset;
                model.NumberOfRecordsReturned = int.Parse(results.numberOfRecordsReturned);
                model.TotalNumberOfRecords    = int.Parse(results.numberOfRecordsMatched);
            }
            return(model);
        }
        private static MetadataIndexViewModel ParseSearchResults(int offset, int limit, SearchResultsType results)
        {
            var model = new MetadataIndexViewModel();
            var metadata = new Dictionary<string, MetadataItemViewModel>();

            if (results.Items != null)
            {
                foreach (var item in results.Items)
                {
                    RecordType record = (RecordType)item;

                    string title = null;
                    string uuid = null;
                    string publisher = null;
                    string creator = null;
                    string organization = null;
                    string type = null;
                    string relation = null;

                    for (int i = 0; i < record.ItemsElementName.Length; i++)
                    {
                        var name = record.ItemsElementName[i];
                        var value = record.Items[i].Text != null ? record.Items[i].Text[0] : null;

                        if (name == ItemsChoiceType24.title)
                            title = value;
                        else if (name == ItemsChoiceType24.identifier)
                            uuid = value;
                        else if (name == ItemsChoiceType24.creator)
                            creator = value;
                        else if (name == ItemsChoiceType24.publisher)
                            publisher = value;
                        else if (name == ItemsChoiceType24.type)
                            type = value;
                        else if (name == ItemsChoiceType24.relation)
                            relation = value;
                    }

                    if (!string.IsNullOrWhiteSpace(publisher))
                    {
                        organization = publisher;
                    }
                    else
                    {
                        organization = creator;
                    }

                    var metadataItem = new MetadataItemViewModel { Title = title, Uuid = uuid, Organization = organization, Type = type, Relation = relation };

                    metadata.Add(uuid, metadataItem);

                }

                model.MetadataItems = metadata.Values.ToList();
                model.Limit = limit;
                model.Offset = offset;
                model.NumberOfRecordsReturned = int.Parse(results.numberOfRecordsReturned);
                model.TotalNumberOfRecords = int.Parse(results.numberOfRecordsMatched);
            }
            return model;
        }