当前位置: 首页>>代码示例>>C#>>正文


C# DataSet.GetData方法代码示例

本文整理汇总了C#中DataSet.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.GetData方法的具体用法?C# DataSet.GetData怎么用?C# DataSet.GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataSet的用法示例。


在下文中一共展示了DataSet.GetData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildBatchResult

        public static FetchClimateBatchResponce BuildBatchResult(DataSet ds)
        {
            if (IsProcessingSuccessful(ds)) // success
            {
                FetchClimateBatchResponce res = new FetchClimateBatchResponce();
                if (ds.Metadata.ContainsKey(Namings.metadataNameServiceVersion))
                    res.ServiceVersion = ds.Metadata[Namings.metadataNameServiceVersion].ToString();
                var activeParameter=Namings.GetParameterByName((string)ds.Metadata[Namings.metadataNameParameter]);
                //var activeCoverage = Namings.GetCoverageByName((string)ds.Metadata[Namings.metadataNameCoverage]);
                res.Values=null;
                double[] result = (double[])ds.Variables[Namings.VarNameResult].GetData();
                double[] uncertatinty = null;
                string[] provenance = null;
                if (ds.Variables.Contains(Namings.VarNameUncertainty))
                    uncertatinty = (double[])ds.Variables[Namings.VarNameUncertainty].GetData();
                else
                    uncertatinty = new double[result.Length];
                provenance = new string[result.Length];

                ushort[] ids = null;
                short[] provArr = null;
                string[] descs = null;

                if (ds.Variables.Contains(Namings.VarNameResultProvenance) && ds.Variables.Contains(Namings.VarNameConfigProcDesc) && ds.Variables.Contains(Namings.VarNameConfigProcId))
                {
                    ids = (ushort[])ds.Variables[Namings.VarNameConfigProcId].GetData();
                    descs = (string[])ds.Variables[Namings.VarNameConfigProcDesc].GetData();
                    provArr = (short[])ds.Variables[Namings.VarNameResultProvenance].GetData();
                    for (int i = 0; i < provArr.Length; i++)
                        provenance[i] = descs[ids[provArr[i]]];
                }
                else
                {
                    provArr=Enumerable.Repeat<short>(0, provenance.Length).ToArray();
                }
                Func<double,double,ClimateParameterValue> ClimateValueConstructor = null;                
                switch(activeParameter)
                {
                    case Service.ClimateParameter.FC_TEMPERATURE:
                        ClimateValueConstructor = (r, u) => new TemperatureValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_PRECIPITATION:
                        ClimateValueConstructor =  (r, u) => new PrecipitationValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_SOIL_MOISTURE:
                        ClimateValueConstructor = (r, u) => new SoilMoistureValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_RELATIVE_HUMIDITY:
                        ClimateValueConstructor =  (r, u) => new RelativeHumidityValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_ELEVATION:
                       ClimateValueConstructor =  (r, u) => new ElevationValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_DIURNAL_TEMPERATURE_RANGE:
                        ClimateValueConstructor =  (r, u) => new DiurnalTemperatureRangeValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_FROST_DAY_FREQUENCY:
                        ClimateValueConstructor =  (r, u) => new FrostDayFrequencyValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_WET_DAY_FREQUENCY:
                        ClimateValueConstructor = (r, u) => new WetDayFrequencyValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_WIND_SPEED:
                        ClimateValueConstructor = (r, u) => new WindSpeedValue(r, u);
                        break;
                    case Service.ClimateParameter.FC_SUN_PERCENTAGE:
                        ClimateValueConstructor = (r,u) => new SunPercentageValue(r,u);
                        break;                    
                    default:
                        throw new NotSupportedException();
                }
                res.Values = result
                    .Zip(uncertatinty, ClimateValueConstructor)
                    .Zip(provArr, (val, id) => { val.ProvenanceId = id; return val; })
                    .Select(val => { val.ProcDesc = descs; val.ProcIds = ids; return val; })
                    .Zip(provenance, (val, prov) => { val.Provenance = prov; return val; })
                    .ToArray();

                res.ProvenanceUsed = ds.Metadata.ContainsKey(Namings.metadataNameProvenanceUsed) && (ds.Metadata[Namings.metadataNameProvenanceUsed]!=null) ?
                    ds.Metadata[Namings.metadataNameProvenanceUsed].ToString()
                    : "Unknown";
                return res;
            }
            else // failure
            {
                StringBuilder sb = new StringBuilder("Computation failed");
                string[] mess = ds.GetData<string[]>(Namings.VarNameLogMessage);
                string[] types = ds.GetData<string[]>(Namings.VarNameLogMessageType);
                DateTime[] times = ds.GetData<DateTime[]>(Namings.VarNameLogMessageTime);
                for (int i = 0; i < mess.Length; i++)
                {
                    sb.AppendLine().Append(String.Format("{0}({1}):{2}", times[i], types[i], mess[i]));
                }
                throw new Exception(sb.ToString());
            }
        }
开发者ID:modulexcite,项目名称:SDSlite,代码行数:96,代码来源:FetchClimateRequestBuilder.cs


注:本文中的DataSet.GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。