5 Replies Latest reply on Feb 24, 2016 1:57 PM by pthivierge

    conversion of pointList.Summaries to datatable using linq

    NEERAJ

      Hi,

       

      I am using below code for converting pointList.Summaries to datatable,but this is slow.Is it possible to do this using linq to make it faster?

       

      PIPointList pointList = new PIPointList(PIPoint.FindPIPoints(pi, "sinu*")); 

                  var vals = pointList.Summaries(new AFTimeRange("*-1h", "*"), new AFTimeSpan(0, 0, 0, 0, 15, 0, 0), OSIsoft.AF.Data.AFSummaryTypes.All, OSIsoft.AF.Data.AFCalculationBasis.TimeWeighted, OSIsoft.AF.Data.AFTimestampCalculation.Auto, new PIPagingConfiguration(PIPageType.TagCount, 10000)); 

       

                  DataTable dt = new DataTable("Summaries"); 

                  dt.Columns.Add("PI Point"); 

                  dt.Columns.Add("Timestamp"); 

                  foreach(string sumName in Enum.GetNames(typeof(AFSummaryTypes))) 

                  { 

                      if (!(sumName.ToLower().StartsWith("all") || sumName.ToLower().StartsWith("none"))) 

                      { 

                          dt.Columns.Add(sumName); 

                          dt.Columns[sumName].AllowDBNull = true

                      } 

                  } 

                  dt.PrimaryKey = new DataColumn[] {dt.Columns["PI Point"], dt.Columns["Timestamp"]}; 

       

                  foreach (IDictionary<AFSummaryTypes, AFValues> val in vals) 

                  { 

                      foreach (string sumName in Enum.GetNames(typeof(AFSummaryTypes))) 

                      { 

                          if (!(sumName.ToLower().StartsWith("all") || sumName.ToLower().StartsWith("none"))) 

                          { 

                              AFValues sumVals = val[(AFSummaryTypes)Enum.Parse(typeof(AFSummaryTypes), sumName)]; 

                              foreach (AFValue sumVal in sumVals) 

                              { 

                                  string pntName = sumVal.PIPoint.Name; 

                                  if (dt.Rows.Contains(new object[] { pntName, sumVal.Timestamp })) 

                                      dt.Select(String.Format("[PI Point]='{0}' AND [Timestamp]=#{1}#", pntName, sumVal.Timestamp)).FirstOrDefault()[sumName] = sumVal.Value.ToString(); 

                                  else 

                                      dt.Rows.Add(pntName, sumVal.Timestamp)[sumName] = sumVal.Value.ToString(); 

                              } 

                          } 

                      } 

                  } 

       

      Thanks!