コード例 #1
0
        /// <summary>
        /// Get the data values for the specific site, variable and time range as a XML document
        /// in the WaterML format
        /// </summary>
        /// <param name="siteCode">the full site code (networkPrefix:siteCode)</param>
        /// <param name="variableCode">the full variable code (vocabularyPrefix:variableCode)</param>
        /// <param name="startTime">the start date/time</param>
        /// <param name="endTime">the end date/time</param>
        /// <param name="estimatedValuesCount">Estimated values count. 
        /// If this value less then zero, the result collection will necessarily contains only 1 file,
        /// otherwise number of file depends from this value.</param>
        /// <param name="progressHandler">Progress handler, may be null.</param>
        /// <returns>Collection of the downloaded xml file names</returns>
        public IEnumerable<string> GetValuesXML(string siteCode, string variableCode, 
                                                DateTime startTime, DateTime endTime, 
                                                int estimatedValuesCount, IGetValuesProgressHandler progressHandler = null)
        {
            if (allInOneRequest == true)
            {
                valuesPerReq = estimatedValuesCount;
            }

            int intervalsCount;

            if (estimatedValuesCount <= 0 || estimatedValuesCount <= valuesPerReq)
                intervalsCount = 1;
            else
                intervalsCount = estimatedValuesCount%valuesPerReq == 0
                                     ? estimatedValuesCount/valuesPerReq
                                     : estimatedValuesCount/valuesPerReq + 1;

            var datesDiff = endTime.Subtract(startTime);
            var daysPerInteval = datesDiff.Days/intervalsCount;

            var loopStartDate = startTime;
            var loopEndDate = loopStartDate.AddDays(daysPerInteval);

            var savedFiles = new List<string>(intervalsCount);
            for(int i = 0; i< intervalsCount; i++)
            {
                if (progressHandler != null &&
                    progressHandler.CancellationPending) break;

                if (i == intervalsCount - 1)
                {
                    loopEndDate = endTime;
                }

                var startGetTime = DateTime.Now;
                try
                {
                    var xmlFile = GetAndSavesValuesXML(siteCode, variableCode, loopStartDate, loopEndDate);
                    savedFiles.Add(xmlFile);
                }finally
                {
                    var endGetTime = DateTime.Now;
                    var timeTaken = endGetTime.Subtract(startGetTime).TotalSeconds;
                    if (progressHandler != null)
                    {
                        progressHandler.Progress(i, intervalsCount, timeTaken);
                    }
                }

                // Set loop dates to next interval
                loopStartDate = loopEndDate.AddMinutes(1); //AddDays(1);
                loopEndDate = loopStartDate.AddDays(daysPerInteval);
            }

            return savedFiles.AsEnumerable();
        }
コード例 #2
0
        /// <summary>
        /// This function is used to get the Values in XML Format based on the selected sites in the layer
        /// </summary>
        /// <param name="info">DownloadInfo</param>
        /// <param name="getValueProgressHandler">Progress handler</param>
        /// <returns>Collection of of the xml files with values</returns>
        /// <exception cref="DownloadXmlException">Some exception during get values from web service</exception>
        public IEnumerable <string> DownloadXmlDataValues(OneSeriesDownloadInfo info, IGetValuesProgressHandler getValueProgressHandler)
        {
            try
            {
                return(GetWsClientInstance(info.Wsdl).GetValuesXML(info.FullSiteCode, info.FullVariableCode,
                                                                   info.StartDate, info.EndDate,
                                                                   info.EstimatedValuesCount,
                                                                   getValueProgressHandler));
            }
            catch (Exception ex)
            {
                Exception exToWrap;
                if (ex is TargetInvocationException &&
                    ex.InnerException != null)
                {
                    exToWrap = ex.InnerException;
                }
                else
                {
                    exToWrap = ex;
                }

                throw new DownloadXmlException(exToWrap.Message, exToWrap);
            }
        }
コード例 #3
0
        /// <summary>
        /// Get the data values for the specific site, variable and time range as a XML document
        /// in the WaterML format
        /// </summary>
        /// <param name="siteCode">the full site code (networkPrefix:siteCode)</param>
        /// <param name="variableCode">the full variable code (vocabularyPrefix:variableCode)</param>
        /// <param name="startTime">the start date/time</param>
        /// <param name="endTime">the end date/time</param>
        /// <param name="estimatedValuesCount">Estimated values count.
        /// If this value less then zero, the result collection will necessarily contains only 1 file,
        /// otherwise number of file depends from this value.</param>
        /// <param name="progressHandler">Progress handler, may be null.</param>
        /// <returns>Collection of the downloaded xml file names</returns>
        public IEnumerable <string> GetValuesXML(string siteCode, string variableCode,
                                                 DateTime startTime, DateTime endTime,
                                                 int estimatedValuesCount, IGetValuesProgressHandler progressHandler = null)
        {
            const int valuesPerReq = 5000;

            int intervalsCount;

            if (estimatedValuesCount <= 0 || estimatedValuesCount <= valuesPerReq)
            {
                intervalsCount = 1;
            }
            else
            {
                intervalsCount = estimatedValuesCount % valuesPerReq == 0
                                     ? estimatedValuesCount / valuesPerReq
                                     : estimatedValuesCount / valuesPerReq + 1;
            }

            var datesDiff      = endTime.Subtract(startTime);
            var daysPerInteval = datesDiff.Days / intervalsCount;

            var loopStartDate = startTime;
            var loopEndDate   = loopStartDate.AddDays(daysPerInteval);

            var savedFiles = new List <string>(intervalsCount);

            for (int i = 0; i < intervalsCount; i++)
            {
                if (progressHandler != null &&
                    progressHandler.CancellationPending)
                {
                    break;
                }

                if (i == intervalsCount - 1)
                {
                    loopEndDate = endTime;
                }

                var startGetTime = DateTime.Now;
                try
                {
                    var xmlFile = GetAndSavesValuesXML(siteCode, variableCode, loopStartDate, loopEndDate);
                    savedFiles.Add(xmlFile);
                }finally
                {
                    var endGetTime = DateTime.Now;
                    var timeTaken  = endGetTime.Subtract(startGetTime).TotalSeconds;
                    if (progressHandler != null)
                    {
                        progressHandler.Progress(i, intervalsCount, timeTaken);
                    }
                }

                // Set loop dates to next interval
                loopStartDate = loopEndDate.AddDays(1);
                loopEndDate   = loopStartDate.AddDays(daysPerInteval);
            }

            return(savedFiles.AsEnumerable());
        }