Esempio n. 1
0
        //---------------------------------------------------------------------------------------------------------------------

        /// <summary>Queries the catalogue and receives the data sets to build the result.</summary>
        /// <param name="minCount">Minimum number of data sets to be included. If the minimum number is not reached, the result will be empty.</param>
        /// <param name="maxCount">Maxium number of data sets to be included.</param>
        public void GetDataSets(int minCount, int maxCount)
        {
            this.minCount = minCount;
            this.maxCount = maxCount;

            if (Url != null)
            {
                // Get the element names from the configuration file
                XmlDocument configDoc     = new XmlDocument();
                XmlElement  catalogueElem = null;
                bool        success       = false;
                try {
                    configDoc.Load(context.SiteConfigFolder + "/services.xml");
                    success = ((catalogueElem = configDoc.SelectSingleNode("/services/dataset/catalogue[@type='application/rdf+xml']") as XmlElement) != null);
                } catch (Exception) {
                }

                if (success)
                {
                    for (int i = 0; i < catalogueElem.ChildNodes.Count; i++)
                    {
                        XmlElement elem = catalogueElem.ChildNodes[i] as XmlElement;
                        if (elem == null || !elem.HasAttribute("name"))
                        {
                            continue;
                        }
                        switch (elem.Attributes["name"].Value)
                        {
                        case "dataset":
                            DataSetXmlName = elem.InnerXml;
                            break;

                        case "value":
                            ResourceXmlName = elem.InnerXml;
                            break;

                        case "_identifier":
                            IdentifierXmlName = elem.InnerXml;
                            break;

                        case "_size":
                            SizeXmlName = elem.InnerXml;
                            break;
                        }
                    }
                }
                else if (context.UserLevel == UserLevel.Administrator)
                {
                    context.AddWarning("Invalid catalogue metadata configuration");
                }

                // Get first result
                context.AddDebug(2, "Catalogue query (base): " + Url);
                if (!AddResultsFromRdf(Url, 0, (maxCount > ResultsPerRequest ? ResultsPerRequest : maxCount)))
                {
                    context.WriteInfo(String.Format("Return 1"));
                    return;
                }

                if (maxCount == 0 || TotalResults < minCount)
                {
                    InitializeData(0);
                    return;
                }

                // If necessary, do more requests
                if (maxCount > TotalResults)
                {
                    maxCount = TotalResults;
                }
                while (ReceivedResults < maxCount)
                {
                    if (!AddResultsFromRdf(Url, ReceivedResults, (maxCount > ReceivedResults + ResultsPerRequest ? ResultsPerRequest : maxCount - ReceivedResults)))
                    {
                        break;
                    }
                }
                context.AddDebug(2, "Catalogue results: " + ReceivedResults + " (total results: " + TotalResults + ")");
            }
            else if (DataSetParameter != null && context is IfyWebContext)
            {
                TotalResults    = DataSetParameter.Values.Length;
                ReceivedResults = TotalResults;

                InitializeData(ReceivedResults);

                string[] paramValues;
                paramValues = StringUtils.Split((context as IfyWebContext).GetParamValue(DataSetParameter.Name + ":_identifier"), DataSetParameter.Separator);
                if (paramValues.Length == ReceivedResults)
                {
                    for (int i = 0; i < ReceivedResults; i++)
                    {
                        DataSetIdentifiers[i] = paramValues[i];
                    }
                }
                paramValues = StringUtils.Split((context as IfyWebContext).GetParamValue(DataSetParameter.Name + ":_size"), DataSetParameter.Separator);
                if (paramValues.Length == ReceivedResults)
                {
                    for (int i = 0; i < ReceivedResults; i++)
                    {
                        Int64.TryParse(paramValues[i], out DataSetSizes[i]);
                    }
                }

                /*for (int i = 0; i < dataSetTotalCount; i++) DataSets[i] = new DataSetInfo(this, i, DataSetParameter.Values[i], sizes[i], startTimes[i], endTimes[i]); */

                for (int i = 0; i < ReceivedResults; i++)
                {
                    DataSets[i]         = new CatalogueDataSetInfo(this, i);
                    DataSetResources[i] = DataSetParameter.Values[i];
                }

                foreach (KeyValuePair <string, string> kvp in MetadataElementNames)
                {
                    metadataValues[kvp.Key] = new TypedValue[ReceivedResults];
                    paramValues             = StringUtils.Split((context as IfyWebContext).GetParamValue(DataSetParameter.Name + ":" + kvp.Key), DataSetParameter.Separator);
                    if (paramValues.Length == ReceivedResults)
                    {
                        for (int i = 0; i < ReceivedResults; i++)
                        {
                            SetMetadataValue(i, kvp.Key, paramValues[i]);
                        }
                    }
                }

                /*string paramValue = context.GetParamValue(paramName);
                 * datasetParam
                 * string[] paramValues = StringUtils.Split(paramValue, ';');
                 * DataSets = new DataSetInfo[];
                 * int[] fileSizes;
                 * DateTime[] startDates;
                 * DateTime[] endDates;*/
            }
        }