public static DataSet Query(Options options) { ServerConnection _historian; var xx = new ConnectionProperties { ServerHostName = options.ServerName, Username = options.UserName, Password = options.Password, ServerCertificateValidationMode = CertificateValidationMode.None }; _historian = new ServerConnection( new ConnectionProperties { ServerHostName = options.ServerName, Username = options.UserName, Password = options.Password, ServerCertificateValidationMode = CertificateValidationMode.None, MaxReceivedMessageSize = Math.Max(1048576, options.MaxMessageSize), OpenTimeout = new TimeSpan(1, 0, 0), SendTimeout = new TimeSpan(1, 0, 0), ReceiveTimeout = new TimeSpan(1, 0, 0) }); _historian.Connect(); var tags = GetTagNames(_historian, options.TagMask); DataSet dataset = new DataSet(); ItemErrors errors; int tagChunkSize = 1000; int offset = 0; while (offset < tags.Count()) { Console.WriteLine("Exporting {0} tags at index {1} of {2}\r", tagChunkSize, offset, tags.Count()); var tagChunk = tags.Skip(offset).Take(tagChunkSize).ToArray(); offset += tagChunkSize; DataSet chunkDataSet; var parms = new DataQueryParams() { Criteria = new DataCriteria(tagChunk) { SamplingMode = options.SamplingMode, CalculationMode = options.CalculationMode, IntervalMicroseconds = options.IntervalMicroseconds, NumberOfSamples = options.NumberOfSamples, Start = options.Start, End = options.End }, Fields = DataFields.Time | DataFields.Value | DataFields.Quality }; _historian.IData.Query(ref parms, out chunkDataSet, out errors); if (errors.Count() > 0) { throw new Exception(string.Join(", ", errors.Select(e => $"{e.Key}: {e.Value}"))); } dataset.AddRange(chunkDataSet); } return(dataset); }
public static DataSet Query(Options options) { ServerConnection _historian; var xx = new ConnectionProperties { ServerHostName = options.ServerName, Username = options.UserName, Password = options.Password, ServerCertificateValidationMode = CertificateValidationMode.None }; // Define connection and establish it _historian = new ServerConnection( new ConnectionProperties { ServerHostName = options.ServerName, Username = options.UserName, Password = options.Password, ServerCertificateValidationMode = CertificateValidationMode.None, MaxReceivedMessageSize = Math.Max(1048576, options.MaxMessageSize) }); _historian.Connect(); var parms = new DataQueryParams() { Criteria = options.Criteria }; DataSet ds; ItemErrors errors; _historian.IData.Query(ref parms, out ds, out errors); if (errors.Count() > 0) { throw new Exception(string.Join(", ", errors.Select(e => $"{e.Key}: {e.Value}"))); } return(ds); }